// pages/my-order/my-order.js const app = getApp(); import { getHwUserInfo } from "../../utils/util"; import { confirmOrderImpl, getOrdersImpl, confirmECOrdersImpl } from '../../service/impl/hwOrder.impl' Page({ /** * 页面的初始数据 */ data: { list: [], //订单列表 show: false, //展示无数据页面 pageNo: 1, //页码 isLast: false, //是否是最后一页 offline: false, status: 0, listNumber: 0, userInfo: { authenticationStatus: 0 } }, /** * 点击切换状态 * @param e */ changeSelect(e: any) { const index = e.currentTarget.dataset.index; this.setData({ status: Number(index), list: [] }, () => { this.getList(1) }) }, /** * 跳转详情页 * @id {string} 订单ID */ toDetail(e: any) { const id = e.currentTarget.dataset.id; wx.navigateTo({ url: `/pages/detail/detail?id=${id}&&status=2`, }) }, /** * 查看合同 * @contract {string} 合同 * */ checkContract(e: any) { const contract = e.currentTarget.dataset.contract; if (contract) { wx.downloadFile({ url: contract, success: (res) => { wx.openDocument({ filePath: res.tempFilePath, }) } }) } else { } }, /** * 确认订单 * @orderId {string} 订单ID */ confirm(e: any) { const id = e.currentTarget.dataset.id; // const index = e.currentTarget.dataset.index; const workContractType = e.currentTarget.dataset.workcontracttype; // const parentindex = e.currentTarget.dataset.parentindex; if (this.data.userInfo.authenticationStatus === 1) { // 电子合同确认 workContractType === 1 && confirmECOrdersImpl({ orderId: id }).then(data => { wx.navigateToMiniProgram({ appId: 'wxa023b292fd19d41d', path: "/" + data.data.url, }); }) // 非电子合同确认 workContractType === 0 && confirmOrderImpl({ orderId: id }).then(res => { if (res.errCode === 0) { workContractType === 0 && wx.showToast({ title: '订单已确认', success: () => { // 确认成功 更改页面订单状态 this.getList() // this.setData({ // [`list[${parentindex}][${index}].status`]: 2, // // [`list[${parentindex}][${index}].serviceStage`]: 2, // }) } }) } }) } else { // wx.showModal({ // title: '提示', // content: '您还未实名,是否立即实名?', // success: res => { // if (res.confirm) { wx.navigateTo({ url: "/pages/realNameAuthentication/realNameAuthentication", }); // } // } // }) } }, /** * 获取订单列表 * @pageNo {number} 页码 * @pageSize {number} 页面条数 */ getList(pageNumber?: number) { let pageNo: number = pageNumber || this.data.pageNo getOrdersImpl({ pageNo, pageSize: 10, status: this.data.status }).then(res => { if (res.errCode === 0) { if (pageNo === 1 && res.data.hwOrderList && res.data.hwOrderList.length === 0) { this.setData({ show: true }, () => { if (this.data.status === 0) { this.setData({ listNumber: this.data.list.length }) } }) } else { pageNo++; this.setData({ list: this.data.list.concat(res.data.hwOrderList), isLast: res.data.isLast, pageNo }, () => { if (this.data.status === 0) { this.setData({ listNumber: this.data.list.length }) } }) } } }).catch(err => { if (err === 'offline') { this.setData({ offline: true }) } }) }, /** * 列表重载 */ reload() { this.getList(1) }, checkLogin(): Boolean { if (wx.getStorageSync('userId') && wx.getStorageSync('userToken')) { return true } else { wx.reLaunch({ url: '/pages/login/login', }) return false } }, /** * 生命周期函数--监听页面加载 */ onLoad: function () { this.checkLogin() }, /** * 生命周期函数--监听页面初次渲染完成 */ onReady: function () { }, /** * 生命周期函数--监听页面显示 */ onShow: async function () { wx.hideHomeButton(); const userInfo = await getHwUserInfo() as { authenticationStatus: number } this.setData({ userInfo }) if (this.checkLogin()) { // 获取订单列表 this.setData({ list: [], pageNo: 1 }, () => { this.getList() }) } }, /** * 生命周期函数--监听页面隐藏 */ onHide: function () { }, /** * 生命周期函数--监听页面卸载 */ onUnload: function () { }, /** * 页面相关事件处理函数--监听用户下拉动作 */ onPullDownRefresh: function () { this.setData({ list: [], pageNo: 1 }, () => { this.getList() }) }, /** * 页面上拉触底事件的处理函数 */ onReachBottom: function () { const isLast = this.data.isLast; if (isLast) { // wx.showToast({ // icon: 'none', // title: '已经是最后一页了', // }) } else { this.getList() } } })