wk
2024-10-23 f22e264b6c282f597a139f549025cb9120fe0da1
pages/driver-page/drvier-my/certifiCate/certifiCate.vue
@@ -8,16 +8,16 @@
         v-if="certificateData.length===0"></u-empty>
         <view class="tran-type">
            <view ><u-button type="primary"
                  @click="editTranClick"
                  @click="editTranClick(-1)"
                  shape="circle"
                  plain>添加运输证</u-button></view>
                  plain>添加通行证</u-button></view>
         </view>
      <view class="main"
         v-if="certificateData.length!==0">
         <view class="information-block"
            v-for="item in certificateData"
            :key="item.id">
            <view class="detail-block">
            <view class="detail-block" @click="editTranClick(item.status,item)">
               <view class="line detail-reason">
                  <u--image :showLoading="true"
                     :src="item.certificateImg != null ? BaseUrl + item.certificateImg : ''"
@@ -36,6 +36,12 @@
               <view class="line detail-value">
                  司机:{{item.driverName}}
               </view>
               <view class="line detail-value">
                  押运员:{{item.supercargoInfo?getUserName(item.supercargoInfo):'无'}}
               </view>
               <view class="line detail-value">
                  {{item.startTime?item.startTime.slice(0,10):""}}-{{item.expirationTime?item.expirationTime.slice(0,10):""}}
               </view>
            </view>
         </view>
      </view>
@@ -49,14 +55,14 @@
               height="400px"></u--image>
         </u-popup>
      </view>
      <!-- 添加道路运输证 -->
      <!-- 添加剧毒通行证 -->
      <view class="editDriverPopup-container">
         <u-popup :show="editTranShow"
            mode="bottom"
            @close="editTranClose"
            @open="editTranOpen"
            :closeable="true">
            <combined-title title="运输证"
            <combined-title title="通行证"
               style="margin-left:20rpx"></combined-title>
            <view class="editDriverPopup-container-box">
               <u--form labelPosition="left"
@@ -64,7 +70,7 @@
                  :rule="sportRules"
                  ref="sportRef">
                  <u-form-item labelWidth="20%"
                     label="运输证号"
                     label="通行证号"
                     prop="certificateNo"
                     required>
                     <u--input v-model="tranSportForm.certificateNo"
@@ -77,14 +83,17 @@
                     label="车牌号"
                     prop="carNo"
                     required>
                     <u--input v-model="tranSportForm.carNo"
                     <xm-cell special label="车牌号" :value="tranSportForm.carNo" @show="showKeyboard('xmKeyboard')"></xm-cell>
                     <xm-keyboard-v2 ref="xmKeyboard" @confirm="(v) => tranSportForm.carNo = v"></xm-keyboard-v2>
                     <!-- <u--input v-model="tranSportForm.carNo"
                        border="none"
                        inputAlign="left"></u--input>
                        inputAlign="left"></u--input> -->
                  </u-form-item>
                  <u-form-item labelWidth="20%"
                     label="产品"
                     ref="item1" 
                     prop='productId'>
                     prop='productName'
                     required>
                     <u--input placeholder="请输入产品"
                        v-model="tranSportForm.productName"
                        class="input"
@@ -93,14 +102,15 @@
                  <u-form-item labelWidth="20%"
                     label="客户"
                     ref="item1" 
                     prop='productId'>
                     prop='customerName'
                     required>
                     <u--input placeholder="请输入客户"
                        v-model="tranSportForm.customerName"
                        class="input"
                        type="text"></u--input>
                  </u-form-item>
                  <u-form-item prop="certificateImg"
                     label="运输证"
                     label="通行证"
                     labelWidth="20%"
                     borderBottom
                     required
@@ -117,8 +127,14 @@
                        :previewFullImage="true">
                     </u-upload>
                  </u-form-item>
                  <u-form-item prop="startTime"
                     label="通行证开始时间"
                     labelWidth="20%"
                     borderBottom>
                     <uni-datetime-picker v-model="tranSportForm.startTime" type="datetime"  />
                  </u-form-item>
                  <u-form-item prop="expirationTime"
                     label="运输证过期时间"
                     label="通行证过期时间"
                     labelWidth="20%"
                     borderBottom>
                     <uni-datetime-picker v-model="tranSportForm.expirationTime" type="datetime" :start="minDate" />
