<template>
	<el-container class="is-vertical">
        <sc-page-header></sc-page-header>

        <scTable ref="xGridTable" v-bind="xGridOptions">
            <template #code_link="{ row }">
                <vxe-text status="primary" @click="table_detail(row)">{{ row.code }}</vxe-text>
            </template>

            <template #action="{ row }">
                <el-button type="primary" link @click="table_freeze(row)">
                    <template #icon><sc-iconify icon="ant-design:edit-outlined"></sc-iconify></template>冻结
                </el-button>
            </template>
        </scTable>
	</el-container>
</template>

<script setup>
import moment from "moment";
import XEUtils from "xe-utils";

import API from "@/api";
import TOOL from "@/utils/tool";
import { mapFormItemInput, mapFormItemSelect, mapFormItemDatePicker } from "@/components/scTable/helper";

import store from "@/store";
const route = useRoute();
console.log('route',route)

const daterangeConfig = reactive({
    resetValue: () => [],
    props: {
        type: "daterange",
        startPlaceholder: "开始日期",
        endPlaceholder: "结束日期",
        format: "YYYY-MM-DD"
    }
});

const xGridOptions = reactive({
    // apiObj: API.production.prePlan,
    toolbarConfig: { enabled: false },
    formConfig: {
        data: {},
        items: [
            mapFormItemInput("nameLike", "产品名称"),
            mapFormItemInput("codeLike", "产品编号"),
            mapFormItemDatePicker("confirmDate", "确认日期", daterangeConfig)
        ]
    },
    paramsColums: [
        { column: "orderBy", defaultValue: "createTime_desc" },
        { column: "nameLike" },
        { column: "codeLike" },
        { column: "confirmDateBegin", field: "confirmDate[0]" },
        { column: "confirmDateEnd", field: "confirmDate[1]" }
    ],
    columns: [
        { type: "seq", fixed: "left", width: 60 },
        { type: "html", field: "warehouseName", title: "仓库", fixed: "left", minWidth: 150, sortable: true },
        { type: "html", field: "batchNumber", title: "批号", minWidth: 150, sortable: true },
        { type: "html", field: "serialNumber", title: "序列号", minWidth: 150, sortable: true },
        { type: "html", field: "productionDate", title: "生产日期", minWidth: 150, sortable: true },
        { type: "html", field: "validityDate", title: "有效日期", minWidth: 150, sortable: true },
        { type: "html", field: "num", title: "数量", minWidth: 150 },
        { type: "html", field: "storageDate", title: "入库日期", minWidth: 150, sortable: true },
        { field: "code", title: "关联入库单", minWidth: 150, sortable: true, className: "vxe-table-link-cell", slots: { default: "code_link" } },
        { title: "操作", fixed: "right", width: 120, slots: { default: "action" } }
    ]
});

// 显示隐藏 筛选表单
const xGridTable = ref();
const refreshTable = (mode = "add") => (xGridTable.value.searchData(mode), xGridTable.value.reloadColumn(columns));

const dispatchRef = ref();
const dispatchDescRef = ref();
const dialog = reactive({
    detail: false,
    desc: false
});

const table_detail = row => {
    dialog.desc = true;
    nextTick(() => dispatchDescRef.value?.setData(row));
}

const table_freeze = ({ id }) => {
    ElMessageBox.confirm("是否确认冻结该库存?", "删除警告", {
        type: "warning",
        confirmButtonText: "确定",
        cancelButtonText: "取消"
    }).then(() => {
        // API.production.plan.del({ id }).then(() => {
        //     ElMessage.success("操作成功");
        //     refreshTable();
        // });
    }).catch(() => {});
}
</script>

<style scoped>
.el-descriptions {padding-left: 10px;}
.el-descriptions :deep(.el-descriptions__cell) {width: calc(100% / 4);}
</style>