// pages/personorder/personorder.js const app = getApp() import orderApi from '../../api/order' Page({ /** * 页面的初始数据 */ data: { activeTab: 0, orderHeight: 0, tabs: [], orderList: [], pageNo: 1, 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, }) } this.getOrderHeight(); }, //动态生成产品的父盒子高度 getOrderHeight: function () { var h = wx.getSystemInfoSync().windowHeight * (750 / wx.getSystemInfoSync().windowWidth); var orderHeight = h - 95; this.setData({ orderHeight }) }, getOrderList: async function (params) { var pageNo = this.data.pageNo; var orderList = await orderApi.getAllOrderList(pageNo, 3); var list = orderList.list; console.log(list) //代消费订单 var writeOffOrderList = []; //待评价订单 var commentOffOrderList = []; //已完成订单 var finishOrderList = []; list.forEach(function (item, u, array) { if (item.status == 2 && item.writeOffStatus == 1) { writeOffOrderList.push(item) } if (item.status == 2 && item.writeOffStatus == 2 && item.discussId != '') { finishOrderList.push(item) } if (item.status == 2 && item.writeOffStatus == 2 && item.discussId == '') { commentOffOrderList.push(item) } }) var tabs = this.data.tabs; tabs[0].list = list; tabs[1].list = writeOffOrderList; tabs[2].list = commentOffOrderList; tabs[3].list = finishOrderList; this.setData({ tabs }) }, // 获取全部列表 getAllOrderList: async function () { const self = this var pageNo = this.data.pageNo; // 获取全部订单 var orderList = await orderApi.getAllOrderList(pageNo, 4); var tabs = this.data.tabs; tabs[0].list = orderList.list; this.setData({ tabs }) // return list; }, // 获取代消费列表 getwriteOffOrderList: async function () { const self = this var pageNo = this.data.pageNo; // 获取代消费订单 var orderList = await orderApi.getOrderList(pageNo, 4, 2, 1); var tabs = this.data.tabs; tabs[1].list = orderList.list; this.setData({ tabs }) // return list; }, // 获取待评价列表 getcommentOffOrderList: async function () { const self = this var pageNo = this.data.pageNo; // 获取代消费订单 var orderList = await orderApi.getOrderList(pageNo, 4, 2, 1); var tabs = this.data.tabs; tabs[2].list = orderList.list; this.setData({ tabs }) // return list; }, // 获取已经完成的列表 getfinishOrderList: async function () { const self = this var pageNo = this.data.pageNo; // 获取代消费订单 var orderList = await orderApi.getOrderList(pageNo, 4, 2, 1); var tabs = this.data.tabs; tabs[3].list = orderList.list; this.setData({ tabs }) // return list; }, onTabClick(e) { const index = e.detail.index this.setData({ activeTab: index }) }, onChange(e) { const index = e.detail.index this.setData({ activeTab: index }) }, handleClick(e) { }, showOrderInfo: async function (e) { console.log(e.currentTarget) var orderId = e.currentTarget.dataset.orderid; var status = e.currentTarget.dataset.status; var writeStatus = e.currentTarget.dataset.writestatus; wx.navigateTo({ url: '/pages/order/order?id=' + orderId, }) /* if(status==2&&writeStatus==1){ wx.navigateTo({ url: 'pages/order/order?orderId='+orderId, }) return } */ }, /** * 生命周期函数--监听页面初次渲染完成 */ onReady: function () { }, /** * 生命周期函数--监听页面显示 */ onShow: async function () { await this.getOrderList() }, /** * 生命周期函数--监听页面隐藏 */ onHide: function () { }, /** * 生命周期函数--监听页面卸载 */ onUnload: function () { }, /** * 页面相关事件处理函数--监听用户下拉动作 */ onPullDownRefresh: function () { }, /** * 页面上拉触底事件的处理函数 */ onReachBottom: function () { }, /** * 用户点击右上角分享 */ 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, }) } })