var config = require("../../config/config.js"); const Http = require("../../utils/HttpBasics"); const imgurl = require("../../utils/imgurl"); Page({ /** * 页面的初始数据 */ data: { bannerUrl: imgurl.banner.url, loadingUrl: imgurl.loading.url, bargaingoods: true, mybargain: false, list: [], lists: [], page: 1, // 设置加载的第几次,默认是第一次 pageSize: 10, //返回数据的个数 searchLoadingComplete: false, //“没有数据”的变量,默认false,隐藏 allow_load: true, // 是否允许继续加载标识 默认 true 允许,false 加载完成 myorder: false, actUrl: imgurl.act.url, loadingUrl: imgurl.loading.url, flag: 'bargaingoods', }, onLoad: function () { let that = this; that.getBannerlist(); var todayDate = new Date().getTime(); that.setData({ todayDate: todayDate }) that.getList(1, "bargaingoods"); that.setData({ flag: "bargaingoods", bargaingoods: true, mybargain: false }) }, //切换拼团列表 getSpellList(){ this.setData({ flag: "bargaingoods" }) this.getList(1, "bargaingoods") }, //切换我的拼团 getmyList(){ this.setData({ flag: "mybargain" }) this.getList(1, "mybargain") }, /** * banner */ getBannerlist: function () { let that = this; Http.get({ url: config.api.bannerlist, data: { pageNum: 1, pageSize: 7 } }).then(res => { that.setData({ list: res.data.list }); }); }, getList(pageNum, flag) { var that = this; console.log(pageNum) if (that.data.allow_load) { /** * mybargain: 我的砍价 * bargaingoods: 砍价商品 */ that.setData({ loading: true, content: '小主,我在玩命加载中...' }) var param = {}; if (flag == 'mybargain') { that.setData({ flag: "mybargain" }) var param = { pageNum: pageNum, pageSize: 10 }; var url = config.api.getMySepllList; } else if (flag == 'bargaingoods') { that.setData({ flag: "bargaingoods" }) var param = { pageNum: pageNum, pageSize: 10, targetAd: 7 }; var url = config.api.couponChannelList; } // 请求接口 Http.get({ url: url, data: param }).then(res => { console.log(res) /** * 加载完成 */ if (pageNum >= res.data.pages) { if (res.data.pages == 0 || res.data.pages == 1) { that.setData({ allow_load: true, loading: false, content: "" }); } else { that.setData({ allow_load: false, loading: true, content: "——— 再拉裤子就掉了啦 ———", }); } } if (pageNum == 1) { that.setData({ lists: [], }) } if (flag == 'bargaingoods') { var tmpArr = that.data.lists; tmpArr.push.apply(tmpArr, res.data.list); that.setData({ lists: tmpArr }) } else if (flag == 'mybargain') { console.log(res.data.list) var tmpArr = that.data.lists; tmpArr.push.apply(tmpArr, res.data.list); console.log(tmpArr) let lists = []; tmpArr.map(file => { if (file.orderStatus != 1) { lists.push(file); } }) that.setData({ lists: lists }) } wx.stopPullDownRefresh(); }) .catch(err => { wx.stopPullDownRefresh(); wx.showToast({ title: err.message, icon: 'none', duration: 2000, mask: false }); }) setTimeout(function () { that.setData({ loading: false, }) }, 1400); } else { that.setData({ loading: true, content: "——— 再拉裤子就掉了啦 ———" }) setTimeout(function () { that.setData({ loading: false, }) }, 1400) } }, /** * 如果是重新砍价,需要重新下单 */ orderSave: function (couponId, couponChannelId) { Http.post({ url: config.api.orderSave, data: { couponId: "" + couponId, couponChannelId: "" + couponChannelId, press: true } }) .then(res => { console.log(res) wx.navigateTo({ url: `/pages/bargain/bargainDatail/bargainDatail?orderId=${res.data.orderNumber}` }) }) .catch(err => { wx.showToast({ title: err.message, icon: "none" }) }) }, inviteFriend: function (e) { /** * 添加标识 */ wx.navigateTo({ url: `/pages/bargain/bargainDatail/bargainDatail?orderId=${e.currentTarget.dataset.id}` }) }, barginAgain: function (e) { let that = this; console.log(e) let couponId = e.currentTarget.dataset.couponid; let couponChannelId = e.currentTarget.dataset.couponchannelid; // let orderId = e.currentTarget.dataset.id; that.orderSave(couponId, couponChannelId) }, mybargain: function () { let that = this; that.setData({ bargaingoods: false, mybargain: true, flag: "mybargain", allow_load: true, loading: false, content: "", page: 1 }) that.getList(1, 'mybargain'); wx.setNavigationBarTitle({ title: '我的砍价' }) }, bargaingoods: function () { let that = this; that.setData({ bargaingoods: true, mybargain: false, flag: "bargaingoods", allow_load: true, loading: false, page: 1, content: "" }) that.getList(1, 'bargaingoods'); wx.setNavigationBarTitle({ title: '砍价专场' }) }, /** * * @param {砍价} 邀请好友砍价 */ invite: function (e) { let couponChannelId = e.currentTarget.dataset.id; let couponId = e.currentTarget.dataset.couponid; if (couponChannelId && couponId) { wx.navigateTo({ url: `/pages/coupon/detail/index?couponChannelId=${couponChannelId}&couponId=${couponId}` }) } }, //加载更多 onReachBottom: function () { let that = this; that.data.page++; that.setData({ page: that.data.page }); that.getList(that.data.page, that.data.flag); }, /** * 刷新 */ onPullDownRefresh: function (e) { let that = this; if (that.data.flag == 'bargaingoods') { that.getBannerlist(); var todayDate = new Date().getTime(); that.setData({ todayDate: todayDate }) that.getList(1, "bargaingoods"); that.setData({ flag: "bargaingoods", bargaingoods: true, mybargain: false }) } else if (that.data.flag == 'mybargain') { that.getList(1, "mybargain"); that.setData({ flag: "mybargain", bargaingoods: false, mybargain: true }) } }, })