index.js 5.4 KB
import ActivityApi from "~/api/activityApi/index"
import Dialog from '@vant/weapp/dialog/dialog';
Page({
  data: {
    showFilter: false,
    showComfirm: false,
    filtterName: '时间',
    showTip: true,
    // 筛选初始化状态标识
    filterInit: true,
    customerList: [],
    total: 0,
    pageNum: 1,
    pageSize: 20,
    noResult: false,
    levelQuery: {
      'PC0036': '续保惠享A套餐',
      'PC0037': '续保优享B套餐',
      'PC0038': '续保乐享C套餐',
      'PC0039': '续保尊享D套餐',
    }
  },
  onLoad(options) {
    this.setNaviTitle(options.type)
    this.setData({
      pageType: +options.type
    })
    if (options.type == 1) {
      this.getSendCustomerList()
    } else {
      this.getListData()
    }
  },
  setNaviTitle(type) {
    let _title = type == 1 ? '已赠送客户' : '意向客户'
    wx.setNavigationBarTitle({
      title: _title
    })
  },
  getFilterResult(e) {
    const _obj = e.detail
    const { pageType } = this.data
    let _setQuery = {
      filterQuery: _obj,
      pageNum: 1
    }
    if (pageType == 1) {
      delete _obj.status
      _setQuery.filtterName = _obj.time.name
    }
    if (pageType == 0) {
      let _isAll = _obj.time.type === 0 && _obj.status.type === 0
      _setQuery.filterInit = _isAll
    }
    this.setData(_setQuery, () => {
      if (pageType == 1) {
        this.getSendCustomerList(_setQuery)
      } else {
        this.getListData(_setQuery)
      }
    })

  },
  toInt(e) {
    this.customerInfo = e.detail.value
  },
  toSearch() {
    const { pageType } = this.data
    this.data.pageNum = 1
    if (pageType == 1) {
      this.getSendCustomerList(this.condition)
    } else {
      this.getListData(this.condition)
    }
  },
  toShowComfirm(e) {
    let { item } = e.currentTarget.dataset
    this.setData({
      showComfirm: true,
      showTip: false,
      currentItem: item
    })
  },
  toShowFilter() {
    this.setData({
      showFilter: true
    })
  },
  onClose() {
    this.setData({
      showComfirm: false
    })
  },
  onConfirm() {
    this.updateStatus()
  },
  toCall(e) {
    let _phone = e.currentTarget.dataset.phone
    if (!_phone) return
    wx.makePhoneCall({
      phoneNumber: _phone
    })
  },
  /**获取列表数据 */
  getListData(condition, isScroll) {
    let { pageNum, customerList, pageSize } = this.data

    let _para = {
      pageNum,
      pageSize,
    }

    if (this.customerInfo) {
      _para.customerInfo = this.customerInfo
    }
    if (condition) {
      this.condition = condition
      const { status, time } = condition.filterQuery
      if (time.type) {
        _para.recentlyDateFlag = time.type
      }
      if (status.type) {
        _para.followUpFlag = status.type
      }
    }
    if (isScroll) {
      Object.assign(_para, this.scrollQuery)
    }
    this.scrollQuery = { ..._para }
    ActivityApi.getFollowCustomer(_para).then(res => {
      this.setData({
        noResult: pageNum > 1 ? false : res.list.length == 0,
        total: res.total,
        customerList: pageNum > 1 ? [...customerList, ...res.list] : res.list,
      })
    })
  },
  /**更新跟进状态 */
  updateStatus() {
    const { currentItem } = this.data
    let _query = {
      id: currentItem.id,
      followUpFlag: currentItem.followUpFlag == 1 ? 2 : 1
    }
    ActivityApi.updateFollowStatus(_query).then(res => {
      if (res) {
        this.getListData()
        wx.$api.showToast('操作成功')
        this.onClose()
      }
    })
  },
  onReachBottom: function () {
    let { pageNum, total, pageSize, pageType } = this.data
    // 判断当前页是否是末页
    // if (Math.floor(total / pageSize) == pageNum - 1) return
    if (pageNum * pageSize >= total) return
    this.setData({
      pageNum: pageNum + 1
    }, () => {
      delete this.scrollQuery.pageNum
      if (pageType == 1) {
        this.getSendCustomerList(null, true)
      } else {
        this.getListData(null, true)
      }
    })
  },
  /** 获取赠送客户列表*/
  getSendCustomerList(condition, isScroll) {
    let { pageNum, customerList, pageSize } = this.data

    let _para = {
      pageNum,
      pageSize,
    }
    if (this.customerInfo) {
      _para.customerInfo = this.customerInfo
    }
    if (condition) {
      this.condition = condition
      const { time } = condition.filterQuery
      if (time.type) {
        _para.recentlyDateFlag = time.type
      }
    }
    if (isScroll) {
      Object.assign(_para, this.scrollQuery)
    }
    this.scrollQuery = { ..._para }
    ActivityApi.getSendFollowList(_para).then(res => {
      this.setData({
        noResult: pageNum > 1 ? false : res.list.length == 0,
        total: res.total,
        customerList: pageNum > 1 ? [...customerList, ...res.list] : res.list,
      })
    })
  },
  /**导出 */
  toExportFile() {
    const { pageType } = this.data
    wx.$api.showLoading('正在导出...')
    const name = pageType == 1 ? 'exportSendFollowList' : 'exportFollowCount'
    ActivityApi[name]().then(ress => {
      if (ress) {
        wx.hideLoading();
        this.exportModal(ress)
      }
    })

  },
  // 导出弹框
  exportModal(url) {
    Dialog.confirm({
      title: '温馨提示',
      message: `导出数据已生成,请复制地址到手机\n浏览器中打开`,
      confirmButtonText: "复制链接",
      cancelButtonText: "取消",
    }).then(() => {
      wx.setClipboardData({
        data: url,
        success() {},
      })
    }).catch(() => {

    })
  },

})