|
...
|
...
|
@@ -35,8 +35,9 @@ Page({ |
|
|
|
coupon_dataList:[],
|
|
|
|
dataStr: Date.now() * 1 / 1000,
|
|
|
|
StyleType:'',
|
|
|
|
couponArr: [],//待领取的优惠券列表
|
|
|
|
},
|
|
|
|
|
|
|
|
couponModal: '',
|
|
|
|
/**
|
|
|
|
* 生命周期函数--监听页面加载
|
|
|
|
*/
|
|
...
|
...
|
@@ -51,6 +52,12 @@ Page({ |
|
|
|
this.getIsCollectionSellerFun(sid)
|
|
|
|
this.getSellerVersionFun(sid)
|
|
|
|
}
|
|
|
|
this.couponModal = this.selectComponent("#couponModal");
|
|
|
|
this.couponModal.showModal()
|
|
|
|
},
|
|
|
|
// 关闭优惠券弹框
|
|
|
|
closeCouponModal() {
|
|
|
|
this.couponModal.closeModal()
|
|
|
|
},
|
|
|
|
// 获取商家是否收藏状态
|
|
|
|
getIsCollectionSellerFun(sid) {
|
|
...
|
...
|
@@ -150,7 +157,7 @@ Page({ |
|
|
|
let data = res.data
|
|
|
|
console.log('data', data);
|
|
|
|
let couponList = []
|
|
|
|
let titleType, home, chef, signboard, store, marketing, coupon, reserve, StyleType;
|
|
|
|
let titleType, home, chef, signboard, store, marketing, coupon, coupon_data_pay, coupon_data_free, reserve, StyleType;
|
|
|
|
chef = util.determine(data.chef);
|
|
|
|
reserve = util.determine(data.reserve);
|
|
|
|
signboard = util.determine(data.signboard);
|
|
...
|
...
|
@@ -158,30 +165,27 @@ Page({ |
|
|
|
home = util.determine(data.home);
|
|
|
|
marketing = util.determine(data.marketing);
|
|
|
|
titleType = data.title_class || '1';
|
|
|
|
StyleType = data.type;if (store) store.content = (store.is_introduce_all == '1' && store.content) ? util.determine(store.content) : '';
|
|
|
|
StyleType = data.type;
|
|
|
|
if (store) store.content = (store.is_introduce_all == '1' && store.content) ? util.determine(store.content) : '';
|
|
|
|
if (chef) chef.content = (chef.is_introduce_all == '1' && chef.content) ? util.determine(chef.content) : '';
|
|
|
|
if (signboard) signboard.content = (signboard.is_introduce_all == '1' && signboard.content) ? util.determine(signboard.content) : '';
|
|
|
|
if (reserve) reserve.content = (reserve.is_introduce_all == '1' && reserve.content) ? util.determine(reserve.content) : '';
|
|
|
|
if (home) home.image = (home && home.image && (!home.id_first_image || home.id_first_image!='0')) ? home.image : '';
|
|
|
|
if (marketing) {
|
|
|
|
marketing.logo = (marketing.logo && (!marketing.is_logo || marketing.is_logo!='0')) ? marketing.logo : '';
|
|
|
|
coupon = marketing.coupon_data ? util.determine(marketing.coupon_data) : '';
|
|
|
|
coupon = (marketing.coupon_data && marketing.is_coupon == '1') ? util.determine(marketing.coupon_data) : '';
|
|
|
|
coupon_data_pay = (marketing.coupon_data_pay && marketing.is_coupon_pay == '1') ? util.determine(marketing.coupon_data_pay) : '';
|
|
|
|
marketing.coupon_data_payList = coupon_data_pay
|
|
|
|
coupon_data_free = (marketing.coupon_data_free && marketing.is_coupon_free == '1') ? util.determine(marketing.coupon_data_free) : '';
|
|
|
|
marketing.coupon_data_freeList = coupon_data_free
|
|
|
|
}
|
|
|
|
// is_cash 代金券 is_discount折扣券 is_dish菜品券 只有代金券有几折显示
|
|
|
|
if (coupon && util.getType(coupon) == 'object') {
|
|
|
|
couponList.push({
|
|
|
|
id: coupon.id
|
|
|
|
});
|
|
|
|
}
|
|
|
|
if (coupon && util.getType(coupon) == 'array') {
|
|
|
|
if (coupon.length > 0) {
|
|
|
|
coupon.forEach(item => {
|
|
|
|
couponList.push({
|
|
|
|
id: item.id
|
|
|
|
})
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// 获取全部的优惠券(商家券、个人券、免费券、付费券)
|
|
|
|
couponList = this.addCoupons(coupon,couponList);
|
|
|
|
couponList = this.addCoupons(coupon_data_pay,couponList);
|
|
|
|
couponList = this.addCoupons(coupon_data_free,couponList);
|
|
|
|
// 根据券ID获取券详情
|
|
|
|
this.getActivityByIdFun(couponList)
|
|
|
|
if (store && store.images && store.images.length > 0) store.images = util.determine(store.images);
|
|
|
|
if (reserve && reserve.park_info_images && reserve.park_info_images.length > 0) reserve.park_info_images = util.determine(reserve.park_info_images);
|
|
|
|
if (signboard && signboard.images) signboard.images = util.determine(signboard.images);
|
|
...
|
...
|
@@ -201,8 +205,6 @@ Page({ |
|
|
|
console.log('获取数据', {
|
|
|
|
...obj
|
|
|
|
});
|
|
|
|
// 根据券ID获取券详情
|
|
|
|
this.getActivityByIdFun(couponList, couponList.length)
|
|
|
|
// 根据充值ID获取充值详情
|
|
|
|
if (marketing && marketing.is_recharge == '1' && marketing.recharge_data) {
|
|
|
|
this.getRechargeDetail(marketing.recharge_data.id)
|
|
...
|
...
|
@@ -245,35 +247,172 @@ Page({ |
|
|
|
})
|
|
|
|
})
|
|
|
|
},
|
|
|
|
// 根据券ID获取券详情
|
|
|
|
getActivityByIdFun(ids, length) {
|
|
|
|
let coupon_dataList = [];
|
|
|
|
ids.forEach(i => {
|
|
|
|
App.Activity.GetActivityById({
|
|
|
|
id: i.id
|
|
|
|
}).then(res => {
|
|
|
|
if (res.data.length > 0) {
|
|
|
|
let detail = res.data[0];
|
|
|
|
detail.stringifyUse = detail.use ? JSON.stringify(detail.use) : '';
|
|
|
|
detail.exp_date = detail.exp_date ? util.determine(detail.exp_date) : '';
|
|
|
|
detail.use = detail.use ? util.determine(detail.use) : '';
|
|
|
|
if ((detail.use && (!detail.use.is_cash || detail.use.is_cash == '1'))) {
|
|
|
|
let cash = detail.use.cash * 1;
|
|
|
|
let price = detail.price * 1;
|
|
|
|
detail.discount = cash != 0 ? ((price / cash) * 10).toFixed(1) : '';
|
|
|
|
}
|
|
|
|
coupon_dataList.push(detail);
|
|
|
|
if (length === coupon_dataList.length) {
|
|
|
|
coupon_dataList = coupon_dataList.filter(item=>{return this.data.dataStr<(item.etime*1) && item.is_open == '1'})
|
|
|
|
console.log('商家详情--------------------优惠券',coupon_dataList);
|
|
|
|
this.setData({
|
|
|
|
coupon_dataList,
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
|
|
|
})
|
|
|
|
})
|
|
|
|
},
|
|
|
|
// 根据券ID获取券详情
|
|
|
|
getActivityByIdFun(obj) {
|
|
|
|
App.Activity.GetActivityById({
|
|
|
|
id: obj.map(item => item.id).join(','),
|
|
|
|
}).then(res => {
|
|
|
|
if (res.data.length > 0) {
|
|
|
|
let list = res.data.filter(item => {
|
|
|
|
return this.data.dataStr < (item.etime * 1) && item.is_open == '1'
|
|
|
|
})
|
|
|
|
list.forEach(detail => {
|
|
|
|
detail.stringifyUse = detail.use ? JSON.stringify(detail.use) : '';
|
|
|
|
detail.exp_date = detail.exp_date ? util.determine(detail.exp_date) : '';
|
|
|
|
detail.use = detail.use ? util.determine(detail.use) : '';
|
|
|
|
if ((detail.use && (!detail.use.is_cash || detail.use.is_cash == '1'))) {
|
|
|
|
let cash = detail.use.cash * 1;
|
|
|
|
let price = detail.price * 1;
|
|
|
|
detail.discount = cash != 0 ? ((price / cash) * 10).toFixed(1) : '';
|
|
|
|
}
|
|
|
|
let num = detail.receiveNum;
|
|
|
|
if (num > 0) {
|
|
|
|
detail.receiveNumText = ''
|
|
|
|
if (num >= 0 && num <= 100) {
|
|
|
|
detail.receiveNumText = num.toString();
|
|
|
|
} else if (num >= 101 && num <= 199) {
|
|
|
|
detail.receiveNumText = '100+';
|
|
|
|
} else if (num >= 200 && num <= 299) {
|
|
|
|
detail.receiveNumText = '200+';
|
|
|
|
} else {
|
|
|
|
detail.receiveNumText = Math.floor(num / 100) * 100 + '+';
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (detail.exp_date && detail.exp_date.week_data) {
|
|
|
|
let noon = this.hasConsecutiveSelect(detail.exp_date.week_data, '1').rArr.join('、')
|
|
|
|
let nig = this.hasConsecutiveSelect(detail.exp_date.week_data, '2').rArr.join('、')
|
|
|
|
if (noon) noon = '午餐:' + noon
|
|
|
|
if (nig) nig = '晚餐:' + nig
|
|
|
|
detail.noonText = noon;
|
|
|
|
detail.nigText = nig;
|
|
|
|
}
|
|
|
|
})
|
|
|
|
let freeCoupons = list.filter(item => {
|
|
|
|
return item.is_type == '3'
|
|
|
|
})
|
|
|
|
// 免费券判断是否领取,弹框领取
|
|
|
|
if (freeCoupons.length > 0) {
|
|
|
|
let length = freeCoupons.length - 1
|
|
|
|
freeCoupons.forEach(i => {
|
|
|
|
this.getCoupon(i, freeCoupons[length].id, obj)
|
|
|
|
})
|
|
|
|
}
|
|
|
|
console.log('邀请函--------------------优惠券', list);
|
|
|
|
this.setData({
|
|
|
|
coupon_dataList: list,
|
|
|
|
})
|
|
|
|
}
|
|
|
|
})
|
|
|
|
},
|
|
|
|
// 获取所有的券并且展示
|
|
|
|
addCoupons(coupons, couponList) {
|
|
|
|
if (coupons && util.getType(coupons) == 'object') {
|
|
|
|
couponList.push({
|
|
|
|
id: coupon.id,
|
|
|
|
number: coupon.number
|
|
|
|
});
|
|
|
|
}
|
|
|
|
if (coupons && util.getType(coupons) === 'array' && coupons.length > 0) {
|
|
|
|
coupons.forEach(item => {
|
|
|
|
couponList.push({
|
|
|
|
id: item.id,
|
|
|
|
number: item.number
|
|
|
|
});
|
|
|
|
});
|
|
|
|
}
|
|
|
|
return couponList
|
|
|
|
},
|
|
|
|
// 弹框领取免费券
|
|
|
|
setcouponFun(arr) {
|
|
|
|
let str = arr.flatMap(item => Array(item.number).fill(item.id)).join(',');
|
|
|
|
console.log('弹框领取免费券id', str);
|
|
|
|
// App.Activity.SetActivityAsReserve({
|
|
|
|
// aid: str,
|
|
|
|
// rid: this.id,
|
|
|
|
// }).then((json) => {
|
|
|
|
// if (json.ret != 200) {
|
|
|
|
// wx.showToast({
|
|
|
|
// title: res.msg,
|
|
|
|
// duration: 2000,
|
|
|
|
// mask: true
|
|
|
|
// })
|
|
|
|
// }
|
|
|
|
// })
|
|
|
|
},
|
|
|
|
// 免费券 0未领取 1已领取 获取未领取的组成数组couponArr
|
|
|
|
getCoupon(item, id, obj) {
|
|
|
|
let couponArr = this.data.couponArr;
|
|
|
|
let totalPrice = this.data.totalPrice;
|
|
|
|
App.Activity.ActivityListByOpenid({
|
|
|
|
aid: item.id
|
|
|
|
}).then(res => {
|
|
|
|
if (res.ret == 200) {
|
|
|
|
if (res.data.length == 0) {
|
|
|
|
couponArr.push(item)
|
|
|
|
}
|
|
|
|
if (item.id == id && couponArr.length > 0) {
|
|
|
|
couponArr.forEach(item => {
|
|
|
|
let match = obj.find(b => b.id === item.id);
|
|
|
|
if (match) {
|
|
|
|
item.number = match.number;
|
|
|
|
}
|
|
|
|
});
|
|
|
|
totalPrice = couponArr.reduce((sum, item) => sum + item.price * item.number, 0);
|
|
|
|
this.setcouponFun(couponArr)
|
|
|
|
this.couponModal.showModal()
|
|
|
|
}
|
|
|
|
console.log('未领取的券列表-----------', couponArr);
|
|
|
|
this.setData({
|
|
|
|
couponArr,
|
|
|
|
totalPrice
|
|
|
|
})
|
|
|
|
}
|
|
|
|
})
|
|
|
|
},
|
|
|
|
// 处理优惠券不可用日期数据
|
|
|
|
hasConsecutiveSelect(arr, type) {
|
|
|
|
let firstTitle = null;
|
|
|
|
let lastTitle = null;
|
|
|
|
let rArr = []
|
|
|
|
let num = 0
|
|
|
|
for (let i = 0; i < arr.length; i++) {
|
|
|
|
let str = type == '1' ? arr[i].selectNoon : arr[i].selectNig
|
|
|
|
if (str) {
|
|
|
|
rArr.push(arr[i].title)
|
|
|
|
num++
|
|
|
|
if (num == 1) {
|
|
|
|
firstTitle = arr[i].title
|
|
|
|
}
|
|
|
|
if (num >= 5) {
|
|
|
|
lastTitle = arr[i].title
|
|
|
|
}
|
|
|
|
if (num >= 5 && i >= (arr.length - 1)) {
|
|
|
|
let fi = rArr.findIndex((item) => {
|
|
|
|
return item == firstTitle
|
|
|
|
})
|
|
|
|
rArr.splice(fi, num, firstTitle + '至' + lastTitle)
|
|
|
|
num = 0
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
if (num < 5) {
|
|
|
|
num = 0
|
|
|
|
firstTitle = null;
|
|
|
|
lastTitle = null;
|
|
|
|
} else {
|
|
|
|
let fi = rArr.findIndex((item) => {
|
|
|
|
return item == firstTitle
|
|
|
|
})
|
|
|
|
rArr.splice(fi, num, firstTitle + '至' + lastTitle)
|
|
|
|
num = 0
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return {
|
|
|
|
rArr,
|
|
|
|
lastTitle,
|
|
|
|
firstTitle
|
|
|
|
};
|
|
|
|
},
|
|
|
|
// 导航
|
|
|
|
looklocation: function () {
|
|
|
|
wx.reportMonitor('1015', 1)
|
...
|
...
|
|