1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
<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 {editAddressApi} 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{
}
},
watch:{
'dialogObj.show':{
deep:true,
handler:function(){
console.log(this.dialogObj)
}
}
},
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.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 : cityObj[0].children[0].label;
this.dialogObj.district = districtObj.length > 0 ? districtObj[0].value : cityObj[0].children[0].value;
},
saveAddress () {
this.$confirm('确定保存?', '提示', {
confirmButtonText: '确定',
cancelButtonText: '取消',
type: 'warning'
}).then(()=>{
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
};
editAddressApi(this.dialogObj.id,json).then(res=>{
this.$message({
type: 'success',
message: '修改成功'
});
this.dialogObj.show=false;
this.$emit("reflash");
});
})
},
},
components:{
vueAddress
},
mounted(){
console.log(this.dialogObj)
}
}
</script>
<style scoped lang="less">
.dialog-footer{
display: block;
text-align: center;
}
</style>