<template>
    <basic-container>
        <!-- 领料出库 -->
        <avue-crud :option="option" :table-loading="loading" :data="data" v-model="form" v-model:page="page" ref="crud"
            @search-change="searchChange" @search-reset="searchReset" :before-open="beforeOpen"
            @selection-change="selectionChange" @current-change="currentChange" @size-change="sizeChange"
            @refresh-change="refreshChange" @on-load="onLoad" @row-save="rowSave">
            <template #menu-left>
                <el-button type="primary"  @click="addFn">新增出库</el-button>
                <el-button type="primary"  @click="handleOut">批量打印</el-button>
                <el-button type="primary"  @click="outboundFn">批量出库</el-button>
                <el-button type="primary"  @click="closeOrder" plain>批量关闭</el-button>
            </template>
            <template #menu="scope">
                <el-button type="text" @click="detailsFn(scope.row)">详情
                </el-button>
                <el-button type="text" @click="editFn(scope.row)" v-if="scope.row.status == '1'">打印
                </el-button>
                <el-button type="text" @click="ouboundFn(scope.row)" v-if="scope.row.status == '1'">出库
                </el-button>
                <el-button type="text" @click="handleDelete" v-if="scope.row.status == '2'">报废
                </el-button>
            </template>
        </avue-crud>
        <addOut v-if="isAddOpen" :showDialog="isAddOpen" @closeDialog="closeDialog"> </addOut>
        <detailsDialog v-if="isDetailsOpen" :showDialog="isDetailsOpen" @closeDialog="closeDialog" :rowItem="rowItem">
        </detailsDialog>
        <outboundDialog v-if="isOutboundOpen" :showDialog="isOutboundOpen" @closeDialog="closeDialog"></outboundDialog>
    </basic-container>
