dialog.vue 2.88 KB
<template>
  <el-dialog
    title="编辑收货地址"
    center
    append-to-body
    :visible.sync="dialogObj.show"
    width="800px">
    <vue-address :province="dialogObj.province" :city="dialogObj.city" :district="dialogObj.district" :detail="dialogObj.detail" :mobile="dialogObj.receive_mobile" :name="dialogObj.receive_name" @change="handlerAddressChange">
    </vue-address>
    <div slot="footer" class="dialog-footer">
      <el-button @click="dialogObj.show = false">取 消</el-button>
      <el-button type="primary" @click="saveAddress">保 存</el-button>
    </div>
  </el-dialog>
</template>

<script>
//  import {getCategoryApi} from "../../service/api";
  import vueAddress from '../framework/address-picker/Address'
import AddressArray from '../framework/address-picker/addr'
  export default {
    name: "dialogObj",
    props:[
      'dialogObj'
    ],
    data(){
      return{
      }
    },
    methods:{
      handlerAddressChange (val) {
        if(!val.province || !val.city || !val.district){
          return
        }
        this.dialogObj.detail = val.detail;
        this.dialogObj.province = val.province;
        this.dialogObj.city = val.city;
        this.dialogObj.district = val.district;
        this.dialogObj.receive_mobile = val.mobile;
        this.dialogObj.receive_name = val.name;
        let provinceObj = AddressArray.filter((item) => {
          return item.value === val.province
        })
        let cityObj = provinceObj[0].children.filter((city) => {
          return city.value === val.city
        })
        let districtObj = cityObj[0].children.filter((district) => {
          return district.value === val.district
        })
        this.dialogObj.province_name = provinceObj[0].label;
        this.dialogObj.city_name = cityObj[0].label;
        this.dialogObj.district_name = districtObj.length > 0 ? districtObj[0].label : '';
      },
      saveAddress () {
        let json = {
          province_id: this.dialogObj.province,
          province_name: this.dialogObj.province_name,
          city_id: this.dialogObj.city,
          city: this.dialogObj.city_name,
          area: this.dialogObj.district_name,
          area_id: this.dialogObj.district,
          address: this.dialogObj.detail,
          receive_name: this.dialogObj.receive_name,
          receive_mobile: this.dialogObj.receive_mobile
        };
        this.$emit("reflash");
//        Service.updateUserAddress(json, this.dialogObj.user_id, this.dialogObj.pay_id).then(res=>{
//          if(res.data.result=='success'){
//            this.$message.success(res.data.message);
//            this.$emit("reflash");
//          }else{
//            this.$message.error(res.data.message);
//          }
//        })
      },
    },
    components:{
      vueAddress
    },
    mounted(){
    }
  }
</script>

<style scoped lang="less">
  .dialog-footer{
    display: block;
    text-align: center;
  }
</style>