...
|
...
|
@@ -13,63 +13,73 @@ Component({ |
|
|
type: String,
|
|
|
value: '',
|
|
|
},
|
|
|
chosenIdx: {
|
|
|
type: String,
|
|
|
value: ''
|
|
|
},
|
|
|
|
|
|
},
|
|
|
data: {
|
|
|
// chosenIdx: ''
|
|
|
activityChosenIdx: '',
|
|
|
expressChosenIdx: ''
|
|
|
},
|
|
|
methods: {
|
|
|
confirm: function () {
|
|
|
let item = this.data.coupons[this.data.chosenIdx];
|
|
|
let codeType = item && item.coupon_type|| '';
|
|
|
let code = item && item.coupon_code || '';
|
|
|
let amount = item && item.coupon_value_str || '';
|
|
|
this.triggerEvent('confirmselect', { code, amount, codeType})
|
|
|
let chosenIdxName = ['activityChosenIdx','expressChosenIdx'];
|
|
|
let code = [];
|
|
|
let amount = 0;
|
|
|
chosenIdxName.forEach(val => {
|
|
|
let item = this.data.coupons[this.data[val]];
|
|
|
let itemCode = item && item.coupon_code || '';
|
|
|
let itemAmount = item && item.coupon_value_str || '';
|
|
|
code.push(itemCode);
|
|
|
amount = itemAmount && parseFloat(itemAmount) + amount;
|
|
|
})
|
|
|
code = code.join(',');
|
|
|
this.triggerEvent('confirmselect', { code, amount})
|
|
|
},
|
|
|
cancel: function () {
|
|
|
this.triggerEvent('cancel')
|
|
|
},
|
|
|
check: function (e) {
|
|
|
let idx = e.currentTarget.dataset.idx;
|
|
|
let that = this;
|
|
|
let type = e.currentTarget.dataset.type;
|
|
|
this.data.coupons.forEach((item, index) => {
|
|
|
let listItem = item;
|
|
|
if (index !== idx && item.isChosen) {
|
|
|
this.setData({
|
|
|
[`coupons[${index}].isChosen`]: false,
|
|
|
[`coupons[${idx}].selected`]: 'N'
|
|
|
});
|
|
|
}
|
|
|
if (index === idx) {
|
|
|
this.setData({
|
|
|
[`coupons[${idx}].isChosen`]: true,
|
|
|
[`coupons[${idx}].selected`]: 'Y'
|
|
|
});
|
|
|
if(item.coupon_type === type) {
|
|
|
if (index !== idx && item.isChosen) {
|
|
|
this.setData({
|
|
|
[`coupons[${index}].isChosen`]: false,
|
|
|
[`coupons[${idx}].selected`]: 'N'
|
|
|
});
|
|
|
}
|
|
|
if (index === idx) {
|
|
|
this.setData({
|
|
|
[`coupons[${idx}].isChosen`]: true,
|
|
|
[`coupons[${idx}].selected`]: 'Y'
|
|
|
});
|
|
|
}
|
|
|
}
|
|
|
|
|
|
});
|
|
|
this.data.chosenIdx = idx;
|
|
|
let idxName = type === 100 ? 'activityChosenIdx' : 'expressChosenIdx'
|
|
|
this.data[idxName] = idx;
|
|
|
},
|
|
|
uncheck: function (e) {
|
|
|
let idx = e.currentTarget.dataset.idx;
|
|
|
|
|
|
let type = e.currentTarget.dataset.type;
|
|
|
this.setData({
|
|
|
[`coupons[${idx}].isChosen`]: false,
|
|
|
[`coupons[${idx}].selected`]: 'N'
|
|
|
});
|
|
|
this.data.chosenIdx = '';
|
|
|
let idxName = type === 100 ? 'activityChosenIdx' : 'expressChosenIdx'
|
|
|
this.data[idxName] = '';
|
|
|
},
|
|
|
_show: function (show) {
|
|
|
if (show) {
|
|
|
if (this.data.selectedCode) {
|
|
|
this.data.coupons.forEach((item, index) => {
|
|
|
if (item.coupon_code === this.data.selectedCode) {
|
|
|
if (this.data.selectedCode.includes(item.coupon_code)) {
|
|
|
this.setData({
|
|
|
[`coupons[${index}].isChosen`]: true
|
|
|
});
|
|
|
this.data.chosenIdx = index;
|
|
|
let idxName = item.coupon_type === 100 ? 'activityChosenIdx' : 'expressChosenIdx'
|
|
|
this.data[idxName] = index;
|
|
|
} else {
|
|
|
this.setData({
|
|
|
[`coupons[${index}].isChosen`]: false
|
...
|
...
|
@@ -82,7 +92,8 @@ Component({ |
|
|
[`coupons[${index}].isChosen`]: false
|
|
|
});
|
|
|
});
|
|
|
this.data.chosenIdx = '';
|
|
|
this.data.activityChosenIdx = '';
|
|
|
this.data.expressChosenIdx = '';
|
|
|
}
|
|
|
}
|
|
|
console.log(this.data.coupons)
|
...
|
...
|
|