zengh
2022-09-14 8ea19a6bb34daab1410f6186992a4c1e90299c92
pages/registerUser/registerUser.vue
@@ -3,24 +3,38 @@
      <u-form :model="form" ref="uForm">
         <u-form-item :label="item.title" :prop="item.froms" label-width="200" :left-icon="item.img"
            :required="item.requireds" v-for="(item, index) in list" :key="index">
            <u-input v-model="form[item.froms]" :placeholder="item.placeholder" />
            <u-input v-model="form[item.froms]" :placeholder="item.placeholder" :type="item.type" />
         </u-form-item>
         <u-form-item label="角色" prop="role" left-icon="account-fill" label-width="200" :required="true">
            <u-radio-group v-model="form.role" @change="radioGroupChange">
               <u-radio v-for="(item, index) in role" :key="index" :name="item.name" :disabled="item.disabled">
                  {{ item.name }}
               </u-radio>
            </u-radio-group>
            <u-input v-model="form.role" type="select" placeholder="请选择角色" :border="true" @click="depl" />
            <u-select v-model="show" mode="mutil-column-auto" :list="roleList" @confirm="radioGroupChange">
            </u-select>
         </u-form-item>
         <u-form-item label="组织机构" prop="obj" left-icon="account-fill" label-width="200" :required="true"
            v-if="xqShow">
            <u-input v-model="form.obj" type="select" placeholder="请选择组织机构" :border="true" @click="depl" />
            <u-select v-model="show" mode="mutil-column-auto" :list="listbm" @confirm="confirm"></u-select>
         <u-form-item v-show="form.role == '民警'" label="警号" prop="signals" left-icon="edit-pen" label-width="200"
            :required="true">
            <u-input v-model="form.signals" placeholder="请输入警号" />
         </u-form-item>
         <u-form-item label="辖区" prop="xq" left-icon="account-fill" label-width="200" :required="true">
            <u-input v-model="form.xq" type="select" placeholder="请选择辖区" :border="true" @click="deplxq" />
         <u-form-item v-show="form.role == '民警'" label="工作单位" prop="xq" left-icon="map" label-width="200"
            :required="true">
            <u-input v-model="form.xq" type="select" placeholder="请选择工作单位" :border="true"
               @click="showxq = 'true'" />
            <u-select v-model="showxq" mode="mutil-column-auto" :list="listxq" @confirm="confirmxq"></u-select>
         </u-form-item>
         <u-form-item v-show="form.role != '民警'" label="服务范围" prop="address" left-icon="map" label-width="200"
            :required="true">
            <u-input v-model="form.address" type="select" placeholder="请选择服务范围" :border="true"
               @click="showxq = 'true'" />
            <u-select v-model="showxq" mode="mutil-column-auto" :list="listxq" @confirm="confirmxq"></u-select>
         </u-form-item>
         <u-form-item label="所属队伍" prop="teamName" left-icon="map" label-width="200" :required="true">
            <u-input v-model="form.teamName" type="select" placeholder="请选择所属队伍" :border="true"
               @click="openTeamPopup" />
         </u-form-item>
         <u-form-item label="性别" label-width="200" left-icon="man">
            <u-radio-group v-model="form.sex">
               <u-radio v-for="(item, index) in sex" :key="index" :name="item.name" :disabled="item.disabled">
