index.vue 8.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303
  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="!isedit&&!isview" @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. att:'',
  109. attId:[]
  110. },
  111. loading:'',
  112. rules: {
  113. empName: [{
  114. type: 'string',
  115. required: true,
  116. message: '人员姓名不能为空',
  117. trigger: ['blur', 'change']
  118. }],
  119. numberCode: [{
  120. type: 'string',
  121. required: true,
  122. message: '特种证书编号',
  123. trigger: ['blur', 'change']
  124. }],
  125. idcardno: [{
  126. type: 'string',
  127. required: true,
  128. 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}$)/,
  129. message: "请输入合法身份证号",
  130. trigger: ['blur', 'change']
  131. }],
  132. // empName: NumericRule(),
  133. },
  134. isedit: '',
  135. isview: '',
  136. dateTime: '',
  137. showSex: false,
  138. actionsSex: getDictDatas(DICT_TYPE.SYSTEM_USER_SEX), //性别
  139. orgaction: [], //单位
  140. showOrg: false
  141. }
  142. },
  143. onReady() {
  144. this.$refs.customForm.setRules(this.rules);
  145. },
  146. mounted() {
  147. uni.createSelectorQuery().in(this).select('.heigthButton').boundingClientRect(data => {
  148. this.wheight = data.height
  149. }).exec()
  150. },
  151. onLoad(option) {
  152. this.formData.orgName = option.orgName ? option.orgName : ''
  153. this.formData.orgId = option.orgId ? option.orgId : ''
  154. //单位信息
  155. this.orgaction = option.orgaction ? JSON.parse(option.orgaction) : []
  156. this.actionsSex.map(i => i.name = i.label)
  157. uni.setNavigationBarTitle({
  158. title: option.title
  159. })
  160. if (option.editData) {
  161. this.isedit = true
  162. this.isview = false
  163. this.parentId = option.editData
  164. this.getData()
  165. // this.formData = JSON.parse(option.editData)
  166. } else if (option.viewData) {
  167. this.isview = true
  168. this.parentId = option.viewData
  169. this.getData()
  170. // this.formData = JSON.parse(option.viewData)
  171. } else {
  172. this.isedit = false
  173. this.isview = false
  174. }
  175. },
  176. methods: {
  177. //查看已上传附件
  178. viewSee(val) {
  179. downSee(val)
  180. },
  181. // 移出图片函数
  182. async deleteFile(e) {
  183. this.formData.attId = [];
  184. },
  185. selectFile(e) {
  186. let promises = [];
  187. for (let i = 0; i < e.tempFilePaths.length; i++) {
  188. const promise = uploadFile(e.tempFilePaths, i,this);
  189. promises.push(promise);
  190. }
  191. Promise.all(promises).then(result => {
  192. // 处理上传文件成功的结果
  193. }).catch(error => {
  194. // 处理上传文件失败的错误
  195. });
  196. },
  197. closeImage() {
  198. this.formData.attId = []
  199. this.formData.att=''
  200. this.$forceUpdate()
  201. },
  202. sexSelect(e) {
  203. this.formData.empGender = e.name
  204. },
  205. orgSelect(e) {
  206. this.formData.orgName = e.name
  207. this.formData.orgId = e.value
  208. },
  209. hideKeyboard() {
  210. uni.hideKeyboard()
  211. },
  212. getData() {
  213. fireSpecialIdGet({
  214. id: this.parentId
  215. }).then(response => {
  216. this.formData = response.data
  217. })
  218. },
  219. bindDateChange(e) {
  220. this.formData.empBirthday = e.detail.value
  221. },
  222. bindDateChange2(e) {
  223. this.formData.issueDate = e.detail.value
  224. },
  225. submit(ref) {
  226. this.$refs[ref].validate().then(res => {
  227. this.formData.att = this.formData.attId.length > 0 && this.formData.attId[0] ? this.formData
  228. .attId[0] : this.formData.att
  229. if (this.isedit) {
  230. fireSpecialUpdate(JSON.stringify(this.formData)).then(res => {
  231. this.$modal.msg('修改成功')
  232. this.isedit = false
  233. setTimeout(() => {
  234. uni.navigateBack()
  235. }, 400)
  236. })
  237. } else if (this.isview) {
  238. this.isview = false
  239. uni.navigateBack()
  240. } else {
  241. fireSpecialCreate(JSON.stringify(this.formData)).then(response => {
  242. this.$modal.msg('新增成功')
  243. setTimeout(() => {
  244. uni.navigateBack()
  245. }, 400)
  246. })
  247. }
  248. }).catch(err => {
  249. })
  250. }
  251. }
  252. }
  253. </script>
  254. <style lang="scss" scoped>
  255. body {
  256. background-color: #f5f7f9;
  257. }
  258. page {
  259. background-color: #f5f7f9 !important;
  260. }
  261. .uni-container {
  262. // height: 100vh;
  263. background-color: #f5f7f9 !important;
  264. }
  265. /deep/.uni-card {
  266. position: relative;
  267. box-shadow: 0px 0px 3px 0px rgba(86, 165, 168, 0.15);
  268. border-radius: 30rpx;
  269. }
  270. .example {
  271. overflow-y: auto;
  272. }
  273. .juli-bottom {
  274. /deep/ .u-form-item__body__left__content__label {
  275. color: #000 !important;
  276. }
  277. }
  278. .org-choice {
  279. /deep/.u-action-sheet {
  280. overflow-y: auto;
  281. height: 1000rpx;
  282. background-color: #fff;
  283. }
  284. }
  285. .selectBtn {
  286. width: 200rpx;
  287. margin-left: 0;
  288. font-size: 30rpx;
  289. background-color: #4cb2b6;
  290. }
  291. </style>