zengh
2022-06-08 60970c9cd58789e7faaca4bf45175400024f11b2
pages/registerUser/registerUser.vue
@@ -14,35 +14,19 @@
            :required="true">
            <u-input v-model="form.signals" placeholder="请输入警号" />
         </u-form-item>
         <!-- <u-form-item label="工作单位" left-icon="home-fill" label-width="200" :required="true">
            <u-radio-group v-model="jobValue">
               <u-radio v-for="(item, index) in jobList" :key="index" :name="item.name" :disabled="item.disabled">
                  {{item.name}}
               </u-radio>
            </u-radio-group>
         </u-form-item> -->
         <u-form-item v-show="form.role == '民警'" label="单位名称" prop="jobUnit" label-width="200" left-icon="home"
         <u-form-item v-show="form.role == '民警'" label="工作单位" prop="xq" left-icon="map" label-width="200"
            :required="true">
            <u-input v-model="form.jobUnit" placeholder="请输入单位名称" />
            <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="xq" left-icon="map-fill" label-width="200"
         <u-form-item v-show="form.role != '民警'" label="服务范围" prop="address" left-icon="map" label-width="200"
            :required="true">
            <u-field :disabled="true" style="width: 100%;" label-width="0" v-model="form.xq" type="textarea"
               placeholder="请选择工作地点" :fixed="true">
               <u-icon @click="regionClick" name="map-fill" slot="right" size="44" label="定位" label-pos="bottom"
                  label-color="#103289" color="#103289"></u-icon>
            </u-field>
         </u-form-item>
         <u-form-item v-show="form.role != '民警'" label="居住地" prop="address" left-icon="map" label-width="200" :required="true">
            <u-field :disabled="true" style="width: 100%;" label-width="0" v-model="form.address" type="textarea"
               placeholder="请选择居住地" :fixed="true">
               <u-icon @click="placeClick" name="map-fill" slot="right" size="44" label="定位" label-pos="bottom"
                  label-color="#103289" color="#103289"></u-icon>
            </u-field>
            <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="性别" label-width="200" left-icon="man">
@@ -285,7 +269,7 @@
               }],
               address: [{
                  required: false,
                  message: '请选择居住地',
                  message: '请选择服务范围',
                  // 可以单个或者同时写两个触发验证方式 
                  trigger: ['change', 'blur'],
               }],
@@ -303,7 +287,7 @@
               }],
               xq: [{
                  required: false,
                  message: '请选择工作地点',
                  message: '请选择工作单位',
                  // 可以单个或者同时写两个触发验证方式 
                  trigger: ['change', 'blur'],
               }],
@@ -353,11 +337,101 @@
            ],
         };
      },
      onLoad() {
         this.deplxq();
      },
      methods: {
         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;
            uni.request({
               url: that.$store.state.piAPI + "/jurisdiction/tree",
               method: 'get',
               success: (res) => {
                  var routerArr = res.data.data;
                  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,
                  //       })
                  //    }
                  // }
                  that.listxq = arr;
               }
            })
         },
         formatRoutes(routerArr) {
            var that = this;
            const arr = [];
            let obj = {};
            routerArr.forEach(router => {
               const tmp = {
                  ...router
               };
               if (tmp.hasChildren == true) {
                  tmp.children = that.formatRoutes(tmp.children);
                  const {
                     id,
                     title
                  } = router;
                  obj = {
                     label: tmp.title,
                     value: tmp.id,
                     children: tmp.children
                  }
               } else if (tmp.hasChildren == false || typeof(tmp.hasChildren) == 'undefined') {
                  obj = {
                     label: tmp.title,
                     value: tmp.id,
                     // children: []
                  }
               }
               arr.push(obj);
            })
            return arr;
         },
         regionClick() {
            let that = this;
@@ -409,11 +483,12 @@
            //判断是否必填警号和工作地点
            if (that.form.role == "民警") {
               that.rules.signals[0].required = true;
               that.rules.jobUnit[0].required = true;
               // that.rules.jobUnit[0].required = true;
               that.rules.xq[0].required = true;
               that.rules.address[0].required = false;
            }else{
            } else {
               that.rules.address[0].required = true;
               that.rules.xq[0].required = false;
            }
            // if (that.jobValue == "有") {
@@ -429,39 +504,16 @@
               }
            });
            uni.request({
               url: that.$store.state.piAPI + '/zc/inspect',
               method: 'GET',
               data: {
                  username: this.form.user
               },
               success: (res) => {
                  if (res.data.code == 400) {
                     uni.showToast({
                        title: res.data.msg,
                        icon: 'none',
                        duration: 2000
                     });
                     return
                  }
                  // that.$refs.uForm.validate(valid => {
                  //    if (valid) {
                  //       var d = that.form;
                  //       uni.navigateTo({
                  //          url: '/pages/registerUser/idphoto?data= ' +
                  //             encodeURIComponent(JSON.stringify(
                  //                d))
                  //       });
                  //    }
                  // });
               }
            });
            // that.$refs.uForm.validate(valid => {
            //    if (valid) {
            //       var d = that.form;
            //       uni.navigateTo({
            //          url: '/pages/registerUser/idphoto?data= ' +
            //             encodeURIComponent(JSON.stringify(
            //                d))
            //       });
            //    }
            // });
         },
@@ -496,16 +548,39 @@
               method: 'POST',
               data: data,
               success: (result) => {
                  uni.showToast({
                     title: '注册成功,请等待审核',
                     icon: 'none',
                     duration: 2000
                  });
                  setTimeout(function() {
                     uni.navigateTo({
                        url: '/pages/loging/loging'
                     })
                  }, 2000);
                  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
                     });
                  }
               }
            });