table.js 5.57 KB
// pages/components/table/table.js
Component({
  /**
   * 组件的属性列表
   */
  properties: {
    table: {
      type: Array,
      value: []
    },
    tableObj: {
      type: Array,
      value: []
    },
    tableFlag: {
      type: Boolean,
      value: true
    },
    tableWidth: {
      type: String,
      value: '100%'
    },
    headerConfig: {
      type: Object,
      value: {}
    },
    itemTableHeight: {
      type: String,
      value: '0rpx'
    },
    itemHeight: {
      type: String,
      value: '72rpx'
    }
  },

  /**
   * 组件的初始数据
   */
  data: {
    // tableWidth: 1088,
    // tableFlag: true,
    table: [
      // {
      //   id: null,
      //   merchantId: 44218100,
      //   merchantName: '测试门店22',
      //   dataDate: null,
      //   getTotal: 0,
      //   usedTotal: 0,
      //   upgradeTotal: 0,
      //   upgradeMoneyTotal: null,
      //   createdBy: null,
      //   createdDate: null,
      //   updatedBy: null,
      //   updatedDate: null,
      //   deletedFlag: null,
      //   startDate: null,
      //   endDate: null,
      //   yqMerchantIds: null,
      //   orderByType: null,
      //   addTotal: 0,
      //   orderMoneyTotal: 0,
      //   merchantIdList: null,
      //   usedPer: null,
      //   upgradePer: null,
      //   totalUsedPer: null,
      //   totalUpgradePer: null,
      //   customerUnitMoney: 0,
      //   upgradeRate: 0,
      //   experienceTotal: 0,
      //   filmTimes: 0,
      //   notUpgradeTotal: null,
      //   filmTimesGrowth: null,
      //   usedTotalGrowth: null,
      //   upgradeTotalGrowth: null,
      //   notUpgradeTotalGrowth: null,
      //   orderMoneyTotalGrowth: null,
      //   customerUnitMoneyGrowth: null,
      //   experienceTotalGrowth: null,
      //   upgradeRateGrowth: null,
      //   goodsOrCouponType: null,
      //   queryRangeType: null
      // },
      // {
      //   id: null,
      //   merchantId: 44218100,
      //   merchantName: '测试门店22',
      //   dataDate: null,
      //   getTotal: 0,
      //   usedTotal: 0,
      //   upgradeTotal: 0,
      //   upgradeMoneyTotal: null,
      //   createdBy: null,
      //   createdDate: null,
      //   updatedBy: null,
      //   updatedDate: null,
      //   deletedFlag: null,
      //   startDate: null,
      //   endDate: null,
      //   yqMerchantIds: null,
      //   orderByType: null,
      //   addTotal: 0,
      //   orderMoneyTotal: 0,
      //   merchantIdList: null,
      //   usedPer: null,
      //   upgradePer: null,
      //   totalUsedPer: null,
      //   totalUpgradePer: null,
      //   customerUnitMoney: 0,
      //   upgradeRate: 0,
      //   experienceTotal: 0,
      //   filmTimes: 0,
      //   notUpgradeTotal: null,
      //   filmTimesGrowth: null,
      //   usedTotalGrowth: null,
      //   upgradeTotalGrowth: null,
      //   notUpgradeTotalGrowth: null,
      //   orderMoneyTotalGrowth: null,
      //   customerUnitMoneyGrowth: null,
      //   experienceTotalGrowth: null,
      //   upgradeRateGrowth: null,
      //   goodsOrCouponType: null,
      //   queryRangeType: null
      // }
    ],
    formattedTable: []
    // tableObj: [
    //   {
    //     name: '贴膜',
    //     unit: '/台',
    //     key: 'filmTimes',
    //     width: 'var(--fontSize110)'
    //   },
    //   {
    //     name: '核销',
    //     unit: '/张',
    //     key: 'usedTotal',
    //     width: 'var(--fontSize110)'
    //   },
    //   {
    //     name: '体验',
    //     unit: '/位',
    //     key: 'experienceTotal',
    //     width: 'var(--fontSize110)'
    //   },
    //   {
    //     name: '转化',
    //     unit: '/单',
    //     key: 'upgradeTotal',
    //     width: 'var(--fontSize110)'
    //   },
    // ]
  },
  observers: {
    'table, tableObj': function (table, tableObj) {
      this.formatTable(table, tableObj)
    }
  },

  /**
   * 组件的方法列表
   */
  methods: {
    navToRegionalLeaders(e) {
      let { headerConfig } = this.data
      //  let { headerConfig } = this.data
      console.log(headerConfig, 'headerConfig')
      if (headerConfig.key == 'regionName') {
        let { item } = e.currentTarget.dataset
        wx.navigateTo({
          url: `/packageIndex/pages/regionalLeaders/regionalLeaders?query=${encodeURIComponent(
            JSON.stringify(item)
          )}`
        })
      }
    },
    formatTable(table, tableObj) {
      const keys = (tableObj || []).map(i => i && i.key).filter(Boolean)
      const src = Array.isArray(table) ? table : []
      const formatted = src.map(row => {
        const copy = { ...row }
        keys.forEach(k => {
          const v = copy[k]
          if (v === null || v === undefined || v === '') {
            copy[k] = '0.00'
            return
          }
          const num = Number(v)
          copy[k] = isNaN(num) ? '0.00' : num.toFixed(2)
        })
        return copy
      })
      this.setData({ formattedTable: formatted })
    },
    scrollonReachBottom() {
      // console.log('scrollonReachBottom')
      // let { pages, pageNum } = this.data
      // // 判断当前页是否是末页
      // if (pages == pageNum) return wx.$util.showToast('列表已到底')
      // this.setData({
      //   pageNum: pageNum + 1
      // })
      // this.getMerchantCouponList()
    },
    restPageNum() {
      // this.setData({
      //   pageNum: 1
      // })
      // this.getMerchantCouponList()
    }
  }
})