<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="primary" @click="handleAdd">新增</el-button>
                <!-- <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="handleImport()">导入</el-button>
            </template>
            <template #menu="scope">
                <!-- <el-button type="text" @click="handle(scope.row.tbId)">调拨</el-button> -->
            </template>

        </avue-crud>
        <basic-import v-if="isShowImport" title="导入" :isShow="isShowImport"
            templateUrl="/blade-desk/QA/CycleTestItem/download-excel-template"
            templateName="试验项目模板.xlsx"
            importUrl="/blade-desk/QA/CycleTestItem/import-excel"
            @closeDialog="closeDialog"></basic-import>
        <add-edit-dialog v-if="showDialog" :title="dialogTitle" :showDialog="showDialog" @closeDialog="closeDialog"></add-edit-dialog>
    </basic-container>
</template>
<script>
import basicImport from '@/components/basic-import/main.vue'
import { getTransferList,delTransfer} from "@/api/storeManagement/binTransfer.js"
import { change } from '@/api/job/jobinfo'
import addEditDialog from './components/addEditDialog.vue'
export default {
    components: {
        basicImport,addEditDialog
    },
    data() {
        return {
            isShowImport: false,
            loading: false,
            selectionList: [],
            dialogTitle:'新增',
            showDialog:false,
            query:{},
            data:[],
            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: false,
                editBtnText: '修改',
                viewBtnText: '详情',
                labelWidth: 120,
                menuWidth: 70,
                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',
                editBtn: false,

                column: [
                    {
                        label: '物料编号',
                        prop: 'goodsCode',
                        // bind: 'stRealtimeStock.coGoods.goodsCode',
                        sortable: true,
                        filter: true,
                        span: 12,
                        search: true,
                        type: 'select',
                        filterable: true,
                        dicUrl:'/api/blade-wms/stGoods/list',
                        remote: true,
                        props:{
                            label: 'goodsCode',
                            value: 'id',
                            res: 'data.records',
                        },
                        rules: [{ required: true, message: '请选择物料编号', trigger: 'blur' }],
                        // onChange:(value =>{
                        //     let tmp = value.dic.find(item => item.id == value.value)
                        //     this.form.goodsName = tmp && tmp.goodsName
                        // })
                    },
                    {
                        label: '物料名称',
                        prop: 'goodsName',
                        // bind: 'stRealtimeStock.coGoods.goodsName',
                        sortable: true,
                        filter: true,
                        span: 12,
                        search: false,
                        disabled: true,
                        rules: [{ required: true, message: '请输入物料名称', trigger: 'blur' }]
                    },
                    {
                        label: '旧库房号',
                        prop: 'shCode',
                        // bind: 'oldStorageLocation.coStorehouse.shName',
                        sortable: true,
                        filter: true,
                        span: 12,
                        search: false,
                        type: 'select',
                        filterable: true,
                        dicUrl:'/api/blade-wms/stStorehouse/list?shName={{key}}',
                        remote: true,
                        props:{
                            label: 'shName',
                            value: 'id',
                            res: 'data.records',
                        },
                        // dicData: [
                        //     {
                        //         label: '库房一',
                        //         value: 1
                        //     },
                        //     {
                        //         label: '库房二',
                        //         value: 2
                        //     }
                        // ],
                        rules: [{ required: true, message: '请选择旧库房号', trigger: 'blur' }]
                    },
                    {
                        label: '旧库位号',
                        prop: 'oldSlId',
                        // bind: 'oldStorageLocation.location',
                        sortable: true,
                        filter: true,
                        span: 12,
                        search: false,
                        type: 'select',
                        filterable: true,
                        dicUrl:'/api/blade-wms/stStorageLocation/list?location={{key}}',
                        remote: true,
                        props:{
                            label: 'location',
                            value: 'id',
                            res: 'data.records',
                        },
                        // dicData: [
                        //     {
                        //         label: '库位一',
                        //         value: 1
                        //     },
                        //     {
                        //         label: '库位二',
                        //         value: 2
                        //     }
                        // ],
                        rules: [{ required: true, message: '请选择旧库位号', trigger: 'blur' }]
                    },

                    {
                        label: '新库房号',
                        prop: 'newShId',
                        // bind: 'newStorageLocation.coStorehouse.shName',
                        sortable: true,
                        filter: true,
                        span: 12,
                        search: false,
                        type: 'select',
                        filterable: true,
                        dicUrl:'/api/blade-wms/stStorehouse/list?shName={{key}}',
                        remote: true,
                        props:{
                            label: 'shName',
                            value: 'id',
                            res: 'data.records',
                        },
                        // dicData: [
                        //     {
                        //         label: '库房一',
                        //         value: 1
                        //     },
                        //     {
                        //         label: '库房二',
                        //         value: 2
                        //     }
                        // ],
                        rules: [{ required: true, message: '请选择新库房号', trigger: 'blur' }]
                    },

                    {
                        label: '新库位号',
                        prop: 'newSIId',
                        // bind: 'newStorageLocation.location',
                        sortable: true,
                        filter: true,
                        span: 12,
                        search: false,
                        type: 'select',
                        filterable: true,
                        dicUrl:'/api/blade-wms/stStorageLocation/list?location={{key}}',
                        remote: true,
                        props:{
                            label: 'location',
                            value: 'id',
                            res: 'data.records',
                        },
                        // dicData: [
                        //     {
                        //         label: '库位一',
                        //         value: 1
                        //     },
                        //     {
                        //         label: '库位二',
                        //         value: 2
                        //     }
                        // ],
                        rules: [{ required: true, message: '请选择新库位号', trigger: 'blur' }]
                    },

                    {
                        label: '物料规格',
                        prop: 'specifications',
                        // bind: 'stRealtimeStock.coGoods.specifications',
                        sortable: true,
                        filter: true,
                        span: 12,
                        search: false,
                    },
                    {
                        label: '生产批次号',
                        prop: 'piNo',
                        // bind: 'stRealtimeStock.piNo',
                        sortable: true,
                        filter: true,
                        span: 12,
                        search: false,
                    },
                    {
                        label: '库存数量',
                        prop: '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: {
        closeDialog(val){
            this.isShowImport = false
            this.showDialog = false
            if(val){
                this.onLoad()
            }
        },
        handleImport() {
            this.isShowImport = true
        },
        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')
                    );
                });
        },
        // 点击新增按钮
        handleAdd(){
            this.showDialog = true
        },
        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
        },
        refreshChange(){
            this.onLoad()
        },
        rowDel(row){
            this.$confirm('确定将选择数据删除?', {
                confirmButtonText: '确定',
                cancelButtonText: '取消',
                type: 'warning',
            }).then(() => {
                delTransfer({ids:row.id}).then(res =>{
                    if(res.data.code == 200){
                        this.$message.success('删除成功')
                        this.onLoad()
                    }
                })
            })
        },
        handleDelete() {
            if (this.selectionList.length === 0) {
                this.$message.warning('请选择至少一条数据');
                return;
            }
            this.$confirm('确定将选择数据删除?', {
                confirmButtonText: '确定',
                cancelButtonText: '取消',
                type: 'warning',
            }).then(() => {
            })
        },
        // 多选
        selectionChange(list) {
            this.selectionList = list;
        },
        onLoad() {
            getTransferList({
                current:this.page.currentPage,
                size:this.page.pageSize
            }).then(res =>{
                this.data = res.data.data.records
                console.log('data-------------',this.data)
                this.page.total = res.data.data.total;
            })
            // this.loading = true
            // this.data = [
            // {}
            // ]
            // this.page.total = this.data.length
            // this.loading = false
            // setTimeout(() => {
            //     this.selectionClear()
            // }, 500)
        }
    }
}
</script>
<style lang="scss" scoped></style>