<template>
  <div class="listDetail pagex">
    <el-descriptions style="width: 600px" :column="4">
      <el-descriptions-item label="导入总数">{{ importDetail.count }}</el-descriptions-item>
      <el-descriptions-item label="导入成功"><span class="alink">{{ importDetail.success_count }}</span></el-descriptions-item>
      <el-descriptions-item label="导入失败"><span style="color: red">{{ importDetail.failed_count }}</span></el-descriptions-item>
      <el-descriptions-item label="导入时间">{{ importDetail.import_time }}</el-descriptions-item>
    </el-descriptions>
    <!--操作区-->
    <div class="operation-area row" style="margin-top: 10px;">
      <div class="operation-button row verCenter">
        <a class="downTemplateExport" @click="exportChange">导出失败数据</a>
        <el-tooltip class="item" effect="dark" placement="top-start">
          <i class="el-icon-question" style="color:#ff7e11;margin-left:5px;cursor:pointer;font-size:16px;"></i>
          <div slot="content">导出失败数据:本次导入的数据,导入结果为成功,先上传提交审核,导入结果为失败,进行导出重新上传</div>
        </el-tooltip>
      </div>
    </div>
    <!--列表区-->
    <div class="data-box" v-if="tableData">
      <el-table :data="tableData" border max-height="600">
        <el-table-column prop="import_res" label="导入结果" width="100" :show-overflow-tooltip="true">
          <template slot-scope="scope">
            <span v-if="scope.row.import_res == 1" class="f-blue">成功</span>
            <span v-else-if="scope.row.import_res == 2" class="f-red1">失败</span>
            <span v-else-if="scope.row.import_res == 3" class="f-yellow1">导入中</span>
          </template>
        </el-table-column>
        <el-table-column prop="failed_reason" label="失败原因" min-width="150" :show-overflow-tooltip="true"></el-table-column>
        <el-table-column prop="goods_name" label="型号" width="150" :show-overflow-tooltip="true"></el-table-column>
        <el-table-column prop="brand_name" label="品牌" width="150" :show-overflow-tooltip="true"></el-table-column>
        <el-table-column prop="start_order_number" label="起订量" width="100" :show-overflow-tooltip="true"></el-table-column>
        <el-table-column prop="currency" label="币种" width="120" :show-overflow-tooltip="true"></el-table-column>
        <el-table-column prop="price_origin" label="价格" width="120" :show-overflow-tooltip="true"></el-table-column>
        <el-table-column prop="batch" label="批次" width="100" :show-overflow-tooltip="true"></el-table-column>
        <el-table-column prop="stock_number" label="库存" width="100" :show-overflow-tooltip="true"></el-table-column>
        <el-table-column prop="delivery_time_cn" label="大陆交期" width="120"></el-table-column>
        <el-table-column prop="delivery_time_hk" label="香港交期" width="120"></el-table-column>
      </el-table>
      <el-pagination layout="total, sizes, prev, pager, next, jumper" :page-sizes="[10, 20, 50, 100, 200]" :total="total" @size-change="handleSizeChange" @current-change="handleCurrentChange" :current-page="page"></el-pagination>
    </div>
    <Menu/>
  </div>
</template>
<script>
import Vue from 'vue';
import Menu from "@/components/menu.vue";

import {Descriptions, DescriptionsItem, Message, Pagination, Table, TableColumn, Tag, Tooltip} from 'element-ui'
import {NODE_ENVS} from "@/ajax";
import Tool from "@/tool";

Vue.prototype.$message = Message;
Vue.use(Pagination).use(TableColumn).use(Table).use(Tag).use(Descriptions).use(DescriptionsItem).use(Tooltip);
export default {
  name: "goodDetail",
  data() {
    return {
      total: 0,
      limit: 10,
      page: 1,
      importDetail: {},
      tableData: [],
      multipleSelection: []
    };
  },
  watch: {
    $route(to, from) {
      if (to.path == '/goodDetail') {
        this.getData();
      }
    }
  },
  created() {
    this.getData()
  },
  methods: {
    /**
     * 获取列表数据
     */
    getData() {
      this.$http('GET', "/api/bestgoods/importDetail", {
        page: this.page,
        limit: this.limit,
        import_sn: this.$route.query.import_sn
      }).then(res => {
        if (res.code === 0) {
          this.importDetail = res.data;
          this.tableData = res.data.list;
          this.total = res.data.count || 0;
        } else {
          this.$message({
            message: res.msg,
            type: 'warning'
          });
        }
      })
    },
    /**
     * 导出文件
     */
    exportChange() {
      var url = NODE_ENVS + '/api/bestgoods/exportFailedGoods?import_sn=' + this.$route.query.import_sn + '&token=' + Tool.getCookie('token');
      const newsUrl = this.$router.resolve(url);
      window.open(url);
    },
    handleSizeChange(val) {
      this.limit = val;
      this.getList();
    },
    handleCurrentChange(val) {
      this.page = val;
      this.getList();
    },
  },
  components: {
    Menu
  }
};
</script>
<style scoped>
@import "../../assets/css/store/listDetail.min.css";

.btn-nav {
  background: #FFFFFF;
  padding: 0 0 20px 20px;
}

::v-deep .el-descriptions-item__label {
  white-space: nowrap;
}

::v-deep .el-descriptions-item__content {
  white-space: nowrap;
}

.downTemplateExport {
  width: 92px;
  height: 28px;
  text-align: center;
  line-height: 28px;
  color: #FFF;
  background-color: #409EFF;
  border-color: #409EFF;
  font-size: 12px;
  border-radius: 3px;
  margin-right: 10px;
  display: block;
  cursor: pointer;
}
</style>