var config = require("../../config/config.js"); const Http = require("../../utils/HttpBasics"); const imgurl = require("../../utils/imgurl"); const { spellStatus,spellStatus02 } = require("../../utils/spell"); Page({ /** * 页面的初始数据 */ data: { bannerUrl: imgurl.banner.url, loadingUrl: imgurl.loading.url, spellList: true, myspellList: false, list: [], lists: [], myLists:[], page: 1, // 设置加载的第几次,默认是第一次 pageSize: 10, //返回数据的个数 searchLoadingComplete: false, //“没有数据”的变量,默认false,隐藏 allow_load: true, // 是否允许继续加载标识 默认 true 允许,false 加载完成 myorder: false, actUrl: imgurl.act.url, loadingUrl: imgurl.loading.url, flag: 'spellList', }, onLoad: function () { let that = this; that.getBannerlist(); var todayDate = new Date().getTime(); that.setData({ todayDate: todayDate }) that.getList(1, "spellList"); that.getUserInfo() that.setData({ flag: "spellList", spellList: true, myspellList: false, lists: null }) }, //切换拼团列表 getSpellList(){ this.setData({ flag: "spellList", page:1, allow_load:true }) this.getList(1, "spellList") }, //去使用 gotoUse(e){ console.log(e) wx.navigateTo({ url: '/pages/couponorder/index/index', }) }, //重新拼团 gotoAgain(){ let data = e.currentTarget.dataset.data wx.navigateTo({ url: `/pages/spellGroup/mySpellGroup/index?couponId=${data.couponId}&couponChannelId=${data.couponChannelId}`, }) }, //跳转到我的拼团详情 gotoStatusDetail(e){ console.log(e,333) let data = e.currentTarget.dataset.data wx.navigateTo({ url: `/pages/spellDetail/index?orderId=${data.orderId}&couponId=${data.couponId}&orderGroupId=${data.orderGroupId}&couponChannelId=${data.couponChannelId}`, }) }, //切换我的拼团 getmyList(){ this.setData({ flag: "myspellList", page: 1, allow_load: true, lists:null }) this.getList(1, "myspellList") }, /** * 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 }); }); }, changeStatus(status){ return spellStatus02.filter(item=>status==item.value)[0].name }, changeStatus02(status) { console.log(status) return spellStatus.filter(item => status == item.value)[0].name }, gotoEdit(e){ console.log(e.currentTarget.dataset.status) let status = e.currentTarget.dataset.status if (status==10){ } }, getUserInfo: function () { let that = this; // 获取用户信息 Http.get({ url: config.api.getScore, data: {} }) .then(res => { console.log(res) that.setData({ nickName: res.data.nickName, avatarUrl: res.data.avatarUrl }) }) }, /** * 用户点击右上角分享 */ // paramData onShareAppMessage: function (res) { if (res.from === 'button') { console.log(res, 3333333333333333333333) // 来自页面内转发按钮 let _this = this; let data = res.target.dataset.data return { title: '拼团', path: `/pages/index/index?couponId=${data.couponId}&orderGroupId=${data.orderGroupId}&couponChannelId=${data.couponChannelId}&orderId=${data.orderId}&avatarUrl=${_this.data.avatarUrl}&nickName=${_this.data.nickName}`, imageUrl: data.coverImg, success: function (res) { // 转发成功 }, fail: function (res) { // 转发失败 } } } else { console.log(res, 444444444444444444) } }, getList(pageNum, flag) { var that = this; console.log(pageNum) if (that.data.allow_load) { /** * myspellList: 我的砍价 * spellList: 砍价商品 */ that.setData({ loading: true, content: '小主,我在玩命加载中...' }) var param = {}; if (flag == 'myspellList') { console.log(22222222) that.setData({ flag: "myspellList" }) var param = { pageNum: pageNum, pageSize: 10 }; var url = config.api.getMySepllList; } else if (flag == 'spellList') { console.log(111111) that.setData({ flag: "spellList" }) 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 == 'spellList') { var tmpArr = that.data.lists; tmpArr.push.apply(tmpArr, res.data.list); that.setData({ lists: tmpArr }) } else if (flag == 'myspellList') { console.log(res.data.list) var tmpArr = that.data.lists; res.data.list.map((item,index)=>{ item.statusText = that.changeStatus(item.status); item.statusText02 = that.changeStatus02(item.status) }) tmpArr.push.apply(tmpArr, res.data.list); console.log(tmpArr) let lists = []; tmpArr.map(file => { 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) }, myspellList: function () { let that = this; that.setData({ spellList: false, myspellList: true, flag: "myspellList", allow_load: true, loading: false, content: "", page: 1 }) that.getList(1, 'myspellList'); wx.setNavigationBarTitle({ title: '我的砍价' }) }, spellList: function () { let that = this; that.setData({ spellList: true, myspellList: false, flag: "spellList", allow_load: true, loading: false, page: 1, content: "" }) that.getList(1, 'spellList'); 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/spellGroup/mySpellGroup/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 == 'spellList') { that.getBannerlist(); var todayDate = new Date().getTime(); that.setData({ todayDate: todayDate }) that.getList(1, "spellList"); that.setData({ flag: "spellList", spellList: true, myspellList: false }) } else if (that.data.flag == 'myspellList') { that.getList(1, "myspellList"); that.setData({ flag: "myspellList", spellList: false, myspellList: true }) } }, })