<template>
    <basic-container>
        <!-- 物料入库 -->
        <avue-crud :option="option" :table-loading="loading" :data="data" v-model="form" v-model:page="page" ref="crud"
            @row-del="rowDel" @search-change="searchChange" @search-reset="searchReset"
            @selection-change="selectionChange" @current-change="currentChange" @size-change="sizeChange"
            @refresh-change="refreshChange" @on-load="onLoad">
            <template #menu-left>
                <el-button icon="el-icon-plus" type="primary" @click="batchPush">批量入库</el-button>
            </template>
            <template #menu="scope">
                <el-button  type="text" @click="warehousing(scope.row)">入库</el-button>
            </template>
            <template #shCode="{row}">{{ row.pushHouse.coStorehouse.shCode }}</template>
            <template #location="{row}">{{ row.pushHouse.location }}</template>
        </avue-crud>
        <el-dialog title="入库" append-to-body v-model="warehouseShow">
            <el-form ref="warehouseForm" :model="warehouseForm" :rules="warehouseRules" label-width="80">
                <el-form-item label="入库仓库" prop="pushHouse.coStorehouse.shId">
                    <el-select v-model="warehouseForm.pushHouse.coStorehouse.shId">
                        <el-option label="仓库一" value="1"></el-option>
                        <el-option label="仓库二" value="2"></el-option>
                    </el-select>
                </el-form-item>
                <el-form-item label="库位号" prop="pushHouse.cslId">
                    <el-select v-model="warehouseForm.pushHouse.cslId">
                        <el-option label="仓库一" value="1"></el-option>
                        <el-option label="仓库二" value="2"></el-option>
                    </el-select>
                </el-form-item>
                <el-form-item label="数量" prop="pushQuantity">
                    <el-input
                        v-model="warehouseForm.pushQuantity"
                        oninput="value=value.replace(/[^0-9.]/g,'')"
                    />
                </el-form-item>
            </el-form>
            <template #footer>
                <span class="dialog-footer">
                <el-button @click="warehouseShow = false">取 消</el-button>
                <el-button type="primary" @click="submitWarehouse">确 定</el-button>
                </span>
            </template>
        </el-dialog>
    </basic-container>
</template>
<script>
export default {
    data() {
        return {
            loading: false,
            data: [],
            form: {},
            selectionList:[],
            warehouseShow:false,
            warehouseForm:{
                pushHouse:{
                    coStorehouse:{}
                }
            },
            warehouseRules:{
                pushHouse:{
                    coStorehouse:{
                        shId:[{required:true,message:'请选择入库仓库',trigger:'blur'}]
                    },
                    cslId:[{required:true,message:'请选择库位号',trigger:'blur'}]
                }
            },
            page: {
                pageSize: 10,
                currentPage: 1,
                total: 0,
            },
            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: 600,
                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: 'prtno',
                        span: 24,
                        overflow: true,
                        search: true,
                        rules: [
                            {
                                required: true,
                                message: '请输入物料编号',
                                trigger: 'blur',
                            },
                        ],
                    },
                    {
                        label: '材料名称',
                        prop: 'prtdesc',
                        span: 24,
                        overflow: true,
                        search: false,
                        rules: [
                            {
                                required: true,
                                message: '请输入材料名称',
                                trigger: 'blur',
                            },
                        ],
                    },
                    {
                        label: '规格',
                        prop: 'prtinfo',
                        span: 24,
                        overflow: true,
                        search: false,
                        rules: [
                            {
                                required: true,
                                message: '请输入规格',
                                trigger: 'blur',
                            },
                        ],
                    },
                    {
                        label: '生产标识',
                        prop: 'prtlotno',
                        span: 24,
                        overflow: true,
                        search: false,
                        rules: [
                            {
                                required: true,
                                message: '请输入生产标识',
                                trigger: 'blur',
                            },
                        ],
                    },
                    {
                        label: '出库单号',
                        prop: 'invadjCode',
                        span: 24,
                        overflow: true,
                        search: false,
                        rules: [
                            {
                                required: true,
                                message: '请输入出库单号',
                                trigger: 'blur',
                            },
                        ],
                    },
                    {
                        label: '出库数量',
                        prop: 'invysqty',
                        span: 24,
                        overflow: true,
                        search: false,
                        rules: [
                            {
                                required: true,
                                message: '请输入出库数量',
                                trigger: 'blur',
                            },
                        ],
                    },
                    {
                        label: '入库数量',
                        prop: 'pushQuantity',
                        span: 24,
                        overflow: true,
                        search: false,
                        rules: [
                            {
                                required: true,
                                message: '请输入入库数量',
                                trigger: 'blur',
                            },
                        ],
                    },
                    {
                        label: '入库库房',
                        prop: 'shCode',
                        span: 24,
                        overflow: true,
                        search: false,
                        rules: [
                            {
                                required: true,
                                message: '请输入入库库房',
                                trigger: 'blur',
                            },
                        ],
                    },
                    {
                        label: '入库库位',
                        prop: 'location',
                        span: 24,
                        overflow: true,
                        search: false,
                        rules: [
                            {
                                required: true,
                                message: '请输入入库库位',
                                trigger: 'blur',
                            },
                        ],
                    },
                    {
                        label: '单位',
                        prop: 'prtum',
                        span: 24,
                        overflow: true,
                        search: false,
                        rules: [
                            {
                                required: true,
                                message: '请输入单位',
                                trigger: 'blur',
                            },
                        ],
                    },
                ]
            }
        }
    },
    mounted(){

    },
    methods:{
        // 多选
        selectionChange(list) {
            this.selectionList = list;
        },
        // 单个入库
        warehousing(){
            this.warehouseShow = true
            this.$refs.warehouseForm.resetFields()
        },
        // 批量入库
        batchPush(){
            if(this.selectionList.length && this.selectionList.length != 0){

            }else{
                this.$message.warning('请选择需要入库物料');
            }
        },
        // 提交入库
        submitWarehouse(){
            this.$refs.warehouseForm.validate(valid => {
                console.log('valid==============',valid)
                if (valid) {
                this.warehouseShow = false
                }
            })
        },
        onLoad(){
            this.data = [
                {id:1,prtno:'001',prtdesc:'材料一',prtinfo:'规格一',prtlotno:'生产标识',invadjCode:'',invysqty:'',pushQuantity:20,
                pushHouse:{
                    coStorehouse:{
                        shCode:'仓库一'
                    },
                    location:'00-10',
                },prtum:'个'},
                {id:2,prtno:'001',prtdesc:'材料一',prtinfo:'规格一',prtlotno:'生产标识',invadjCode:'',invysqty:'',pushQuantity:20,
                pushHouse:{
                    coStorehouse:{
                        shCode:'仓库一'
                    },
                    location:'00-10',
                },prtum:'个'},
            ]
            this.page.total = this.data.length
        }
    }
}
</script>
<style lang="scss" scoped></style>