qingyiay
2023-03-28 5c01be6370291febe52adfa74fad8101a197c388
pages/register/register.vue
@@ -1,6 +1,5 @@
<template>
   <view class="register">
      <!-- <home-species title="注册"></home-species> -->
      <view class="registerForm">
         <u--form :rules="rules" :model="registerFormModel" ref="regesterFormRef">
            <u-form-item labelWidth="20%" label="选择身份" borderBottom ref="roleRef" required>
@@ -18,49 +17,50 @@
               </u-radio-group>
            </u-form-item>
            <u-form-item prop="name" label="姓名" labelWidth="20%" borderBottom required>
               <u--input v-model="registerFormModel.name" placeholder="请输入内容"></u--input>
               <u--input v-model="registerFormModel.name" placeholder="请输入内容" clearable></u--input>
            </u-form-item>
            <u-form-item prop="idCard" label="身份证" labelWidth="20%" borderBottom required>
               <u--input v-model="registerFormModel.idCard" placeholder="请输入内容"></u--input>
               <u--input v-model="registerFormModel.idCard" placeholder="请输入内容" clearable></u--input>
            </u-form-item>
            <u-form-item prop="phone" label="手机号" labelWidth="20%" borderBottom required>
               <u--input v-model="registerFormModel.phone" placeholder="请输入内容"></u--input>
               <u--input v-model="registerFormModel.phone" placeholder="请输入内容" clearable></u--input>
            </u-form-item>
            <u-form-item prop="password" label="密码" labelWidth="20%" borderBottom required>
               <u--input v-model="registerFormModel.password" placeholder="请输入内容"></u--input>
               <u--input v-model="registerFormModel.password" placeholder="请输入内容" password clearable></u--input>
            </u-form-item>
            <u-form-item prop="confirmPassword" label="确认密码" labelWidth="20%" borderBottom required>
               <u--input v-model="registerFormModel.confirmPassword" placeholder="请输入内容" password clearable @blur="jiaoYanPassword"></u--input>
            </u-form-item>
            <u-form-item prop="carNo" label="车牌号" labelWidth="20%" borderBottom v-if="radiovalue1 == '司机'" required>
               <u--input v-model="registerFormModel.carNo" placeholder="请输入内容"></u--input>
               <u--input v-model="registerFormModel.carNo" placeholder="请输入内容" clearable></u--input>
            </u-form-item>
            <u-form-item prop="carPhoto" label="车辆照片" labelWidth="20%" borderBottom v-if="radiovalue1 == '司机'" required>
               <u-upload :fileList="fileList6" @afterRead="afterRead" @delete="deletePic" name="6" multiple :maxCount="1" width="250" height="150">
            <u-form-item prop="carImg" label="车辆照片" labelWidth="20%" borderBottom v-if="radiovalue1 == '司机'" required>
               <u-upload :fileList="fileList1" deletable @afterRead="afterRead" @delete="deletePic" name="1" multiple :maxCount="1" width="250" height="150">
                  <!-- <image src="https://cdn.uviewui.com/uview/demo/upload/positive.png"
                  mode="widthFix" style="width: 250px;height: 150px;"></image> -->
               </u-upload>
            </u-form-item>
            <u-form-item prop="drivingLicense" label="行驶证" labelWidth="20%" borderBottom v-if="radiovalue1 == '司机'" required>
               <u-upload :fileList="fileList5" @afterRead="afterRead" @delete="deletePic" name="5" multiple :maxCount="1" width="250" height="150">
            <u-form-item prop="drivingImg" label="行驶证" labelWidth="20%" borderBottom v-if="radiovalue1 == '司机'" required>
               <u-upload :fileList="fileList2" deletable @afterRead="afterRead" @delete="deletePic" name="2" multiple :maxCount="1" width="250" height="150">
                  <!-- <image src="https://cdn.uviewui.com/uview/demo/upload/positive.png"
                  mode="widthFix" style="width: 250px;height: 150px;"></image> -->
               </u-upload>
            </u-form-item>
            <u-form-item label="推荐人账号" labelWidth="25%" borderBottom ><u--input v-model="registerFormModel.tuiJianMa" placeholder="请输入内容"></u--input></u-form-item>
            <u-form-item label="推荐人账号" labelWidth="25%" borderBottom>
               <u--input v-model="registerFormModel.tuiJianMa" placeholder="请输入内容" clearable></u--input>
            </u-form-item>
         </u--form>
      </view>
      <view class="roleModel">
         <u-modal :show="editRoleModelShow" :title="title" :content="content" :showCancelButton="true" @confirm="roleConfirm" @cancel="roleCancel"></u-modal>
      </view>
      <view class="registerBtn"><u-button text="注册" type="primary" @click="registerClick"></u-button></view>
      <!-- <view class="utils">
         <text @click="callingIn">打电话</text>
      </view> -->
   </view>
