<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 type="danger" @click="handle()">删除</el-button>
            </template>
            <template #menu-right>
                <!-- <el-button type="primary" @click="allocationFun()">批量调拨</el-button> -->
                <el-button type="primary" @click="handle()">导入</el-button>
            </template>
            <template #menu="scope">
                <!-- <el-button type="text" @click="handle(scope.row.tbId)">调拨</el-button> -->
            </template>

        </avue-crud>
    </basic-container>
</template>
<script>
export default {
    data() {
        return {
            selectionList: [],
            option: {
                height: 'auto',
                calcHeight: 32,
                tip: false,
                size: 'medium',
                simplePage: true,
                searchShow: true,
                searchMenuSpan: 18,
                searchIcon: true,
                searchIndex: 3,
                tree: false,
                border: true,
                index: true,
                selection: true,
                viewBtn: false,
                delBtn: true,
                addBtn: true,
                editBtnText: '修改',
                viewBtnText: '详情',
                labelWidth: 120,
                menuWidth: 180,
                dialogWidth: 1040,
                dialogClickModal: false,
                searchEnter: true,
                excelBtn: false,
                filterBtn: true,
                searchShowBtn: false,
                columnSort: true,
                excelBtn: true,
                columnSort: true,
                index: false,
                showOverflowTooltip: true,
                searchLabelPosition: 'left',
                searchGutter: 24,
                searchSpan: 6,
                menuAlign: 'left',
                gridBtn: false,
                searchMenuPosition: 'right',
                addBtnIcon: ' ',
                viewBtnIcon: ' ',
                delBtnIcon: ' ',
                editBtnIcon: ' ',
                align: 'center',

                column: [
                    {
                        label: '物料编号',
                        prop: 'stRealtimeStock.coGoods.goodsCode',
                        bind: 'stRealtimeStock.coGoods.goodsCode',
                        sortable: true,
                        filter: true,
                        span: 12,
                        search: true,
                        type: 'select',
                        filterable: true,
                        dicData: [
                            {
                                label: '物料一',
                                value: 1
                            },
                            {
                                label: '物料二',
                                value: 2
                            }
                        ],
                        rules: [{ required: true, message: '请输入物料编号', trigger: 'blur' }]
                    },
                    {
                        label: '物料名称',
                        prop: 'stRealtimeStock.coGoods.goodsName',
                        bind: 'stRealtimeStock.coGoods.goodsName',
                        sortable: true,
                        filter: true,
                        span: 12,
                        search: false,
                        disabled: true,
                        rules: [{ required: true, message: '请输入物料名称', trigger: 'blur' }]
                    },
                    {
                        label: '旧库房号',
                        prop: 'oldStorageLocation.coStorehouse.shName',
                        bind: 'oldStorageLocation.coStorehouse.shName',
                        sortable: true,
                        filter: true,
                        span: 12,
                        search: false,
                        type: 'select',
                        filterable: true,
                        dicData: [
                            {
                                label: '库房一',
                                value: 1
                            },
                            {
                                label: '库房二',
                                value: 2
                            }
                        ],
                        rules: [{ required: true, message: '请输入旧库房号', trigger: 'blur' }]
                    },
                    {
                        label: '旧库位号',
                        prop: 'oldStorageLocation.location',
                        bind: 'oldStorageLocation.location',
                        sortable: true,
                        filter: true,
                        span: 12,
                        search: false,
                        type: 'select',
                        filterable: true,
                        dicData: [
                            {
                                label: '库位一',
                                value: 1
                            },
                            {
                                label: '库位二',
                                value: 2
                            }
                        ],
                        rules: [{ required: true, message: '请输入旧库房号', trigger: 'blur' }]
                    },

                    {
                        label: '新库房号',
                        prop: 'newStorageLocation.coStorehouse.shName',
                        bind: 'newStorageLocation.coStorehouse.shName',
                        sortable: true,
                        filter: true,
                        span: 12,
                        search: false,
                        type: 'select',
                        filterable: true,
                        dicData: [
                            {
                                label: '库房一',
                                value: 1
                            },
                            {
                                label: '库房二',
                                value: 2
                            }
                        ],
                        rules: [{ required: true, message: '请输入物料编号', trigger: 'blur' }]
                    },

                    {
                        label: '新库位号',
                        prop: 'newStorageLocation.location',
                        bind: 'newStorageLocation.location',
                        sortable: true,
                        filter: true,
                        span: 12,
                        search: false,
                        type: 'select',
                        filterable: true,
                        dicData: [
                            {
                                label: '库位一',
                                value: 1
                            },
                            {
                                label: '库位二',
                                value: 2
                            }
                        ],
                        rules: [{ required: true, message: '请输入物料编号', trigger: 'blur' }]
                    },

                    {
                        label: '物料规格',
                        prop: 'stRealtimeStock.coGoods.specifications',
                        bind: 'stRealtimeStock.coGoods.specifications',
                        sortable: true,
                        filter: true,
                        span: 12,
                        search: false,
                    },
                    {
                        label: '生产批次号',
                        prop: 'stRealtimeStock.piNo',
                        bind: 'stRealtimeStock.piNo',
                        sortable: true,
                        filter: true,
                        span: 12,
                        search: false,
                    },
                    {
                        label: '库存数量',
                        prop: 'stRealtimeStock.quantity',
                        bind: 'stRealtimeStock.quantity',
                        sortable: true,
                        filter: true,
                        span: 12,
                        search: false,
                        type: 'number',
                        step: 1,
                    },


                ]
            },
            form: {

            },
            page: {
                pageSize: 10,
                currentPage: 1,
                total: 0,
            },
        }
    },
    methods: {
        allocationFun(arId) {
            // if (arId == null && this.selectionArr.length === 0) {
            //     return this.$message.warning('请先选择数据再进行调拨！');
            // }
            this.$confirm('是否确认调拨', '提示', {
                confirmButtonText: '确认',
                cancelButtonText: '取消',
                type: 'warning'
            })
                .then(() => {
                    const obj = { list: [] };
                    if (arId == null) {
                        this.selectionArr.forEach(item => {
                            obj.list.push(item.arId);
                        });
                    } else {
                        obj.list.push(arId);
                    }
                    //   this.$ajax.post('stAllotRecord/updateLocation', obj).then(res => {
                    //     if (res.code === 0) {
                    //       this.$message.success(this.$t('store.allocationOk'));
                    //       this.$refs.myTable.load();
                    //     }
                    //   });
                })
                .catch(() => {
                    this.$message.info(
                        this.$t('global.canceled') + this.$t('store.allocation')
                    );
                });
        },
        handleDelete() {
            if (this.selectionList.length === 0) {
                this.$message.warning('请选择至少一条数据');
                return;
            }
            this.$confirm('确定将选择数据删除?', {
                confirmButtonText: '确定',
                cancelButtonText: '取消',
                type: 'warning',
            }).then(() => {
            })
        },
        // 多选
        selectionChange(list) {
            this.selectionList = list;
        },
        onLoad() {
            this.loading = true
            this.data = [
            {}
            ]
            this.page.total = this.data.length
            this.loading = false
            setTimeout(() => {
                this.selectionClear()
            }, 500)
        }
    }
}
</script>
<style lang="scss" scoped></style>