const api = require("../../api/api"), app = getApp() Page({ data: { listArr : [], identity_id : "", permissions : false, year : "", month : "", searchIndex : 0, typeArr : [ {id: "" , name:"全部"}, {id: 1 , name:"核销成功"}, {id: 2 , name:"核销失败"} ], typeIndex : 0, all_count : '', today_count : '', endDate : '', isNowMonth : false, page : 1, meta : {}, isLogin : false, isLay : false, type : "", //券类型 1满减 2实物 }, // 页面加载 onLoad() { const date = new Date() let year = date.getFullYear(), month = date.getMonth() + 1 if(month < 10){ month = '0' + month } this.setData({ identity_id: app.globalData.userInfo.identity_id, permissions: app.globalData.userInfo.perferential, year : year, month : month, endDate : year + "-" + month }) }, // 页面显示 onShow(){ this.setData({ listArr: [] }) this.welfareList() my.showLoading(); my.showNavigationBarLoading(); }, // 列表 welfareList(tel){ let url = "coupon/lists", dateYear = this.data.year + '-' + this.data.month if(this.data.searchIndex == 1){ dateYear = "today" } else if(this.data.searchIndex == 2){ dateYear = "yesterday" } api.request({ url : url, header: { "Authorization": app.globalData.token }, method: "POST", data : { date : dateYear, mobile : tel || "", status : this.data.typeArr[this.data.typeIndex].id, settle : "", page : this.data.page } }).then(res=>{ let atArr = this.data.listArr, newArr = [] newArr = atArr.concat(res.data.lists.data) this.setData({ listArr : newArr, all_count : res.data.all_count, today_count : res.data.today_count, isNowMonth : res.data.isNowMonth, page : res.data.lists.page }) my.hideLoading(); my.stopPullDownRefresh(); my.hideNavigationBarLoading(); }) }, // 选择日期 selectTime(){ my.datePicker({ currentDate : this.data.year + "-" + this.data.month, endDate : this.data.endDate, format : "yyyy-MM", success : res=>{ let dateString = String(res.date), yearString = dateString.substring(0,4), monthString = dateString.substring(5,7) this.setData({ year : yearString, month : monthString, page : 1, listArr: [] }) this.welfareList() my.showLoading(); } }) }, // 筛选日期 searchTab(e){ this.setData({ page : 1, listArr : [] }) if(e.target.dataset.index != this.data.searchIndex){ this.setData({ searchIndex: e.target.dataset.index }) this.welfareList() my.showLoading(); } if(e.target.dataset.index == 0 && !this.data.isNowMonth){ const date = new Date() let year = date.getFullYear(), month = date.getMonth() + 1 if(month < 10){ month = '0' + month } this.setData({ year : year, month : month }) this.welfareList() my.showLoading(); } }, // 类型筛选 screenClass(e){ this.setData({ typeIndex: e.detail.value, page : 1, listArr : [] }) this.welfareList() my.showLoading(); }, // 搜索手机号码 searchForm(e){ this.setData({ page : 1, listArr : [] }) let tel = e.detail.value.searchValue this.welfareList(tel) }, // 分页 onReachBottom(){ let meta = this.data.meta, atPage = this.data.page this.setData({ isLogin: true }) if(meta.current_page < meta.last_page){ this.setData({ page: atPage + 1 }) this.welfareList() my.showLoading(); } }, // 下拉刷新 onPullDownRefresh(){ this.setData({ listArr : [] }) this.welfareList() }, //弹出价格 onLay(){ this.setData({ isLay: !this.data.isLay }) }, //扫码选项 onMelt(e){ my.showActionSheet({ items : ["实物券核销","满减券核销"], success : res=>{ if(e.currentTarget.dataset.type == "nav"){ if(res.index == 0 || res.index == 1){ my.navigateTo({ url: '../nuclear_code/nuclear_code?type=' + res.index }); } }else{ if(res.index == 0){ this.qrcodeScan("", "entity") this.type = 2 }else if(res.index == 1){ this.onLay() this.type = 1 } } } }); }, //扫码核销 qrcodeScan(e, type){ let price = e.detail ? e.detail.value.price : 0 if(price == "" && type != "entity"){ my.showToast({ type : "none", content : "请输入消费金额~" }) return } my.scan({ scanType : "qrCode", hideAlbum : true, success : res=>{ let code_no = res.code if(code_no){ my.showLoading({ content: "加载中" }) api.request({ url : "coupon/scan", header: { "Authorization": app.globalData.token }, method: "POST", data : { no : code_no, total : price, type : this.type, //1满减 2实物 } }).then(res=>{ my.hideLoading() console.log(res) my.alert({ title : "提示", content : res.data, success : res=>{ my.showLoading() console.log(res) this.setData({ page: 1, listArr: [] }) this.welfareList() } }) }).catch(err=>{ my.hideLoading() my.showToast({ type : "fail", content : err.data.message }) }) } } }); if(this.data.isLay) this.onLay() } });