<template>
    <basic-container>
        <!-- 库存汇总 -->
        <avue-crud :option="option" :table-loading="loading" :data="data" v-model="form" v-model:page="page" ref="crud"
            @row-update="rowUpdate" @row-save="rowSave" @search-change="searchChange" @search-reset="searchReset"
            @selection-change="selectionChange" @current-change="currentChange" @size-change="sizeChange"
            @refresh-change="refreshChange" @on-load="onLoad">
            <template #zyQuantity="scope">
                <el-button type="text" size="mini" @click="detailList(scope.row.rlsId)">{{ scope.row.zyQuantity
                    }}</el-button>
            </template>
            <template #goodsStatus="scope">
                {{scope.row.goodsStatus === false ? '合格' : scope.row.goodsStatus === true ? '限用' : ''}}
            </template>

            <template #menu-left>
                <el-button type="primary" @click="handlePrint">标签打印</el-button>
                <el-button type="primary" @click="handlePrintCard">存料登记卡打印</el-button>
            </template>
        </avue-crud>
        <el-dialog title="预占用详情" append-to-body v-model="detailOpen">
            <el-table :data="detailData">
                <el-table-column label="工作订单号" align="center" prop="woNo" min-width="150" />
                <el-table-column label="占用数" align="center" prop="zyQuantity" min-width="150" />
                <el-table-column label="占用时间" align="center" prop="generateTime" min-width="100" />
            </el-table>
        </el-dialog>
        <el-dialog title="打印" append-to-body v-model="showPrint">
            <el-form ref="printForm" :model="printForm" :rules="printRules">
                <el-form-item label="数量" prop="quantity">
                    <el-input v-model.number="printForm.quantity" placeholder="请输入数量" type="default"
                        oninput="value=value.replace(/[^\d]/g,'')" />
                </el-form-item>
            </el-form>
            <template #footer>
                <span class="dialog-footer">
                    <el-button @click="showPrint = false">取 消</el-button>
                    <el-button type="primary" @click="submitPrint">确 定</el-button>
                </span>
            </template>
        </el-dialog>
    </basic-container>
</template>

