wk
2024-08-05 76543a9506a9b43476e750c79c5ff595aa4bae36
pages/register/register.vue
@@ -17,7 +17,6 @@
                  iconSize="20">
                  <u-radio labelSize="14px"
                     size="20px"
                     :customStyle="{ marginBottom: '8px' }"
                     v-for="(item, index) in radiolist1"
                     :key="index"
                     :label="item.name"
@@ -43,6 +42,48 @@
                  placeholder="请输入内容"
                  clearable></u--input>
            </u-form-item>
            <u-form-item prop="cardImg1"
               label="身份证正面"
               labelWidth="20%"
               borderBottom
               required
               @click="beforeRead">
               <u-upload :fileList="fileList5"
                  deletable
                  @afterRead="afterRead"
                  @delete="deletePic"
                  name="5"
                  multiple
                  :maxCount="1"
                  width="250"
                  height="150"
                  :previewFullImage="true">
               </u-upload>
            </u-form-item>
            <u-form-item prop="cardImg2"
               label="身份证反面"
               labelWidth="20%"
               borderBottom
               required
               @click="beforeRead">
               <u-upload :fileList="fileList6"
                  deletable
                  @afterRead="afterRead"
                  @delete="deletePic"
                  name="6"
                  multiple
                  :maxCount="1"
                  width="250"
                  height="150"
                  :previewFullImage="true">
               </u-upload>
            </u-form-item>
            <u-form-item prop="expirationTimeIdcard"
               label="身份证过期时间"
               labelWidth="20%"
               borderBottom>
               <uni-datetime-picker v-model="registerFormModel.expirationTimeIdcard" type="date" :start="minDate" />
            </u-form-item>
            <u-form-item prop="phone"
               label="手机号"
               labelWidth="20%"
@@ -62,6 +103,21 @@
                  password
                  clearable></u--input>
            </u-form-item>
        <view class="intensity">
          <view class="psdText">密码强度</view>
          <view
              class="line"
              :class="[level.includes('low') ? 'low' : '']"></view>
          <view
              class="line"
              :class="[level.includes('middle') ? 'middle' : '']"></view>
          <view
              class="line"
              :class="[level.includes('high') ? 'high' : '']"></view>
          <div class="warningtext">
            密码应由8-16位数字、字母、符号组成。请不要使用容易被猜到的密码
          </div>
        </view>
            <u-form-item prop="confirmPassword"
               label="确认密码"
               labelWidth="20%"
@@ -82,6 +138,19 @@
               <u--input v-model="registerFormModel.carNo"
                  placeholder="请输入内容"
                  clearable></u--input>
            </u-form-item>
            <u-form-item labelWidth="20%"
               label="车辆类型"
               borderBottom
               ref="roleRef"
               prop='carType'
               v-if="radiovalue1 == '司机'">
               <niceui-data-select-input v-model="registerFormModel.carType"
                  :localdata="radiolist2"
                  label="车辆类型选择"
                  placeholder="请选择车辆类型"
                  @change="productcarTypeChange"
                  ></niceui-data-select-input>
            </u-form-item>
            <u-form-item prop="carImg"
               label="车辆照片"
@@ -121,8 +190,15 @@
                  :previewFullImage="true">
               </u-upload>
            </u-form-item>
            <u-form-item prop="roadTransportImg"
               label="道路运输证"
            <u-form-item prop="expirationTimeDriving"
               label="行驶证过期时间"
               labelWidth="20%"
               borderBottom
               v-if="radiovalue1 == '司机'">
               <uni-datetime-picker v-model="registerFormModel.expirationTimeDriving" type="date"  :start="minDate" />
            </u-form-item>
            <u-form-item prop="driverImg"
               label="驾驶证"
               labelWidth="24%"
               borderBottom
               v-if="radiovalue1 == '司机'"
