
import { excelHead, updateExcelHead } from '@/api/dataFactory'
export function uploadFile (type, multipartFile, headRowNumber = 1, productId) {
  const query = new FormData()
  query.append('type', type)
  query.append('multipartFile', multipartFile)
  query.append('headRowNumber', headRowNumber)
  query.append('productId', productId)
  return new Promise((resolve, reject) => {
    excelHead(query)
      .then(res => {
        resolve(res)
      })
      .catch(error => {
        reject(error)
      })
  })
}

export function excelUpdate (filePath, sheetName, headRowNumber = 1, productId) {
  return new Promise((resolve, reject) => {
    updateExcelHead({ filePath, sheetName, headRowNumber, productId })
      .then(res => {
        resolve(res)
      })
      .catch(error => {
        reject(error)
      })
  })
}

// 判断数组中有没有相同的项
export function isAllEqual (array, key) {
  for (let i = 0; i < array.length; i++) {
    for (let j = i + 1; j < array.length; j++) {
      if (array[i][key] === array[j][key]) {
        return true
      }
    }
  }
  return false
}
