// pages/personorder/personorder.js const app = getApp() import order from '../../api/order' import orderApi from '../../api/order' Page({ /** * 页面的初始数据 */ data: { activeTab: 0, tabs: [], orderList: [], pageNo: [1, 1, 1, 1], pageSum: [], loadingEnd: false, tabs: [{ title: '全部' }, { title: '待消费' }, { title: '待评价' }, { title: '已完成' }, ] }, /** * 生命周期函数--监听页面加载 */ onLoad: async function () { console.log(this) const isAuth = await app.isAuth() if (!isAuth) { wx.redirectTo({ url: '/pages/prompt/prompt?page=' + this.route, }) } }, // 获取全部列表 getAllOrderList: async function () { const self = this let pageNo = this.data.pageNo; let tabs = this.data.tabs; let pageSum = this.data.pageSum; // 获取全部订单 var orderList = await orderApi.getAllOrderList(pageNo[0], 4); var list = orderList.list; if (!tabs[0].list) { tabs[0].list = [] } if (pageNo[0] == 1) { tabs[0].list = list; } else { list.forEach((item, i, array) => { tabs[0].list.push(item) }) } pageSum[0] = orderList.pageCount; this.setData({ tabs, pageSum }) // return list; }, // 获取代消费列表 getwriteOffOrderList: async function () { const self = this let pageNo = this.data.pageNo; let tabs = this.data.tabs; let pageSum = this.data.pageSum; // 获取代消费订单 var orderList = await orderApi.getOrderList(pageNo[1], 4, 2, 1); var list = orderList.list; if (!tabs[1].list) { tabs[1].list = [] } if (pageNo[1] == 1) { tabs[1].list = list; } else { list.forEach((item, i, array) => { tabs[1].list.push(item) }) } pageSum[1] = orderList.pageCount; this.setData({ tabs, pageSum }) // return list; }, // 获取待评价列表 getcommentOffOrderList: async function () { const self = this let pageNo = this.data.pageNo; let tabs = this.data.tabs; let pageSum = this.data.pageSum; // 获取代消费订单 var orderList = await orderApi.getOrderList(pageNo[2], 4, 2, 2); var list = orderList.list; if (!tabs[2].list) { tabs[2].list = [] } if (pageNo[2] == 1) { let tabList = []; list.forEach((item, i, array) => { if (item.discussId == '') { tabList.push(item) } }) tabs[2].list = tabList; } else { list.forEach((item, i, array) => { if (item.discussId == '') { tabs[2].list.push(item) } }) } pageSum[2] = orderList.pageSum this.setData({ tabs, pageSum }) // return list; }, // 获取已经完成的列表 getfinishOrderList: async function () { const self = this let pageNo = this.data.pageNo; let tabs = this.data.tabs; let pageSum = this.data.pageSum; // 获取代消费订单 var orderList = await orderApi.getOrderList(pageNo[3], 4, 2, 2); var list = orderList.list; if (!tabs[3].list) { tabs[3].list = [] } if (pageNo[3] == 1) { tabs[3].list = list; } else { list.forEach((item, i, array) => { if (item.discussId != '') { tabs[3].list.push(item) } }) } pageSum[3] = orderList.pageCount; this.setData({ tabs, pageSum }) // return list; }, onTabClick(e) { const index = e.detail.index this.setData({ activeTab: index }) }, onChange(e) { const index = e.detail.index this.setData({ activeTab: index, pageNo: [1, 1, 1, 1] }) if(index==0){ this.getAllOrderList() return } if (index == 1) { this.getwriteOffOrderList() return } if (index == 2) { this.getcommentOffOrderList() return } if (index == 3) { this.getfinishOrderList() } }, handleClick(e) { }, showOrderInfo: async function (e) { var orderId = e.currentTarget.dataset.orderid; console.log(orderId) var status = e.currentTarget.dataset.status; var writeStatus = e.currentTarget.dataset.writestatus; wx.navigateTo({ url: '../order/order?id=' + orderId, }) }, /** * 生命周期函数--监听页面初次渲染完成 */ onReady: function () { }, /** * 生命周期函数--监听页面显示 */ onShow: async function () { await this.getAllOrderList() }, /** * 生命周期函数--监听页面隐藏 */ onHide: function () { }, /** * 生命周期函数--监听页面卸载 */ onUnload: function () { }, /** * 页面相关事件处理函数--监听用户下拉动作 */ onPullDownRefresh: function () { }, /** * 页面上拉触底事件的处理函数 */ onReachBottom: async function () { console.log("到底啦") var self = this; let activeTab = this.data.activeTab; if (activeTab == 0) { console.log("all") let pageNo = this.data.pageNo; pageNo[0]++; self.setData({ pageNo }) if (self.data.pageNo[0] <= self.data.pageSum[0]) { await this.getAllOrderList() return } } if (activeTab == 1) { console.log("xiaofei") let pageNo = this.data.pageNo; pageNo[1]++; self.setData({ pageNo }) if (self.data.pageNo[1] <= self.data.pageNo[1]) { await this.getwriteOffOrderList() return } } if (activeTab == 2) { console.log("pingjia") let pageNo = this.data.pageNo; pageNo[2]++; self.setData({ pageNo }) if (self.data.pageNo[2] <= self.data.pageSum[2]) { await this.getcommentOffOrderList() return } } if (activeTab == 4) { let pageNo = this.data.pageNo; pageNo[3]++; self.setData({ pageNo }) if (self.data.pageNo[3] <= self.data.pageSum[3]) { await this.getfinishOrderList() return } } }, /** * 用户点击右上角分享 */ onShareAppMessage: function () { }, gotoComment: function (e) { var orderId = e.currentTarget.dataset.orderid; var shopId = e.currentTarget.dataset.shopid; var productId = e.currentTarget.dataset.productid; wx.navigateTo({ url: '../commentinfo/commentinfo?id=' + orderId + '&shopId=' + shopId + '&productId=' + productId, }) }, // 再来一单 buyAgain: function (e) { var shopId = e.currentTarget.dataset.shopid; var productId = e.currentTarget.dataset.productid; var productImg = e.currentTarget.dataset.productimg; var productName = e.currentTarget.dataset.productname; var price = e.currentTarget.dataset.price; wx.navigateTo({ url: '../appointment/appointment?' + 'shopId=' + shopId + '&productId=' + productId + '&productImg=' + productImg + '&productName=' + productName + '&price=' + price, }) } })