clue.js 8.91 KB
// packagesList/mineDetail/pages/clue.js
import { IMG_URL } from '~/utils/constantData.js'
import { unreadApi, pageApi, tagApi } from '~/api/index.js'
const IMAGES = Object.freeze({
  arrow: `${IMG_URL}/index/point.png`,
  actArrow: `${IMG_URL}/index/actArrow.png`
})

Page({

  /**
   * 页面的初始数据
   */
  data: {
    IMAGES,
    IMG_URL,
    disLikeRecordFlag: true,
    typeList: [
      {
        0: '无电话',
        1: '有电话',
        2: '联系电话',
        selectIndex: 2,
        key: 'hasPhone'
      },
      {
        0: '非意向客户',
        1: '是意向客户',
        2: '意向客户',
        selectIndex: 2,
        key: 'starTag'
      },
      {
        0: '来自访客',
        1: '来自门店',
        2: '线索来源',
        selectIndex: 2,
        key: 'clueSource'
      },
      {
        2: '重置',
        selectIndex: 2
      }
    ],
    levelTagObj: {
      1: {
        label: '初步了解'
      },
      2: {
        label: '深入了解',
        class: 'tag-red'
      },
      3: {
        label: '签约成交',
        class: 'tag-blue'
      }
    },
    clueList: [],
    // 看线索部分
    unreadClueCount: 0,
    cluePageSize: 1000,
    clueCurrentPage: 1,
    disLikeFlag: true,
    clueParams: {} //看线索参数
  },

  //点击收藏
  showToast: function (e) {
    wx.$storage.set('disLikeRecordFlag', false)
    let disLikeRecordFlag = wx.$storage.get('disLikeRecordFlag')
    this.setData({
      disLikeFlag: false,
      disLikeRecordFlag
    })
    let { type, item } = e.currentTarget.dataset
    // console.log('type,item: ', type, item)
    let tipObj = {}
    if (item.starTag == 1) {
      tipObj = {
        type: 'fail',
        title: '取消标记为意向客户'
      }
    } else {
      tipObj = {
        type: 'success',
        title: '成功标记为意向客户'
      }
    }
    this.data.prompt.showToast({
      type: tipObj.type,
      title: tipObj.title,
      duration: 1000,
      compelete: function () {
        // console.log("toast框隐藏之后,会调用该函数");
        //例如:跳转页面wx.navigateTo({ url: 'xxx' });
      }
    })

    //切换收藏标记
    let index = e.currentTarget.dataset.outidx
    let completeStatus = `clueList[${index}].like`
    this.setData({
      [completeStatus]: !this.data.clueList[index].like
    })
    //发请求
    let { sessionId } = wx.$storage.get()
    let params = {
      clueId: item.clueId,
      sessionId
    }
    this.getTagApi(params)
  },
  //看线索重置
  resetCluelist() {
    let { typeList } = this.data
    typeList.forEach(item => {
      item.selectIndex = 2
    })
    this.setData({
      typeList,
      clueParams: {}
    })
    //重置数据
    this.clearclueData()
    this.getPageApi()
  },

  filterTypeFn(e) {
    let { typeList } = this.data
    let index = e.currentTarget.dataset.index
    // 重置筛选
    if (index == 3) {
      return this.resetCluelist()
    }

    let itemList = Object.values(typeList[index]).slice(0, 2)
    itemList.push('全部')
    let _this = this
    wx.pro.showActionSheet({
      itemList,
      success(res) {
        //重置数据
        _this.clearclueData()

        //  选中全部
        let selectIndex = res.tapIndex
        // console.log('selectIndex: ', selectIndex);
        typeList[index].selectIndex = selectIndex
        let params = typeList.reduce((obj, item, index) => {
          // console.log(' item: ', item)
          if (item['key']) {
            let itemIndx = item.selectIndex
            // key: 'clueSource'
            if (item['key'] == 'clueSource') {
              // itemIndx += 1
              obj[item['key']] = itemIndx == 2 ? '' : itemIndx + 1
            } else {
              obj[item['key']] = itemIndx == 2 ? '' : itemIndx
            }
          }
          return obj
        }, {})
        // console.log(params)
        // 清空数据
        _this.setData({ typeList, clueParams: params })
        _this.getPageApi(params)
      },
      fail(res) {
        // console.log(res.errMsg)
      }
    })
  },
  //重置数据
  clearclueData() {
    this.setData({
      clueList: [],
      clueCurrentPage: 1
      // hasPhone: '',
      // starTag: '',
      // clueSource: '',
    })
  },
  // 打电话
  phoneCallFn(e) {
    let { phone } = e.currentTarget.dataset
    wx.$api.phoneCall(phone)
  },
  // 复制号码
  setCopyDataFn(e) {
    let { phone } = e.currentTarget.dataset
    wx.$api.setCopyData(phone)
  },
  getClueInit(param) {
    this.getUnreadApi(param)
    this.getPageApi(param)
  },
  //未读消息
  async getUnreadApi(param) {
    let { code, data } = await unreadApi(param)
    if (code == 0) {
      this.setData({
        unreadClueCount: data.unreadClueCount
      })
    }
  },
  //获取浏览线索数据列表
  async getPageApi(param) {
    let { cluePageSize, clueCurrentPage, clueList } = this.data
    let params = {
      pageSize: cluePageSize,
      currentPage: clueCurrentPage,
      ...param
    }
    let { code, data } = await pageApi(params)
    if (code == 0) {
      let arr = data.list.map(item => {
        if (item.visitList && item.visitList.length > 5) {
          item.getMoreFlag = true
        }
        return item
      })

      //添加分页数据
      // let concatArr = []
      // if(arr.length > 0) {
      //   concatArr = clueList.concat(arr)

      // }

      this.setData({
        clueList: arr
      })
      let arrinx = arr.findIndex(e => e.clueType == 1 && e.starTag == 0)
      this.setData({
        disLikeFlagIdx: arrinx,
        triggered: false
      })
    }
  },
  //喜欢收藏功能
  async getTagApi(param) {
    let { clueParams } = this.data
    let res = await tagApi(param)

    if (res.code == 0) {
      let clueListPamas = {
        ...param,
        ...clueParams
      }
      this.getPageApi(clueListPamas)
    }
  },
  // 上拉刷新
  scrolltolowerFn() {

    let { clueCurrentPage, clueParams } = this.data
    let params = {
      ...clueParams,
      clueCurrentPage: clueCurrentPage++
    }

    this.setData({
      clueCurrentPage
    })
    this.getPageApi(params)
  },
  // 下拉刷新
  refreshList() {
    // console.log('onPullDownRefresh: ');
    let { clueParams } = this.data
    this.getClueInit(clueParams)
    // this.resetCluelist()
    // this.onLoad()
    wx.pro.showToast({
      title: '刷新成功',
      icon: 'success',
      duration: 1500
    })
  },
  gotoApply(e) {
    let { type, item } = e.currentTarget.dataset
    // let {  } = e.currentTarget.dataset
    // console.log(item)
    // return
    if (type == 'active') {
      let { userInfo } = wx.$storage.get()
      let pMerchantName = userInfo.subLoginUser.merchantName
      let pMerchantId = userInfo.subLoginUser.merchantId
      // let sceneActive
      // switch (this.data.actNum) {
      //   case 0:
      //     sceneActive = 1
      //     break
      //   case 1:
      //     sceneActive = 2
      //     break
      //   case 2:
      //     sceneActive = 3
      //     break
      //   case 3:
      //     sceneActive = 4
      //     break
      // }
      // let pMerchantId = userInfo.subLoginUser.merchantId

      // console.log("type,item: ", type, item);
      const params = {
        merchantInfo: {
          pMerchantId,
          pMerchantName,
          merchantId: item.visitList[0].merchantId,
          merchantName: item.visitList[0].merchantName
        },
        // sceneActive,
        clueId: item.clueId
        // sceneCodeList: ['SC001', 'SC002','SC003','SC004']
      }
      //申请活动
      // wx.$router.go("packageOutput.openBusiness", params);
      wx.$router.go('packagesList.openBusiness', params)
    } else {
      //申请门店
      // let { type, item } = e.currentTarget.dataset
      wx.$router.go('packagesList.apply', item?.clueId || '')
    }
    // wx.$router.go('apply',1235)
  },
  getMore(e) {
    // console.log("显示更多数据");
    let index = e.currentTarget.dataset.outidx
    // console.log("index: ", index);
    let completeStatus = `clueList[${index}].getMoreFlag`
    this.setData({
      [completeStatus]: !this.data.clueList[index].getMoreFlag
    })
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad(options) {
    // 看线索
    this.getClueInit()
    this.data.prompt = this.selectComponent('#toast')
    let disLikeRecordFlag = wx.$storage.get('disLikeRecordFlag')
    this.setData({
      disLikeRecordFlag
    })
  },

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

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

  },

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

  },

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

  },

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

  },

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

  },

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

  }
})