MerchantScene.js 2.61 KB
// pages/tab/outputValue/components/merchantCom/MerchantScene/MerchantScene.js
import constant from '../constant'
Component({
  /**
   * 组件的属性列表
   */
  properties: {
    curInfo: {
      type: Object,
      value: () => { },
      observer(n) {
        if (n) {
          this.dealYearMonth()
          this.dealCrowdData()
        }
      }
    },
    searchForm: {
      type: Object,
      value: () => {
        return {
          // 服务商商户号
          partnerMerchantId: '',
          // 4S店商户号
          merchantId: '',
          // 年月(yyyy-MM)
          yearMonth: '',
          // 场景(1精品升级,3众筹,0会员权益)
          sceneType: '1'
        }
      },
      observer: function (n) {
        n & this.dealData()
      }
    }
  },

  /**
   * 组件的初始数据
   */
  data: {
    sceneToInfo: constant.sceneToInfo,
    sceneTopList: constant.membranesTopList,
    sceneFormList: constant.membranesFormList,
    sceneObj: {},
    date: {
      year: '',
      month: ''
    },
    currentMonth: new Date().format('yyyy-MM')
  },

  /**
   * 组件的方法列表
   */
  methods: {
    dealYearMonth() {
      let { yearMonth } = this.data.curInfo
      this.setData({
        ['date.year']: new Date(yearMonth || '').getFullYear(),
        ['date.month']: new Date(yearMonth || '').getMonth() + 1,
      })
    },
    dealCrowdData() {
      let { searchForm, curInfo } = this.data
      // 众筹数据处理
      if (searchForm.sceneType == 3) {
        curInfo?.merchantDataList.length && curInfo?.merchantDataList.forEach(item => {
          let productCodes = item.productCodes || []
          item.activityTotal = 0
          item.orderTotal = 0
          item?.curMonthTotalData?.length && item?.curMonthTotalData?.forEach(subItem => {
            subItem.isShow = productCodes.includes(subItem.productCode)
            if(subItem.isShow) {
              item.activityTotal = item.activityTotal + subItem.activityTotal
              item.orderTotal = item.orderTotal + subItem.orderTotal
            }
          })
        })
        this.setData({
          curInfo: curInfo
        })
      }
    },
    dealData() {
      let { searchForm, sceneToInfo } = this.data
      let sceneObj = sceneToInfo.find(item => item.type == (searchForm.sceneType || 1))
      this.setData({
        sceneObj: sceneObj,
        sceneTopList: constant[(sceneObj.name || 'membranes') + 'TopList'],
        sceneFormList: constant[(sceneObj.name || 'membranes') + 'FormList']
      })
    },
    jump(e) {
      let { info } = e.currentTarget.dataset
      wx.$router.go('packagesList.newSummary', info)
    },
  }
})