transportCarAdd.vue 12 KB

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