employeeInspection.js 7.18 KB
// packageEquity/pages/employeeInspection.js
import carLifeApi from '../../carEquityApi'
Page({

  /**
   * 页面的初始数据
   */
  data: {
    showStoreSelectPopup: false,
    flag: true,
    isopen: false,
    total: 0,
    scrollTop: 0,
    pageNum: 1,
    nothing: false,
    inspectList: [],
    selectedYqMerchantList: [],
    merchantName: '全部',
    tempList: [],
    searchValue: '',
    keyword: '',
    bussinessType: 1,
    triggered: false,
    merchantDTOList: [],
    isStorePop: false,
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad(options) {
    this.getStoreList()
    this.loadData()
  },
  loadData() {
    const day = new Date().setDate(new Date().getDate() - 1)
    const searchdate = new Date(day).format('yyyy-MM-dd')
    this.setData({
      searchdate
    })
  },
  changeBussinessType(e) {
    let {
      type
    } = e.target.dataset
    this.setData({
      bussinessType: type,
      nothing: false,
      pageNum: 1,
    }, () => {
      this.getList(true)
    })
  },
  getList(isReset = false) {
    let {
      data: {
        pageNum,
        keyword,
        bussinessType,
        nothing,
        RecMerchantNo,
        searchdate
      }
    } = this;

    let params = {
      pageSize: 10,
      pageNum: isReset ? 1 : pageNum,
      searchdate,
      keyword,
      BussinessType: bussinessType
    }
    if (RecMerchantNo) params.RecMerchantNo = RecMerchantNo
    if (nothing) return
    carLifeApi.employeeBadgeReclistWithPage(params).then(res => {
      let {
        code,
        data,
        message
      } = res
      if (code == 0) {
        let tempList = isReset ? data?.list : this.data.inspectList.concat(data?.list)
        tempList.map(e => {
          if (e.seconds) e._seconds = this.formatTime(e.seconds)
          // e.tempServer = e.serviceList.slice(0, 3)
          console.log(e.merchantDTOList)
          e.tempStore = e.merchantDTOList && e.merchantDTOList.length > 0 ? e.merchantDTOList.slice(0, 3) : []
        })
        this.setData({
          inspectList: tempList,
          total: data?.total,
          triggered: false,
          nothing: data?.total == tempList.length,
        })
      } else {
        wx.$util.showToast(message)
      }
    })
  },
  getStoreList() {
    let {
      searchValue,
      selectedYqMerchantList
    } = this.data
    let params = {
      merchantName: searchValue
    }
    carLifeApi.selectrecmerchantList(params).then(res => {
      let {
        code,
        data,
        message
      } = res
      if (code == 0) {
        data?.unshift({
          merchantNo: '',
          merchantName: '全部',
          active: true
        })
        selectedYqMerchantList.unshift({
            merchantNo: '',
            merchantName: '全部',
            active: true
          }),
          this.setData({
            storeRangeList: data,
            tempList: data,
            selectedYqMerchantList
          }, () => {
            this.getList(true)
          })
      } else {
        wx.$util.showToast(message)
      }
    })
  },
  input(e) {
    let {
      value
    } = e.detail
    this.setValue(value)
    this.triggerEvent('input', {
      value
    })
  },
  inputConfifm(e) {
    this.setData({
      nothing: false
    })
    this.getList(true)
  },
  setValue(value) {
    if (this.properties.filterEmoji) {
      if (wx.$util.haveEmoji(value)) value = wx.$util.replaceEmoji(value)
    }
    this.setData({
      keyword: value
    })
  },
  handleReset() {
    this.setData({
      keyword: '',
      nothing: false
    })
    this.getList(true)
  },
  formatTime(seconds) {
    // seconds = Math.floor(seconds / 1000)
    let formattedTime = ''
    if (seconds < 60) return seconds + 's'
    else {
      let hours = Math.floor(seconds / 3600),
        minutes = Math.floor((seconds % 3600) / 60),
        remainingSeconds = seconds % 60
      if (hours > 0) formattedTime += hours + 'h'
      if (minutes > 0 || hours > 0) formattedTime += minutes + 'min'
      if (remainingSeconds > 0) formattedTime += remainingSeconds + 's'
      return formattedTime
    }
  },
  showStoreSelectPopup(e) {
    let {
      tempList
    } = this.data;
    this.setData({
      showStoreSelectPopup: true,
      storeRangeList: tempList
    })
  },
  scrollonReachBottom() {
    let {
      pageNum
    } = this.data
    this.setData({
      pageNum: pageNum + 1,
    })
    this.getList()
  },
  search() {
    this.setData({
      pageNum: 1,
      nothing: false,
      total: 0
    })
    this.getList(true)
  },
  storeConfirm(e) {
    let selectedYqMerchantList = e?.detail;
    let RecMerchantNo = selectedYqMerchantList.length > 0 ? selectedYqMerchantList.map(item => item.merchantNo).join(',') : ''
    let merchantName = selectedYqMerchantList.length > 0 ? selectedYqMerchantList.map(item => item.merchantName).join(',') : '全部'
    this.setData({
      showStoreSelectPopup: false,
      selectedYqMerchantList,
      RecMerchantNo,
      merchantName,
      nothing: false
    })
    this.getList(true)
  },
  updata(e) {
    let {
      storeRangeList,
      tempList,
      searchValue
    } = this.data, arr;
    searchValue = e?.detail
    if (searchValue) {
      arr = tempList.filter(item => {
        if (item.merchantName.includes(searchValue)) {
          return item
        }
      })
    } else {
      storeRangeList = tempList
    }
    this.setData({
      storeRangeList: searchValue ? arr : tempList
    })
  },
  hideStorePopup() {
    this.setData({
      showStoreSelectPopup: false
    })
    this.filterStore()
  },
  filterStore(arr) {
    let {
      selectedYqMerchantList,
      tempList
    } = this.data,
      list = arr ? arr : selectedYqMerchantList;
    tempList.forEach(val => {
      list.forEach(v => {
        if (v.merchantNo == val.merchantNo) {
          val.active = v.active
        }
      })
    })
    let res = false;
    tempList.forEach(item => {
      if (item.merchantName !== '全部' && item.active) {
        res = true
      }
    })
    if (!res) {
      tempList[0].active = true
    } else {
      tempList[0].active = false
    }
    if (arr) {
      this.setData({
        tempList
      })
    } else {
      this.setData({
        storeRangeList: tempList
      })
    }

  },
  showOpen(e) {
    let {
      open
    } = e.currentTarget.dataset
    this.setData({
      isopen: !this.data.isopen
    })
    if (open) {
      this.setData({
        pageNum: 1,
        nothing: false,
        keyword: ''
      }, () => {
        this.getList(true)
      })
    }
  },
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  changeDate({
    detail
  }) {
    this.setData({
      pageNum: 1,
      nothing: false,
      searchdate: detail
    }, () => {
      this.getList(true)
    })

  },
  onReady() {

  },

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

  },

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

  },

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

  },

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

  },

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

  },

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

  }
})