</template>
<script>
import addOut from './components/addDialog.vue'
import detailsDialog from './components/detailsDialog.vue'
import outboundDialog from './components/outboundDialog.vue'
export default {
    components: {
        addOut,
        detailsDialog,
        outboundDialog
    },
    data() {
        return {
            loading: false,
            data: [],
            form: {},
            page: {
                pageSize: 10,
                currentPage: 1,
                total: 0,
            },
            selectionList: [],
            option: {
                columnSort: true,
                tip: false,
                height: 'auto',
                align: 'center',
                calcHeight: 32,
                simplePage: false,
                searchShow: true,
                searchMenuSpan: 6,
                searchIcon: true,
                searchIndex: 3,
                tree: false,
                border: true,
                index: false,
                selection: true,
                viewBtn: false,
                delBtn: false,
                editBtn: false,
                editBtnText: '修改',
                editBtnIcon: ' ',
                delBtnIcon: ' ',
                addBtn: false,
                labelWidth: 140,
                searchLabelWidth: 120,
                menu: true,
                menuWidth: 200,
                dialogWidth: 1200,
                dialogClickModal: false,
                searchEnter: true,
                excelBtn: true,
                gridBtn: false,
                searchShowBtn: false,
                showOverflowTooltip: true,
                searchLabelPosition:'left',
searchLabelPosition:'left',
 searchGutter:24,
  searchSpan:6,
menuAlign: 'left',
gridBtn:false,
searchMenuPosition:'right',
addBtnIcon: ' ',
        viewBtnIcon: ' ',
        delBtnIcon: ' ',
        editBtnIcon: ' ',
        

                column: [
                    {
                        label: '出库单号',
                        prop: 'brCode',
                        search: true,
                        width: 120,
                        searchLabelWidth: 75,
                    },
                    {
                        label: '车间订单号',
                        prop: 'woCode',
                        search: true,
                        width: 120,
                        searchLabelWidth: 100,
                    },
                    {
                        label: '零件号',
                        prop: 'partCode',
                        search: true,
                        width: 120,
                        searchLabelWidth: 70,
                    },
                    {
                        label: '零件名称',
                        prop: 'partName',
                        search: false,
                        width: 120,
                    },
                    {
                        label: '批次号',
                        prop: 'batchNo',
                        search: false,
                        width: 120,
                    },
                    {
                        label: '生产数量',
                        prop: 'okNum',
                        search: false,
                        width: 120,
                    },
                    {
                        label: '物料号',
                        prop: 'c_materiel_id',
                        search: false,
                        width: 120,
                    },
                    {
                        label: '物料名称',
                        prop: 'partNames',
                        search: false,
                        width: 120,
                    },
                    {
                        label: '物料需求数量',
                        prop: 'xuqiushuliang',
                        search: false,
                        width: 120,
                    },
                    {
                        label: '物料出库数量',
                        prop: 'chukushuliang',
                        search: false,
                        width: 120,
                    },
                    {
                        label: '物料批次号',
                        prop: 'goodbatchNo',
                        search: false,
                        width: 120,
                    },
                    {
                        label: '仓库',
                        prop: 'bsStoreRoomSet',
                        search: false,
                        width: 120,
                    },
                    {
                        label: '物料库位',
                        prop: 'goodsKuwei',
                        search: false,
                        width: 120,
                    },
                    {
                        label: '状态',
                        prop: 'status',
                        search: true,
                        width: 120,
                        searchLabelWidth: 60,
                        type: 'select',
                        dicData: [
                            {
                                label: '待出库',
                                value: '1',
                            },
                            {
                                label: '已出库',
                                value: '2',
                            },
                            {
                                label: '订单关闭',
                                value: '3',
                            },
                            {
                                label: '订单完成',
                                value: '4',
                            },
                        ]
                    },
                    {
                        label: '预计领料日期',
                        prop: 'goodsCode',
                        search: true,
                        width: 120,
                        searchLabelWidth: 100,
                        hide: true,
                        type: 'date',
                        searchRange: true,
                        startPlaceholder: '开始时间',
                        endPlaceholder: '结束时间',

                    },
                    {
                        label: '预计使用时间',
                        prop: 'times',
                        search: false,
                        width: 120,
                    },
                ]
            },
            isAddOpen: false,
            isDetailsOpen: false,
            isOutboundOpen: false,
            rowItem: {}
        }
    },
    mounted() {

    },
    methods: {
        addFn() {
            this.isAddOpen = true
        },
        detailsFn(row) {
            this.isDetailsOpen = true
            this.rowItem = row
        },
        outboundFn() {
            this.isOutboundOpen = true
        },
        closeDialog() {
            this.isAddOpen = false
            this.isDetailsOpen = false
            this.isOutboundOpen = false
        },
        // 多选
        selectionChange(list) {
            this.selectionList = list;
        },
        // 批量出库
        handleOut() {
            // this.$confirm('确定将选择数据删除?', {
            //     confirmButtonText: '确定',
            //     cancelButtonText: '取消',
            //     type: 'warning',
            // })
            //     .then(() => {
            //         return remove(row.id);
            //     })
            //     .then(() => {
            //         this.onLoad(this.page);
            //         this.$message({
            //             type: 'success',
            //             message: '操作成功!',
            //         });
            //     });
        },
        closeOrder() {
            this.$confirm('确定是否关闭订单?', {
                confirmButtonText: '确定',
                cancelButtonText: '取消',
                type: 'warning',
            })
                .then(() => {
                    // return remove(row.id);
                })
                .then(() => {
                    // this.onLoad(this.page);
                    // this.$message({
                    //     type: 'success',
                    //     message: '操作成功!',
                    // });
                });
        },
        // 出库
        ouboundFn() {
            this.$confirm('确定是否出库?', {
                confirmButtonText: '确定',
                cancelButtonText: '取消',
                type: 'warning',
            })
                .then(() => {
                    // return remove(row.id);
                })
                .then(() => {
                    // this.onLoad(this.page);
                    // this.$message({
                    //     type: 'success',
                    //     message: '操作成功!',
                    // });
                });
        },
        onLoad() {
            this.data = [
                {
                    brCode: 'aaaa',
                    woCode: 'WO-090899899',
                    partCode: 'E6-78787-E1',
                    partName: '零件一',
                    batchNo: '9098900',
                    okNum: '88',
                    c_materiel_id: '89',
                    partNames: '8989',
                    xuqiushuliang: 99,
                    chukushuliang: 67,
                    goodbatchNo: '898989',
                    bsStoreRoomSet: '仓库一',
                    goodsKuwei: '库位一',
                    status: 1,
                    statusName: '待出库',
                    times: '2025-09-08'
                },
                {
                    brCode: 'aaaa',
                    woCode: 'WO-090899899',
                    partCode: 'E6-78787-E1',
                    partName: '零件一',
                    batchNo: '9098900',
                    okNum: '88',
                    c_materiel_id: '89',
                    partNames: '8989',
                    xuqiushuliang: 99,
                    chukushuliang: 67,
                    goodbatchNo: '898989',
                    bsStoreRoomSet: '仓库一',
                    goodsKuwei: '库位一',
                    status: 2,
                    statusName: '已出库',
                    times: '2025-09-08'
                },
                {
                    brCode: 'aaaa',
                    woCode: 'WO-090899899',
                    partCode: 'E6-78787-E1',
                    partName: '零件一',
                    batchNo: '9098900',
                    okNum: '88',
                    c_materiel_id: '89',
                    partNames: '8989',
                    xuqiushuliang: 99,
                    chukushuliang: 67,
                    goodbatchNo: '898989',
                    bsStoreRoomSet: '仓库一',
                    goodsKuwei: '库位一',
                    status: 3,
                    statusName: '订单关闭',
                    times: '2025-09-08'
                },
                {
                    brCode: 'aaaa',
                    woCode: 'WO-090899899',
                    partCode: 'E6-78787-E1',
                    partName: '零件一',
                    batchNo: '9098900',
                    okNum: '88',
                    c_materiel_id: '89',
                    partNames: '8989',
                    xuqiushuliang: 99,
                    chukushuliang: 67,
                    goodbatchNo: '898989',
                    bsStoreRoomSet: '仓库一',
                    goodsKuwei: '库位一',
                    status: 4,
                    statusName: '订单完成',
                    times: '2025-09-08'
                },
                {
                    brCode: 'aaaa',
                    woCode: 'WO-090899899',
                    partCode: 'E6-78787-E1',
                    partName: '零件一',
                    batchNo: '9098900',
                    okNum: '88',
                    c_materiel_id: '89',
                    partNames: '8989',
                    xuqiushuliang: 99,
                    chukushuliang: 67,
                    goodbatchNo: '898989',
                    bsStoreRoomSet: '仓库一',
                    goodsKuwei: '库位一',
                    status: 1,
                    statusName: '待出库',
                    times: '2025-09-08'
                }
            ]
            this.page.total = this.data.length
        }
    }
}
</script>