index.vue 9.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308
  1. <template>
  2. <view class="uni-container">
  3. <view class="example container" :style="'height: ' + (screenHeight - wheight - 85) + 'px'">
  4. <u--form ref="customForm" :model="formData" labelPosition="left" labelWidth="100%" labelAlign="left">
  5. <view class="juli-bottom">
  6. <u-form-item label="所属单位" prop="orgName" @click="showOrg = true; hideKeyboard()">
  7. <u-input v-model="formData.orgName" placeholder="请输入" :disabled="isview" />
  8. </u-form-item>
  9. <u-form-item label="人员姓名" prop="empName" :required="true">
  10. <u-input v-model="formData.empName" placeholder="请输入" :disabled="isview" />
  11. </u-form-item>
  12. <u-form-item label="特种证书编号" prop="numberCode" :required="true">
  13. <u-input v-model="formData.numberCode" placeholder="请输入" :disabled="isview" />
  14. </u-form-item>
  15. <u-form-item label="身份证号" prop="idcardno" :required="true">
  16. <u-input v-model="formData.idcardno" placeholder="请输入" :disabled="isview" />
  17. </u-form-item>
  18. <u-form-item label="性别" prop="empGender" @click="showSex = true; hideKeyboard()">
  19. <u-input v-model="formData.empGender" placeholder="请选择" :disabled="isview" />
  20. </u-form-item>
  21. <picker mode="date" :value="dateTime" @change="bindDateChange" :disabled="isview">
  22. <view class="datatime-street">
  23. <u-form-item label="人员出生日期" prop="empBirthday">
  24. <u-input v-model="formData.empBirthday" placeholder="人员出生日期" class="add-date"
  25. :disabled="isview" />
  26. </u-form-item>
  27. </view>
  28. </picker>
  29. <picker mode="date" @change="bindDateChange2" :disabled="isview">
  30. <view class="datatime-street">
  31. <u-form-item label="颁证时间" prop="issueDate">
  32. <u-input v-model="formData.issueDate" placeholder="颁证时间" class="add-date"
  33. :disabled="isview" />
  34. </u-form-item>
  35. </view>
  36. </picker>
  37. <u-form-item label="附件">
  38. <!-- 选择文件上传,limit="1则最多选择一张图片,del-icon隐藏删除按钮 -->
  39. <uni-file-picker v-model="formData.attId" del-icon limit="1" auto-upload file-mediatype="all"
  40. @select="selectFile" @delete="deleteFile" :disabled="isview">
  41. <button type="primary" class="selectBtn" :disabled="isview">选择文件</button>
  42. <!-- 加载中 -->
  43. <isLodingModel v-if="loading"></isLodingModel>
  44. </uni-file-picker>
  45. </u-form-item>
  46. <u-form-item label="已上传附件:" v-if="formData.att" labelWidth="150">
  47. <u-icon name="close" color="#4CB2B6" size="24" @click="closeImage()" v-if="!isview">
  48. </u-icon>
  49. <!-- #ifdef MP-WEIXIN -->
  50. <text style="color:#00a3f4;cursor: pointer;margin-left: 20px !important;"
  51. @click.native="viewSee(formData.att)">点击预览文件</text>
  52. <!-- #endif -->
  53. <!-- #ifdef H5 -->
  54. <a style="color:#00a3f4;cursor: pointer;margin-left: 20px !important;"
  55. @click="viewSee(formData.att)">点击预览文件</a>
  56. <!-- #endif -->
  57. </u-form-item>
  58. </view>
  59. </u--form>
  60. </view>
  61. <view class="heigthButton">
  62. <u-button v-if="isedit" @click="submit('customForm')" type="primary" shape="circle" size="large"
  63. color="#4CB2B6" text="确认修改" style="width:200px">
  64. </u-button>
  65. <u-button v-else-if="!formData.id" @click="submit('customForm')" type="primary" shape="circle" size="large"
  66. color="#4CB2B6" text="确认新增" style="width:200px">
  67. </u-button>
  68. <u-button v-else-if="isview" @click="submit('customForm')" type="primary" shape="circle" size="large"
  69. color="#4CB2B6" text="返回" style="width:200px">
  70. </u-button>
  71. </view>
  72. <u-action-sheet :show="showSex" :actions="actionsSex" title="请选择性别" @close="showSex = false"
  73. @select="sexSelect">
  74. </u-action-sheet>
  75. <u-action-sheet :show="showOrg" :actions="orgaction" title="请选择单位" class="org-choice" @close="showOrg = false"
  76. @select="orgSelect"></u-action-sheet>
  77. </view>
  78. </template>
  79. <script>
  80. import {
  81. fireSpecialUpdate,
  82. fireSpecialCreate,
  83. fireSpecialIdGet
  84. } from '@/api/fireSpecial';
  85. import {
  86. NumericRule,
  87. downSee,
  88. uploadFile
  89. } from '@/utils/common.js';
  90. import config from '@/config'
  91. import {
  92. DICT_TYPE,
  93. getDictDatas
  94. } from "@/utils/dict";
  95. const baseUrlImg = config.baseUrlImg
  96. export default {
  97. data() {
  98. return {
  99. screenHeight: this.$screenHeight,
  100. wheight: '',
  101. formData: {
  102. orgName: '',
  103. orgId: '',
  104. empName: '',
  105. numberCode: '',
  106. idcardno: '',
  107. empGender: '',
  108. empBirthday: '',
  109. issueDate: '',
  110. att:'',
  111. attId:[]
  112. },
  113. loading:'',
  114. rules: {
  115. empName: [{
  116. type: 'string',
  117. required: true,
  118. message: '人员姓名不能为空',
  119. trigger: ['blur', 'change']
  120. }],
  121. numberCode: [{
  122. type: 'string',
  123. required: true,
  124. message: '特种证书编号',
  125. trigger: ['blur', 'change']
  126. }],
  127. idcardno: [{
  128. type: 'string',
  129. required: true,
  130. pattern: /(^[1-9]\d{5}(18|19|([23]\d))\d{2}((0[1-9])|(10|11|12))(([0-2][1-9])|10|20|30|31)\d{3}[0-9Xx]$)|(^[1-9]\d{5}\d{2}((0[1-9])|(10|11|12))(([0-2][1-9])|10|20|30|31)\d{2}$)/,
  131. message: "请输入合法身份证号",
  132. trigger: ['blur', 'change']
  133. }],
  134. // empName: NumericRule(),
  135. },
  136. isedit: '',
  137. isview: '',
  138. dateTime: '',
  139. showSex: false,
  140. actionsSex: getDictDatas(DICT_TYPE.SYSTEM_USER_SEX), //性别
  141. orgaction: [], //单位
  142. showOrg: false
  143. }
  144. },
  145. onReady() {
  146. this.$refs.customForm.setRules(this.rules);
  147. },
  148. mounted() {
  149. uni.createSelectorQuery().in(this).select('.heigthButton').boundingClientRect(data => {
  150. this.wheight = data.height
  151. }).exec()
  152. },
  153. onLoad(option) {
  154. this.formData.orgName = option.orgName ? option.orgName : ''
  155. this.formData.orgId = option.orgId ? option.orgId : ''
  156. this.orgaction = option.orgaction ? JSON.parse(option.orgaction) : []
  157. this.actionsSex.map(i => i.name = i.label)
  158. uni.setNavigationBarTitle({
  159. title: option.title
  160. })
  161. if (option.editData) {
  162. this.isedit = true
  163. this.isview = false
  164. this.parentId = option.editData
  165. this.getData()
  166. // this.formData = JSON.parse(option.editData)
  167. } else if (option.viewData) {
  168. this.isview = true
  169. this.parentId = option.viewData
  170. this.getData()
  171. // this.formData = JSON.parse(option.viewData)
  172. } else {
  173. this.isedit = false
  174. this.isview = false
  175. }
  176. console.log(this.isedit,'ffffffff',this.isview);
  177. },
  178. methods: {
  179. //查看已上传附件
  180. viewSee(val) {
  181. downSee(val)
  182. },
  183. // 移出图片函数
  184. async deleteFile(e) {
  185. this.formData.attId = [];
  186. // console.log('移除了:');
  187. },
  188. selectFile(e) {
  189. let promises = [];
  190. for (let i = 0; i < e.tempFilePaths.length; i++) {
  191. const promise = uploadFile(e.tempFilePaths, i,this);
  192. promises.push(promise);
  193. }
  194. Promise.all(promises).then(result => {
  195. // 处理上传文件成功的结果
  196. }).catch(error => {
  197. // 处理上传文件失败的错误
  198. });
  199. },
  200. closeImage() {
  201. this.formData.attId = []
  202. this.formData.att=''
  203. this.$forceUpdate()
  204. },
  205. sexSelect(e) {
  206. this.formData.empGender = e.name
  207. },
  208. orgSelect(e) {
  209. this.formData.orgName = e.name
  210. this.formData.orgId = e.value
  211. },
  212. hideKeyboard() {
  213. uni.hideKeyboard()
  214. },
  215. getData() {
  216. fireSpecialIdGet({
  217. id: this.parentId
  218. }).then(response => {
  219. this.formData = response.data
  220. console.log(response, 'response')
  221. })
  222. },
  223. bindDateChange(e) {
  224. this.formData.empBirthday = e.detail.value
  225. },
  226. bindDateChange2(e) {
  227. this.formData.issueDate = e.detail.value
  228. },
  229. submit(ref) {
  230. this.$refs[ref].validate().then(res => {
  231. this.formData.att = this.formData.attId?this.formData.attId.join(''):this.formData.att
  232. if (this.isedit) {
  233. fireSpecialUpdate(JSON.stringify(this.formData)).then(res => {
  234. this.$modal.msg('修改成功')
  235. this.isedit = false
  236. setTimeout(() => {
  237. uni.navigateBack()
  238. }, 400)
  239. })
  240. } else if (this.isview) {
  241. this.isview = false
  242. uni.navigateBack()
  243. } else {
  244. fireSpecialCreate(JSON.stringify(this.formData)).then(response => {
  245. this.$modal.msg('新增成功')
  246. setTimeout(() => {
  247. uni.navigateBack()
  248. }, 400)
  249. })
  250. }
  251. }).catch(err => {
  252. console.log(err);
  253. })
  254. }
  255. }
  256. }
  257. </script>
  258. <style lang="scss" scoped>
  259. body {
  260. background-color: #f5f7f9;
  261. }
  262. page {
  263. background-color: #f5f7f9 !important;
  264. }
  265. .uni-container {
  266. // height: 100vh;
  267. background-color: #f5f7f9 !important;
  268. }
  269. /deep/.uni-card {
  270. position: relative;
  271. box-shadow: 0px 0px 3px 0px rgba(86, 165, 168, 0.15);
  272. border-radius: 30rpx;
  273. }
  274. .example {
  275. overflow-y: auto;
  276. }
  277. .juli-bottom {
  278. /deep/ .u-form-item__body__left__content__label {
  279. color: #000 !important;
  280. }
  281. }
  282. .org-choice {
  283. /deep/.u-action-sheet {
  284. overflow-y: auto;
  285. height: 1000rpx;
  286. background-color: #fff;
  287. }
  288. }
  289. .selectBtn {
  290. width: 200rpx;
  291. margin-left: 0;
  292. font-size: 30rpx;
  293. background-color: #4cb2b6;
  294. }
  295. </style>