@@ -182,6 +198,24 @@
                           border="none"
                           inputAlign="left"></u--input>
                     </u-form-item>
                     <u-form-item prop="certificateImg"
                        label="资质证明"
                        labelWidth="20%"
                        borderBottom
                        required
                        @click="beforeRead">
                        <u-upload :fileList="item.fileList"
                           deletable
                           @afterRead="afterReads"
                           @delete="deletePics"
                           multiple
                           :name="index.toString()"
                           :maxCount="1"
                           width="250"
                           height="150"
                           :previewFullImage="true">
                        </u-upload>
                     </u-form-item>
                  </view>
                  
                  <u-form-item labelWidth="20%"
@@ -193,43 +227,10 @@
                  </u-form-item>
               </u--form>
               <view class="person-utils">
                  <u-button text="提交道路运输证"
                  <u-button text="提交剧毒通行证"
                     @click="updateRoad"
                     :disabled="upload"
                     type="primary"></u-button>
               </view>
            </view>
         </u-popup>
         <u-popup :closeable='true'
            :round="30"
            mode='bottom'
            :show="selfDeliverShow"
            @close="selfDeliverClose"
            @open="selfDeliverOpen">
            <view class="name-list-section">
               <view class="name-list_title">
                  选择客户
               </view>
               <view class="name-list_container">
                  <u-empty mode="data"
                     icon="http://cdn.uviewui.com/uview/empty/data.png"
                     text="暂无数据"
                     textSize="30"
                     iconSize="1000"
                     v-if="customerNameList.length===0"></u-empty>
                  <view class="name-list_container_item"
                     v-for="(item,index) in customerNameList" :key="index"
                     @click="selectCustomer(item)">
                     <view class="item-image">
                        <image src="https://mx.jzeg.cn:9096/appimg/image/banner/address.png"
                           mode="widthFix"
                           style="width: 18px;"></image>
                     </view>
                     <view class="item-customerName">
                        {{item.customerName}}
                     </view>
                  </view>
               </view>
            </view>
         </u-popup>
