// pages/coupon/couponT.js // var sliderWidth = 96; // 需要设置slider的宽度,用于计算中间位置 const app = getApp(); const card = require('../../utils/card.js'); const util = require('../../utils/util.js'); Page({ /** * 页面的初始数据 */ data: { hidden: false, tabs: [{ "name": "未使用", "checked": true, }, { "name": "已使用", "checked": false, }, { "name": "已过期", "checked": false, } ], activeIndex: 0, sliderOffset: 0, sliderLeft: 0, isUpdate: false, couponList1: [], couponList2: [], couponList3: [] }, /** * 生命周期函数--监听页面加载 */ onLoad: function(options) { var that = this; this.cy_selectCouponList(0); }, /** * 选择状态 */ cy_selectTypeCoupon: function(e) { var index = e.currentTarget.dataset.index; for (var i = 0; i < this.data.tabs.length; i++) { var map = this.data.tabs[i]; map.checked = false; if (i == index) { map.checked = true; } } this.setData({ activeIndex: index, tabs: this.data.tabs, hidden: false }); this.cy_selectCouponList(index); }, /** * 查询优惠券信息 */ cy_selectCouponList: function(status) { var that = this; var property = "memberId"; var keyword = app.memberId; var status = parseInt(status) + 1; var params = { "property": property, "keyword": keyword, "status": status, "shopNo": app.shopNo, "posNo": app.posNo, "amount": 0, "amountFilter": 0 } card.queryGroupCouponsList(params, function success(json) { var result = json.data; if (result.status == 1) { var couponList = result.list; var couponDatas = []; for (var value of couponList) { var couponObject = {}; couponObject.couponCount = value.couponCount; couponObject.couponId = value.couponId; couponObject.couponDesc = value.couponDesc; couponObject.cardId = value.cardId; couponObject.code = value.code; couponObject.title = value.title; couponObject.color = value.color; couponObject.cardType = value.cardType; couponObject.cardTypeCn = value.cardType == "CASH" ? "代金券" : value.cardType == "DISCOUNT" ? "折扣券" : value.cardType == "GIFT" ? "兑换券" : ""; var worth = value.cardType == "CASH" ? value.reduceCost / 100 : value.cardType == "DISCOUNT" ? value.discount : ""; couponObject.worth = worth; couponObject.wxStatus = value.wxStatus; couponObject.startDate = util.formatTimeV(new Date(value.startDate), "yyyy-MM-dd"); couponObject.endDate = util.formatTimeV(new Date(value.endDate), "yyyy-MM-dd"); if (value.endTimestamp == (couponObject.endDate + " 00:00:00")) { var endDate = value.endDate; var endTimestampDate = new Date(endDate); endTimestampDate.setDate(endTimestampDate.getDate() - 1); //设置天数 -1 天 couponObject.endDate = util.formatTimeV(endTimestampDate, 'yyyy-MM-dd'); } couponObject.wxStatus = value.wxStatus; if (couponObject.wxStatus == 0) { var nowDateFormat = util.formatTimeV(new Date(), "yyyy-MM-dd"); if (couponObject.startDate != nowDateFormat) { couponObject.wxStatus = 2 } } var useLabel = "消费金额无限制"; var leastCost = value.leastCost / 100; if (leastCost && leastCost != "") { leastCost = parseInt(leastCost); if (leastCost > 0) { useLabel = '满' + leastCost + '元可用'; } } couponObject.useLabel = useLabel; couponDatas.push(couponObject); } if (status == 1) { that.setData({ couponList1: couponDatas, hidden: true, }); } else if (status == 2) { that.setData({ couponList1: couponDatas, hidden: true, }); } else if (status == 3) { that.setData({ couponList1: couponDatas, hidden: true, }); } } }, function fail(err) { that.setData({ hidden: true, }); wx.showToast({ title: '网络链接失败', icon: "none" }) }); }, /** * 点击选项卡 */ cy_tabClick: function(e) { var that = this; var activeIndex = e.currentTarget.id; that.setData({ sliderOffset: e.currentTarget.offsetLeft, activeIndex: activeIndex }); console.log(activeIndex); this.cy_selectCouponList(activeIndex); }, /** * 优惠券明细 */ cy_couponDetail: function(e) { var index = e.currentTarget.dataset.index; var tempCoupon = this.data.couponList1[index]; var content = JSON.stringify(tempCoupon); var url = 'couponInfo?content=' + content; wx.navigateTo({ url: url, }) }, /** * 领券中心 */ cy_couponCenter: function(e) { var url = 'couponCenter'; wx.navigateTo({ url: url, }) }, /** * 生命周期函数--监听页面显示 */ onShow: function() { if (this.data.isUpdate) { this.cy_selectCouponList(this.data.activeIndex); } this.data.isUpdate = true; }, })