</template>
<script>
// import HomeSpecies from '@/components/home-species/HomeSpecies.vue';
import { apiRegister } from '@/api/publicInterface.js';
import { BaseUrl } from '@/api/publicInterface.js';
export default {
   // onLoad: function() {
   //   // 查看是否授权
@@ -77,9 +77,6 @@
   //     }
   //   })
   // },
   components: {
      // HomeSpecies
   },
   // 监听页面初次渲染完成。注意如果渲染速度快,会在页面进入动画完成前触发
   onReady() {
      // this.$refs.regesterFormRef.setRules(this.rules);
@@ -99,15 +96,18 @@
            phone: '',
            password: '',
            name: '',
            username:'',
            username: '',
            openId: '',
            type: 2,
            idCard: '',
            carNo: '',
            carImg: '',
            drivingImg: '',
            tuiJianMa: ''
            tuiJianMa: '',
            confirmPassword: ''
         },
         fileList1: [],
         fileList2: [],
         rules: {
            name: {
               type: 'string',
@@ -142,8 +142,20 @@
               },
               {
                  min: 6,
                  max: 8,
                  message: '长度在6-8个字符之间'
                  max: 12,
                  message: '长度在6-12个字符之间'
               }
            ],
            confirmPassword: [
               {
                  required: true,
                  message: '请设置初始密码',
                  trigger: ['blur', 'change']
               },
               {
                  min: 6,
                  max: 12,
                  message: '长度在6-12个字符之间'
               }
            ],
            carNo: [
@@ -154,18 +166,18 @@
                  trigger: ['blur', 'change']
               }
            ],
            // carPhoto: {
            //    type: 'string',
            //    required: true,
            //    message: '请上传车辆图片',
            //    trigger: ['blur', 'change']
            // },
            // drivingLicense: {
            //    type: 'string',
            //    required: true,
            //    message: '请上传行驶证照片',
            //    trigger: ['blur', 'change']
            // }
            carImg: {
               type: 'string',
               required: true,
               message: '请上传车辆图片',
               trigger: ['blur', 'change']
            },
            drivingImg: {
               type: 'string',
               required: true,
               message: '请上传行驶证照片',
               trigger: ['blur', 'change']
            }
         },
         // 基本案列数据
         radiolist1: [
@@ -181,8 +193,6 @@
         // u-radio-group的v-model绑定的值如果设置为某个radio的name,就会被默认选中
         radiovalue1: '货代',
         beforeChangeValue: '',
         fileList5: [],
         fileList6: [],
         // 更换角色弹框
         editRoleModelShow: false,
         title: '提示',
@@ -215,42 +225,39 @@
   },
   methods: {
      registerClick() {
         this.$refs.regesterFormRef
            .validate()
            .then(res => {
               console.log(this.registerFormModel);
               this.registerFormModel.username = this.registerFormModel.name
               apiRegister(this.registerFormModel)
                  .then(res => {
                     console.log(res);
                     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)
                     }
                  })
                  .catch(err => {
                     console.log('错误', err);
                  });
            })
            .catch(err => {
               console.log('err', err);
               uni.$u.toast('效验失败');
            });
         if (this.registerFormModel.password == this.registerFormModel.confirmPassword) {
            this.$refs.regesterFormRef
               .validate()
               .then(res => {
                  console.log(this.registerFormModel);
                  this.registerFormModel.username = this.registerFormModel.phone;
                  apiRegister(this.registerFormModel)
                     .then(res => {
                        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.data ? res.data.data : '添加失败');
                        }
                     })
                     .catch(err => {
                        console.log('错误', err);
                     });
               })
               .catch(err => {
                  console.log('err', err);
                  uni.$u.toast('请规范输入内容');
               });
         } else {
            this.$u.toast('两次密码不一致');
         }
      },
      // 音视频通话
      // callingIn() {
      //    uni.navigateTo({
      //       url: '/pages/calling-index/calling-index'
      //    });
      // },
      // 单选框事件
      groupChange(e) {
         console.log('单选框小组', e);
@@ -267,6 +274,11 @@
            console.log('变了');
            this.$refs.regesterFormRef.clearValidate();
            this.beforeChangeValue = e;
         }
      },
      jiaoYanPassword() {
         if (this.registerFormModel.password != this.registerFormModel.confirmPassword) {
            this.$u.toast('两次密码不一致');
         }
      },
      // 上传图片方法
@@ -288,7 +300,7 @@
            });
         });
         for (let i = 0; i < lists.length; i++) {
            const result = await this.uploadFilePromise(lists[i].url);
            const result = await this.uploadFilePromise(lists[i].url, event.name);
            let item = this[`fileList${event.name}`][fileListLen];
            this[`fileList${event.name}`].splice(
               fileListLen,
@@ -302,19 +314,22 @@
            fileListLen++;
         }
      },
      uploadFilePromise(url) {
      uploadFilePromise(url, num) {
         return new Promise((resolve, reject) => {
            let a = uni.uploadFile({
               url: 'http://192.168.2.21:7001/upload', // 仅为示例,非真实的接口地址
               url: BaseUrl + '/admin/sys-file/uploadUnToken',
               filePath: url,
               name: 'file',
               formData: {
                  user: 'test'
               },
               // formData: {
               //    user: 'test'
               // },
               success: res => {
                  setTimeout(() => {
                     resolve(res.data.data);
                  }, 1000);
                  resolve(JSON.parse(res.data).data.url);
                  if (num == 1) {
                     this.registerFormModel.carImg = JSON.parse(res.data).data.url;
                  } else if (num == 2) {
                     this.registerFormModel.drivingImg = JSON.parse(res.data).data.url;
                  }
               }
            });
         });
@@ -331,7 +346,6 @@
          * @resetFields 不管用时候用上边的代替
          */
         this.$refs.regesterFormRef.resetFields();
         this.editRoleModelShow = false;
      },
      roleCancel() {
@@ -339,17 +353,6 @@
         this.$nextTick(() => {
            this.editRoleModelShow = false;
         });
         // switch (this.radiovalue1) {
         //    case '客户':
         //       this.radiovalue1 = '';
         //       break;
         //    case '货代':
         //       this.radiovalue1 = '司机';
         //       break;
         //    case '司机':
         //       this.radiovalue1 = '货代';
         //       break;
         // }
      }
   }
};