<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"
      @changeRadioGroup="changeRadioGroup">
      <template #code="{ item }">
        <div>
          <a style="color: #409eff; cursor: pointer; word-break: break-all" @click="clickCode(item)">{{ item.code }}</a>
        </div>
      </template>
      <template #address="{ item }">
        <div>{{ item.province }}, {{ item.city }}, {{ item.county }}, {{ item.detailedAddress }}</div>
      </template>
    </byTable>
  </el-card>
</template>

<script setup>
import byTable from "/src/components/byTable/index";
import { getNearDays } from "/src/utils/util";

const { proxy } = getCurrentInstance();
const sourceList = ref({
  data: [],
  pagination: {
    total: 0,
    pageNum: 1,
    pageSize: 10,
    orderCode: "",
    orderWlnCode: "",
    skuSpecCode: "",
    skuSpecName: "",
    bomSpecCode: "",
    bomSpecName: "",
    productionWorkOrderCode: "",
    beginTime: "",
    endTime: "",
    type: 3,
  },
});
const loading = ref(false);
const searchConfig = computed(() => {
  return [
    {
      type: "input",
      prop: "orderCode",
      label: "订单号",
    },
    {
      type: "input",
      prop: "orderWlnCode",
      label: "万里牛单号",
    },
    {
      type: "input",
      prop: "skuSpecCode",
      label: "SKU品号",
    },
    {
      type: "input",
      prop: "skuSpecName",
      label: "SKU品名",
    },
    {
      type: "input",
      prop: "bomSpecCode",
      label: "BOM品号",
    },
    {
      type: "input",
      prop: "bomSpecName",
      label: "BOM品名",
    },
    {
      type: "input",
      prop: "productionWorkOrderCode",
      label: "工单号",
    },
    {
      type: "radio-group",
      prop: "type",
      label: "交期",
      data: [
        {
          dictKey: 1,
          dictValue: "近3天",
        },
        {
          dictKey: 3,
          dictValue: "近7天",
        },
        {
          dictKey: 15,
          dictValue: "近31天",
        },
      ],
    },
    {
      type: "date",
      propList: ["beginTime", "endTime"],
      label: "日期",
    },
  ];
});
const config = computed(() => {
  return [
    {
      attrs: {
        label: "订单号",
        prop: "orderCode",
        width: 180,
      },
    },
    {
      attrs: {
        label: "万里牛单号",
        prop: "orderWlnCode",
        width: 150,
      },
    },
    {
      attrs: {
        label: "SKU品号",
        prop: "skuSpecCode",
        width: 140,
      },
    },
    {
      attrs: {
        label: "SKU品名",
        prop: "skuSpecName",
        'min-width': 220,
      },
    },
    {
      attrs: {
        label: "BOM品号",
        prop: "bomSpecCode",
        width: 140,
      },
    },
    {
      attrs: {
        label: "BOM品名",
        prop: "bomSpecName",
        'min-width': 280,
      },
    },
    {
      attrs: {
        label: "生产状态",
        prop: "status",
        width: 100,
      },
      render(val) {
        if (val == 0) {
          return "待投产";
        }
      },
    },
    // {
    //   attrs: {
    //     label: "工艺路线",
    //     prop: "departmentName",
    //     width: 120,
    //   },
    // },
    // {
    //   attrs: {
    //     label: "投产时间",
    //     prop: "departmentName",
    //     width: 160,
    //     align: "center",
    //     fixed: "right",
    //   },
    // },
    {
      attrs: {
        label: "完成时间",
        prop: "completeTime",
        width: 160,
        align: "center",
        fixed: "right",
      },
    },
    // {
    //   attrs: {
    //     label: "生产用时",
    //     prop: "departmentName",
    //     width: 160,
    //     align: "center",
    //     fixed: "right",
    //   },
    // },
  ];
});
const getList = async (req, status) => {
  if (status) {
    sourceList.value.pagination = {
      pageNum: sourceList.value.pagination.pageNum,
      pageSize: sourceList.value.pagination.pageSize,
      type: 3,
      beginTime: getNearDays(3).beginTime,
      endTime: getNearDays(3).endTime,
    };
  } else {
    sourceList.value.pagination = { ...sourceList.value.pagination, ...req };
  }
  loading.value = true;
  proxy.post("/productionWorkOrder/page", sourceList.value.pagination).then((res) => {
    sourceList.value.data = res.rows;
    sourceList.value.pagination.total = res.total;
    setTimeout(() => {
      loading.value = false;
    }, 200);
  });
};
getList({ beginTime: getNearDays(3).beginTime, endTime: getNearDays(3).endTime });
const clickReset = () => {
  getList("", true);
};
const changeRadioGroup = () => {
  getList({ beginTime: getNearDays(sourceList.value.pagination.type).beginTime, endTime: getNearDays(sourceList.value.pagination.type).endTime });
};
const clickCode = (row) => {
  proxy.$router.replace({
    path: "/addOrder",
    query: {
      detailId: row.id,
      text: "订单详情",
      random: proxy.random(),
      orderInquiry: true,
    },
  });
};
</script>

<style lang="scss" scoped>
:deep(.el-dialog) {
  margin-top: 10px !important;
  margin-bottom: 10px !important;
}
</style>
