<template>
  <div>
    <upload-excel :on-success="success"></upload-excel>
  </div>
</template>

<script>
import { importChannel } from '@/api/productManage'
export default {
  methods: {
    async success({ header, results }) {
      const channelRelations = {
        渠道编码: 'channelCode',
        渠道名称: 'channelName',
        子渠道编码: 'childChannelCode',
        子渠道名称: 'childChannelName'
      }
      var newArr = results.map(item => {
        var channelInfo = {}
        Object.keys(item).forEach(key => {
          channelInfo[channelRelations[key]] = item[key]
        })
        return channelInfo
      })
      console.log(newArr)
      await importChannel(newArr)
      this.$message.success('导入成功')
    }
  }
}
</script>

<style></style>
