clueList.js 5.35 KB
// packageEquity/pages/clueList/clueList.js
import carLifeApi from '../../carEquityApi'
import NP from 'number-precision'
Page({

  /**
   * 页面的初始数据
   */
  data: {
    activeIndex: 0,
    pageNum: 1,
    searchValue: '',
    list: [],
    customerTips: '今日新增0客户',
    tabList: [{
      text: '全部',
      count: 0,
      key: 'total'
    }, {
      text: '待跟进',
      count: 0,
      key: 'waitFollow'

    },
    {
      text: '已升级',
      count: 0,
      key: 'upgrade'
    },
    {
      text: '战败',
      count: 0,
      key: 'defeat'
    }
    ],
  },
  onRoute(options) {
    console.log(options, 'options');
    if (options.activeIndex) {
      this.setData({
        activeIndex: 1
      })
      this.status = 1
      this.getCustomerClueTodayCount()
    }
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad(options) {

    const {
      sceneType
    } = wx.$util.getUserInfo()
    /**sceneType 
     * 1精品升级 
     * 0会员权益/升级*/
    this.setData({
      sceneType: sceneType
    })
    // this.getCustomerClueList()
    this.getCustomerClueTodayCount()
  },
  search() {
    this.setData({
      pageNum: 1,
      list: [],
      flag: false,
      nothing: false
    })
    this.getCustomerClueList()
  },
  tabClick(e) {
    this.status = [null, 1, 2, -1][e.detail]
    this.search()
  },
  async getCustomerClueList() {
    try {
      const {
        searchValue,
        sceneType,
        pageNum,
      } = this.data, {
        status
      } = this, {
        shopMerchantId: merchantId
      } = wx.$util.getUserInfo(),
        params = {
          search: searchValue,
          sceneType,
          pageNum,
          merchantId: [merchantId]
        }
      if (status !== null) params.status = status
      wx.$util.showLoading()
      const {
        code,
        data,
        message
      } = await carLifeApi.getCustomerClueList(params)
      if (code == 0) {
        wx.hideLoading()
        const TimeFormat = 'yyyy.MM.dd hh:mm:ss'
        data.list.map(e => {
          if (sceneType == 1) {
            //权益服务
            e.vqOrders?.map(i => {
              i.quotedPriceUpdate = this.truncateDecimal(NP.times(i.quotedPriceUpdate || 0, 0.01))
              if (i.payTime) i.payTime = new Date(i.payTime).format(TimeFormat)
              i.vdQuotationGoodsList?.map(x => {
                x.goodsPrice = this.truncateDecimal(NP.times(x.goodsPrice || 0, 0.01))
              })
            })
          } else {
            //精品加装 
            e.boutiqueOrders?.map(i => {
              i.totalPrice = this.truncateDecimal(i.totalPrice || 0)
              if (i.payOrder && i.payOrder.successDate) i.successDate = new Date(i.payOrder.successDate).format(TimeFormat)
              i.subOrderList?.map(x => {
                x.totalPrice = this.truncateDecimal(x.totalPrice || 0)
              })
            })
          }
          if (e.customerInfo && e.customerInfo.carPrice) e.customerInfo.price = this.truncateDecimal(NP.times(e.customerInfo.carPrice, 0.01))
        })
        this.setData({
          [`list[${pageNum - 1}]`]: data.list || [],
          total: data.total,
          flag: true
        })
      } else throw message
    } catch (error) {
      wx.hideLoading()
      this.setData({
        flag: true
      })
      console.log(error)
      wx.$util.showToast(error)
    }
  },
  async getCustomerClueTodayCount() {
    const {
      sceneType,
    } = this.data, {
      shopMerchantId: merchantId
    } = wx.$util.getUserInfo(), {
      data
    } = await carLifeApi.getCustomerClueTodayCount({
      sceneType,
      merchantId: [merchantId]
    })
    if (data) this.setData({
      customerTips: data
    })
  },
  async getCustomerClueStatistics() {
    const {
      sceneType,
      tabList
    } = this.data, {
      shopMerchantId: merchantId
    } = wx.$util.getUserInfo(), {
      data
    } = await carLifeApi.getCustomerClueStatistics({
      sceneType,
      merchantId: [merchantId]
    })
    if (data) {
      tabList.map(e => {
        Object.keys(data).map(key => {
          if (key == e.key) e.count = data[key] || 0
        })
      })
      this.setData({
        tabList
      })
    }
  },
  input(e) {
    let {
      value
    } = e.detail
    this.setData({
      searchValue: value
    })
  },
  handleReset() {
    this.setData({
      searchValue: ''
    })
    this.search()
  },
  truncateDecimal(number, decimalPlaces = 2) {
    let [integer, decimals] = String(number).split('.')
    if (!decimals) decimals = '00'
    if (decimals.length > 2) decimals = decimals.substring(0, decimalPlaces)
    if (decimals.length == 1) decimals += '0'
    return `${integer}.${decimals}`
  },
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady() {

  },

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

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

  },

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

  },

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

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom() {
    let {
      total,
      pageNum
    } = this.data
    wx.$util.onReachBottom({
      total,
      pageNum
    }, res => {
      this.getCustomerClueList()
    })
  }
})