@@ -140,12 +216,18 @@
                  :previewFullImage="true">
               </u-upload>
            </u-form-item>
            <u-form-item prop="expirationTimeDriver"
               label="驾驶证过期时间"
               labelWidth="20%"
               borderBottom
               v-if="radiovalue1 == '司机'">
               <uni-datetime-picker v-model="registerFormModel.expirationTimeDriver" type="date"  :start="minDate" />
            </u-form-item>
            <u-form-item prop="tradeQualificationImg"
               label="从业资格证"
               labelWidth="24%"
               borderBottom
               v-if="radiovalue1 == '司机'"
               required
               @click="beforeRead">
               <u-upload :fileList="fileList4"
                  deletable
@@ -158,21 +240,34 @@
                  height="150"
                  :previewFullImage="true">
               </u-upload>
               <span style="color:red">
                  凡是运输有毒化学物品的车辆必须上传从业资格证并填写从业资格证有效时间
               </span>
            </u-form-item>
            <u-form-item label="是否非煤车辆"
               v-if="radiovalue1 == '司机'"
               labelWidth="30%"
            <u-form-item prop="expirationTimeTradequalification"
               label="从业资格过期时间"
               labelWidth="20%"
               borderBottom
               prop="isNonCoal">
               <u-checkbox-group v-model="registerFormModel.isNonCoal"
               v-if="radiovalue1 == '司机'">
               <uni-datetime-picker v-model="registerFormModel.expirationTimeTradequalification" type="date"  :start="minDate" />
            </u-form-item>
            <u-form-item labelWidth="20%"
               v-if="radiovalue1 == '司机'"
               label="环保类型"
               borderBottom
               prop="countryNumberCar">
               <u-radio-group v-model="registerFormModel.countryNumberCar"
                  placement="row"
                  size="40"
                  @change="isNonCoalChange">
                  <u-checkbox :label="registerFormModel.isNonCoal.length!==0?'是':'否'"
                     name="是"
                     label-size="30">
                  </u-checkbox>
               </u-checkbox-group>
                  size="30"
                  shape="circle"
                  iconSize="20">
                  <u-radio labelSize="14px"
                     size="20px"
                     v-for="(item, index) in countryNumberCarList"
                     :key="index"
                     :label="item.label"
                     :name="item.name"></u-radio>
               </u-radio-group>
            </u-form-item>
         </u--form>
      </view>
