receptionRecords.js 8.69 KB
// packageEquity/pages/receptionRecords/receptionRecords.js
import {
  getReceptionRecordList,
  getRecordDetailList
} from "../../receptionRecordsApi"
import carLifeApi from "../../carEquityApi";
import reportPageTrackMixin from '~/mixins/reportPageTrackMixin'
Page({
  behaviors: [reportPageTrackMixin],
  /**
   * 页面的初始数据
   */
  data: {
    navBarHeight: 113.5,
    show_reception_confirm: false,
    showReceptionRendering: false,
    scrollTop: 0,
    listData: [],
    pageNum: 1,
    searchForm: {},
    nothing: false,
    showEmployeeName: false, // 是否展示销售顾问字段
    isShowDefeatBtn: true,
    loaded: false,
    track_event_code: 'staff_reception_list', //埋点动作类型
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad(options) {
    let userInfo = wx.$util.getUserInfo() || {}
    if (userInfo?.isSuper || userInfo?.loginRole == 3 || userInfo.loginRole == 5) this.setData({
      showEmployeeName: true,
      isShowDefeatBtn: false
    })
    // 超管获取所有质检门店/员工
    this.setData({
      nothing: false
    })
    if (userInfo?.isSuper || userInfo?.loginRole == 3 || userInfo.loginRole == 5) {
      this.getStoreList()
    } else {
      this.getReceptionList()
    }
  },
  getStoreList() {
    carLifeApi.selectrecmerchantList({}).then(res => {
      let {
        code,
        data,
        message
      } = res
      if (code == 0) {
        this.setData({
          storeRangeList: data,
          listData: []
        }, () => {
          this.getReceptionList()
        })
      } else {
        wx.$util.showToast(message)
      }
    })
  },
  getParams() {
    let {
      searchForm,
      isFilterDefeat,
      isFilterUpgrade,
      storeRangeList
    } = this.data
    let userInfo = wx.$util.getUserInfo() || {};
    const now = new Date();
    const threeMonthsAgo = new Date(now.getFullYear(), now.getMonth() - 3, now.getDate() + 1)
    if (!searchForm.orderResult?.length) searchForm.orderResult = (isFilterDefeat ? [2] : []).concat(isFilterUpgrade ? [1] : [])
    let obj = {
      startDateTime: searchForm?.startDateTime || new Date(threeMonthsAgo).format('yyyy-MM-dd'),
      endDateTime: searchForm?.endDateTime || now.format('yyyy-MM-dd'),
      customerName: searchForm?.customerName || '',
      phoneNumber: searchForm?.customerName || '',
      qualityCheckScoreBegin: searchForm?.qualityCheckScoreBegin || '',
      qualityCheckScoreEnd: searchForm?.qualityCheckScoreEnd || '',
      customerTypes: searchForm?.customerTypes,
      carModels: searchForm?.carModels,
      orderResult: searchForm?.orderResult,
      merchantNo: !searchForm?.merchantNo?.length ? (userInfo?.isSuper ? storeRangeList.map(v => {
        if (v.merchantNo) return v.merchantNo
      }) : userInfo?.loginRole == 3 || userInfo.loginRole == 5 ? '' : [userInfo?.default4SStoreInfo?.merchantId]) : searchForm?.merchantNo,
      staffUuids: userInfo.isSuper || userInfo?.loginRole == 3 || userInfo.loginRole == 5 ? searchForm?.staffUuids : [userInfo.uuid]
    }
    return obj
  },
  // 详情页面
  goReceptionDetail(e) {
    let {
      item
    } = e.currentTarget.dataset
    wx.$router.go('receptionDetail', item)
  },
  navbarReady(e) {
    let navBarHeight = e.detail.height;
    this.setData({
      navBarHeight,
    });
  },

  showScreenPop() {
    let {
      isFilterDefeat,
      isFilterUpgrade
    } = this.data
    this.setData({
      showScreen: true,
      showReceptionRendering: true,
      show_reception_confirm: true,
      isFilterDefeat,
      isFilterUpgrade
    });
  },

  hideScreenPopup() {
    this.setData({
      showScreen: false,
      show_reception_confirm: false
    })
  },

  // 筛选确认
  searchScreen(e) {
    let searchForm = e.detail
    const orderResult = searchForm?.orderResult || []
    this.setData({
      isFilterUpgrade: orderResult?.includes(1),
      isFilterDefeat: orderResult?.includes(2),
      searchForm,
      nothing: false,
      listData: []
    }, () => {
      this.getReceptionList()
      wx.$track.setTrackData(0, 'staff_reception_search', this.getParams())
    })
    this.containerBack();
  },

  containerBack() {
    this.hideScreenPopup()
  },

  // 获取接待记录统计数据
  getReceptionList() {
    let {
      listData
    } = this.data
    let params = this.getParams()
    this.setData({
      loaded: false
    }, () => {
      wx.showLoading({
        title: '加载中'
      })
      getReceptionRecordList({
        merchantNo: params.merchantNo,
        startDateTime: params.startDateTime,
        endDateTime: params.endDateTime,
        staffUuids: params.staffUuids
      }).then(res => {
        let {
          code,
          message,
          data
        } = res
        if (code == 0) {
          data?.forEach(val => {
            val.receptionStaticInfoDTOList = []
            val.staticDateStr = `${new Date(val.staticDate).getMonth() + 1}月${new Date(val.staticDate).getDate()}日`
          })
          this.setData({
            listData: listData.concat(data),
            pageNum: 1
          }, () => {
            this.getReceptionRecordDetailInfo()
          })
        } else {
          wx.$util.showToast(message)
        }
      }).catch(err => {
        wx.hideLoading()
      })
    })

  },
  // 获取接待记录接待时间轴详情数据
  getReceptionRecordDetailInfo() {
    let {
      pageNum,
      listData,
      nothing
    } = this.data
    let params = {
      pageNum,
      ...this.getParams()
    }
    if (nothing) return
    wx.showLoading({
      title: '加载中'
    })
    this.track_businessParam = params //埋点业务参数
    getRecordDetailList(params).then(res => {
      let {
        code,
        data,
        message
      } = res
      if (code == 0) {
        listData?.forEach(val => {
          data?.list?.forEach(subV => {
            if (val.staticDate == subV.staticDate && val.receptionStaticInfoDTOList?.findIndex(v => v.fileUrl == subV.fileUrl) < 0) val.receptionStaticInfoDTOList.push(subV)
          })
        })
        let listDataLength = listData.reduce((acc, curr) => acc + curr?.receptionStaticInfoDTOList?.length, 0)
        this.setData({
          loaded: true,
          listData,
          pageNum: pageNum + 1,
          triggered: false,
          nothing: pageNum == data?.pages || listDataLength == data?.total
        })
      } else {
        wx.$util.showToast(message)
      }
      wx.hideLoading()
    }).catch(err => {
      wx.hideLoading()
    })
  },
  // 过滤升级/战败接待记录数据
  filterItemData(e) {
    let {
      type
    } = e.currentTarget.dataset
    let {
      isFilterUpgrade,
      isFilterDefeat,
      searchForm
    } = this.data
    let orderResult = searchForm?.orderResult || []
    let index
    if (type == 'upgrade' || type == 'defeat') {
      let targetType = type == 'upgrade' ? 1 : 2;
      index = orderResult.findIndex(v => v == targetType)
      if (type == 'upgrade') {
        if (!isFilterUpgrade) {
          orderResult.push(1)
        } else {
          orderResult.splice(index, 1)
        }
        this.setData({
          isFilterUpgrade: !isFilterUpgrade,
          'searchForm.orderResult': orderResult
        });
      } else if (type == 'defeat') {
        if (!isFilterDefeat) {
          orderResult.push(2)
        } else {
          orderResult.splice(index, 1)
        }
        this.setData({
          isFilterDefeat: !isFilterDefeat,
          'searchForm.orderResult': orderResult
        })
      }
    }
    this.setData({
      nothing: false,
      listData: [],
      ['searchForm.orderResult']: orderResult
    }, () => {
      this.getReceptionList()
    })
  },
  // 触底加载更多
  onBottomRefresh() {
    this.getReceptionRecordDetailInfo()
  },
  // 下拉刷新数据
  refreshListData() {
    this.setData({
      listData: [],
      nothing: false
    }, () => {
      this.getReceptionList()
    })
  },
  goto(e) {
    let {
      record
    } = e.currentTarget.dataset
    wx.$router.go('packageEquity.receptionDetail', record)
    wx.$track.setTrackData(0, 'reception_detail', {
      batchId: record.batchId
    })
  },
  back() {
    wx.$router.back()
  },

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

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow() {
    this.onPageShow()
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide() {
    this.onPageHide()
  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload() {
    this.onPageHide()
  },

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

  },

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

  },

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

  }
})