index.vue 9.9 KB

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