dealMixin.js 1.58 KB
export default {
  methods: {
    createHeadColumn (headColumnData = []) {
      let headColumn = []
      if (headColumnData.length) {
        let i = 0, temp = {}
        headColumnData.forEach((item, index) => {
          let matched = item.split('_')
          if (matched.length > 1) {
            if (temp[matched[1]]) {
              temp[matched[1]].push({
                prop: `defaultOrg${index++}`,
                label: matched[0]
              })
            } else {
              temp[matched[1]] = [{
                prop: `defaultOrg${index++}`,
                label: matched[0]
              }]
            }
          }
        })
        headColumn = Object.keys(temp).map((key) => {
          return {
            label: key + '/' + this.$t('format.seconds'),
            children: temp[key]
          }
        })
        headColumn.unshift({
          prop: `defaultOrg${i++}`,
          label: headColumnData[0]
        })
      }
      return headColumn
    },
    buildTableContent(headData, data) {
      let result = [], temp = {}
      if (headData.length) {
        data.forEach((item, index) => {
          temp = {}
          item.data.forEach((dataItem, dataIndex) => {
            temp[`defaultOrg${dataIndex}`] = (
              (typeof(dataItem) === 'number'
              || typeof(dataItem) === 'string')
              && dataItem !== 'null'
            ) ? dataItem : '--'
          })
          result.push(temp)
        })
      }
      return result
    },
    // add total column
    addTotalColumn(data) {
      data.reduce((arr, item) => {
        //
      })
    }
  }
}