transportPersonAdd.vue 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497
  1. <!-- 运输人员新增 -->
  2. <template>
  3. <view id="register">
  4. <view class="register_li">
  5. <view class="register_li_min">
  6. <view>*</view>
  7. <view>姓名:</view>
  8. <input v-model="form.userName" maxlength="10" type="text" placeholder-style="color:#999;" placeholder="请输入姓名">
  9. </view>
  10. <view class="register_li_min" style="border: none;">
  11. <view>*</view>
  12. <view>联系方式:</view>
  13. <input v-model="form.phone" type="text" placeholder-style="color:#999;" placeholder="请输入联系方式">
  14. </view>
  15. </view>
  16. <view class="register_li2" v-for="(item,index) in userCredentialsDtos" :key="index">
  17. <view class="register_li_t"><text v-if="item.required==1" style="color: #f00;margin-right: 10rpx;">*</text>{{item.naturalName}}</view>
  18. <view class="register_li_b">
  19. <img class="register_li_b_img1" src="@/pages_supplier/images/icon_zc_scbg.png">
  20. <img class="register_li_b_img2" v-if="item.naturalName" :src="baseUrl+item.naturalUrl">
  21. <img class="register_li_b_img3" src="@/pages_supplier/images/icon_zc_sc.png" @click="selectImage(item)">
  22. </view>
  23. <view class="register_li_b2">
  24. <view><text v-if="item.required==1" style="color: #f00;margin-right: 10rpx;">*</text>有效期</view>
  25. <picker mode="date" @change="startChange(item,$event)">
  26. <input class="picker-text" disabled type="text" v-model="item.startTime" placeholder="开始时间">
  27. </picker>
  28. <view>-</view>
  29. <picker mode="date" @change="endChange(item,$event)">
  30. <input class="picker-text2" disabled type="text" v-model="item.endTime" placeholder="结束时间">
  31. </picker>
  32. </view>
  33. <view class="register_li_b3">{{item.remark}}</view>
  34. </view>
  35. <view class="sub_btn" @click="submitForm()">提交</view>
  36. </view>
  37. </template>
  38. <script>
  39. import {certificateList,transportUser,transportUserDetail,transportUserAmend} from '@/api/apiDemo/index.js'
  40. import { config } from '@/api/request/config.js'
  41. export default {
  42. data() {
  43. return {
  44. baseUrl:config.base_url,
  45. form:{
  46. userName:'',
  47. phone:'',
  48. },
  49. userCredentialsDtos:[],
  50. status:null,//0添加1编辑
  51. id:null,
  52. }
  53. },
  54. onLoad(option) {
  55. this.status=option.status;
  56. this.id=option.id;
  57. },
  58. onShow(){
  59. },
  60. methods: {
  61. // 图片上传
  62. selectImage(item) {
  63. let self = this;
  64. wx.chooseImage({
  65. count: 1,
  66. sizeType: ["original", "compressed"],
  67. sourceType: ["album", "camera"],
  68. success: function(res) {
  69. let tempFilePaths = res.tempFilePaths[0];
  70. self.uploadImg(item,tempFilePaths);
  71. }
  72. });
  73. },
  74. async uploadImg(item,tempFilePaths){
  75. var self = this;
  76. uni.showLoading({
  77. title: '上传中',
  78. mask: true
  79. });
  80. uni.uploadFile({
  81. url: config.base_url + '/system/file/upload', //仅为示例,非真实的接口地址
  82. header:{'Authorization':uni.getStorageSync('token')},
  83. filePath: tempFilePaths,
  84. name: 'file',
  85. formData: {
  86. 'user': 'test'
  87. },
  88. success: (uploadFileRes) => {
  89. let res = JSON.parse(uploadFileRes.data);
  90. if(res.code == 200){
  91. item.naturalUrl=res.data.url;
  92. }else{
  93. uni.showToast({
  94. title: res.msg,
  95. icon:"none",
  96. mask:true,
  97. duration: 2000
  98. });
  99. }
  100. },
  101. fail: err => {},
  102. complete: () => {
  103. uni.hideLoading()
  104. }
  105. });
  106. },
  107. //删除图片
  108. delImg(index){
  109. this.newData.imgList.splice(index,1);
  110. },
  111. //开始时间选中事件
  112. startChange(item,e){
  113. if(new Date(e.target.value).getTime()>=new Date(item.endTime).getTime()){
  114. uni.showToast({
  115. title: '结束时间不能小于开始时间',
  116. icon:"none",
  117. mask:true,
  118. duration: 2000
  119. });
  120. }else{
  121. item.startTime=e.target.value
  122. }
  123. },
  124. //结束时间选中事件
  125. endChange(item,e){
  126. if(new Date(item.startTime).getTime()>=new Date(e.target.value).getTime()){
  127. uni.showToast({
  128. title: '结束时间不能小于开始时间',
  129. icon:"none",
  130. mask:true,
  131. duration: 2000
  132. });
  133. }else{
  134. item.endTime=e.target.value
  135. }
  136. },
  137. //校验特殊字符
  138. verify(){
  139. if(!(/^1[3456789]\d{9}$/.test(this.form.phone))){
  140. uni.showToast({
  141. title: '请输入正确的手机号',
  142. icon:"none",
  143. mask:true,
  144. duration: 2000
  145. });
  146. this.form.phone='';
  147. }
  148. },
  149. //获取列表数据
  150. async getList(){
  151. let _this = this;
  152. const {data} = await certificateList({type:2})
  153. if(data.code==200){
  154. //重新渲染后台返回数据
  155. data.data.forEach(function(item){
  156. _this.userCredentialsDtos.push({'required':item.required,'naturalName':item.name,'naturalUrl':'','startTime':'','endTime':'','remark':item.remark,'certificateId':item.id})
  157. })
  158. }
  159. },
  160. //获取详情
  161. async getInfo(){
  162. let _this = this;
  163. const {data} = await transportUserDetail(this.id)
  164. if(data.code==200){
  165. let res=data.data
  166. this.isAudit=res.isAudit;
  167. this.form=res;
  168. _this.userCredentialsDtos.forEach(function(item){
  169. res.userCredentialsVos.forEach(function(item2){
  170. if(item.certificateId==item2.certificateId){
  171. item.naturalUrl=item2.naturalUrl
  172. item.startTime=item2.startTime
  173. item.endTime=item2.endTime
  174. }
  175. })
  176. })
  177. }
  178. },
  179. //注册提交
  180. async submitForm(){
  181. let _this = this;
  182. let isPass=true;
  183. if(!this.form.userName){
  184. uni.showToast({
  185. title: '请输入联系人姓名',
  186. icon:"none",
  187. mask:true,
  188. duration: 2000
  189. });
  190. return
  191. }
  192. if(!this.form.phone){
  193. uni.showToast({
  194. title: '请输入手机号!',
  195. icon:"none",
  196. mask:true,
  197. duration: 2000
  198. });
  199. return
  200. }
  201. if(!(/^1[3456789]\d{9}$/.test(this.form.phone))){
  202. uni.showToast({
  203. title: '请输入正确的手机号!',
  204. icon:"none",
  205. mask:true,
  206. duration: 2000
  207. });
  208. return
  209. }
  210. //提交的时候过滤空数据
  211. let arr=[];
  212. for(let i=0;i<_this.userCredentialsDtos.length;i++){
  213. if(_this.userCredentialsDtos[i].required==1){
  214. if(!_this.userCredentialsDtos[i].naturalUrl){
  215. isPass=false;
  216. uni.showToast({
  217. title: '未上传'+_this.userCredentialsDtos[i].naturalName+',请上传'+_this.userCredentialsDtos[i].naturalName,
  218. icon:"none",
  219. mask:true,
  220. duration: 2000
  221. });
  222. return
  223. }
  224. if(!_this.userCredentialsDtos[i].startTime || !_this.userCredentialsDtos[i].endTime){
  225. isPass=false;
  226. uni.showToast({
  227. title: '请选择'+_this.userCredentialsDtos[i].naturalName+'有效期',
  228. icon:"none",
  229. mask:true,
  230. duration: 2000
  231. });
  232. return
  233. }
  234. arr.push(_this.userCredentialsDtos[i])
  235. }else{
  236. arr.push(_this.userCredentialsDtos[i])
  237. }
  238. }
  239. // let arr=[];
  240. // _this.userCredentialsDtos.forEach(function(item){
  241. // if(item.required==1){
  242. // if(!item.naturalUrl){
  243. // isPass=false;
  244. // uni.showToast({
  245. // title: '未上传'+item.naturalName+',请上传'+item.naturalName,
  246. // icon:"none",
  247. // mask:true,
  248. // duration: 2000
  249. // });
  250. // return
  251. // }
  252. // if(!item.startTime || !item.endTime){
  253. // isPass=false;
  254. // uni.showToast({
  255. // title: '请选择'+item.naturalName+'有效期',
  256. // icon:"none",
  257. // mask:true,
  258. // duration: 2000
  259. // });
  260. // return
  261. // }
  262. // arr.push(item)
  263. // }else{
  264. // arr.push(item)
  265. // }
  266. // })
  267. if(isPass){
  268. _this.form.userCredentialsDtos=arr;
  269. if(this.status==0){//新增
  270. const {data} = await transportUser(_this.form);
  271. if(data.code == 200){
  272. uni.showToast({
  273. title: '提交成功',
  274. icon:"none",
  275. mask:true,
  276. duration: 2000
  277. });
  278. setTimeout(function(){
  279. uni.redirectTo({
  280. url: '/pages/supplierWorkbench',
  281. });
  282. },2000);
  283. }
  284. }else if(this.status==1){//编辑
  285. _this.form.userCredentialsVos=null;
  286. const {data} = await transportUserAmend(_this.form);
  287. if(data.code == 200){
  288. uni.showToast({
  289. title: '提交成功',
  290. icon:"none",
  291. mask:true,
  292. duration: 2000
  293. });
  294. setTimeout(function(){
  295. uni.redirectTo({
  296. url: '/pages/supplierWorkbench',
  297. });
  298. },2000);
  299. }
  300. }
  301. }
  302. },
  303. },
  304. mounted(){
  305. this.getList();
  306. if(this.status==1){
  307. this.getInfo();
  308. }
  309. },
  310. }
  311. </script>
  312. <style lang="stylus" scoped>
  313. #register{
  314. height:auto
  315. width:100%;
  316. display flex
  317. flex-direction column;
  318. padding-bottom: 220rpx;
  319. .register_li{
  320. background #fff;
  321. border-radius:20rpx;
  322. margin:20rpx 20rpx 0;
  323. padding:20rpx 0;
  324. box-sizing: border-box;
  325. .register_li_min{
  326. margin:0 26rpx;
  327. display flex;
  328. align-items center;
  329. border-bottom: 1px solid #F5F5F5;
  330. view{
  331. line-height:100rpx;
  332. font-size:28rpx;
  333. }
  334. view:nth-child(1){
  335. color:red;
  336. line-height:28rpx;
  337. margin-right: 12rpx;
  338. }
  339. view:nth-child(2){
  340. width:140rpx;
  341. font-size: 28rpx;
  342. font-family: PingFang SC;
  343. font-weight: 500;
  344. color: #333333;
  345. }
  346. >input{
  347. width 490rpx;
  348. text-align: right;
  349. font-size: 24rpx;
  350. font-family: PingFang SC;
  351. font-weight: 500;
  352. color: #333333;
  353. }
  354. }
  355. }
  356. .register_li2{
  357. background #fff;
  358. border-radius:20rpx;
  359. margin:20rpx 20rpx 0;
  360. padding:0 20rpx;
  361. box-sizing: border-box;
  362. .register_li_t{
  363. font-size: 28rpx;
  364. font-family: PingFang SC;
  365. font-weight: 500;
  366. color: #333333;
  367. line-height: 28rpx;
  368. margin: 36rpx 0;
  369. }
  370. .register_li_b{
  371. width: 450rpx;
  372. height: 270rpx;
  373. margin-left: 106rpx;
  374. position: relative;
  375. // >img:nth-child(1){
  376. // width: 450rpx;
  377. // height: 270rpx;
  378. // position: absolute;
  379. // left: 0;
  380. // top: 0;
  381. // }
  382. // >img:nth-child(2){
  383. // width: 100rpx;
  384. // height: 100rpx;
  385. // position: absolute;
  386. // left: 187rpx;
  387. // top: 86rpx;
  388. // }
  389. .register_li_b_img1{
  390. width: 450rpx;
  391. height: 270rpx;
  392. position: absolute;
  393. left: 0;
  394. top: 0;
  395. }
  396. .register_li_b_img2{
  397. width: 450rpx;
  398. height: 270rpx;
  399. position: absolute;
  400. left: 0;
  401. top: 0;
  402. }
  403. .register_li_b_img3{
  404. width: 100rpx;
  405. height: 100rpx;
  406. position: absolute;
  407. left: 187rpx;
  408. top: 86rpx;
  409. }
  410. }
  411. .register_li_b2{
  412. border-bottom: 1px solid #f5f5f5;
  413. height: 100rpx;
  414. display: flex;
  415. justify-content: flex-start;
  416. align-items: center;
  417. >view:nth-child(1){
  418. font-size: 28rpx;
  419. font-family: PingFang SC;
  420. font-weight: 500;
  421. color: #999999;
  422. line-height: 100rpx;
  423. margin-right: 120rpx;
  424. }
  425. .picker-text{
  426. font-size: 24rpx;
  427. font-family: PingFang SC;
  428. font-weight: 500;
  429. color: #CCCCCC;
  430. line-height: 100rpx;
  431. width: 188rpx;
  432. }
  433. >view:nth-child(2){
  434. font-size: 24rpx;
  435. font-family: PingFang SC;
  436. font-weight: 500;
  437. color: #CCCCCC;
  438. line-height: 100rpx;
  439. }
  440. .picker-text2{
  441. font-size: 24rpx;
  442. font-family: PingFang SC;
  443. font-weight: 500;
  444. color: #CCCCCC;
  445. line-height: 100rpx;
  446. width: 188rpx;
  447. text-align: right;
  448. }
  449. }
  450. .register_li_b3{
  451. font-size: 24rpx;
  452. font-family: PingFang SC;
  453. font-weight: 500;
  454. color: #999999;
  455. line-height: 36rpx;
  456. margin: 34rpx 0;
  457. }
  458. }
  459. /* 按钮 */
  460. .sub_btn{
  461. width: 650rpx;
  462. height: 100rpx;
  463. background: #0183FA;
  464. border-radius: 20rpx;
  465. font-size: 28rpx;
  466. font-family: PingFang SC;
  467. font-weight: 500;
  468. color: #FFFFFF;
  469. line-height: 100rpx;
  470. text-align: center;
  471. margin-left: 50rpx;
  472. position: fixed;
  473. bottom:30rpx;
  474. z-index: 1000;
  475. }
  476. }
  477. /deep/.input-value-border{
  478. display :none !important;
  479. }
  480. </style>