<template>
  <el-card class="box-card">
    <byTable
      :source="sourceList.data"
      :pagination="sourceList.pagination"
      :config="config"
      :loading="loading"
      :searchConfig="searchConfig"
      highlight-current-row
      :action-list="[
        {
          text: '新增采购入库清单',
          action: () => clickModal(),
        },
      ]"
      @get-list="getList"
      @clickReset="clickReset">
    </byTable>

    <el-dialog title="新增采购入库清单" v-if="openAdd" v-model="openAdd" width="90%">
      <Add @clickCancel="clickCancel"></Add>
    </el-dialog>

    <el-dialog title="采购入库清单" v-if="openDetail" v-model="openDetail" width="90%">
      <Detail :rowData="rowData" @clickCancel="clickCancel"></Detail>
    </el-dialog>
  </el-card>
</template>

<script setup>
import byTable from "/src/components/byTable/index";
import Add from "/src/views/production/warehouse/purchase-stock-pending/add.vue";
import Detail from "/src/views/production/warehouse/purchase-stock-pending/detail.vue";

const { proxy } = getCurrentInstance();
const sourceList = ref({
  data: [],
  pagination: {
    total: 0,
    pageNum: 1,
    pageSize: 10,
    code: "",
    arrivalCode: "",
    purchaseCode: "",
  },
});
const loading = ref(false);
const searchConfig = computed(() => {
  return [
    {
      type: "input",
      prop: "code",
      label: "采购入库单号",
    },
    {
      type: "input",
      prop: "arrivalCode",
      label: "到货单号",
    },
    {
      type: "input",
      prop: "purchaseCode",
      label: "采购合同单号",
    },
  ];
});
const config = computed(() => {
  return [
    {
      attrs: {
        label: "采购入库单号",
        prop: "code",
      },
    },
    {
      attrs: {
        label: "到货单号",
        prop: "arrivalCode",
      },
    },
    {
      attrs: {
        label: "采购合同单号",
        prop: "purchaseCode",
      },
    },
    {
      attrs: {
        label: "到货数量",
        prop: "arrivalQuantity",
        width: 120,
      },
    },
    {
      attrs: {
        label: "入库时间",
        prop: "createTime",
        width: 160,
        align: "center",
      },
    },
    {
      attrs: {
        label: "供应商",
        prop: "supplierName",
      },
    },
    {
      attrs: {
        label: "操作",
        width: 80,
        align: "center",
        fixed: "right",
      },
      renderHTML(row) {
        return [
          {
            attrs: {
              label: "查看详情",
              type: "primary",
              text: true,
            },
            el: "button",
            click() {
              clickDetails(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("/purchasePendingStorage/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 openAdd = ref(false);
const clickModal = () => {
  openAdd.value = true;
};
const openDetail = ref(false);
const rowData = ref({});
const clickDetails = (row) => {
  rowData.value = row;
  openDetail.value = true;
};
const clickCancel = (status) => {
  openAdd.value = false;
  openDetail.value = false;
  if (status) {
    getList();
  }
};
</script>

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