// pages/user/order/list.js import commonApi from "../../../utils/https/common" import util from "../../../utils/util" let app = getApp() Page({ /** * 页面的初始数据 */ data: { list:[], keywords:"", orderState:app.globalData.orderState, type:"" }, /** * 生命周期函数--监听页面加载 */ onLoad: function (options) { this.setData({ type:options.type }) this.getList() }, changeKeyword:function(e){ this.setData({ keywords:e.detail.value }) }, refundInfo:function(e){ let id = e.currentTarget.dataset.id; wx.navigateTo({ url: 'refundInfo/index?id='+id, }) }, gotoComment:function(e){ let id = e.currentTarget.dataset.id; wx.navigateTo({ url: '/pages/order/comment/index?id='+id, }) }, // 再次预定 order:function(e){ let item = e.currentTarget.dataset.item; util.orderMoreTime(item) }, pay:function(e){ let id = e.currentTarget.dataset.id; wx.navigateTo({ url: '/pages/order/pay/index?id='+id, }) }, search:function(){ this.setData({ realKeyword:this.data.keywords, list:[], total:1 }) this.getList() }, getList:function(){ let list = this.data.list; if(list.length>=this.data.total) return; commonApi.user_post("order/list",{ state:this.data.type, offset:this.data.list.length, limit:10, keywords:this.data.keywords }).then(res=>{ res.data.list.map(item=>{ let orderNum = 0; item.order_product_list.map(order=>{ orderNum = orderNum + order.product_num; }) item.orderNum = orderNum; }) this.setData({ total:res.data.total, list:list.concat(res.data.list) }) }) }, gotoDetail:function(e){ let item = e.currentTarget.dataset.item; util.gotoOrder(item) }, gotoProductDetail:function(e){ let item = e.currentTarget.dataset.item; util.orderMoreTime({order_product_list:[item]}) }, changeType:function(e){ let type = e.currentTarget.dataset.type; this.setData({ type:type, list:[], total:1 }) this.getList() }, refund:function(e){ let index = e.currentTarget.dataset.index,list = this.data.list,item = list[index],that = this; wx.showModal({ title:"提示", content:"确定取消吗?", success:function(res){ if(res.confirm){ // 确定取消 commonApi.user_post("order/refund",{ order_id:item.order_id }).then(res=>{ if(res.code==1){ wx.showToast({ title: '已取消', icon:'success' }) if(that.data.type){ list.splice(index,1); } else { list[index].state='WAIT_REFUND'; } that.setData({ list:list }) } }) } } }) }, cancel:function(e){ let index = e.currentTarget.dataset.index,list = this.data.list,item = list[index],that = this; wx.showModal({ title:"提示", content:"确定取消吗?", success:function(res){ if(res.confirm){ // 确定取消 commonApi.user_post("order/close",{ order_id:item.order_id }).then(res=>{ if(res.code==1){ wx.showToast({ title: '已取消', icon:'success' }) if(that.data.type){ list.splice(index,1); } else { list[index].state='CLOSED'; } that.setData({ list:list }) } }) } } }) }, /** * 生命周期函数--监听页面初次渲染完成 */ onReady: function () { }, /** * 生命周期函数--监听页面显示 */ onShow: function () { }, /** * 生命周期函数--监听页面隐藏 */ onHide: function () { }, /** * 生命周期函数--监听页面卸载 */ onUnload: function () { }, /** * 页面相关事件处理函数--监听用户下拉动作 */ onPullDownRefresh: function () { }, /** * 页面上拉触底事件的处理函数 */ onReachBottom: function () { this.getList() } })