@@ -28,41 +42,140 @@
               </u-radio>
            </u-radio-group>
         </u-form-item>
         <!-- <u-form-item label="是否人脸登录" label-width="240" left-icon="server-man">
            <u-radio-group v-model="radioValue">
               <u-radio v-for="(item, index) in radioList" :key="index" :name="item.name"
                  :disabled="item.disabled">
                  {{item.name}}
               </u-radio>
            </u-radio-group>
            (功能研发中)
         </u-form-item> -->
      </u-form>
      <view class="agree">
         <u-checkbox v-model="userConsent" shape="circle">
            我已阅读并同意
            <text class="a" @click="agreement(0)">用户协议</text>
            和
            <text class="a" @click="agreement(1)">隐私政策</text>
         </u-checkbox>
      </view>
      <u-popup v-model="showTeam" border-radius="14" length="60%" mode="bottom" zIndex="9999" closeable="true"
         @close="showTeam = false">
         <view class="team-popup">
            <view class="title">
               选择所属队伍
            </view>
            <scroll-view scroll-y="true" style="height: calc(100% - 88rpx);">
               <view @click="currentTeam(item)" v-for="(item, index) in teamList" :key="index">
                  <u-icon v-show="item.isBrand == '1'" size="40" name="/static/images/icon/medal.png"></u-icon>
                  {{item.name}}
               </view>
            </scroll-view>
         </view>
      </u-popup>
      <u-button class="submit" @click="zc">
         下一步</u-button>
      <!-- <u-button class="submit" @click="submit">提交</u-button> -->
         注册</u-button>
   </view>
