address_edit.vue 4.97 KB
Newer Older
1 2 3 4 5
<template>
  <view>
    <dHeader :title="$lang.lang.addressInfo.editInfo"></dHeader>
    <view class="container">
      <uni-forms ref="form" :model="form" :label-width="80" :rules="rules">
chenwei's avatar
chenwei committed
6 7 8 9 10
        <uni-forms-item
          :label="$lang.lang.addressInfo.consignee"
          required
          name="name"
        >
11 12 13 14
          <uni-easyinput
            class="input"
            :trim="true"
            :inputBorder="false"
15
            v-model="form.name"
16 17 18
            :placeholder="$lang.lang.notices.consignee"
          />
        </uni-forms-item>
chenwei's avatar
chenwei committed
19 20 21 22 23
        <uni-forms-item
          :label="$lang.lang.addressInfo.phone"
          required
          name="phone"
        >
24 25 26 27 28 29 30 31 32 33 34 35 36 37 38
          <view class="phone-box">
            <view class="phone-code">+86</view>
            <uni-easyinput
              class="input"
              :trim="true"
              :inputBorder="false"
              v-model.trim="form.phone"
              :placeholder="$lang.lang.notices.phone"
            />
          </view>
        </uni-forms-item>
        <uni-forms-item
          class="item"
          :label="$lang.lang.addressInfo.fullAddress"
          required
39
          name="address"
40 41 42 43 44 45 46 47 48
        >
          <view class="textarea-box">
            <uni-easyinput
              class="input"
              type="textarea"
              :trim="true"
              autoHeight
              :inputBorder="false"
              :maxlength="100"
49
              v-model.trim="form.address"
50 51 52
              :placeholder="$lang.lang.notices.fullAddress"
            >
            </uni-easyinput>
chenwei's avatar
chenwei committed
53 54 55
            <view class="placeholder">{{
              $lang.lang.notices.fullAddressLength
            }}</view>
56 57
          </view>
        </uni-forms-item>
chenwei's avatar
chenwei committed
58 59 60
        <view class="btn" @click="saveAddress">{{
          $lang.lang.notices.saveAddress
        }}</view>
61 62 63 64 65 66
      </uni-forms>
    </view>
  </view>
</template>

<script>
chenwei's avatar
chenwei committed
67
import dHeader from "../../components/dHeader/index.vue";
68 69
export default {
  components: {
chenwei's avatar
chenwei committed
70
    dHeader,
71 72 73 74
  },
  data() {
    return {
      form: {
chenwei's avatar
chenwei committed
75 76 77 78 79
        name: "",
        phone: "",
        address: "",
      },
    };
80
  },
81
  onLoad(route) {
chenwei's avatar
chenwei committed
82
    this.getAddress(route.id);
83
  },
84 85 86
  computed: {
    rules() {
      return {
87
        name: {
chenwei's avatar
chenwei committed
88 89 90
          rules: [
            { required: true, errorMessage: this.$lang.lang.notices.consignee },
          ],
91 92
        },
        phone: {
93 94 95 96
          rules: [
            { required: true, errorMessage: this.$lang.lang.notices.phone },
            {
              validateFunction: (rule, value) => /^\d+$/.test(value),
chenwei's avatar
chenwei committed
97 98 99
              errorMessage: this.$lang.lang.notices.nophone,
            },
          ],
100
        },
101
        address: {
102
          rules: [
chenwei's avatar
chenwei committed
103 104 105 106 107 108 109 110 111 112 113 114
            {
              required: true,
              errorMessage: this.$lang.lang.notices.fullAddress,
            },
            {
              maxLength: 100,
              errorMessage: this.$lang.lang.notices.fullAddressLength,
            },
          ],
        },
      };
    },
115 116 117 118
  },
  methods: {
    saveAddress() {
      // console.log(this.form)
119 120 121 122
      this.$refs.form.validate().then(async (res) => {
        if (res) {
          try {
            const { code } = await this.$request.post(
chenwei's avatar
chenwei committed
123
              "/app-api/member/user-address/update",
124
              this.form
chenwei's avatar
chenwei committed
125
            );
126
            if (code == 0) {
chenwei's avatar
chenwei committed
127 128 129
              this.$route.params.addressId = "00000";
              uni.$emit("refreshPreviousPage", "show");
              uni.navigateBack();
130 131 132
            }
          } catch (err) {}
        }
chenwei's avatar
chenwei committed
133
      });
134 135 136 137
    },
    // 获取地址信息 回显
    async getAddress(id) {
      try {
chenwei's avatar
chenwei committed
138 139 140 141
        const { code, data } = await this.$request.get(
          "/app-api/member/user-address/get",
          { id }
        );
142
        if (code == 0 && data) {
chenwei's avatar
chenwei committed
143
          this.form = data;
144 145
        }
      } catch (err) {}
chenwei's avatar
chenwei committed
146 147 148
    },
  },
};
149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224
</script>

<style>
page {
  padding-top: 190upx;
}
.uni-forms {
  padding: 0 48upx;
  box-sizing: border-box;
}
.uni-forms-item {
  padding: 0 24upx;
  margin-bottom: 44upx;
  width: 100%;
  align-items: center;
  min-height: 80upx;
  box-sizing: border-box;
  border-radius: 12upx;
  background-color: #fff;
}
.item {
  align-items: start;
}
.input {
  font-size: 24upx;
}
.textarea-box {
  padding: 0 0 30upx;
}
.placeholder {
  position: absolute;
  bottom: 8upx;
  right: 0;
  font-size: 24upx;
  color: #b3b3b3;
}
.phone-box {
  display: flex;
  align-items: center;
}
.phone-code {
  margin-right: 10upx;
  padding-right: 10upx;
  border-right: 1px solid #e6e6e6;
  font-size: 24upx;
  color: #000;
}
.btn {
  width: 100%;
  height: 80upx;
  line-height: 80upx;
  text-align: center;
  background-color: #3d6ef6;
  color: #fff;
  border-radius: 80upx;
  margin-top: 40upx;
}

::v-deep .uni-forms-item__label {
  font-size: 28upx !important;
  font-weight: 500 !important;
  color: #000;
}
::v-deep .uni-easyinput__content-input {
  padding-left: 0 !important;
}

::v-deep .uni-easyinput__content-textarea {
  height: 100upx;
  min-height: 100upx;
  /* #ifndef APP-NVUE */
  min-height: 100upx;
  width: auto;
  /* #endif */
}
</style>