index.js
2.27 KB
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
import mineApi from '~/api/module/mine.js'
Component({
/**
* 组件的属性列表
*/
properties: {
defaultAddress: Object,
address:Array,
show: {
type: Boolean,
observer: function (val, o) {
if (val && this.properties.address.length) {
console.log(this.properties.defaultAddress?.id)
this.properties.address.forEach((item, index) => {
item.active = false
if (item.id == this.properties.defaultAddress?.id) {
item.active = true
}
})
this.setData({
address: this.properties.address
})
}
}
},
staff:Boolean
},
/**
* 组件的初始数据
*/
data: {
addressList: []
},
/**
* 组件的方法列表
*/
methods: {
back() {
this.cancel()
},
addNew (e) {
let { url } = e.currentTarget.dataset
wx.p.router.go(url,{
platform:true,
staff:this.data.staff,
notIntercept:this.data.staff
})
},
// 确认
confirm(e) {
let { address } = this.data
const item = address?.find(val => val.active == true)
if (!item || !Object.keys(item)?.length) return wx.p.wxApi.showToast('请选择收货地址')
const contactAddress = item.provinceName+item.cityName+item.countyName+item.address
this.triggerEvent('getAddress', {defaultAddress:item,contactAddress})
this.cancel()
},
cancel() {
this.setData({
show: false
})
this.triggerEvent('cancel')
},
toSelect(e) {
const { item } = e.currentTarget.dataset
let { address } = this.data
address?.forEach(val => {
val.active = false
if (item.id == val.id) val.active = true
})
this.setData({address})
},
addressList() {
mineApi.getCustomerAddressList().then(data => {
// 新增地址后默认将新增的选中
data?.forEach((val, index) => {
val.active = false
if (index == 0) val.active = true
})
this.setData({
address: data
})
wx.hideLoading()
})
}
},
lifetimes: {
attached: function () {
wx.p.eventbus.on('REFRESH_PLATFORM_ADDRESS',()=>{
this.addressList()
})
},
},
})