import GoodApi from '../../../../services/good' import checkauth from '../../../../utils/checkauth' import Navi from '../../../../utils/navi' // pages/mine/myorder/list/index.ts Page({ /** * 页面的初始数据 */ data: { searchText: '', stickyProps: { zIndex: 2, }, wait: false, loadMoreStatus: 0, orders: [], orderInput: { filterText: '', skipCount: 0, maxResultCount: 10, }, total: 0, recode: '', showConfirm: false, }, behaviors: [checkauth], /** * 生命周期函数--监听页面加载 */ onLoad() {}, /** * 生命周期函数--监听页面初次渲染完成 */ onReady() {}, /** * 生命周期函数--监听页面显示 */ onShow() { const self = this //@ts-ignore this.afterAuth(() => { self.load(true) }) }, /** * 生命周期函数--监听页面隐藏 */ onHide() {}, /** * 生命周期函数--监听页面卸载 */ onUnload() {}, /** * 页面相关事件处理函数--监听用户下拉动作 */ onPullDownRefresh() { if (!this.data.wait) { this.setData( { orderInput: { ...this.data.orderInput, skipCount: 0, }, }, () => { this.load(true) }, ) } }, /** * 页面上拉触底事件的处理函数 */ onReachBottom() { if (this.data.loadMoreStatus === 0 && this.data.orders.length < this.data.total) { this.setData( { orderInput: { ...this.data.orderInput, skipCount: this.data.orderInput.skipCount + 10, }, }, () => { this.load() }, ) } }, /** * 用户点击右上角分享 */ onShareAppMessage() {}, load(rest = false) { this.setData({ wait: true, loadMoreStatus: 1, }) GoodApi.GetOrderList(this.data.orderInput) .then((rsp) => { if (rsp.result) { const { items = [], totalCount = 0 } = rsp.result const nowItems = rest ? items : this.data.orders.concat(items as any) this.setData({ wait: false, total: totalCount, orders: nowItems as any, loadMoreStatus: nowItems.length === totalCount ? 2 : 0, }) } }) .catch(() => { this.setData({ wait: false, loadMoreStatus: 0, }) }) .finally(() => { wx.stopPullDownRefresh() }) }, onSearchChange(e: WechatMiniprogram.CustomEvent<{ value: string }>) { const txt = e.detail.value this.setData({ searchText: txt, }) }, onSearchSubmit(e: WechatMiniprogram.CustomEvent<{ value: string }>) { const txt = e.detail.value this.setData( { orderInput: { ...this.data.orderInput, filterText: txt, skipCount: 0, }, }, () => { this.load(true) }, ) }, gotoDetail(e: WechatMiniprogram.CustomEvent<{}, {}, { code: string }>) { Navi.navigateTo({ url: '/pages/mine/myorder/detail/index?code=' + e.currentTarget.dataset.code, }) }, onRebuy(e: WechatMiniprogram.CustomEvent<{}, {}, { code: string }>) { this.setData({ showConfirm: true, recode: e.currentTarget.dataset.code, }) }, confirmDialog() { this.setData({ showConfirm: false, wait: true, }) GoodApi.OrderDeplicate({ code: this.data.recode, }) .then((rsp) => { if (rsp.result === 'ok') { Navi.switchTab({ url: '/pages/cart/index', }) } this.setData({ wait: false, }) }) .catch(() => { this.setData({ wait: false, }) }) }, closeDialog() { this.setData({ showConfirm: false, recode: '', }) }, })