<script>
import {getList,getPrint} from "@/api/storeManagement/inventorySummary"
export default {
    data() {
        return {
            detailOpen: false,
            detailData: [],
            showPrint: false,
            printForm: {},
            printRules: {
                quantity: [{ required: true, message: '请输入数量', trigger: 'blur' }]
            },
            selectionList: [],
            loading: false,
            data: [],
            form: {},
            query:{},
            page: {
                pageSize: 10,
                currentPage: 1,
                total: 0,
            },
            option: {
                height: 'auto',
                align: 'center',
                calcHeight: 32,
                tip: false,
                size: 'medium',
                simplePage: true,
                searchShow: true,
                searchMenuSpan: 6,
                searchIcon: true,
                searchIndex: 3,
                tree: false,
                border: true,
                index: false,
                selection: true,
                viewBtn: false,
                delBtn: false,
                addBtn: false,
                editBtn: false,
                editBtnText: '修改',
                addBtnIcon: ' ',
                viewBtnIcon: ' ',
                delBtnIcon: ' ',
                editBtnIcon: ' ',
                viewBtnText: '详情',
                labelWidth: 120,
                searchLabelWidth: 120,
                menu: false,
                menuWidth: 220,
                dialogWidth: 1200,
                dialogClickModal: false,
                searchEnter: true,
                excelBtn: false,
                filterBtn: true,
                searchShowBtn: false,
                columnSort: true,
                excelBtn: true,
                columnSort: true,
                showOverflowTooltip: true,
                searchLabelPosition: 'left',
                searchGutter: 24,
                searchSpan: 6,
                menuAlign: 'left',
                gridBtn: false,
                searchMenuPosition: 'right',
                column: [
                    {
                        label: '库房编号',
                        prop: 'shCode',
                        // bind: 'coStorehouse.shCode',
                        width: 200,
                        search: true,
                        sortable: true,
                        overHidden: true,
                        rules: [
                            {
                                required: true,
                                message: '请输入库房编号',
                                trigger: 'blur',
                            },
                        ],
                    },
                    // {
                    //     label: '仓库',
                    //     prop: 'shId',
                    //     // bind: 'coStorehouse.shId',
                    //     // type: 'select',
                    //     width: 200,
                    //     hide: true,
                    //     search: true,
                    //     sortable: true,
                    //     overHidden: true,
                    //     rules: [
                    //         {
                    //             required: true,
                    //             message: '请输入仓库',
                    //             trigger: 'blur',
                    //         },
                    //     ],
                    // },
                    {
                        label: '库位',
                        prop: 'location',
                        // bind: 'storageLocation.location',
                        width: 200,
                        search: true,
                        sortable: true,
                        overHidden: true,
                        rules: [
                            {
                                required: true,
                                message: '请输入库位',
                                trigger: 'blur',
                            },
                        ],
                    },
                    // {
                    //     label: '部门',
                    //     prop: 'factoryId',
                    //     type: 'select',
                    //     width: 200,
                    //     hide: true,
                    //     search: false,
                    //     sortable: true,
                    //     overHidden: true,
                    //     rules: [
                    //         {
                    //             required: true,
                    //             message: '请输入部门',
                    //             trigger: 'blur',
                    //         },
                    //     ],
                    //     dicData: [
                    //         {
                    //             value: 5,
                    //             label: '模塑分厂'
                    //         },
                    //         {
                    //             value: 102,
                    //             label: '热表分厂'
                    //         }
                    //     ]
                    // },
                    {
                        label: '物料编号',
                        prop: 'goodsCode',
                        // bind: 'coGoods.goodsCode',
                        width: 200,
                        search: true,
                        sortable: true,
                        overHidden: true,
                        rules: [
                            {
                                required: true,
                                message: '请输入物料编号',
                                trigger: 'blur',
                            },
                        ],
                    },
                    {
                        label: '物料名称',
                        prop: 'goodsName',
                        // bind: 'coGoods.goodsName',
                        width: 200,
                        search: true,
                        sortable: true,
                        overHidden: true,
                        rules: [
                            {
                                required: true,
                                message: '请输入物料名称',
                                trigger: 'blur',
                            },
                        ],
                    },
                    {
                        label: '单位',
                        prop: 'unitName',
                        // bind: 'coGoods.unitName',
                        width: 200,
                        search: false,
                        sortable: true,
                        overHidden: true,
                        rules: [
                            {
                                required: true,
                                message: '请输入单位',
                                trigger: 'blur',
                            },
                        ],
                    },
                    {
                        label: '质量编号',
                        prop: 'checkCode',
                        width: 200,
                        search: false,
                        sortable: true,
                        overHidden: true,
                        rules: [
                            {
                                required: true,
                                message: '请输入质量编号',
                                trigger: 'blur',
                            },
                        ],
                    },
                    {
                        label: '批次号',
                        prop: 'piNo',
                        width: 200,
                        search: true,
                        sortable: true,
                        overHidden: true,
                        rules: [
                            {
                                required: true,
                                message: '请输入批次号',
                                trigger: 'blur',
                            },
                        ],
                    },
                    {
                        label: '炉批号',
                        prop: 'stovePiNo',
                        width: 200,
                        search: true,
                        sortable: true,
                        overHidden: true,
                        rules: [
                            {
                                required: true,
                                message: '请输入炉批号',
                                trigger: 'blur',
                            },
                        ],
                    },
                    {
                        label: '现存数量',
                        prop: 'quantity',
                        width: 200,
                        search: false,
                        sortable: true,
                        overHidden: true,
                        rules: [
                            {
                                required: true,
                                message: '请输入现存数量',
                                trigger: 'blur',
                            },
                        ],
                    },
                    {
                        label: '占用数量',
                        prop: 'occupyQuantity',
                        width: 200,
                        search: false,
                        sortable: true,
                        overHidden: true,
                        rules: [
                            {
                                required: true,
                                message: '请输入占用数量',
                                trigger: 'blur',
                            },
                        ],
                    },
                    {
                        label: '到期日期',
                        prop: 'scrapCycle',
                        width: 200,
                        search: false,
                        sortable: true,
                        overHidden: true,
                        rules: [
                            {
                                required: true,
                                message: '请输入到期日期',
                                trigger: 'blur',
                            },
                        ],
                    },
                    {
                        label: '型号/牌号',
                        prop: 'materialModel',
                        // bind: 'coGoods.mtltmrk',
                        width: 200,
                        search: false,
                        sortable: true,
                        overHidden: true,
                        rules: [
                            {
                                required: true,
                                message: '请输入型号/牌号',
                                trigger: 'blur',
                            },
                        ],
                    },
                    {
                        label: '物料状态',
                        prop: 'goodsStatus',
                        width: 200,
                        type: 'select',
                        search: false,
                        sortable: true,
                        overHidden: true,
                        rules: [
                            {
                                required: true,
                                message: '请输入物料状态',
                                trigger: 'blur',
                            },
                        ],
                        // /**
                        // * 需报料
                        // */
                        // public static Short NEED_REPORT = 1;
                        // /**
                        //  * 需跟踪
                        //  */
                        // public static Short NEED_TRACK = 2;
                        // /**
                        //  * 待领料
                        //  */
                        // public static Short TO_BE_PICKED = 3;
                        // /**
                        //  * 正常
                        //  */
                        // public static Short NORMAL = 4;
                        // /**
                        //  * 长期未使用
                        //  */
                        // public static Short NOT_USED = 5;
                        dicData:[
                            {label:'需报料',value:1},
                            {label:'需跟踪',value:2},
                            {label:'待领料',value:3},
                            {label:'正常',value:4},
                            {label:'长期未使用',value:5}
                        ]
                    },
                    {
                        label: '生产标识',
                        prop: 'inQuantityLevel',
                        width: 200,
                        search: false,
                        sortable: true,
                        overHidden: true,
                        rules: [
                            {
                                required: true,
                                message: '请输入生产标识',
                                trigger: 'blur',
                            },
                        ],
                    },
                    {
                        label: '物料规格',
                        prop: 'specifications',
                        // bind: 'coGoods.specifications',
                        width: 200,
                        search: false,
                        sortable: true,
                        overHidden: true,
                        rules: [
                            {
                                required: true,
                                message: '请输入物料规格',
                                trigger: 'blur',
                            },
                        ],
                    },
                        {
                        label: '是否印字',
                        prop: 'printMark',
                        // bind: 'coGoods.isPrint',
                        width: 200,
                        search: false,
                        sortable: true,
                        overHidden: true,
                        type: 'select',
                        dicData: [
                            {
                                label: '是',
                                value: true,
                            },
                            {
                                label: '否',
                                value: false,
                            },
                        ],
                        rules: [
                            {
                                required: true,
                                message: '请输入是否印字',
                                trigger: 'blur',
                            },
                        ],
                    },
                    {
                        label: '粉重',
                        prop: 'powderWeight',
                        // bind: 'coGoods.weight',
                        width: 200,
                        search: false,
                        sortable: true,
                        rules: [
                            {
                                required: true,
                                message: '请输入粉重',
                                trigger: 'blur',
                            },
                        ],
                    },
                    {
                        label: '材料号',
                        prop: 'materialNo',
                        // bind: 'coGoods.materialNo',
                        width: 200,
                        search: false,
                        sortable: true,
                        rules: [
                            {
                                required: true,
                                message: '请输入材料号',
                                trigger: 'blur',
                            },
                        ],
                    },
                    {
                        label: '成型厚度',
                        prop: 'thickness',
                        // bind: 'coGoods.moldingThickness',
                        width: 200,
                        search: false,
                        sortable: true,
                        rules: [
                            {
                                required: true,
                                message: '请输入成型厚度',
                                trigger: 'blur',
                            },
                        ],
                    },
                    {
                        label: '入库时间',
                        prop: 'inOutDate',
                        width: 200,
                        search: true,
                        sortable: true,
                        overHidden: true,
                        type: 'date',
                        format: 'YYYY-MM-DD',
                        valueFormat: 'YYYY-MM-DD',
                        startPlaceholder: '开始日期',
                        endPlaceholder: '结束日期',
                        searchRange: true,
                        rules: [
                            {
                                required: true,
                                message: '请输入入库时间',
                                trigger: 'blur',
                            },
                        ],
                    },
                    {
                        label: '入库数量',
                        prop: 'inQuantity',
                        width: 200,
                        rules: [
                            {
                                required: true,
                                message: '请输入入库日期',
                                trigger: 'blur',
                            },
                        ],
                    },
                    // {
                    //     label: '入库时间',
                    //     prop: 'inOutDate',
                    //     width: 200,
                    //     search: false,
                    //     sortable: true,
                    //     overHidden: true,
                    //     rules: [
                    //         {
                    //             required: true,
                    //             message: '请输入入库日期',
                    //             trigger: 'blur',
                    //         },
                    //     ],
                    // },
                    
                    {
                        label: '单价',
                        prop: 'balanceMoney',
                        width: 200,
                        search: false,
                        sortable: true,
                        overHidden: true,
                        rules: [
                            {
                                required: true,
                                message: '请输入单价',
                                trigger: 'blur',
                            },
                        ],
                    },
                    {
                        label: '库存部门',
                        prop: 'deptName',
                        width: 200,
                        search: false,
                        sortable: true,
                        overHidden: true,
                        rules: [
                            {
                                required: true,
                                message: '请输入库存部门',
                                trigger: 'blur',
                            },
                        ],
                    },
                    {
                        label: '供应商名称',
                        prop: 'splyCode',
                        width: 200,
                        search: false,
                        sortable: true,
                        overHidden: true,
                        rules: [
                            {
                                required: true,
                                message: '请输入供应商名称',
                                trigger: 'blur',
                            },
                        ],
                    },
                    {
                        label: '保管员',
                        prop: 'keeperName',
                        // bind: 'coStorehouse.saveUser.userName',
                        // type: 'select',
                        width: 200,
                        search: true,
                        sortable: true,
                        overHidden: true,
                        rules: [
                            {
                                required: true,
                                message: '请输入保管员',
                                trigger: 'blur',
                            },
                        ],
                        // props: {
                        //     label: 'realName',
                        //     value: 'id',
                        // },
                        // dicUrl:'/api/blade-system/user/list-all-by-role-alias?roleAlias=保管员'
                    },
                ]
            }
        }
    },
    mounted() {

    },
    methods: {
        handlePrint() {
            if (this.selectionList.length == 0) {
                this.$message.error('请先选择数据')
                return
            }
            this.showPrint = true
        },
        handlePrintCard() {
            if (this.selectionList.length == 0) {
                this.$message.error('请先选择数据')
                return
            }
            getPrint({id:this.selectionList[0].id}).then(res =>{
                console.log('res--------------',res)
            })
        },
        searchChange(params, done){
            this.query = params;
            this.page.currentPage = 1
            this.onLoad()
            done()
        },
        searchReset(){
            this.query = {}
            this.onLoad()
        },
        currentChange(currentPage){
            this.page.currentPage = currentPage
        },
        sizeChange(pageSize){
            this.page.pageSize = pageSize
        },
        detailList() {
            this.detailOpen = true
        },
        submitPrint() {
            this.$refs.printForm.validate(valid => {
                if (valid) {
                    this.showPrint = false
                }
            })
        },
        selectionChange(val) {
            this.selectionList = val
        },
        onLoad() {
            this.loading = true
            let params = {
                ...this.query,
                startInOutDate:this.query.inOutDate && this.query.inOutDate.length != 0 && this.query.inOutDate[0],
	            endInOutDate:this.query.inOutDate && this.query.inOutDate.length != 0 && this.query.inOutDate[0]
            }
            const {inOutDate,...invalideParams} = params
            getList({
                current:this.page.currentPage,
                size:this.page.pageSize,
                ...invalideParams
            }).then(res =>{
                this.data = res.data.data.records
                this.page.total = res.data.data.total
                this.loading = false
            })
        }
    }
}
</script>

<style></style>