| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235 |
- // pages/my-order/my-order.js
- const app = getApp();
- import { confirmOrderImpl, getOrdersImpl, confirmECOrdersImpl } from '../../service/impl/hwOrder.impl'
- Page({
- /**
- * 页面的初始数据
- */
- data: {
- list: [], //订单列表
- show: false, //展示无数据页面
- pageNo: 1, //页码
- isLast: false, //是否是最后一页
- offline: false,
- status: 0,
- listNumber: 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 (workContractType === 1) {
- confirmECOrdersImpl({
- orderId: id
- }).then(res => {
- if (res.errCode === 0) {
- // 跳转webview
- wx.reLaunch({
- url: `/pages/web-view/web-view?url=${encodeURIComponent(res.data.url)}`,
- success: () => {
- // 存入缓存方便跳回
- app.globalData.webview = `/${this.route}`;
- // wx.setStorageSync('web_view', `/${this.route}`)
- }
- })
- }
- })
- }
- // 非电子合同确认
- if (workContractType === 0) {
- confirmOrderImpl({
- orderId: id
- }).then(res => {
- if (res.errCode === 0) {
- wx.showToast({
- title: '订单已确认',
- success: () => {
- // 确认成功 更改页面订单状态
- this.getList()
- // this.setData({
- // [`list[${parentindex}][${index}].status`]: 2,
- // // [`list[${parentindex}][${index}].serviceStage`]: 2,
- // })
- }
- })
- }
- })
- }
- },
- /**
- * 获取订单列表
- * @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
- })
- } 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: function () {
- wx.hideHomeButton();
- 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()
- }
- }
- })
|