warningStoreList.js 4.97 KB
// packageIndex/pages/salesSummary/salesSummary.js
import IndexApi from '~/api/index/index'
import { tsFormatTime } from '~/utils/format'

function formatYMDHM(val) {
  if (!val) return '-'
  const d = new Date(val)
  if (isNaN(d.getTime())) return '-'
  const yyyy = d.getFullYear()
  const MM = String(d.getMonth() + 1).padStart(2, '0')
  const DD = String(d.getDate()).padStart(2, '0')
  // const HH = String(d.getHours()).padStart(2, '0')
  // const mm = String(d.getMinutes()).padStart(2, '0')
  return `${yyyy}-${MM}-${DD}`
}
Page({
  /**
   * 页面的初始数据
   */
  data: {
    activeIndex: 0,
    tabList: [
      {
        count: 0,
        text: '兜底指标预警'
      },
      {
        count: 0,
        text: '丢店风险预警'
      },
      {
        count: 0,
        text: '亏损预警'
      }
    ],
    list: []
  },
  getWarningStores() {
    let { month, staffUuid, regionId, tabList, activeIndex } = this.data
    let params = { month }
    if (staffUuid) {
      params.staffUuid = staffUuid
    }
    if (regionId) {
      params.regionId = regionId
    }
    IndexApi.getWarningStores(params).then(res => {
      console.log(res, 'res')
      let {
        backstopWarningCount,
        lostShopWarningCount,
        lossWarningCount,
        backstopWarningList = [],
        lostShopWarningList = [],
        lossWarningList = []
      } = res.data
      tabList[0].count = backstopWarningCount || 0
      tabList[1].count = lostShopWarningCount || 0
      tabList[2].count = lossWarningCount
      const mapExpected = arr =>
        Array.isArray(arr)
          ? arr.map(item => ({
              ...item,
              expectedOperationDateFormatted: formatYMDHM(
                item.expectedOperationDate
              ),
              signedTimeFormatted: formatYMDHM(item.signedTime)
            }))
          : []
      const _backstop = mapExpected(backstopWarningList)
      const _lostShop = mapExpected(lostShopWarningList)
      const _loss = mapExpected(lossWarningList)
      // list 根据
      this.setData({
        tabList,
        backstopWarningList: _backstop,
        lostShopWarningList: _lostShop,
        lossWarningList: _loss,
        list:
          activeIndex == 0
            ? _backstop || []
            : activeIndex == 1
            ? _lostShop || []
            : _loss || []
      })
    })
  },

  getList() {
    let { activeIndex } = this.data

    IndexApi.summaryMonthShowPersonList({
      personType: activeIndex == 0 ? 1 : 2
    }).then(res => {
      console.log(res)
      res.data = res.data.map(item => ({
        ...item,
        lastFollowUpTime: item.lastFollowUpTime
          ? tsFormatTime(item.lastFollowUpTime)
          : '-'
      }))
      this.setData({
        list: res.data
      })
    })
  },
  initTablist() {
    IndexApi.summaryMonthShow({}).then(res => {
      console.log(res)
      const { noExpansionPersonCount = 0, noSignCustomerCount = 0 } =
        res.data || {}
      const tabList = this.data.tabList.map(item => ({ ...item }))
      tabList[0].count = noExpansionPersonCount
      tabList[1].count = noSignCustomerCount
      this.setData({ tabList })
      // this.setData({
      //   tabList[0].count: res.data.noExpansionPersonCount,
      //   tabList[1].count: res.data.noSignCustomerCount,
      // })
    })
  },
  tabClick(e) {
    // 根据索引获取数据
    let { backstopWarningList, lostShopWarningList, lossWarningList } =
      this.data
    let list =
      e.detail == 0
        ? backstopWarningList
        : e.detail == 1
        ? lostShopWarningList
        : lossWarningList
    this.setData({
      activeIndex: e.detail,
      list: list || []
    })
  },
  navigateToStoreDetail(e) {
    let { item } = e.currentTarget.dataset
    item.currentTab = 2
    wx.navigateTo({
      url: `/packageCustomer/pages/merchantDetail/merchantDetail?query=${encodeURIComponent(
        JSON.stringify(item)
      )}`
    })
  },
  onRoute(options) {
    console.log(options, 'options')
    // console.log(options, 'options')
    this.setData({
      month: options.month,
      staffUuid: options.staffUuid,
      regionId: options.regionId,
      activeIndex: options.index || 0
    })
    this.getWarningStores()
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad(options) {},

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

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

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

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

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

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

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