index.js
4.39 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
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
import NP from 'number-precision'
import cartApi from '~/api/module/cart.js'
Component({
/**
* 组件的属性列表
*/
properties: {
show: Boolean,
address: Array,
type: String,
goods: {
type: Object,
observer: function(n) {
this.setDefaultSku(n)
}
},
defaultAddress: Object,
defaultAds: String,
staffShop:Boolean,
canPay:Boolean
},
data: {
currentIndex: 0,
goodsNumber: 1,
showJfModal:false,
jfCount:0
},
/**
* 组件的方法列表
*/
methods: {
setDefaultSku(skuData) {
let { specificationList } = skuData
let [specificationDetailList] = skuData.specificationDetailList
console.log(specificationDetailList, specificationList)
let defaultGoods = specificationDetailList.specificationData.split('&')
specificationList.map(e => {
defaultGoods.map(i => {
let [key, value] = i.split('-')
if (key == e.specificationName) {
e.specificationValueList.map(c => {
if (c.specificationValue == value) c.active = true
})
}
})
})
specificationDetailList.retailPrice = specificationDetailList.retailPrice
this.setData({
goods: skuData
})
},
computeJf(num) {
let {goods,jfCount,staffShop} = this.data
if(!staffShop)return
jfCount = NP.times(goods.redeemPoints,num)
this.setData({
jfCount
})
},
cancel() {
this.setData({
show: false
})
this.triggerEvent('cancelSku')
},
changeCount(e) {
this.triggerEvent('getCount', e.detail)
this.computeJf(e.detail)
this.setData({
goodsNumber: e.detail
})
},
toShowAddressModal() {
this.setData({
showAddress: true
})
},
getAddress(e) {
this.setData({
defaultAds: e.detail.contactAddress,
defaultAddress: e.detail.defaultAddress
})
this.triggerEvent('sameAddress', e.detail)
},
intRemain(e) {
this.setData({
remain: e.detail.value
})
},
choose(e) {
let { ind, index } = e.currentTarget.dataset
let {
goods: { specificationList, specificationDetailList }
} = this.data
let activeList = []
if (specificationList[index].specificationValueList[ind].active) return
specificationList[index].specificationValueList.map(i => (i.active = false))
specificationList[index].specificationValueList[ind].active = true
specificationList.map(i => {
i.specificationValueList.map(c => {
if (c.active) activeList.push(`${i.specificationName}-${c.specificationValue}`)
})
})
let specificationData = activeList.join('&')
this.setData({
[`goods.specificationList[${index}]`]: specificationList[index]
})
this.setData({
goodsNumber: 1
})
const thisPage = wx.p.router.getPageInstance()
thisPage.setData({
activeSku: specificationData
})
},
toCreatedOrder() {
const userInfo = wx.p.storage.get('userInfo')
const { remain, goods, goodsNumber, defaultAddress,staffShop, clickType } = this.data
if(!defaultAddress.receiveName){
return wx.$api.showToast('请选择收货地址')
}
const params = {
receiveName: defaultAddress.receiveName,
receiveMobile: defaultAddress.receiveMobile,
provinceId: defaultAddress.provinceId,
provinceName: defaultAddress.provinceName,
cityId: defaultAddress.cityId,
cityName: defaultAddress.cityName,
countyId: defaultAddress.countyId,
countyName: defaultAddress.countyName,
address: defaultAddress.address,
customerOpenId:staffShop?userStorage.weChatOpenId:userInfo.openId,
buyerMsg: remain,
orderGoodsList: [{
goodsSkuCode: goods.goodsSkuCode,
goodsSkuName: goods.goodsSkuName,
sellQty: goodsNumber,
}],
}
if (clickType == 'join') {
// 添加购物车
cartApi.addToCart().then(res => {
let { code, message } = res
if (code == 0) {
this.closeSku()
wx.p.wxApi.showToast('加入购物车成功')
} else {
wx.p.wxApi.showToast(message)
}
})
} else {
wx.p.router.go('/pageIndex/pages/confirmOrder/index')
}
}
}
})