绿满眶商城微信小程序-uniapp
peng
2025-09-16 577042a77ff72607e2cd5de3a06f33a1c9d3f703
pages/mine/address/add.vue
@@ -12,7 +12,7 @@
        </u-form-item>
        <u-form-item label="手机号码" label-width="130" prop="mobile">
          <u-input v-model="form.mobile" type="number" maxlength="11" placeholder="请输入收货人手机号码" />
          <u-input v-model="form.mobile" type="number"   maxlength="15" placeholder="请输入收货人手机号码" />
        </u-form-item>
        <u-form-item label="所在区域" label-width="130" prop="___path">
          <div  @click="showPicker" >
@@ -55,6 +55,11 @@
    // 判断当前系统权限定位是否开启
  },
  methods: {
    changePhone(e) {
      console.log('-------------------->手机号码修改', e);
      // 去除空格
      this.form.mobile = this.form.mobile.replace(/\s/g, '');
    },
    // 关闭地图
    closeMap() {
      this.mapFlag = false;
@@ -145,6 +150,7 @@
    // 保存当前 地址
    save() {
     this.$refs.uForm.setRules(this.rules);
      this.$refs.uForm.validate((valid) => {
        if (valid) {
          let pages = getCurrentPages(); //获取页面栈
@@ -287,8 +293,16 @@
  },
  // 初始化rules必须要在onReady生命周期,因为onLoad生命周期组件可能尚未创建完毕
  onReady() {
    this.$refs.uForm.setRules(this.rules);
    // this.$refs.uForm.setRules(this.rules);
  },
  watch:{
    'form.mobile': function(newVal, oldVal) {
      // 当手机号变化时,自动去除空格
      if (newVal && typeof newVal === 'string') {
        this.form.mobile = newVal.replace(/\s/g, '');
      }
    }
  }
};
</script>
<style scoped lang="scss">