// 例:[
//   ['日期', '销售额', '客总数', '回头客', '回头率'],
//   ['2016', 10, 11, 13, 13],
//   ['2017', 20, 21, 23, 13],
//   ['2018', 30, 31, 24, 13]
// ]
// 输出：[{ text: '日期', value: 'fieldValue_*' data: ['2016', '2017','2018'] }, { text: "销售额", data: [ 10, 20, 30 ] }, { text: "客总数", data: [ 13, 23, 24 ] }, ...]
export function dealExcelToSettingList (data) {
  const arr = []
  data.forEach((row, rowIndex) => {
    row.forEach((rowItem, columnIndex) => {
      if (Boolean(rowItem) && rowItem !== 0) {
        if (rowIndex === 0) arr.push({ text: rowItem, value: ('fieldValue_' + columnIndex), data: [], hasNum: false })
        else {
          if (/^(-)?\d+(\.\d+)?$/.test(rowItem)) arr[columnIndex].hasNum = true // 判断是否为纯数值，不包括.999数值类型
          arr[columnIndex].data.push(rowItem)
        }
      }
    })
  })
  return arr
}

// 例:[
//   ['日期', '销售额', '客总数', '回头客', '回头率'],
//   ['2016', 10, 11, 13, 13],
//   ['2017', 20, 21, 23, 13],
//   ['2018', 30, 31, 24, 13]
// ]
// 输出：headers = [{ text: '日期', value: 'fieldValue_0'},
//                  { text: '销售额', value: 'fieldValue_1'}
//                 ...]
//      tableData = [{ fieldValue_0: '2016', fieldValue_1: 10, fieldValue_2: 11, ... },
//                  { fieldValue_0: '2017', fieldValue_1: 20, fieldValue_2: 21, ... }
//                 ...]
export function dealExcelToTableData (data) {
  const headers = []; const tableData = []
  data.forEach((row, index) => {
    row.forEach((i, iIndex) => {
      if (i !== null) {
        if (!index) {
          headers.push({ text: i, value: 'fieldValue_' + iIndex })
        } else {
          if (!tableData[index - 1]) tableData[index - 1] = {}
          tableData[index - 1]['fieldValue_' + iIndex] = i
        }
      }
    })
  })
  return { headers, tableData }
}