@@ -207,7 +302,84 @@
         }
      },
      data() {
      const validatePass = (rule, value, callback) => {
        if (this.registerFormModel.confirmPassword !== "") {
          if (value !== this.registerFormModel.password) {
            callback(new Error("两次输入密码不一致!"));
          } else {
            callback();
          }
        } else {
          callback();
        }
      };
      const checkPassword = (rule, value, callback) => {
        // let roles = this.$store.getters.roles;//当前用户角色id
        // let passL = 8;
        // if (roles.concat(1)){
        //   passL = 10
        // }
        let passL = 8;
        this.level = []
        if(!value) {
          return callback('密码不能为空')
        }
        if(value.length < passL) {
          return callback(`密码不能少于${passL}位`)
        }
        if(value.length > 16) {
          return callback('密码不能大于16位')
        }
        //校验是数字
        const regex1 = /^\d+$/
        // 校验字母
        const regex2 = /^[A-Za-z]+$/
        // 校验符号
        const regex3 =
            /^[`~!@#$%^&*()_\-+=<>?:"{}|,.\/;'\\[\]·~!@#¥%……&*()——\-+={}|《》?:“”【】、;‘',。、]+$/;
        if(regex1.test(value)) {
          this.level.push('low')
          return callback('密码强度过低')
        }else if(regex2.test(value)) {
          this.level.push('low')
          return callback('密码强度过低')
        }else if(regex3.test(value)) {
          this.level.push('low')
          return callback('密码强度过低')
        }else if(/^[A-Za-z\d]+$/.test(value)) {
          this.level.push('low')
          this.level.push('middle')
          return callback('密码强度过低')
        }else if(
            /^[`~!@#$%^&*()_\-+=<>?:"{}|,.\/;'\\[\]·~!@#¥%……&*()——\-+={}|《》?:“”【】、;‘',。、\d]+$/.test(
                value
            )
        ) {
          this.level.push('low')
          this.level.push('middle')
          return callback('密码强度过低')
        }else if(
            /^[`~!@#$%^&*()_\-+=<>?:"{}|,.\/;'\\[\]·~!@#¥%……&*()——\-+={}|《》?:“”【】、;‘',。、A-Za-z]+$/.test(
                value
            )
        ) {
          this.level.push('low')
          this.level.push('middle')
          return callback('密码强度过低')
        } else if (
            /^[`~!@#$%^&*()_\-+=<>?:"{}|,.\/;'\\[\]·~!@#¥%……&*()——\-+={}|《》?:“”【】、;‘',。、A-Za-z\d]+$/.test(
                value
            )
        ) {
          this.level.push('low')
          this.level.push('middle')
          this.level.push('high')
        }
        return callback()
      };
         return {
        level:[],  //密码强度数组
            minDate: this.getToday(),
            // 车牌号键盘控制
            carNumShow: false,
            keyValue: '',
@@ -225,21 +397,48 @@
               tuiJianMa: '',
               confirmPassword: '',
               tradeQualificationImg: '',
               roadTransportImg: '',
               isNonCoal: [],
               isCoalCar: 1 //是否为煤炭车辆(司机使用字段) 1 是 2 不是
               driverImg: '',
               countryNumberCar: 2, //环保类型;国五 1,国六 2
               carType:null,
            },
            fileList1: [],
            fileList2: [],
            fileList3: [],
            fileList4: [],
            fileList5: [],
            fileList6: [],
            rules: {
               name: {
               countryNumberCar: {
                  required: false,
               },
               expirationTimeIdcard: {
                  required: false,
               },
               expirationTimeDriving: {
                  required: false,
               },
               expirationTimeDriver: {
                  required: false,
               },
               expirationTimeTradequalification: {
                  required: false,
               },
               name: [{
                  type: 'string',
                  required: true,
                  message: '请填写姓名',
                  trigger: ['blur', 'change']
               },
               },{
                     pattern: /^[\u4e00-\u9fa5]{1,6}$/, //限制长度最多为 6 位
                     message: '姓名只能是中文',
                     trigger: ['blur', 'change']
                  }],
                  carType:[{
                     type: 'number',
                     required: true,
                     message: '请选择车辆类型',
                     trigger: ['blur', 'change']
                  }],
               idCard: [{
                     type: 'string',
                     required: true,
@@ -272,27 +471,19 @@
                  }
               ],
               password: [{
                     required: true,
                     message: '请设置初始密码',
                     trigger: ['blur', 'change']
                  },
                  {
                     min: 6,
                     max: 12,
                     message: '长度在6-12个字符之间'
                  }
               ],
            required: true,
            message: '请设置初始密码',
            trigger: ['blur', 'change']
          },
            {
              validator: checkPassword,
              trigger: 'change'
            }],
               confirmPassword: [{
                     required: true,
                     message: '请设置初始密码',
                     trigger: ['blur', 'change']
                  },
                  {
                     min: 6,
                     max: 12,
                     message: '长度在6-12个字符之间'
                  }
               ],
            required: true,
            validator: validatePass,
            trigger: "blur"
          }],
               carNo: [{
                     type: 'string',
                     required: true,
@@ -310,6 +501,18 @@
                     trigger: ['change', 'blur']
                  }
               ],
               cardImg1:{
                  type: 'string',
                  required: true,
                  message: '请上传身份证正面',
                  trigger: ['blur', 'change']
               },
               cardImg2:{
                  type: 'string',
                  required: true,
                  message: '请上传身份证反面',
                  trigger: ['blur', 'change']
               },
               carImg: {
                  type: 'string',
                  required: true,
@@ -322,16 +525,10 @@
                  message: '请上传行驶证照片',
                  trigger: ['blur', 'change']
               },
               roadTransportImg: {
               driverImg: {
                  type: 'string',
                  required: true,
                  message: '请上传道路运输证照片',
                  trigger: ['blur', 'change']
               },
               tradeQualificationImg: {
                  type: 'string',
                  required: true,
                  message: '请上传从业资格证照片',
                  message: '请上传驾驶证照片',
                  trigger: ['blur', 'change']
               }
            },
