pointsReview.js 5.56 KB
// pages/pointsReview/index.js
import api from '~/api/api'
Page({

  /**
   * 页面的初始数据
   */
  data: {
    tabList: ['全部', '待审批', '已审批', '已失效'],
    keyword: '',
    sceneType: '',
    listData: [],
    statusObj: {
      0: {
        text: '待审批',
        color: '#FF9D0A',
        background: '#FFF5E6'
      },
      1: {
        text: '已审批',
        color: '#347BFF',
        background: '#EAF1FF'
      },
      2: {
        text: '已失效',
        color: '#F24724',
        background: '#FDECE9'
      }
    },
    listItemObj: [{
      label: '订单编号',
      key: 'orderCode'
    }, {
      label: '支付时间',
      key: 'payTime'
    }, {
      label: '推荐人',
      arr: ['referrerName', 'referrerPhone']
    }, {
      label: '门店名称',
      key: 'merchantName'
    }, {
      label: '订单时间',
      key: 'orderTime'
    }, {
      label: '交易流水号',
      key: 'tradeNo'
    }, {
      label: '积分归属',
      key: 'staffSource'
    }, {
      label: '备注',
      key: 'remark'
    }],
    imageUrlData: [],
    pageNum: 1,
    nothing: false,
    total: 0
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad(options) {
  },

  onRoute(options) {
    this.setData({
      sceneType: options?.scene
    })
  },

  tabClick(e) {
    this.setData({
      tabIndex: e?.detail
    }, () => {
      this.search()
    })
  },

  search() {
    this.setData({
      listData: [],
      pageNum: 1,
      flag: false,
      nothing: false
    }, () => {
      this.getListData()
    })
  },

  getListData() {
    let { sceneType, listData, pageNum, nothing, keyword, tabIndex } = this.data
    let statusObj = {0: '', 1: 0, 2: 1, 3: 2}
    let params = {
      // sceneType,
      pageNum,
      pageSize: 4,
      search: keyword,
      supervisorStatus: statusObj[tabIndex]
    }
    if (nothing) return
    api.getPointsReviewListAPI(params).then(res => {
      let { code, data, message } = res
      if (code == 0) {
        data?.list?.forEach(val => {
          val.payTime = (val.payTime && (new Date(val.payTime).format('yyyy.MM.dd hh:mm:ss') || val.payTime)) || '' // 支付时间
          val.orderTime = (val.orderTime && (new Date(val.orderTime).format('yyyy.MM.dd hh:mm:ss') || val.orderTime)) || '' // 订单时间
          val.subOrderList = val?.goodsName?.split(',') // 商品
          val.failTime = (val.failTime && (new Date(val.failTime).format('yyyy.MM.dd hh:mm:ss') || val.failTime)) || '' // 退款,撤单,错单时间
          val.operateTime = (val?.operationList?.[0]?.operateTime && (new Date(val.operationList[0].operateTime).format('yyyy.MM.dd hh:mm:ss') || val.operationList[0].operateTime)) || '' // 审批时间
          val.operator = val?.operationList?.[0]?.operator || '' // 审批人
          val.operatorPhone = val?.operationList?.[0]?.operatorPhone || '' // 审批人手机号
          val.staffSource = val.staffSource == 1 ? '驻店员工' : '门店员工' // 积分归属
        })
        let tempList = listData?.concat(data?.list)
        this.setData({
          listData: tempList,
          nothing: data?.total == (tempList?.length - 1),
          total: data?.total,
          flag: true,
          triggered: false
        })
      } else {
        wx.$util.showToast(message)
      }
    }).catch(err => {})
  },

  // 查看全部商品
  showAllGoodsList(e) {
    let {
      item
    } = e.currentTarget.dataset
    let {
      listData
    } = this.data
    listData.forEach(subVal => {
      if (subVal.id == item.id) subVal.showAllGoodsListFlag = !subVal?.showAllGoodsListFlag
    })
    this.setData({
      listData
    })
  },

  // 审批
  handleReview(e) {
    let { item } = e.currentTarget.dataset
    this.setData({
      show: true,
      approvedItem: item,
      imageUrlData: item?.attachments?.split(',') || []
    })
  },

  handleConfirm() {
    let {approvedItem} = this.data
    let userInfo = wx.$util.getUserInfo()
    let params = {
      id: approvedItem?.id,
      auditResult: 0,
      operatorId: userInfo?.uuid
    }
    api.approvedPointsAPI(params).then(res => {
      let { code, message } = res
      if (code == 0) {
        this.search()
      } else {
        wx.$util.showToast(message)
      }
    }).catch(err => {})
    this.hideDialog()
  },

  handleCancel() {
    this.hideDialog()
  },

  hideDialog() {
    this.setData({
      show: false
    })
  },

  viewImage(e) {
    let { url } = e.currentTarget.dataset
    let { imageUrlData } = this.data
    wx.previewImage({
      urls: imageUrlData,
      current: url
    })
  },

  input(e) {
    let { value } = e.detail
    this.setData({
      keyword: value
    })
  },
  clear() {
    this.setData({
      keyword: ''
    }, () => {
      this.search()
    })
  },

  scrollonReachBottom() {
    let {
      total,
      pageNum,
      nothing
    } = this.data
    wx.$util.onReachBottom({
        total,
        pageNum,
        nothing,
        pageSize: 4
      },
      res => {
        this.getListData()
      }
    )
  },

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

  },

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

  },

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

  },

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

  },

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

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom() {
  },

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

  }
})