orderList.js 7.55 KB
import util from '../../../utils/util.js'
import api from '../../restapi.js'
import {
  pageData
} from '../index/properties.js'
import filter from '../../../utils/filter'
const {
  globalData
} = getApp()
Page(filter.identityFilter({

  /**
   * 页面的初始数据
   */
  data: {
    searchValue: null,
    searchType: 0,
    searchText: ['全部', '月份'],
    endTime: new Date().format('yyyy-MM'),
    orderList: pageData.orderList,
    orderObj: pageData.orderObj,
    orderStatus: pageData.orderStatus,
    pageNum: 1,
    status: '',
    //1待升级;2:不升级;3待支付;4已支付;6:已完成
    tabList: [{
        name: '全部',
        value: ''
      },
      {
        name: '待跟进',
        value: 1
      },
      {
        name: '已支付',
        value: 4
      },
      {
        name: '待支付',
        value: 3
      },
      {
        name: '已评价',
        value: 6
      },
      {
        name: '不升级',
        value: 2
      },
      {
        name: '已撤销',
        value: 9
      }
    ],
    tabIndex: 0,
    to: 'tab-0'
  },
  chooseStatus(e) {
    let {
      value,
      index
    } = e.currentTarget.dataset
    this.setData({
      status: value,
      orderFlag: false,
      nothing: false,
      orderList: [],
      pageNum: 1,
      tabIndex: index,
      to: `tab-${index}`
    })
    let {
      userId,
      keyword,
      startDate,
      endDate
    } = this.data
    let params = {
      userId,
      keyword,
      startDate,
      endDate
    }
    Object.keys(params).map(i => {
      if (!params[i]) delete params[i]
    })
    this.getOrderList(params)
  },
  bindrefresherrefresh(e) {
    this.setData({
      orderFlag: false,
      nothing: false,
      orderList: [],
      pageNum: 1
    })
    let {
      userId,
      keyword,
      startDate,
      endDate
    } = this.data
    let params = {
      userId,
      keyword,
      startDate,
      endDate
    }
    Object.keys(params).map(i => {
      if (!params[i]) delete params[i]
    })
    this.getOrderList(params)
  },

  search(e) {
    let {
      startDate,
      endDate
    } = this.data
    let keyword = e.detail
    let params = {
      keyword
    }
    if (startDate && endDate) params = {
      ...params,
      startDate,
      endDate
    }
    this.setData({
      orderList: [],
      orderFlag: false,
      keyword,
      nothing: false
    })
    this.getOrderList(params)
  },
  showSearchType() {
    let {
      searchPickerStatus
    } = this.data
    this.setData({
      searchPickerStatus: !searchPickerStatus
    })
  },
  getDayNumber(year, month) {
    let days = 31
    switch (month) {
      case 2:
        days = (year % 4 == 0 && year % 100 !== 0) || year % 400 == 0 ? 29 : 28
        break;
      case 4:
      case 6:
      case 9:
      case 11:
        days = 30
        break;
    }
    return days
  },
  changeSearchType(e) {
    let {
      index
    } = e.currentTarget.dataset
    let data = {
      searchType: index,
      searchPickerStatus: false,
      orderList: [],
      orderFlag: false,
      nothing: false
    }
    let {
      keyword,
      userId
    } = this.data
    if (index == 1) {
      let {
        value
      } = e.detail
      let [year, month] = value.split('-')
      let maxDay = this.getDayNumber(year, Number(month))
      console.log(year, month, maxDay)
      data.startDate = `${value}-01 00:00:00`
      data.endDate = `${value}-${maxDay} 23:59:59`
    }
    this.setData(data)
    this.getOrderList({
      keyword: keyword || '',
      startDate: data.startDate || '',
      endDate: data.endDate || '',
      userId: userId || ''
    })
  },
  jump(e) {
    console.log(e)
    let {
      item: {
        orderCode
      }
    } = e.currentTarget.dataset
    util.navigateTo(`../orderDetails/orderDetails?orderCode=${orderCode}`)
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    let {
      userInfo
    } = globalData
    let {
      merchantId,
      userType
    } = userInfo
    if (userType == 1) {
      api.getEmployeesByMerchantId({
        merchantId
      }, res => {
        console.log(res)
        let employeeList = []
        if (res.returnCode == 0) {
          employeeList = res.data
        }
        this.setData({
          employeeList,
          userType
        })
      })
    }
    this.getOrderList()
  },

  searchEmployee(e) {
    let {
      keyword,
      endDate,
      startDate,
      employeeList
    } = this.data
    console.log(e)
    let {
      value
    } = e.detail
    let {
      uuid
    } = employeeList[value]
    this.setData({
      orderList: [],
      pageNum: 1,
      userId: uuid,
      nothing: false
    })
    this.getOrderList({
      keyword: keyword || '',
      startDate: startDate || '',
      endDate: endDate || '',
      userId: uuid
    })
  },
  onLogin() {},
  getOrderList(params = {}) {
    util.showLoading('加载中...')
    let {
      status,
      pageNum,
      orderList
    } = this.data
    if (status) params.status = status
    let arr = []
    let total = 0
    util.promise(resolve => {
      console.log(params)
      api.getOrderList({
        ...params,
        pageNum,
        pageSize: 10
      }, res => {
        console.log('转化订单', res)
        let {
          returnCode,
          data
        } = res
        if (returnCode == '0' && data) {
          data.list.map(e => {
            if (e.installUpgradeTime) e.time = new Date(e.installUpgradeTime).format('yyyy.MM.dd hh:mm')
            e.totalPrice = `${e.totalPrice || 0}元`
            if (e.profitAllocatinList && e.profitAllocatinList.length > 0) {
              let shopProfitMoney = 0
              e.profitAllocatinList.map(i => {
                shopProfitMoney += i.shopProfitMoney
              })
              e.shopProfitMoney = `${shopProfitMoney}元`
            }
            arr.push({
              ...e.customer,
              ...e,
              goodsListName: e.upgradeGoodsName && e.upgradeGoodsName.join('、')
            })
          })
          total = data.total
        }
        resolve()
      })
    }).then(() => {
      util.hideLoading()
      this.setData({
        orderList: [...orderList, ...arr],
        orderFlag: true,
        total
      })
    })

  },
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {
    let {
      total,
      userId,
      keyword,
      pageNum,
      endDate,
      startDate
    } = this.data
    util.onReachBottom(this, {
      total,
      pageNum,
    }, () => {
      this.getOrderList({
        keyword: keyword || '',
        startDate: startDate || '',
        endDate: endDate || '',
        userId: userId || ''
      })
    })
  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
}))