DateScreen.js 9.34 KB
// pages/tabDateIndex/components/DateScreen/DateScreen.js
import api from '~/api/api'
const IMG_URL = 'https://img02.glsx.com.cn/weapp/resource/dj-car-boutique-work-wechat/'
Component({

  /**
   * 组件的属性列表
   */
  properties: {
    userInfo: Object,
    navBarHeight: String,
    show: {
      type: Boolean,
      observer: function (n, o) {
        if (n) {
          this.setViewData()
          let { userInfo } = this.data
          // 非超管 获取转化人员 销售顾问
          if (!(userInfo?.isSuper || userInfo?.loginRole == 3 || userInfo.loginRole == 5)) {
            if (wx.$orderListDateListScreenRefresh) { // 切换门店将数据清空
              this.setData({
                'form.userIdList': [],
                'form.issuerUserIdList': []
              })
            }
            this.getScreenList()
          }
        } else {
          this.setData({
            x: this.data.windowWidth
          })
        }
      }
    },
    inviteStatus: {
      type: Number,
      value: -1,
      observer: function (n) {
        if (n != -1) {
          this.setInviteStatusList(n)
        }
      }
    },
  },

  /**
   * 组件的初始数据
   */
  data: {
    IMG_URL,
    dateTimeList: [{
      name: '全部',
      active: true
    }, {
      name: '今日',
      startDate: new Date().format('yyyy-MM-dd'),
      endDate: new Date().format('yyyy-MM-dd')
    }, {
      name: '明日',
      startDate: new Date(new Date().setDate(new Date().getDate() + 1)).format('yyyy-MM-dd'),
      endDate: new Date(new Date().setDate(new Date().getDate() + 1)).format('yyyy-MM-dd')
    }, {
      startDate: '',
      endDate: '',
      type: 'custom'
    }],
    showStoreSelectPopup: false
  },

  /**
   * 组件的方法列表
   */
  methods: {
    init() {
      let { dateTimeList } = this.data
      this.setData({
        ['form.dateTimeList']: wx.$util.deepClone(dateTimeList)
      })
      this.setInviteStatusList()
    },
    getScreenList() {
      let { userInfo } = this.data
      wx.$orderListDateListScreenRefresh = false
      this.getConversionEmployeeList(userInfo?.merchantId, 0)
      this.getConversionEmployeeList(userInfo?.shopMerchantId, 1)
    },
    /**转化人员 & 销售人员*/
    getConversionEmployeeList(merchantId, type) {
      let target = type == 0 ? 'form.userIdList' : 'form.issuerUserIdList'
      let targetItem = type == 0 ? 'userIdList' : 'issuerUserIdList'
      let { form } = this.data
      wx.showLoading()
      if (merchantId) {
        api
          .getConversionEmployeeList({
            merchantId,
            sceneList: type == 1 ? [1] : ''
          })
          .then(res => {
            wx.hideLoading()
            let arr = [
              {
                staffName: '全部',
                active: true,
                value: []
              }
            ]
            let { code, data, message } = res
            if (code == 0) {
              data.map(e => {
                e.value = [e.uuid]
                arr.push(e)
              })
            } else {
              wx.$util.showToast(message)
            }
            console.log(arr)
            let formArr = wx.$util.arrayUnique(arr?.concat(form?.[targetItem] || []), 'uuid')
            this.setData({
              [target]: formArr
            })
          })
      } else {
        wx.hideLoading()
        this.setData({
          [target]: [
            {
              staffName: '全部',
              active: true,
              value: []
            }
          ]
        })
      }
    },
    showStoreSelectPopup(e) {
      let { type } = e.currentTarget.dataset
      this.setData({ storeType: type, showStoreSelectPopup: true })
    },
    hideStorePopup() {
      this.setData({ showStoreSelectPopup: false })
    },
    storeConfirm(e) {
      let { storeType } = this.data
      if (storeType == 1) this.setData({ 'form.selectedYqMerchantList': e?.detail })
      if (storeType == 2) this.setData({ 'form.selectedMerchantList': e?.detail })
      this.setData({ showStoreSelectPopup: false })
    },
    choose(e) {
      let { index, listName } = e.currentTarget.dataset
      let target = this.data.form[listName]
      if (target[index].disabled) return
      if (listName === 'userIdList' || listName === 'issuerUserIdList') {
        if (index == 0) {
          target.forEach(i => i.active = false)
          target[index].active = true
        } else {
          target[index].active = !target[index].active
          target[0].active = false
          if (!target.filter(val => val.active).length) target[0].active = true
        }
      } else {
        target.forEach(i => {
          i.active = false
        })
        target[index].active = true
      }
      this.setData({
        [`form.${listName}`]: target,
        isReset: false
      })
    },
    yqMerchantChoose() {
      this.setData({
        'form.selectedYqMerchantList': []
      })
    },
    merchantChoose() {
      this.setData({
        'form.selectedMerchantList': []
      })
    },
    showMore(e) {
      let { type } = e.currentTarget.dataset
      let { employShowMore, salesmanShowMore } = this.data
      let prop = type == 1 ? 'employShowMore' : 'salesmanShowMore'
      this.setData({
        [prop]: type == 1 ? !employShowMore : !salesmanShowMore
      })
    },
    rangeSelect(e) {
      let { index, name } = e.currentTarget.dataset
      let data = this.data.form[name]
      let {
        date: { start, end }
      } = e.detail
      data?.map(i => (i.active = false))
      let obj = {
        active: true,
        startDate: start,
        endDate: end,
        type: 'custom'
      }
      data[index] = obj
      this.setData({
        [`form.${name}`]: data,
      })
    },
    // 日期组件
    showCalendar(e) {
      let calendarModule = this.selectComponent('#calendar')
      calendarModule.showCalendar && calendarModule.showCalendar(e)
    },
    setViewData() {
      let { navBarHeight } = this.data
      wx.$util.getViewInfo(
        '.btn-box',
        res => {
          this.setData({
            height: navBarHeight,
            btnHeight: res.height
          })
        },
        this
      )
    },
    /**预约状态 */
    setInviteStatusList(n = 0) {
      let arr = [
        {
          name: '全部',
          active: true,
          value: []
        },
        {
          name: '待预约',
          value: [1]
        },
        {
          name: '已预约',
          value: [2]
        },
        {
          name: '超时未到店',
          value: [5]
        },
        {
          name: '取消预约',
          value: [3]
        },
        {
          name: '已施工',
          value: [4]
        }
      ]
      this.setData({
        ['form.inviteStatusList']: arr
      })
      this.setInviteStatusListDisabled(n)
    },
    setInviteStatusListDisabled(statusType) {
      let { inviteStatusList } = this.data.form
      inviteStatusList.map((e, index) => {
        if (statusType == 0) {
          e.disabled = false
        } else if (statusType == 1) {
          if (index == 1 || index == 4) e.disabled = true
        } else {
          if (index == 2 || index == 3 || index == 5) e.disabled = true
        }
      })
      this.setData({
        ['form.inviteStatusList']: inviteStatusList
      })
    },
    reset() {
      let { userIdList, issuerUserIdList } = this.data.form
      userIdList?.map((val, index) => {
        val.active = false
        if (index == 0) val.active = true
      })
      issuerUserIdList?.map((val, index) => {
        val.active = false
        if (index == 0) val.active = true
      })
      this.setData({
        'form.selectedYqMerchantList': [],
        'form.selectedMerchantList': [],
        'form.userIdList': userIdList || [],
        'form.issuerUserIdList': issuerUserIdList || []
      })
      this.init()
    },
    confirm() {
      let { form, userInfo, isReset } = this.data
      let obj = {}
      Object.keys(form).forEach((e) => {
        let arr = []
        form[e]?.forEach((i) => {
          if (i.active) {
            let { value, startDate, endDate, merchantId } = i
            obj[e] = value
            if (e == 'inviteStatusList') {
              obj['inviteStatus'] = value[0]
              delete obj[e]
            }
            if (startDate && endDate) {
              startDate = `${startDate} 00:00:00`
              endDate = `${endDate} 23:59:59`
              obj.inviteDateStartDate = startDate
              obj.inviteDateEndDate = endDate
            }
            if (e == 'userIdList' || e == 'issuerUserIdList') {
              arr.push(value[0])
              obj[e] = arr
            }
            if (e == 'selectedMerchantList') {
              arr.push(merchantId)
              obj['merchantIdList'] = arr
            }
            if (e == 'selectedYqMerchantList') {
              arr.push(merchantId)
              obj['sellerMerchantIds'] = arr
            }
          }
        })
      })
      let page = wx.$router.getPageInstance()
      if (isReset) {
        obj = {}
      }
      page.setData({
        searchObj: obj
      })
      page.back()
      page.search()
    }
  },
  attached() {
    wx.$util.getSystemInfo(info => {
      let { windowWidth } = info
      this.setData({
        x: windowWidth,
        windowWidth,
        isFullSucreen: wx.$util.isFullSucreen(true),
        userInfo: wx.$util.getUserInfo()
      })
    })
    this.init()
    // this.getScreenList()
  }
})