@@ -245,7 +246,13 @@
         return {
            minDate: this.getToday(),
            previewImageShow: false,
            supercargoList:[],
            supercargoList:[{
               driverName:"",
               driverIdcard:"",
               driverPhone:"",
               fileList:[]
            }],
            userInfo: {},
            scoreDetailList: [],
            editTranShow:false,
            upload:false,
@@ -253,8 +260,6 @@
            BaseUrl,
            previewImageSrc: '',
            certificateData:[],
            userInfo: {},
            customerNameList:[],
            driverList:[{
               driverName:"",
               driverIdcard:""
@@ -265,18 +270,42 @@
               customerId:""
            },
            sportRules:{
               productName:{
                  type: 'string',
                  required: true,
                  message: '请填写产品名称',
                  trigger: ['blur', 'change']
               },
               customerName:{
                  type: 'string',
                  required: true,
                  message: '请填写客户名称',
                  trigger: ['blur', 'change']
               },
               certificateNo: {
                  type: 'string',
                  required: true,
                  message: '请填写运输证号',
                  message: '请填写通行证号',
                  trigger: ['blur', 'change']
               },
               expirationTime: {
               expirationTime: [{
                  type: 'string',
                  required: true,
                  message: '请选择运输证过期时间',
                  message: '请选择通行证过期时间',
                  trigger: ['blur', 'change']
               },
               },{
                  pattern: /^\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}$/,
                  message: '请选择开始时间'
               }],
               startTime:[{
                  type: 'string',
                  required: true,
                  message: '请选择通行证开始时间',
                  trigger: ['blur', 'change']
               },{
                  pattern: /^\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}$/,
                  message: '请选择开始时间'
               }],
               carNo: [{
                     type: 'string',
                     required: true,
@@ -302,17 +331,20 @@
      },
      onLoad() {
         this.getScoreDetail()
         this.$reqGet('getUserEntity').then(res => {
            this.userInfo = res.data;
            this.$reqGetId('getDriverListById', this.userInfo.userId).then(res => {
               this.certificateData = res.data;
            });
         });
         this.getData()
      },
      methods: {
         ...mapMutations(['changeisUploadimg']),
         beforeRead() {
            this.changeisUploadimg(true);
         },
         getData(){
            this.$reqGet('getUserEntity').then(res => {
               this.userInfo = res.data;
               this.$reqGetId('getDriverListById', this.userInfo.userId).then(res => {
                  this.certificateData = res.data;
               });
            });
         },
         imageClick(data) {
            this.previewImageSrc = data;
@@ -324,6 +356,10 @@
            this.previewImageShow = false;
         },
         previewImageOpen() {},
         deletePics(event) {
            this.changeisUploadimg(true);
            this.supercargoList[event.name].fileList.splice(event.index, 1);
         },
         // 删除
         deletePic(event) {
            this.changeisUploadimg(true);
@@ -356,9 +392,43 @@
               }
            });
         },
         editTranClick(){
            this.getShipToList()
            this.editTranShow = true;
         editTranClick(e,data){
            if(e==-1){
               this.editTranShow = true;
               this.tranSportForm={
                  carNo:"",
                  productId:"",
                  customerId:""
               }
                this.driverList=[]
                this.supercargoList=[]
                this.fileList9=[]
                this.tranSportForm.carNo=this.userInfo.carNo
                this.driverList[0]={
                   driverName:this.userInfo.name,
                   driverIdcard:this.userInfo.idCard
                }
               if(data){
                  this.tranSportForm=Object.assign({},this.tranSportForm,data)
                  if((!this.tranSportForm.supercargoInfo==''||null)||(!this.tranSportForm.highlyToxicImg==''||null) ){
                     this.supercargoList =this.tranSportForm.supercargoInfo.split(",").map((item,index)=>{
                        return {driverName:item.split("|")[0],driverIdcard:item.split("|")[1],driverPhone:item.split("|")[2],fileList:[{url:`${BaseUrl}${this.tranSportForm.highlyToxicImg.split(',')[index]}`}]}
                     })
                  }
                  this.driverList=this.tranSportForm.driverName.split(",").map((item,index)=>{
                     return {driverName:item,driverIdcard:this.tranSportForm.driverIdcard.split(",")[index]}
                  })
                  if (this.fileList9.length == 0 && this.tranSportForm.certificateImg) {
                     this.fileList9.push({
                        url: `${BaseUrl}${this.tranSportForm.certificateImg}`
                     });
                  }
               }
            }
         },
         showKeyboard(ref){
            this.$refs[ref].toShow(this.tranSportForm.carNo)
         },
         editTranClose(){
            this.editTranShow = false;
@@ -368,21 +438,17 @@
            this.$refs.sportRef
               .validate()
               .then(res => {
                  if (this.tranSportForm.productName == '' ) {
                     uni.showToast({
                        title: '请选择产品!',
                        icon: 'error',
                        duration: 2000
                     });
                  }else if(this.tranSportForm.customerName == ''){
                     uni.showToast({
                        title: '请选择客户!',
                        icon: 'error',
                        duration: 2000
                     });
                  }
                  let submit=true
                  let idcardtext=/^([1-6][1-9]|50)\d{4}(18|19|20)\d{2}((0[1-9])|10|11|12)(([0-2][1-9])|10|20|30|31)\d{3}[0-9Xx]$/
                  if(this.driverList.length>0){
                  const regex = /\*/;
                  if (this.fileList9.length==0) {
                     uni.showToast({
                        title: '请选择通行证!',
                        icon: 'error',
                        duration: 2000
                     });
                     submit=false
                  }else if(this.driverList.length>0){
                     this.driverList.forEach((item,index)=>{
                        if(!item.driverName){
                           uni.showToast({
@@ -390,19 +456,21 @@
                              icon: 'error',
                              duration: 2000
                           });
                        }
                        if(!item.driverIdcard){
                           submit=false
                        }else if(!item.driverIdcard){
                           uni.showToast({
                              title: `请填写驾驶身份证!`,
                              icon: 'error',
                              duration: 2000
                           });
                        }else if(!idcardtext.test(item.driverIdcard)){
                           submit=false
                        }else if(!idcardtext.test(item.driverIdcard)&&!regex.test(item.driverIdcard)){
                           uni.showToast({
                              title: `请检验驾驶员身份证!`,
                              icon: 'error',
                              duration: 2000
                           });
                           submit=false
                        }
                     })
                  }
@@ -414,70 +482,190 @@
                              icon: 'error',
                              duration: 2000
                           });
                        }
                        if(!item.driverIdcard){
                           submit=false
                        }else if(!item.driverIdcard){
                           uni.showToast({
                              title: `请填写押运身份证!`,
                              icon: 'error',
                              duration: 2000
                           });
                           submit=false
                        }else if(!idcardtext.test(item.driverIdcard)){
                           uni.showToast({
                              title: `请检验押运身份证!`,
                              icon: 'error',
                              duration: 2000
                           });
                        }
                        if(!item.driverPhone){
                           submit=false
                        }else if(!item.driverPhone){
                           uni.showToast({
                              title: `请填写押运手机号!`,
                              icon: 'error',
                              duration: 2000
                           });
                           submit=false
                        }else if( !/^1[23456789]\d{9}$/.test(item.driverPhone)){
                           uni.showToast({
                              title: `请检验押运手机号!`,
                              icon: 'error',
                              duration: 2000
                           });
                           submit=false
                        }else if(item.fileList.length==0){
                           uni.showToast({
                              title: `请上传资质证明!`,
                              icon: 'error',
                              duration: 2000
                           });
                           submit=false
                        }
                     })
                  }
                  let driverName=""
                  let driverIdcard=""
                  let supercargoInfo=''
                  driverName = this.driverList.map((item, index) => {
                          return item.driverName;
                        }).join(",");
                  driverIdcard = this.driverList.map((item, index) => {
                         return item.driverIdcard;
                        }).join(",");
                  supercargoInfo = this.supercargoList.map((item, index) => {
                      return item.driverName+ '|'+item.driverIdcard+"|"+item.driverPhone
                     }).join(",");
                     if(this.tranSportForm.expirationTime){
                        this.tranSportForm.expirationTime=this.tranSportForm.expirationTime.slice(0,16)
                     if(submit){
                        let driverName=""
                        let driverIdcard=""
                        let supercargoInfo=''
                        let highlyToxicImg=''
                        driverName = this.driverList.map((item, index) => {
                                return item.driverName;
                              }).join(",");
                        driverIdcard = this.driverList.map((item, index) => {
                               return item.driverIdcard;
                              }).join(",");
                        supercargoInfo = this.supercargoList.map((item, index) => {
                            return item.driverName+ '|'+item.driverIdcard+"|"+item.driverPhone
                           }).join(",");
                        highlyToxicImg= this.supercargoList.map((item, index) => {
                           return item.fileList[0].url.replace(BaseUrl,'')
                           }).join(",")
                          if(this.tranSportForm.id){
                           this.$reqPut('putJcroadtransport',{
                              id:this.tranSportForm.id,
                              certificateNo:this.tranSportForm.certificateNo,
                              carNo:this.tranSportForm.carNo,
                              certificateImg:this.tranSportForm.certificateImg,
                              customerName:this.tranSportForm.customerName,
                              productName:this.tranSportForm.productName,
                              startTime:this.tranSportForm.startTime,
                              expirationTime:this.tranSportForm.expirationTime,
                              status:0,
                              customerId:this.tranSportForm.customerId,
                              productId:this.tranSportForm.productId,
                              userId:this.userInfo.userId,
                              driverName:driverName,
                              driverIdcard:driverIdcard,
                              supercargoInfo:supercargoInfo,
                              highlyToxicImg:highlyToxicImg
                           }, 'json').then(res => {
                              if (res.code == 0) {
                                 this.editTranShow = false;
                                 this.$u.toast('提交成功');
                                 this.tranSportForm={
                                    carNo:"",
                                    productId:"",
                                    customerId:""
                                 }
                                 this.driverList=[{
                                    driverName:"",
                                    driverIdcard:""
                                 }]
                                 this.supercargoList=[{
                                    driverName:"",
                                    driverIdcard:"",
                                    driverPhone:"",
                                    fileList:[]
                                 }]
                                 this.fileList9=[]
                                 this.getData();
                              } else {
                                 uni.showToast({
                                    title: res.msg,
                                    icon: 'none',
                                    duration: 2000
                                 });
                              }
                           })
                          }else{
                           this.$reqPost('addJcroadtransport', {
                              userId:this.userInfo.userId,
                              ...this.tranSportForm,
                              driverName:driverName,
                              driverIdcard:driverIdcard,
                              supercargoInfo:supercargoInfo,
                              highlyToxicImg:highlyToxicImg
                           }, 'json').then(res => {
                              if (res.code == 0) {
                                 this.editTranShow = false;
                                 this.$u.toast('提交成功');
                                 this.tranSportForm={
                                    carNo:"",
                                    productId:"",
                                    customerId:""
                                 }
                                 this.driverList=[{
                                    driverName:"",
                                    driverIdcard:""
                                 }]
                                 this.supercargoList=[{
                                    driverName:"",
                                    driverIdcard:"",
                                    driverPhone:"",
                                    fileList:[]
                                 }]
                                 this.fileList9=[]
                                 this.getData();
                              } else {
                                 uni.showToast({
                                    title: res.msg,
                                    icon: 'none',
                                    duration: 2000
                                 });
                              }
                           })
                          }
                     }
                  this.$reqPost('addJcroadtransport', {
                     userId:this.userInfo.userId,
                     ...this.tranSportForm,
                     driverName:driverName,
                     driverIdcard:driverIdcard,
                     supercargoInfo:supercargoInfo
                  }, 'json').then(res => {
                     if (res.code == 0) {
                        this.editTranShow = false;
                        this.$u.toast('修改成功');
                        this.init();
                     } else {
                        uni.showToast({
                           title: res.msg,
                           icon: 'none',
                           duration: 2000
                        });
                     }
                  })
               })
         },
         async afterReads(event) {
            // 当设置 mutiple 为 true 时, file 为数组格式,否则为对象格式
            let lists = [].concat(event.file);
            let fileListLen = this.supercargoList[event.name].fileList.length;
            lists.map(item => {
               this.supercargoList[event.name].fileList.push({
                  ...item,
                  status: 'uploading',
                  message: '上传中'
               });
            });
            for (let i = 0; i < lists.length; i++) {
               const result = await this.uploadFilePromises(lists[i].url, event.name);
               let item = this.supercargoList[event.name].fileList[fileListLen];
               this.supercargoList[event.name].fileList.splice(
                  fileListLen,
                  1,
                  Object.assign(item, {
                     status: 'success',
                     message: '上传成功',
                     url: result
                  })
               );
               fileListLen++;
            }
         },
         uploadFilePromises(url, num) {
            return new Promise((resolve, reject) => {
               let a = uni.uploadFile({
                  url: BaseUrl + '/admin/sys-file/uploadUnToken',
                  filePath: url,
                  name: 'file',
                  // formData: {
                  //    user: 'test'
                  // },
                  success: res => {
                        resolve(`${BaseUrl}${JSON.parse(res.data).data.url}`);
                  }
               });
            });
         },
         async afterRead(event) {
            // 当设置 mutiple 为 true 时, file 为数组格式,否则为对象格式
@@ -524,17 +712,6 @@
               });
            });
         },
         // 获取客户
         getShipToList() {
            this.$reqGet('getShipToList')
               .then(res => {
                  if (res.code == 0) {
                     this.customerNameList = res.data
                  }else {
                  this.$u.toast('加载失败')
               }
            })
         },
         getScoreDetail() {
            uni.showLoading({
               title: '加载中’'
@@ -548,7 +725,8 @@
            this.supercargoList.push({
               driverName:"",
               driverIdcard:"",
               driverPhone:""
               driverPhone:"",
               fileList:[]
            })
         },
         addDriver(){
@@ -558,10 +736,20 @@
            })
         },
         deleteSupercar(){
            this.supercargoList.splice(this.supercargoList.length - 1, 1)
            if(this.supercargoList.length>1){
               this.supercargoList.splice(this.supercargoList.length - 1, 1)
            }
         },
         deleteDriver(){
            this.driverList.splice(this.driverList.length - 1, 1);
            if(this.driverList.length>1){
               this.driverList.splice(this.driverList.length - 1, 1);
            }
         },
         getUserName(e){
            let data= e.split(',').map(item=>{
               return item.split("|")[0]
            }).join(',')
            return data
         }
      }
   }