<template>
  <el-card class="box-card">
    <byTable
      :source="sourceList.data"
      :pagination="sourceList.pagination"
      :config="config"
      :loading="loading"
      :searchConfig="searchConfig"
      highlight-current-row
      @get-list="getList"
      @clickReset="clickReset">
      <template #size="{ item }">
        <div>{{ item.length }} * {{ item.width }} * {{ item.height }}</div>
      </template>
    </byTable>
  </el-card>
</template>

<script setup>
import byTable from "/src/components/byTable/index";

const { proxy } = getCurrentInstance();
const sourceList = ref({
  data: [],
  pagination: {
    total: 0,
    pageNum: 1,
    pageSize: 10,
    code: "",
    name: "",
  },
});
const loading = ref(false);
const searchConfig = computed(() => {
  return [
    {
      type: "input",
      prop: "code",
      label: "BOM品号",
    },
    {
      type: "input",
      prop: "name",
      label: "BOM品名",
    },
  ];
});
const config = computed(() => {
  return [
    {
      attrs: {
        label: "BOM品号",
        prop: "code",
        width: 160,
      },
    },
    {
      attrs: {
        label: "BOM品名",
        prop: "name",
        "min-width": 220,
      },
    },
    {
      attrs: {
        label: "颜色",
        prop: "colour",
        width: 160,
      },
    },
    {
      attrs: {
        label: "尺寸（长宽高，cm）",
        slot: "size",
        width: 220,
      },
    },
    {
      attrs: {
        label: "成本价",
        prop: "costPrice",
        width: 120,
      },
    },
    {
      attrs: {
        label: "对内销售价（含税）",
        prop: "internalSellingPrice",
        width: 160,
      },
    },
    {
      attrs: {
        label: "对外销售价（含税）",
        prop: "externalSellingPrice",
        width: 160,
      },
    },
    {
      attrs: {
        label: "安全库存",
        prop: "safetyStock",
        width: 120,
      },
    },
  ];
});
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("/bomSpec/page", sourceList.value.pagination).then((res) => {
    sourceList.value.data = res.rows;
    sourceList.value.pagination.total = res.total;
    setTimeout(() => {
      loading.value = false;
    }, 200);
  });
};
getList();
const clickReset = () => {
  getList("", true);
};
</script>

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