xuxueyang
2024-07-30 e4233b5c4e123c4b79a38d0a9b0c8b60631e1683
pages/user/address/address.vue
@@ -1,5 +1,5 @@
<template>
  <!-- 收获地址列表 -->
   <!-- 收货地址列表 -->
  <view class="p15 container-address">
    <no-data v-if="!list||list.length==0" style="width: 100%;"></no-data>
@@ -12,8 +12,12 @@
            <view class="tel">{{ item.tel || '-' }}</view>
          </view>
          <view class="address">
                  {{ item['province'] || '' }}{{ item['city'] && ('/' + item['city']) || '' }}{{
                    item['region'] && ('/' + item['region']) || ''
                  }}
               </view>
               <view class="address">
            {{ item.address }}
          </view>
        </view>
        <!-- <view class="h-line"></view> -->
@@ -49,15 +53,8 @@
    <view style="height: 92rpx;width: 690rpx;">
      &nbsp;
    </view>
    <view class="button-green button-fixed-bottom" style="width: 690rpx;line-height: 92rpx;height: 92rpx;" @click=" ()=>{
            delete this.submitForm.id
            this.submitForm['name'] = ''
            this.submitForm['tel'] = ''
            this.submitForm['tel'] = ''
            this.submitForm['area'] = ''
            openAddressForm()
         }">添加收货地址
      <view class="button-green button-fixed-bottom" style="width: 690rpx;line-height: 92rpx;height: 92rpx;"
         @click="addAddress">添加收货地址
    </view>
    <uni-popup ref="popup_form" type="top" :mask-click="false">
@@ -78,7 +75,15 @@
          </view>
          <view class="form-item">
            <view class="form-item-label require">
              收获地址
                     手机号
                  </view>
                  <view class="form-item-value">
                     <input v-model="submitForm.tel" placeholder="请输入收货人手机号" class="form-input"></input>
                  </view>
               </view>
               <view class="form-item">
                  <view class="form-item-label require">
                     收货地址
            </view>
            <view class="m-l-a m-r-0 flex " :class="[!dto['province']?'desc-gray':'']">
              <uni-data-picker :area="true" @change="(e)=>{PickArea(submitForm,e)}" placeholder=""
@@ -90,10 +95,7 @@
              <u-icon class="m-l-a" name="arrow-right"></u-icon>
            </view>
            <!--            <view class="form-item-value" @click="chooseLocation">-->
            <!--              <input v-model="submitForm.room" placeholder="请选择收获地址" disabled class="form-input"></input>-->
            <!--              &lt;!&ndash;  点击定位 &ndash;&gt;-->
            <!--            </view>-->
          </view>
          <view class="form-item">
            <view class="form-item-label require">
@@ -159,6 +161,17 @@
    };
  },
  methods: {
         addAddress() {
            delete this.submitForm.id
            this.submitForm['name'] = ''
            this.submitForm['tel'] = ''
            this.submitForm['address'] = ''
            this.submitForm['province'] = ''
            this.submitForm['city'] = ''
            this.submitForm['region'] = ''
            this.submitForm['isDefault'] = false
            this.openAddressForm()
         },
    PickArea(item, e) {
      console.log('PickArea', item, e)
      if (e.detail.value) {
@@ -249,7 +262,8 @@
          this.$message.showLoading()
          var {
            code
          } = await this.$http.request('post', '/api/address/set/default/'+item.id, {
                  } = await this.$http.request('post', '/api/address/set/default/' + item
                     .id, {
           data:{
              id:item.id
           },
@@ -271,7 +285,7 @@
          }
        }, err => {
          this.$nextTick(() => {
            this.list[index].defaulted = false
                     this.list[index].isDefault = false
            this.$forceUpdate()
            console.log('err', err, this.list[index])
          })
@@ -281,7 +295,7 @@
      })
    },
    async selectAddress(item) {
      await this.$message.confirm('确定选择此地址作为收获地址吗')
            await this.$message.confirm('确定选择此地址作为收货地址吗')
      //携带,然后返回
      this.$store.commit('setDefaultAddress', {
        ...item
@@ -297,6 +311,10 @@
      this.$message.hideLoading()
      if (code === 0) {
        this.$message.showToast('删除成功')
               if (item.isDefault) {
                  //要清空地址了
                  this.$store.commit('setDefaultAddress', {})
               }
        setTimeout(() => {
          this.page.current = 1
          this.getList()
@@ -354,10 +372,10 @@
      if (code === 0) {
        this.$refs.popup_form.close()
        this.$message.showToast(this.submitForm.id ? '修改成功' : '新增成功')
               let tmp = this
        setTimeout(() => {
          this.page.current = 1
          this.getList()
                  tmp.page.current = 1
                  tmp.refreshList()
        }, 300)
      }
    },