@@ -342,6 +539,36 @@
               {
                  name: '货代',
                  disabled: false
               }
            ],
            radiolist2: [{
                  text: '普通运输车',
                  value:1
               },
               {
                  text: '集装箱平板车',
                  value:2
               },
               {
                  text: '液氯槽车',
                  value:3
               },
               {
                  text: '液碱槽车',
                  value:4
               }
            ],
            countryNumberCarList: [{
                  name: 1,
                  label: '国五',
               },
               {
                  name: 2,
                  label: '国六',
               },
               {
                  name: 3,
                  label: '新能源',
               }
            ],
            radiovalue1: '司机',
@@ -376,45 +603,75 @@
                  break;
            }
            return;
         }
         },
      },
      methods: {
         ...mapMutations(['changeisUploadimg']),
         getToday() {
           let now = new Date();
           let year = now.getFullYear();
           let month = this.padStart(now.getMonth() + 1); // 月份是从0开始的
           let day = this.padStart(now.getDate());
           return `${year}-${month}-${day}`;
         },
         padStart(value) {
           return value.toString().padStart(2, '0');
         },
         productcarTypeChange(e){
            console.log(this.registerFormModel.carType,this.radiolist2.find(v => v.value === e).value)
            this.registerFormModel.carType = this.radiolist2.find(v => v.value === e).value
         },
         registerClick() {
            if (this.registerFormModel.password == this.registerFormModel.confirmPassword) {
               this.$refs.regesterFormRef
                  .validate()
                  .then(res => {
                     console.log(this.registerFormModel);
                     this.registerClickloading = true;
                     this.registerFormModel.username = this.registerFormModel.phone;
                     apiRegister(this.registerFormModel)
                        .then(res => {
                           this.registerClickloading = false;
                           if (res.data.code == 0) {
                              uni.showToast({
                                 title: '注册成功,即将返回登录页',
                                 icon: 'none',
                                 duration: 1000
                              });
                              setTimeout(() => {
                                 uni.redirectTo({ url: '/pages/login/login' });
                              }, 1000);
                           } else {
                              this.$u.toast(res.data.msg ? res.data.msg : '添加失败');
                           }
                        })
                        .catch(err => {
                           console.log('错误', err);
                        });
                  })
                  .catch(err => {
                     console.log('err', err);
                     this.$u.toast('请规范输入内容');
                  });
            } else {
               this.$u.toast('两次密码不一致');
            }
        if(this.registerFormModel.carType==3&&!this.registerFormModel.tradeQualificationImg||this.registerFormModel.carType==4&&!this.registerFormModel.tradeQualificationImg){
          uni.showToast({
            title: '请上传从业资格证!',
            icon: 'error',
            duration: 2000
          });
        }else{
          this.$refs.regesterFormRef
              .validate()
              .then(res => {
                this.registerClickloading = true;
                this.registerFormModel.username = this.registerFormModel.phone;
                this.registerFormModel.idCardImg = this.registerFormModel.cardImg1+","+this.registerFormModel.cardImg2;
                if(this.registerFormModel.expirationTimeDriver){
                  this.registerFormModel.expirationTimeDriver=this.registerFormModel.expirationTimeDriver.slice(0,16)
                }
                if(this.registerFormModel.expirationTimeDriving){
                  this.registerFormModel.expirationTimeDriving=this.registerFormModel.expirationTimeDriving.slice(0,16)
                }
                if(this.registerFormModel.expirationTimeIdcard){
                  this.registerFormModel.expirationTimeIdcard=this.registerFormModel.expirationTimeIdcard.slice(0,16)
                }
                if(this.registerFormModel.expirationTimeTradequalification){
                  this.registerFormModel.expirationTimeTradequalification=this.registerFormModel.expirationTimeTradequalification.slice(0,16)
                }
                this.$reqPost('registerDriver', this.registerFormModel, 'json')
                    .then(res => {
                      this.registerClickloading = false;
                      if (res.code == 0) {
                        uni.showToast({
                          title: '注册成功,即将返回登录页',
                          icon: 'none',
                          duration: 1000
                        });
                        setTimeout(() => {
                          uni.redirectTo({ url: '/pages/login/login' });
                        }, 1000);
                      } else {
                        this.$u.toast(res.msg ? res.msg : '添加失败');
                      }
                    })
                    .catch(err => {
                      console.log('错误', err);
                    });
              })
              .catch(err => {
                console.log('err', err);
                this.$u.toast('请规范输入内容');
              });
        }
         },
         // 单选框事件
         groupChange(e) {},
@@ -477,9 +734,6 @@
                  url: BaseUrl + '/admin/sys-file/uploadUnToken',
                  filePath: url,
                  name: 'file',
                  formData: {
                     // user: ''
                  },
                  success: res => {
                     if (num == 1) {
                        this.registerFormModel.carImg = JSON.parse(res.data).data.url;
@@ -488,11 +742,19 @@
                        this.registerFormModel.drivingImg = JSON.parse(res.data).data.url;
                        resolve(`${BaseUrl}${JSON.parse(res.data).data.url}`);
                     } else if (num == 3) {
                        this.registerFormModel.roadTransportImg = JSON.parse(res.data).data
                        this.registerFormModel.driverImg = JSON.parse(res.data).data
                           .url;
                        resolve(`${BaseUrl}${JSON.parse(res.data).data.url}`);
                     } else if (num == 4) {
                        this.registerFormModel.tradeQualificationImg = JSON.parse(res.data)
                           .data.url;
                        resolve(`${BaseUrl}${JSON.parse(res.data).data.url}`);
                     }else if(num==5){
                        this.registerFormModel.cardImg1 = JSON.parse(res.data)
                           .data.url;
                        resolve(`${BaseUrl}${JSON.parse(res.data).data.url}`);
                     }else if(num==6){
                        this.registerFormModel.cardImg2 = JSON.parse(res.data)
                           .data.url;
                        resolve(`${BaseUrl}${JSON.parse(res.data).data.url}`);
                     }
@@ -519,9 +781,6 @@
            this.$nextTick(() => {
               this.editRoleModelShow = false;
            });
         },
         isNonCoalChange() {
            this.registerFormModel.isCoalCar = this.registerFormModel.isNonCoal.length !== 0 ? 1 : 2
         }
      }
   };
@@ -560,4 +819,43 @@
         }
      }
   }
</style>
  .intensity {
    width: 100%;
    margin-top: 10rpx;
    .psdText {
      font-size: 14px;
      margin-right: 10px;
    }
    .line {
      display: inline-block;
      width: 70rpx;
      height: 8rpx;
      background: #d8d8d8;
      border-radius: 6rpx;
      margin-right: 16rpx;
      &.low {
        background: #f4664a;
      }
      &.middle {
        background: #ffb700;
      }
      &.high {
        background: #2cbb79;
      }
    }
    .level {
      margin: 0 32rpx 0 16rpx;
    }
    .warningtext {
      color: #5a5a5a;
      font-size: 24rpx;
      margin-top: 10rpx;
    }
  }
</style>