merchantList.js 9.07 KB
// pages/accountItems/accountItems.js
import { get4SStoreList, getShopSceneConfig } from '~/store/index'
const IMG_URL = 'https://img02.glsx.com.cn/weapp/resource/dj-car-boutique-work-wechat/'
import api from '~/api/api'
import constantData from '../constant/data'
Page({
  /**
   * 页面的初始数据
   */
  data: {
    searchValue: '',
    edit: false,
    copyLoginUserInfoList: [],
    loginUserInfoList: [],
    shopMerchantId: '',
    shopMerchantName: '',
    IMG_URL,
    openSceneArr: [],
    jumpPageFlag: false,
    selectData: ['搜门店', '搜客户'],
    selectIndex: 0,
    customStoreList: [],
    statusText: ['待跟进', '已升级', '战败', '待支付'],
    customSearchFlag: false,
    pageNum: 1,
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    this.getMerchantList()
    this.getSceneArr()
  },
  open() {
    this.setData({
      edit: true,
      inputFocus: true
    })
  },

  // 查询条件类型切换
  selectTap() {
    this.setData({
      showSelect: !this.data.showSelect
    });
  },
  optionTap(e) {
    let { index } = e.currentTarget.dataset
    this.setData({
      selectIndex: index,
      showSelect: !this.data.showSelect,
      searchValue: '',
      nothing: false,
      pageNum: 1,
      customSearchFlag: false
    })
    this.searchEvent(true)
  },
  closeSelect() {
    this.setData({
      showSelect: false
    })
  },
  clearInputText() {
    this.setData({
      searchValue: '',
      edit: false,
      nothing: false,
      pageNum: 1,
      customSearchFlag: false
    })
    this.searchEvent(true)
  },
  getSceneArr() {
    let userInfo = wx.$util.getUserInfo()
    // 超管开通全部场景
    if (userInfo?.isSuper) return
    wx.$util.showLoading()
    // 获取4s店关联场景数据
    getShopSceneConfig({ yqMerchantId: userInfo?.subLoginUser?.merchantId, merchantId: userInfo?.shopMerchantId }).then(result => {
      wx.$util.hideLoading()
      this.setData({ openSceneArr: result.map(val => { if (val.sceneOpenFlag == 0) return val.scene }) || [] })
    })
  },

  getMerchantList(e) {
    let userInfo = wx.$util.getUserInfo()
    let params = {
      merchantId: userInfo?.isSuper || userInfo?.loginRole == 3 || userInfo.loginRole == 5 ? '' : userInfo?.merchantId,
      staffUUID: userInfo?.isSuper || userInfo?.loginRole == 3 || userInfo.loginRole == 5 ? '' : userInfo?.uuid
    }
    get4SStoreList(params, userInfo?.isSuper || userInfo?.loginRole == 3 || userInfo.loginRole == 5, true)
      .then(result => {
        this.setData({
          loginUserInfoList: result,
          copyLoginUserInfoList: result,
          flag: true
        })
      })
      .catch(err => { })
  },
  jumpPage(item) {
    let { shopMerchantName, shopMerchantId, openSceneArr, selectIndex } = this.data
    if (!openSceneArr?.length && !wx.$util.getUserInfo()?.isSuper) return wx.$util.showToast('暂无开通业务,请联系总部管理员')
    wx.$util.setUserInfo({
      ...wx.$util.getUserInfo(),
      shopMerchantName,
      shopMerchantId,
      default4SStoreInfo: {
        merchantId: shopMerchantId,
        merchantName: shopMerchantName
      },
      default4SStoreInfo_crowdFunding: {
        merchantId: shopMerchantId,
        merchantName: shopMerchantName
      },
      default4SStoreInfo_newCarConversion: {
        merchantId: shopMerchantId,
        merchantName: shopMerchantName
      }
    })
    wx.$storage.rm('dateStaffPop')
    if (selectIndex == 0) { // 搜门店
      wx.$router.go('pages.sceneIndex')
      this.setData({ jumpPageFlag: false })
    } else { // 搜客户
      if (!openSceneArr.includes(0)) return wx.$util.showToast('暂未开通精品升级场景')
      // 进入精品升级场景 工单/预约详情
      api.selectMerchantScene({
        merchantId: shopMerchantId,
        merchantName: shopMerchantName,
        sceneType: 1
      }).then(res => {
        let { code, data, message } = res
        this.setData({ jumpPageFlag: false })
        if (code == 0) {
          wx.$util.setUserInfo({ ...wx.$util.getUserInfo(), sceneType: 1 })
          // listStatus 0 待跟进 1已升级 2战败 3待支付
          let queryParams = {
            isGoPage: true,
            listStatus: item.listStatus,
            status: item.status, // 工单状态
            selectPayType: item.selectPayType, // 支付方式
            constructionFlag: item.constructionFlag, // 已施工标识
            pageParams: {
              id: item.inviteRecordId || '', // 预约id
              orderCode: item.orderCode || '' // 工单号
            }
          }
          let now = new Date()
          let { uuid } = wx.$util.getUserInfo()
          api.loginRecordSave({
            staffUuid: uuid,
            loginTime: now.format('yyyy-MM-dd hh:mm:ss'),
            merchantId: shopMerchantId,
            merchantName: shopMerchantName
          }, 'merchantlist')
          wx.$router.reLaunch(constantData?.pageUrl[1], queryParams)

        } else {
          wx.$util.showToast(message)
        }
      })
    }

  },
  setValue(value) {
    if (this.properties.filterEmoji) {
      if (wx.$util.haveEmoji(value)) value = wx.$util.replaceEmoji(value)
    }
    this.setData({
      searchValue: value
    })
  },
  input(e) {
    let {
      value
    } = e.detail
    this.setValue(value)
  },
  inputBlur(e) {
    this.emit(e)
  },
  inputConfifm(e) {
    this.emit(e)
  },
  emit(e) {
    let {
      detail: {
        value
      }
    } = e
    this.setData({
      edit: false,
      searchValue: value,
      nothing: false,
      pageNum: 1,
      customSearchFlag: false
    })
    this.setValue(value)
    this.searchEvent(true)
  },
  scrollonReachBottom() {
    this.searchEvent()
  },
  // 搜索过滤
  searchEvent(isReset = false) {
    let { searchValue, copyLoginUserInfoList, shopMerchantId, selectIndex, pageNum, nothing } = this.data
    let userInfo = wx.$util.getUserInfo()
    if (selectIndex == 0) { // 搜门店
      copyLoginUserInfoList.map(val => {
        val.active = false
        if (val.merchantId == shopMerchantId) val.active = true
        return val
      })
      let filterArr = copyLoginUserInfoList.filter(val => val.merchantName.includes(searchValue) || val.merchantId == searchValue) || []
      this.setData({
        loginUserInfoList: filterArr
      })
      if (!searchValue) {
        this.setData({
          loginUserInfoList: copyLoginUserInfoList
        })
      }
      this.setData({
        customSearchFlag: true
      })
    } else { // 搜客户
      let params = {
        pageNum: pageNum,
        pageSize: 10,
        keyword: searchValue,
        sellerMerchantId: userInfo?.merchantId || ''
      }
      if (!searchValue) {
        this.setData({ customStoreList: [] })
        return
      }
      if (nothing) return
      api.searchOrderCustomer(params).then(res => {
        let { code, data, message } = res
        if (code == 0) {
          data?.list.forEach(val => {
            // upgradeFlag Y已升级 N已战败
            // listStatus 0待跟进 1已升级 2战败 3待支付
            val.listStatus = val.upgradeFlag == 'Y' ? 1 : val.upgradeFlag == 'N' ? 2 : (!val.upgradeFlag && val.status == 1) ? 0 : (!val.upgradeFlag && val.status == 3) ? 3 : ''
          })
          let tempList = isReset ? data?.list : this.data.customStoreList.concat(data?.list)
          this.setData({
            customStoreList: tempList,
            pageNum: pageNum + 1,
            total: data?.total,
            nothing: data?.total == tempList.length,
          })
        } else {
          wx.$util.showToast(message)
        }
        this.setData({
          customSearchFlag: true
        })
      })
    }
  },
  chooseAccount(e) {
    if (this.data.jumpPageFlag) return
    this.setData({ jumpPageFlag: true })
    let { item, type } = e.currentTarget.dataset
    let { loginUserInfoList, customStoreList, selectIndex } = this.data
    let listArr = selectIndex == 0 ? loginUserInfoList : customStoreList
    listArr.map(i => {
      i.active = false
      // 搜客户
      if (type == 1) {
        if (i.id == item.id) {
          i.active = true
        }
      } else { // 搜门店
        if (i.merchantId == item?.merchantId) {
          i.active = true
        }
      }
      return i
    })
    this.setData({
      loginUserInfoList: listArr,
      customStoreList: listArr,
      shopMerchantId: item.merchantId,
      shopMerchantName: item.merchantName
    })
    this.jumpPage(item)
  },

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

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
    wx.hideHomeButton()
    this.setData({ jumpPageFlag: false })
  },

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

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

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

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

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