Goods.js
7.24 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
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
// packageEquity/pages/carQuotation/components/skuGoods/Goods.js
import { getSystemInfoSync } from '~/utils/systemInfo'
import { normalizeMarketingMetaOnItem } from '~/utils/marketingFlag'
import { seedMarketingActivitySellPrice } from '../../utils/orderSubOrderExtras.js'
Component({
/**
* 组件的属性列表
*/
properties: {
//1:精品升级 0 会员权益
sceneType: {
type: String
},
show: {
type: Boolean,
observer: function (n) {}
},
goodsData: {
type: Object,
observer: function (n) {
console.log(n, '999', this.data.chooseGoodsList)
this.setGoodsActive()
}
},
chooseGoodsList: {
type: Array,
observer: function (n) {
// this.setGoodsActive();
}
}
},
observers: {
show: function (value, old) {
console.log(value, old, 'show')
this.triggerEvent('visibilityChange', { show: value })
}
},
/**
* 组件的初始数据
*/
data: {},
/**
* 组件的方法列表
*/
methods: {
setGoodsActive() {
//同步数量
let { chooseGoodsList, goodsData } = this.data
if (
goodsData &&
goodsData.multipleSpecificationsGoods &&
goodsData.multipleSpecificationsGoods.skuGoodsList
) {
goodsData.multipleSpecificationsGoods.skuGoodsList.forEach(c => {
if (chooseGoodsList && chooseGoodsList.length > 0) {
chooseGoodsList.map(x => {
if (x.goodsFlag == 2) {
if (
x.multipleSpecificationsGoods.goods &&
x.multipleSpecificationsGoods.goods.goodsId == c.goodsId
) {
c.count = x.count || 0
}
}
})
}
})
this.setData({
goodsData
})
}
},
hidePopup() {
this.setData({
show: false
})
this.triggerEvent('cancel')
},
choose(e) {
let { item, index } = e.currentTarget.dataset
let { goodsData } = this.data
let { active } = item
//全部取消选择
goodsData.multipleSpecificationsGoods.skuGoodsList.forEach(
item => (item.active = false)
)
goodsData.multipleSpecificationsGoods.skuGoodsList[index].active = !active
this.setData({
goodsData
})
},
input(e) {
let { index } = e.currentTarget.dataset
let { goodsData } = this.data
console.log(e)
let { value } = e.detail
if (value < 1) value = 1
if (value > 999) value = 999
goodsData.multipleSpecificationsGoods.skuGoodsList[index].count = value
// this.setData({
// // goodsData
// })
},
blur() {
this.setData({
goodsData: this.data.goodsData
})
},
getChooseList() {
let { chooseGoodsList, goodsData } = this.data
console.log(chooseGoodsList, goodsData)
let chooseList = [],
selectList = []
goodsData.multipleSpecificationsGoods.skuGoodsList.forEach(c => {
if (c.active) {
const specRoot = goodsData.multipleSpecificationsGoods || {}
const marketingFlag =
goodsData.marketingFlag ?? specRoot.marketingFlag ?? c.marketingFlag ?? 0
const activityId =
goodsData.activityId ?? specRoot.activityId ?? c.activityId ?? null
//构建多规格需要的数据格式
selectList.push({
active: true,
count: c.count,
goods: null,
goodsFlag: 2,
isFlag: true,
marketingFlag: marketingFlag == 1 || marketingFlag === '1' ? 1 : 0,
activityId,
multipleSpecificationsGoods: {
baseGoodsName: specRoot.baseGoodsName,
id: specRoot.id,
marketingFlag:
specRoot.marketingFlag ?? (marketingFlag == 1 || marketingFlag === '1' ? 1 : 0),
activityId,
specificationGoodsMap: specRoot.specificationGoodsMap,
specificationList: specRoot.specificationList,
goods: {
...c,
marketingFlag: c.marketingFlag ?? specRoot.marketingFlag ?? marketingFlag,
activityId: c.activityId ?? specRoot.activityId ?? activityId
}
}
})
}
})
console.log(selectList, 'selectList')
//精品升级需要处理数量,会员权益不需要
if (selectList.length) {
selectList.forEach(c => {
if (!c.count) c.count = 1
let price = c.multipleSpecificationsGoods.goods.sellPrice || 0
// 会员权益
if (this.data.sceneType == '0') {
price = Math.round(price * 100)
}
c.multipleSpecificationsGoods.goods.price = price
seedMarketingActivitySellPrice(c.multipleSpecificationsGoods.goods)
if (chooseGoodsList.length > 0) {
chooseGoodsList.map(x => {
if (x.goodsFlag == 2 && x.multipleSpecificationsGoods) {
console.log(
x.multipleSpecificationsGoods.goods &&
x.multipleSpecificationsGoods.goods.goodsId ==
c.multipleSpecificationsGoods.goods.goodsId,
'x.multipleSpecificationsGoods.goods && x.multipleSpecificationsGoods.goods.goodsId == c.multipleSpecificationsGoods.goods.goodsId'
)
if (
x.multipleSpecificationsGoods.goods &&
x.multipleSpecificationsGoods.goods.goodsId ==
c.multipleSpecificationsGoods.goods.goodsId
) {
console.log(c)
//精品升级需要处理数量,会员权益不需要
x.count = c.multipleSpecificationsGoods.goods.count || 0
}
}
})
let arr = chooseGoodsList.filter(
item =>
item.multipleSpecificationsGoods &&
item.multipleSpecificationsGoods.goods
)
console.log(arr)
selectList.forEach(oldval => {
if (oldval.multipleSpecificationsGoods) {
if (
!arr.some(
newVal =>
newVal.multipleSpecificationsGoods.goods.goodsId ==
oldval.multipleSpecificationsGoods.goods.goodsId
)
) {
chooseList.push(oldval)
}
}
})
} else {
chooseList = selectList
}
})
}
console.log(chooseList, 'chooseList')
chooseList = chooseList.concat(chooseGoodsList)
chooseList.forEach(item => normalizeMarketingMetaOnItem(item))
console.log(chooseList, 'chooseList')
return [selectList, chooseList]
},
confirm() {
let [selectList, chooseList] = this.getChooseList()
console.log(selectList, chooseList)
if (!selectList.length) return wx.$util.showToast('请勾选商品')
this.triggerEvent('confirm', chooseList)
this.setData({
show: false
})
}
},
lifetimes: {
attached() {
console.log(77777)
this.setData({
windowHight: getSystemInfoSync().windowHeight
})
}
}
})