<template>
  <el-card class="box-card">
    <byTable
      :hidePagination="true"
      :source="sourceList.data"
      :pagination="sourceList.pagination"
      :config="config"
      :loading="loading"
      :searchConfig="searchConfig"
      highlight-current-row
      :action-list="[
        {
          text: '导出Excel',
          action: () => deriveExcel(),
        },
      ]"
      @get-list="getList"
      @clickReset="clickReset">
      <template #skuPrice>
        <el-table-column label="裸垫" prop="skuSpecUnitPrice" align="center" width="80" />
        <el-table-column label="激光logo" prop="skuSpecUnitPriceLogo" align="center" width="100" />
        <el-table-column label="激光体位线" prop="skuSpecUnitPriceLine" align="center" width="110" />
      </template>
      <template #priceComposition>
        <el-table-column label="主材" prop="bomSpecUnitPrice" align="center" width="80" />
        <el-table-column label="包材配件" prop="packagingMaterialCost" align="center" width="90" />
        <el-table-column label="激光logo" prop="logoProcessingFee" align="center" width="100" />
        <el-table-column label="激光体位线" prop="lineProcessingFee" align="center" width="110" />
        <el-table-column label="代发费" prop="issueFee" align="center" width="80" />
        <el-table-column label="快递包材费" prop="deliveryMaterialsFee" align="center" width="100" />
        <el-table-column label="包装人工费" prop="packingLabor" align="center" width="100" />
        <el-table-column label="管理费" prop="managementFee" align="center" width="80" />
      </template>
    </byTable>
  </el-card>
</template>

<script setup>
import byTable from "/src/components/byTable/index";
import { ElMessageBox } from "element-plus";

const { proxy } = getCurrentInstance();
const sourceList = ref({
  data: [],
  pagination: {
    total: 0,
    skuSpecCode: "",
    skuSpecName: "",
  },
});
const loading = ref(false);
const searchConfig = computed(() => {
  return [
    {
      type: "input",
      prop: "skuSpecCode",
      label: "SKU品号",
    },
    {
      type: "input",
      prop: "skuSpecName",
      label: "SKU品名",
    },
  ];
});
const config = computed(() => {
  return [
    {
      attrs: {
        label: "品牌",
        prop: "brand",
        width: 100,
      },
    },
    {
      attrs: {
        label: "SKU品号",
        prop: "skuSpecCode",
        width: 140,
      },
    },
    {
      attrs: {
        label: "SKU品名",
        prop: "skuSpecName",
        "min-width": 220,
      },
    },
    {
      attrs: {
        label: "SKU单价（含税）",
        slot: "skuPrice",
        align: "center",
      },
    },
    {
      attrs: {
        label: "价格组成",
        slot: "priceComposition",
        align: "center",
      },
    },
  ];
});
const getList = async (req, status) => {
  if (status) {
    sourceList.value.pagination = {
      pageNum: sourceList.value.pagination.pageNum,
      pageSize: sourceList.value.pagination.pageSize,
    };
  } else {
    sourceList.value.pagination = { ...sourceList.value.pagination, ...req };
  }
  loading.value = true;
  proxy.post("/skuSpecQuotationBoard/getSkuSpecQuotationList", sourceList.value.pagination).then((res) => {
    sourceList.value.data = res;
    setTimeout(() => {
      loading.value = false;
    }, 200);
  });
};
getList();
const clickReset = () => {
  getList("", true);
};
const deriveExcel = () => {
  ElMessageBox.confirm("你是否确认此操作", "提示", {
    confirmButtonText: "确定",
    cancelButtonText: "取消",
    type: "warning",
  })
    .then(() => {
      proxy.postFile("/skuSpecQuotationBoard/exportExcel", sourceList.value.pagination).then((res) => {
        proxy.downloadFile(res, "SKU报价看板.xlsx");
      });
    })
    .catch(() => {});
};
</script>

<style lang="scss" scoped></style>