</template>
<script>
   export default {
      data() {
         var validateUser = (rule, value, callback) => {
            var phone = /^1(3\d|4[5-9]|5[0-35-9]|6[567]|7[0-8]|8\d|9[0-35-9])\d{8}$/;
            var identity =
               /(^[1-9]\d{5}(18|19|([23]\d))\d{2}((0[1-9])|(10|11|12))(([0-2][1-9])|10|20|30|31)\d{3}[0-9Xx]$)|(^[1-9]\d{5}\d{2}((0[1-9])|(10|11|12))(([0-2][1-9])|10|20|30|31)\d{2}$)/;
            // if (value.length <= 11) {
            //    if (phone.test(value)) {
            //       this.form.phone = value;
            //       return true
            //    } else {
            //       return callback(new Error('手机号格式不正确'));
            //    }
            // }
            if (identity.test(value)) {
               this.form.carId = value;
               return true
            } else {
               return callback(new Error('身份证号格式不正确'));
            }
            // if (value.length > 11) {
            // }
         };
         return {
            // 工作地点经纬度
            jobLng: '',
            jobLat: '',
            // 居住地经纬度
            liveLng: '',
            liveLat: '',
            teamList: '',
            userConsent: false,
            jobValue: '无',
            jobList: [{
                  name: '有',
                  disabled: false
               },
               {
                  name: '无',
                  disabled: false
               }
            ],
            radioList: [{
                  name: '是',
                  disabled: false
               },
               {
                  name: '否',
                  disabled: false
               }
            ],
            radioValue: '否',
            show: false,
            showxq: false,
            xqShow: true,
            listbm: [],
            listxq: [],
            deptXb: "",
            flag: false,
            list: [{
                  title: '账号',
                  title: '手机号',
                  img: 'phone-fill',
                  froms: 'phone',
                  requireds: true,
                  placeholder: '请输入真实手机号'
               },
               {
                  title: '身份证',
                  img: 'man-add-fill',
                  froms: 'user',
                  requireds: true,
                  placeholder: '请输入帐号'
                  placeholder: '请输入身份证号'
               },
               {
                  title: '密码',
                  type: 'password',
                  img: 'lock-fill',
                  froms: 'pass',
                  requireds: true,
                  placeholder: '请输入密码'
                  placeholder: '请输入6~16位密码'
               },
               {
                  title: '确认密码',
                  type: 'password',
                  img: 'lock-fill',
                  froms: 'passTwo',
                  requireds: true,
@@ -73,21 +186,7 @@
                  img: 'account',
                  froms: 'name',
                  requireds: true,
                  placeholder: '请输入姓名'
               },
               {
                  title: '身份证',
                  img: 'fingerprint',
                  froms: 'carId',
                  requireds: true,
                  placeholder: '请输入身份证'
               },
               {
                  title: '手机号',
                  img: 'phone-fill',
                  froms: 'phone',
                  requireds: false,
                  placeholder: '请输入手机号'
                  placeholder: '请输入真实姓名'
               },
               // {
               //    title: '部门',
@@ -106,30 +205,6 @@
                  disabled: false
               },
            ],
            role: [{
                  name: '民警',
                  disabled: false
               },
               {
                  name: '群众',
                  disabled: false
               },
               {
                  name: '群防队伍',
                  disabled: false
               },
               // {
               //    name: '保安',
               //    disabled: false
               // },
            ],
            objList: [{
                  text: '赣州'
               },
               {
                  text: '南昌'
               }
            ],
            form: {
               user: '',
               pass: '',
@@ -138,27 +213,37 @@
               carId: '',
               phone: '',
               sex: '男',
               obj: '',
               objId: '',
               xq: '',
               xqobjId: '',
               jsid: ''
               jurisdiction: '',
               jsid: '',
               address: '',
               jobUnit: '',
               signals: '',
               workjurisdiction: '',
               teamName: '',
               teamId: '',
            },
            rules: {
               user: [{
                  required: true,
                  message: '请输入账号',
                  // 可以单个或者同时写两个触发验证方式
                  /*
                   u-form提供的可直接调用的js验证,
                   具体有哪些可以观看官方文档,这里就不在赘述了。
                  */
                  validator: validateUser,
                  trigger: ['change', 'blur'],
               }],
               }, ],
               pass: [{
                  required: true,
                  message: '请输入密码',
                  message: '请输入6~16位密码',
                  // 可以单个或者同时写两个触发验证方式 
                  trigger: ['change', 'blur'],
               }, {
                  min: 6,
                  message: '密码不能少于6个字',
                  message: '密码不能少于6位',
                  trigger: ['change', 'blur']
               }, {
                  max: 16,
                  message: '密码不能超出16位',
                  trigger: ['change', 'blur']
               }],
               passTwo: [{
@@ -168,7 +253,6 @@
                  trigger: ['change', 'blur'],
               }, {
                  validator: (rule, value, callback) => {
                     console.log(this.form.pass, value)
                     if (this.form.pass == value) {
                        return true
                     } else {
@@ -181,19 +265,37 @@
               }],
               name: [{
                  required: true,
                  message: '请输入姓名',
                  message: '请输入真实姓名',
                  // 可以单个或者同时写两个触发验证方式 
                  trigger: ['change', 'blur'],
               }],
               obj: [{
               phone: [{
                  required: true,
                  message: '请选择组织机构',
                  message: '请输入正确的手机号',
                  // 可以单个或者同时写两个触发验证方式
                  trigger: ['change', 'blur'],
               }, {
                  validator: (rule, value, callback) => {
                     var phone = /^1(3\d|4[5-9]|5[0-35-9]|6[567]|7[0-8]|8\d|9[0-35-9])\d{8}$/;
                     if (phone.test(value)) {
                        this.form.phone = value;
                        return true
                     } else {
                        return callback(new Error('手机号格式不正确'));
                     }
                  },
                  trigger: ['change', 'blur'],
               }],
               jobUnit: [{
                  required: false,
                  message: '请输入单位名称',
                  // 可以单个或者同时写两个触发验证方式 
                  trigger: ['change', 'blur'],
               }],
               xq: [{
                  required: true,
                  message: '请选择辖区',
               address: [{
                  required: false,
                  message: '请选择服务范围',
                  // 可以单个或者同时写两个触发验证方式 
                  trigger: ['change', 'blur'],
               }],
@@ -203,94 +305,121 @@
                  // 可以单个或者同时写两个触发验证方式 
                  trigger: ['change', 'blur'],
               }],
               depts: [{
                  required: true,
                  message: '请输入姓名',
               signals: [{
                  required: false,
                  message: '请输入警号',
                  // 可以单个或者同时写两个触发验证方式 
                  trigger: ['change', 'blur'],
               }],
               carId: [{
                     required: true,
                     message: '请输入身份证',
                     // 可以单个或者同时写两个触发验证方式
                     trigger: ['change', 'blur'],
                  },
                  {
                     validator: (rule, value, callback) => {
                        return this.$u.test.idCard(value);
                     },
                     message: '身份证号码不正确',
                     trigger: ['change', 'blur'],
                  }
               ],
               // phone: [{
               //    required: false,
               //    message: '请输入手机号',
               //    // 可以单个或者同时写两个触发验证方式
               //    trigger: ['change', 'blur'],
               // }, {
               //    validator: (rule, value, callback) => {
               //       return this.$u.test.mobile(value);
               //    },
               //    message: '手机号码不正确',
               //    trigger: ['change', 'blur'],
               // }],
               xq: [{
                  required: false,
                  message: '请选择工作单位',
                  // 可以单个或者同时写两个触发验证方式
                  trigger: ['change', 'blur'],
               }],
               teamName: [{
                  required: true,
                  message: '请选择所属队伍',
                  // 可以单个或者同时写两个触发验证方式
                  trigger: ['change', 'blur'],
               }],
               depts: [{
                  required: true,
                  message: '请输入真实姓名',
                  // 可以单个或者同时写两个触发验证方式
                  trigger: ['change', 'blur'],
               }],
            },
            showGetFace: false,
            faceState: -2,
            facebc: '#fff',
            faceco: '#000',
            faceMsg: ''
            faceMsg: '',
            roleList: [{
               label: '洪城义警',
               value: "1416225906918195201"
            }, {
               label: '民警',
               value: "1417092295132561409"
            }],
            showTeam: false
         };
      },
      onLoad() {
         this.deplxq();
      },
      methods: {
         zc() {
            var that = this;
            this.$refs.uForm.validate(valid => {
               if (valid) {
                  var d = this.form;
                  uni.navigateTo({
                     url: '/pages/registerUser/idphoto?data= ' + encodeURIComponent(JSON.stringify(
                        d))
                  });
               }
            });
         /**
          * 当前选中的队伍
          */
         currentTeam(params) {
            this.form.teamId = params.id
            this.form.teamName = params.name
            this.showTeam = false
         },
         depl() {
         /**
          * 所属队伍的弹窗
          */
         openTeamPopup() {
            var that = this;
            var data = that.form;
            var xq = "";
            if (data.role == "民警") {
               xq = data.xq
            } else if (data.role == "洪城义警") {
               xq = data.jurisdiction
            }
            if (xq == "") {
               uni.showToast({
                  title: "请先选择角色或服务范围",
                  icon: 'none',
                  duration: 2000
               });
               return
            }
            uni.request({
               url: that.$store.state.piAPI + "/blade-system/dept/trees",
               url: that.$store.state.piAPI + "/team/page?current=1&size=999&police=" + xq,
               method: 'get',
               success: (res) => {
                  var routerArr = res.data.data;
                  var arr = that.formatRoutes(routerArr);
                  var list = [];
                  if (that.deptXb != "") {
                     list.push(arr[that.deptXb]);
                     for (var i = 0; i < list.length; i++) {
                        list[i].children.unshift({
                           label: '--请选择--',
                           value: 0,
                           children: []
                        })
                        for (var j = 0; j < list[i].children.length; j++) {
                           list[i].children[j].children.unshift({
                              label: '--请选择--',
                              value: 0,
                           })
                        }
                     }
                     that.listbm = list;
                     that.show = true;
                  } else {
                     uni.showToast({
                        title: '请选择角色',
                        icon: "none",
                        duration: 1000
                     });
                  }
                  that.teamList = res.data.data.records;
                  that.showTeam = true;
               }
            })
         },
         agreement(e) {
            uni.navigateTo({
               url: '/pages/registerUser/agreement?e=' + e
            });
         },
         confirmxq(e) {
            var arr = "";
            var data = [];
            // for (var i = 0; i < e.length; i++) {
            //    if (e[i].value != "0") {
            //       arr += e[i].value + ",";
            //       data.push(e[i]);
            //    }
            // }
            // var obj = arr.substr(0, arr.length - 1);
            // this.form.xqobjId = e[2].value;
            if (this.form.role == "民警") {
               this.form.xq = e[2].label;
               this.form.workjurisdiction = e[2].value;
               this.form.address = "";
               this.form.jurisdiction = "";
            } else {
               this.form.address = e[2].label;
               this.form.jurisdiction = e[2].value;
               this.form.xq = "";
               this.form.workjurisdiction = "";
            }
            console.log(this.form.xqobjId)
         },
         deplxq() {
            var that = this;
@@ -302,50 +431,22 @@
                  var arr = that.formatRoutes(routerArr);
                  var list = [];
                  list.push(arr);
                  for (var i = 0; i < arr.length; i++) {
                     arr[i].children.unshift({
                        label: '--请选择--',
                        value: 0,
                        children: []
                     })
                     for (var j = 0; j < arr[i].children.length; j++) {
                        arr[i].children[j].children.unshift({
                           label: '--请选择--',
                           value: 0,
                        })
                     }
                  }
                  // for (var i = 0; i < arr.length; i++) {
                  //    arr[i].children.unshift({
                  //       label: '--请选择--',
                  //       value: 0,
                  //       children: []
                  //    })
                  //    for (var j = 0; j < arr[i].children.length; j++) {
                  //       arr[i].children[j].children.unshift({
                  //          label: '--请选择--',
                  //          value: 0,
                  //       })
                  //    }
                  // }
                  that.listxq = arr;
                  that.showxq = true;
               }
            })
         },
         confirm(e) {
            var arr = "";
            var data = [];
            for (var i = 0; i < e.length; i++) {
               if (e[i].value != "0") {
                  arr += e[i].value + ",";
                  data.push(e[i]);
               }
            }
            var obj = arr.substr(0, arr.length - 1);
            this.form.obj = data[data.length - 1].label;
            this.form.objId = obj;
         },
         confirmxq(e) {
            var arr = "";
            var data = [];
            for (var i = 0; i < e.length; i++) {
               if (e[i].value != "0") {
                  arr += e[i].value + ",";
                  data.push(e[i]);
               }
            }
            var obj = arr.substr(0, arr.length - 1);
            this.form.xq = data[data.length - 1].label;
            this.form.xqobjId = obj;
            console.log(obj)
         },
         formatRoutes(routerArr) {
            var that = this;
@@ -372,45 +473,178 @@
                  obj = {
                     label: tmp.title,
                     value: tmp.id,
                     children: []
                     // children: []
                  }
               }
               arr.push(obj);
            })
            return arr;
         },
         startRecord() {
            this.flag = true;
            // this.$message.success('开始录制')
            this.$refs.video.startRecord();
         regionClick() {
            let that = this;
            //监听事件
            uni.$on('getLocation', (res) => {
               that.form.xq = res.mapLocationName
               that.form.workjurisdiction = res.regionID
               that.jobLng = res.mapLocationLongitude
               that.jobLat = res.mapLocationLatitude
               //清除监听,不清除会消耗资源
               uni.$off('getLocation');
            })
            uni.navigateTo({
               url: '/pages/registerUser/map?lng=' + that.jobLng + '&lat=' + that.jobLat,
            });
         },
         stopRecord() {
            this.flag = false;
            // this.$message.success('请看控制台视频文件的base64')
            this.$refs.video.stopRecord();
         placeClick() {
            let that = this;
            //监听事件
            uni.$on('getLocation', (res) => {
               that.form.address = res.mapLocationName
               that.form.jurisdiction = res.regionID
               that.liveLng = res.mapLocationLongitude
               that.liveLat = res.mapLocationLatitude
               //清除监听,不清除会消耗资源
               uni.$off('getLocation');
            })
            uni.navigateTo({
               // url: '/pages/registerUser/map'
               url: '/pages/registerUser/map?lng=' + that.liveLng + '&lat=' + that.liveLat
            });
         },
         dataChange(data) {
            console.log(data);
         zc() {
            if (this.userConsent == false) {
               uni.showToast({
                  title: "请先阅读并同意协议",
                  icon: 'none',
                  duration: 2000
               });
               return
            }
            var that = this;
            //判断是否必填警号和工作地点
            if (that.form.role == "民警") {
               that.rules.signals[0].required = true;
               // that.rules.jobUnit[0].required = true;
               that.rules.xq[0].required = true;
               that.rules.address[0].required = false;
            } else {
               that.rules.address[0].required = true;
               that.rules.xq[0].required = false;
            }
            // if (that.jobValue == "有") {
            //    that.rules.jobUnit[0].required = true;
            //    that.rules.xq[0].required = true;
            // }
            that.$refs.uForm.validate(valid => {
               if (valid) {
                  that.registerEvent()
               } else {
                  return
               }
            });
            // that.$refs.uForm.validate(valid => {
            //    if (valid) {
            //       var d = that.form;
            //       uni.navigateTo({
            //          url: '/pages/registerUser/idphoto?data= ' +
            //             encodeURIComponent(JSON.stringify(
            //                d))
            //       });
            //    }
            // });
         },
         objCallback(index) {
            this.form.obj = this.objList[index].text;
         registerEvent() {
            var that = this;
            var d = that.form;
            var url = that.$store.state.piAPI + '/zc/inster',
               data = {
                  // deptid: ,
                  password: d.pass,
                  password2: d.passTwo,
                  phone: d.phone,
                  sex: d.sex == '男' ? 1 : 2,
                  sname: d.name,
                  username: d.user,
                  parentId: d.jsid,
                  cardid: d.carId,
                  // 居住地址
                  address: d.address,
                  // 单位名称
                  jobUnit: d.jobUnit,
                  // 居住辖区
                  jurisdiction: d.jurisdiction,
                  // 工作地址
                  workaddress: d.xq,
                  // 工作辖区
                  workjurisdiction: d.workjurisdiction,
                  signals: d.signals,
                  team: d.teamId
               }
            uni.request({
               url: url,
               method: 'POST',
               data: data,
               success: (result) => {
                  if (result.data.code == 400) {
                     uni.showToast({
                        title: result.data.msg,
                        icon: 'none',
                        duration: 2000
                     });
                     return
                  }
                  if (result.data.code == 200) {
                     uni.showToast({
                        title: '注册成功,请等待审核',
                        icon: 'none',
                        duration: 2000
                     });
                     setTimeout(function() {
                        uni.navigateTo({
                           url: '/pages/loging/loging'
                        })
                     }, 2000);
                  } else {
                     uni.showToast({
                        title: '注册失败,请确认信息后重试',
                        icon: 'none',
                        duration: 2000
                     });
                  }
               }
            });
         },
         depl() {
            this.show = true;
         },
         // 选中任一radio时,由radio-group触发
         radioGroupChange(e) {
            this.xqShow = true;
            if (e == "群众") {
               this.xqShow = false;
               this.form.jsid = '1416225849858883585';
               this.form.objId = '1424616967934959617,1424617046523633666';
            } else if (e == "民警") {
               this.form.jsid = '1417092295132561409';
               this.deptXb = "0";
            } else if (e == "群防队伍") {
               this.deptXb = "1";
               this.form.jsid = '1372092102682521602';
            } else if (e == "保安") {
               this.form.jsid = '';
            }
            this.form.role = e[0].label
            this.form.jsid = e[0].value
            this.show = false;
         }
      },
      onReady() {
@@ -418,7 +652,6 @@
      },
      watch: {
         faceState() {
            // console.log(this.faceState);
            if (this.faceState == -1) {
               this.facebc = '#ff7f29';
               this.faceco = '#fff';
@@ -433,6 +666,7 @@
               this.faceMsg = '(服务连接失败!)';
            }
         }
      }
   };
</script>
@@ -483,4 +717,40 @@
   .registerUser {
      padding: 0 1.2rem;
   }
   .agree {
      margin-top: 28rpx;
      font-size: 22rpx;
      font-family: Adobe Heiti Std;
      font-weight: normal;
      color: #cacaca;
      line-height: 34rpx;
      text-align: center;
      .a {
         margin: 0 10rpx;
         color: #103289;
      }
   }
   .team-popup {
      height: 100%;
      overflow: hidden;
      .title {
         font-size: 30rpx;
         font-weight: bold;
         text-align: center;
         border-bottom: 1rpx solid #ccc;
         height: 88rpx;
         line-height: 88rpx;
      }
      view {
         padding: 0 20rpx;
         height: 72rpx;
         line-height: 72rpx;
         vertical-align: middle;
      }
   }
</style>