<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">
    </byTable>
  </el-card>
</template>

<script setup name="Draft-design-management">
import byTable from "/src/components/byTable/index";

const { proxy } = getCurrentInstance();
const statusList = ref([
  {
    dictKey: 0,
    dictValue: "待制作",
  },
  {
    dictKey: 1,
    dictValue: "待确认",
  },
  {
    dictKey: 2,
    dictValue: "已驳回",
  },
  {
    dictKey: 3,
    dictValue: "已确认",
  },
]);
const sourceList = ref({
  data: [],
  pagination: {
    total: 0,
    pageNum: 1,
    pageSize: 10,
    status: "",
  },
});
const loading = ref(false);
const searchConfig = computed(() => {
  return [
    {
      type: "select",
      prop: "status",
      label: "图稿状态",
      data: statusList.value,
    },
  ];
});
const config = computed(() => {
  return [
    {
      attrs: {
        label: "订单号",
        prop: "orderCode",
      },
    },
    {
      attrs: {
        label: "图稿状态",
        prop: "status",
      },
      render(val) {
        return proxy.dictKeyValue(val, statusList.value);
      },
    },
    {
      attrs: {
        label: "SKU品号",
        prop: "skuSpecCode",
      },
    },
    {
      attrs: {
        label: "主材品号",
        prop: "bomSpecCode",
      },
    },
    {
      attrs: {
        label: "下单时间",
        prop: "orderCreateTime",
      },
    },
    {
      attrs: {
        label: "图稿确认时间",
        prop: "artworkConfirmTime",
      },
    },
    {
      attrs: {
        label: "操作",
        width: 120,
        align: "center",
        fixed: "right",
      },
      renderHTML(row) {
        return [
          {
            attrs: {
              label: "详情",
              type: "primary",
              text: true,
            },
            el: "button",
            click() {
              clickDetail(row);
            },
          },
        ];
      },
    },
  ];
});
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("/orderSkuArtworkMake/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);
};
const clickDetail = (row) => {
  proxy.$router.replace({
    path: "/draft-design-drawing",
    query: {
      id: row.id,
      random: proxy.random(),
    },
  });
};
</script>

<style lang="scss" scoped>
::v-deep(.el-input-number .el-input__inner) {
  text-align: left;
}
</style>
