customerList.js 3.72 KB
// packageMine/pages/customerManagement/customerList/customerList.js
import { IMG_URL } from '~/utils/constantData'
import mineCustomerApi from '~/api/mineApi/mineCustomer'
import mineApi from '~/api/mineApi/index'
Page({

  /**
   * 页面的初始数据
   */
  data: {
    IMG_URL,
    maxNum: 99,
    bgUrl: `${IMG_URL}/personal/empty_tran.png`,
    active: 'customer',
    selectInfo: {
      yqMerchantName: '全部服务中心'
    },
    popupShow: false,
    serviceList: [],
    allServiceIds: [],
    customerList: [],
    total: -1,
    pageCof: {
      pageNum: 1,
      pageSize: 10
    },
    isAsk: false
  },

  tabChange(e) {
    let { name } = e.detail
    this.setData({
      active: name
    })
  },

  // 筛选服务中心
  filterTypeFn() {
    this.setData({
      popupShow: !this.data.popupShow
    })
  },

  // 邀请销售
  handleSale(e) {
    let { target } = e.currentTarget.dataset
    wx.$router.go('packageMine.saleList', target)
  },

  handleTechnician(e) {
    let { target } = e.currentTarget.dataset
    wx.$router.go('packageMine.technicianList', target)
  },

  handleEdit(e) {
    let { type } = e.currentTarget.dataset
    let params = {
      addOrEdit: type,
      target: e.currentTarget.dataset?.target || {}
    }
    wx.$router.go('packageMine.editCustomer', params)
  },

  onRefreshBottom() {
    wx.$api.hideLoading()
    this.setData({
      total: -1,
      ['pageCof.pageNum']: 1,
    })
    this.getList(true)
  },

  handleSearch(e) {
    wx.$api.hideLoading()
    this.setData({
      selectInfo: e.detail,
      total: -1,
      ['pageCof.pageNum']: 1,
    })
    this.getList(true)
  },

  scrollonReachBottom() {
    this.getList()
  },

  getList(isReset = false) {
    let { customerList, pageCof, total, selectInfo, isAsk } = this.data
    let _this = this
    if (total == customerList.length || isAsk) {
      return true
    }
    let params = {
      ...pageCof,
      serviceCenterMerchantId: selectInfo?.yqMerchantId || ''
    }
    this.setData({
      isAsk: true
    })
    mineCustomerApi.getCustomerList(params).then(res => {
      let { list, total } = res
      this.setData({
        customerList: pageCof.pageNum == 1 ? (list || []) : customerList.concat(list || []),
        ['pageCof.pageNum']: pageCof.pageNum + 1,
        triggered: false,
        total
      })
      if (isReset) {
        this.setData({
          scrollTop: 0
        })
      }
    }).finally(function () {
      _this.setData({
        isAsk: false
      })
    })
  },

  // 获取服务中心数据
  getServiceList() {
    mineApi.getServiceCenterListAPI({}).then(res => {
      let data = res || []
      let serviceIds = data.map(val => { return val.yqMerchantId })
      this.setData({
        serviceList: res || [],
        allServiceIds: serviceIds,
        ['pageCof.pageNum']: 1,
        total: -1
      })
      this.getList(true)
    })
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad(options) {
    if (options?.activeTab) {
      this.tabChange({
        detail: {
          name: options?.activeTab
        }
      })
    }
  },

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

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow() {
    this.setData({
      total: -1,
      ['pageCof.pageNum']: 1,
    })
    this.getServiceList(true)
  },

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

  },

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

  },

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

  },

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

  },

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

  }
})