index.vue 9.3 KB

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