index.js
2.13 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
import { IMG_URL } from '~/config';
import { env } from '~/api/env/index'
import { MERCHANT_STATIC_LIST} from '~/utils/constants'
Component({
properties: {
show:{
type:Boolean,
observer(n) {
if (n) this.getMerchantList()
}
}
},
data: {
storeList: []
},
methods: {
closeModal() {
this.setData({
show: false
})
},
// 检查是否是首次
checkFirst() {
const FIRST = wx.p.storage.get('first_enter_miniprograme')
if (FIRST) {
this.setData({
show: false
})
return true
}
},
// 获取门店信息
async getMerchantList() {
const have_enter = this.checkFirst()
if(have_enter)return
// 获取mock配置门店
const MOCKDATA = wx.p.storage.get("mock_data");
let MerchantList = MERCHANT_STATIC_LIST[env]
if (MOCKDATA && MOCKDATA.add_wuye_merchant) {
const ADD_MERCHANT_LIST = MOCKDATA.add_wuye_merchant[env]
if (ADD_MERCHANT_LIST && ADD_MERCHANT_LIST.length) {
MerchantList = [...MerchantList, ...ADD_MERCHANT_LIST]
}
}
let storeList = [], index = 0
storeList = await this.getMerchantListData(MerchantList)
storeList.forEach((ele, i) => {
ele.merchantId = ele.merchantNo
if (this.defaultMerchant == ele.merchantId) {
index = i
}
})
this.setData({
storeList,
show:true
})
},
// 选择门店
toSelect(e) {
const { item } = e.currentTarget.dataset
wx.p.storage.set('merchant_info', {
merchantId: item.merchantNo,
})
wx.$merchant_id = item.merchantNo
wx.p.storage.set('first_enter_merchantId', item.merchantNo)
wx.p.storage.set('first_enter_miniprograme', true)
this.triggerEvent('freshMerchant')
wx.p.eventbus.emit('STORE')
this.setData({
show: false
})
},
// 获取门店列表
async getMerchantListData(merchantIdList) {
const res = await wx.p.api.shopmallApi.getStoreList({ merchantIdList })
return res || []
},
},
lifetimes: {
attached() {
}
}
})