<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="allocationFun()">即将到期</el-button>
                <el-button type="primary" @click="allocationFun()">已到期</el-button>
                <el-button type="primary" @click="allocationFun()">到期处理</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="handle()">导入</el-button> -->
            </template>
            <template #menu="scope">
                <el-button type="text" @click="handle(scope.row.tbId)">报废出库</el-button>
            </template>
            <template #stopUse="scope">
                <el-switch v-model="scope.row.stopUse" active-text="限用" inactive-text="合格" active-color="#13ce66" inactive-color="#ff4949" @change="usedOpenView(scope.row)" />
            </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: 6,
                searchIcon: true,
                searchIndex: 3,
                tree: false,
                border: true,
                index: true,
                selection: true,
                editBtn: false,
                viewBtn: false,
                delBtn: false,
                addBtn: false,
                editBtnText: '修改',
                viewBtnIcon: ' ',
                delBtnIcon: ' ',
                editBtnIcon: ' ',
                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,
                menu: true,
                searchLabelPosition:'left',
searchLabelPosition:'left',
 searchGutter:24,
  searchSpan:6,
menuAlign: 'left',
gridBtn:false,
searchMenuPosition:'right',
                column: [
                    {
                        label: '物料编号',
                        prop: 'coGoods.goodsCode',
                        bind:'coGoods.goodsCode',
                        sortable: true,
                        filter: true,
                        span: 12,
                        search: false,
                        width: 120,
                    },
                    {
                        label: '物料名称',
                        prop: 'coGoods.goodsName',
                        bind:'coGoods.goodsName',
                        sortable: true,
                        filter: true,
                        span: 12,
                        search: false,
                        width: 120,
                    },
                    {
                        label: '物料规格',
                        prop: 'coGoods.specifications',
                        bind:'coGoods.specifications',
                        sortable: true,
                        filter: true,
                        span: 12,
                        search: false,
                        width: 120,
                    },
                    {
                        label: '物料状态',
                        prop: 'stopUseTitle',
                        sortable: true,
                        filter: true,
                        span: 12,
                        search: false,
                        width: 120,
                    },
                    {
                        label: '仓库号',
                        prop: 'coStorehouse.shName',
                        bind:'coStorehouse.shName',
                        sortable: true,
                        filter: true,
                        span: 12,
                        search: false,
                        width: 120,
                    },
                    {
                        label: '库位号',
                        prop: 'storageLocation.location',
                        bind:'storageLocation.location',
                        sortable: true,
                        filter: true,
                        span: 12,
                        search: false,
                        width: 120,
                    },
                    {
                        label: '登记',
                        prop: 'quantityLevel',
                        sortable: true,
                        filter: true,
                        span: 12,
                        search: false,
                        width: 120,
                    },
                    {
                        label: '质量编号',
                        prop: 'checkCode',
                        sortable: true,
                        filter: true,
                        span: 12,
                        search: false,
                        width: 120,
                    },
                    {
                        label: '生产批次号',
                        prop: 'piNo',
                        sortable: true,
                        filter: true,
                        span: 12,
                        search: false,
                        width: 120,
                    },
                    {
                        label: '炉批号',
                        prop: 'stovePiNo',
                        sortable: true,
                        filter: true,
                        span: 12,
                        search: false,
                        width: 120,
                    },
                    {
                        label: '数量',
                        prop: 'quantity',
                        sortable: true,
                        filter: true,
                        span: 12,
                        search: false,
                        width: 120,
                    },
                    {
                        label: '价格',
                        prop: 'balanceMoney',
                        sortable: true,
                        filter: true,
                        span: 12,
                        search: false,
                        width: 120,
                    },
                    {
                        label: '到期日期',
                        prop: 'scrapCycle',
                        sortable: true,
                        filter: true,
                        span: 12,
                        search: false,
                        width: 120,
                    },
                    {
                        label: '备注',
                        prop: 'memo',
                        sortable: true,
                        filter: true,
                        span: 12,
                        search: false,
                        width: 120,
                    },
                    {
                        label: '库存限用',
                        prop: 'stopUse',
                        sortable: true,
                        filter: true,
                        span: 12,
                        search: false,
                        width: 160,
                        fixed: 'right',
                       
                    },


                ]
            },
            form: {

            },
            page: {
                pageSize: 10,
                currentPage: 1,
                total: 0,
            },
        }
    },
    methods: {
        warehousing() {

        },
        warehousingLog() {

        },
        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 = [
                {
                    "allMoney": null,
                    "balanceMoney": 15.0,
                    "barCode": null,
                    "checkCode": "ck001",
                    "coGoods": {
                        "allGoodsQuantity": null,
                        "batch": null,
                        "bomQuantity": null,
                        "buyQuantity": null,
                        "cavityno": null,
                        "checkoutCode": "2222",
                        "coGoodsClass": null,
                        "coStorageLocation": null,
                        "cplb": null,
                        "createTime": "2023-07-15 16:18:30",
                        "curQuantity": 2999.0,
                        "cycle": null,
                        "deleted": false,
                        "deliveryDate": null,
                        "dept": null,
                        "drawingNo": null,
                        "ecnno": null,
                        "enditem": 0,
                        "erpQuantity": null,
                        "goodsCode": "21E543-6108-B1",
                        "goodsCodeAndGoodsName": "null——21E543-6108-B1——石墨模",
                        "goodsId": 170,
                        "goodsName": "石墨模",
                        "grade": null,
                        "houseQuantity": null,
                        "lockQuantity": 0.0,
                        "madeIn": null,
                        "matbigclassify": null,
                        "matsmallclassify": null,
                        "maxNum": 300.0,
                        "memo": null,
                        "minNum": 50.0,
                        "mtlsgrt": null,
                        "mtltmrk": "4",
                        "mustCheck": 0,
                        "newGoodsName": null,
                        "newSpecifications": null,
                        "numAcc": null,
                        "onthewayQuantity": 0.0,
                        "partLink": null,
                        "piNo": null,
                        "price": null,
                        "priority": null,
                        "prtType": "零件",
                        "prtrevedit": null,
                        "prtstd": null,
                        "prtwt": 0.0,
                        "purchaseQuantity": 0.0,
                        "releaseno": null,
                        "releasenoTime": null,
                        "remark": null,
                        "rlsId": null,
                        "singlePieceQuota": null,
                        "source": null,
                        "special": null,
                        "specifications": null,
                        "syQuantity": null,
                        "trademark": null,
                        "unitName": "每个",
                        "updateTime": "2023-07-15 16:18:30",
                        "used": true
                    },
                    "coStorehouse": {
                        "codeAndName": null,
                        "createTime": "2023-12-25 10:08:43",
                        "deleted": false,
                        "factoryId": 41,
                        "memo": null,
                        "saveUser": {
                            "accountId": null,
                            "card": null,
                            "createTime": "2023-04-06",
                            "curStatus": 1,
                            "deleted": false,
                            "deptName": null,
                            "dimissionTime": null,
                            "factoryId": 41,
                            "head": 0,
                            "jobName": "软件工程师",
                            "keyValue": 521,
                            "ldapName": null,
                            "mail": null,
                            "mobile": null,
                            "pfDepartment": {
                                "appLink": null,
                                "createTime": "2022-08-31",
                                "deleted": false,
                                "deptCode": "001",
                                "deptId": 1,
                                "deptName": "MES开发部",
                                "deptType": 1,
                                "deptTypeTitle": "厂",
                                "keyValue": 1,
                                "memo": null,
                                "orders": "00",
                                "parentDeptId": null,
                                "parentPath": null,
                                "ucDeptId": null,
                                "updateTime": "2022-08-31 16:32:46"
                            },
                            "ucUserId": null,
                            "updateTime": "2023-04-06 16:23:38",
                            "userCode": "0001",
                            "userId": 521,
                            "userName": "测试",
                            "userSex": 1,
                            "userSources": "测试",
                            "userString": "521:A:测试",
                            "userType": "A",
                            "yearsOfService": null
                        },
                        "shCode": "RB001",
                        "shId": 183,
                        "shLevel": null,
                        "shName": "石墨模",
                        "toolingType": null,
                        "toolingTypeStr": null,
                        "type": 0,
                        "typeStr": "模具库",
                        "updateTime": null
                    },
                    "createTime": "2023-12-25 10:26:44",
                    "facType": 0,
                    "factoryId": 41,
                    "goodsCodeAndGoodsName": null,
                    "goodsId": null,
                    "goodsStatus": 0,
                    "inStoreDay": 665,
                    "isApplyFor": false,
                    "keeper": null,
                    "memo": null,
                    "modelOrBrandStr": "4/null",
                    "moldBaseMaterial": false,
                    "moldStock": null,
                    "outQuantity": null,
                    "piNo": "Y20231225001",
                    "quantity": 2999.0,
                    "quantityLevel": "ccc",
                    "rlsId": 222,
                    "scrapCycle": "2024-09-18 00:00:00",
                    "splyCode": null,
                    "stayMaintainNum": 0,
                    "stockSource": 0,
                    "stopUse": false,
                    "stopUseTitle": "合格",
                    "storageLocation": {
                        "coStorehouse": {
                            "codeAndName": null,
                            "createTime": "2023-12-25 10:08:43",
                            "deleted": false,
                            "factoryId": 41,
                            "memo": null,
                            "saveUser": {
                                "accountId": null,
                                "card": null,
                                "createTime": "2023-04-06",
                                "curStatus": 1,
                                "deleted": false,
                                "deptName": null,
                                "dimissionTime": null,
                                "factoryId": 41,
                                "head": 0,
                                "jobName": "软件工程师",
                                "keyValue": 521,
                                "ldapName": null,
                                "mail": null,
                                "mobile": null,
                                "pfDepartment": {
                                    "appLink": null,
                                    "createTime": "2022-08-31",
                                    "deleted": false,
                                    "deptCode": "001",
                                    "deptId": 1,
                                    "deptName": "MES开发部",
                                    "deptType": 1,
                                    "deptTypeTitle": "厂",
                                    "keyValue": 1,
                                    "memo": null,
                                    "orders": "00",
                                    "parentDeptId": null,
                                    "parentPath": null,
                                    "ucDeptId": null,
                                    "updateTime": "2022-08-31 16:32:46"
                                },
                                "ucUserId": null,
                                "updateTime": "2023-04-06 16:23:38",
                                "userCode": "0001",
                                "userId": 521,
                                "userName": "测试",
                                "userSex": 1,
                                "userSources": "测试",
                                "userString": "521:A:测试",
                                "userType": "A",
                                "yearsOfService": null
                            },
                            "shCode": "RB001",
                            "shId": 183,
                            "shLevel": null,
                            "shName": "石墨模",
                            "toolingType": null,
                            "toolingTypeStr": null,
                            "type": 0,
                            "typeStr": "模具库",
                            "updateTime": null
                        },
                        "cslId": 222,
                        "deleted": false,
                        "goodsCode": "21E543-6108-B1",
                        "goodsName": null,
                        "location": "RB001SM02",
                        "mtltmrk": null,
                        "specifications": null
                    },
                    "stovePiNo": null,
                    "sumNum": 0,
                    "thickness": null,
                    "updateTime": null,
                    "useQuantity": 2999.0,
                    "zyQuantity": 0.0
                },
                {
                    "allMoney": null,
                    "balanceMoney": 30.0,
                    "barCode": null,
                    "checkCode": "CK002",
                    "coGoods": {
                        "allGoodsQuantity": null,
                        "batch": null,
                        "bomQuantity": null,
                        "buyQuantity": null,
                        "cavityno": null,
                        "checkoutCode": "1111",
                        "coGoodsClass": null,
                        "coStorageLocation": null,
                        "cplb": null,
                        "createTime": "2023-07-15 16:18:30",
                        "curQuantity": 1950.0,
                        "cycle": null,
                        "deleted": false,
                        "deliveryDate": null,
                        "dept": null,
                        "drawingNo": null,
                        "ecnno": null,
                        "enditem": 0,
                        "erpQuantity": null,
                        "goodsCode": "04-05-025",
                        "goodsCodeAndGoodsName": "null——04-05-025——锡铂金",
                        "goodsId": 169,
                        "goodsName": "锡铂金",
                        "grade": null,
                        "houseQuantity": null,
                        "lockQuantity": 0.0,
                        "madeIn": null,
                        "matbigclassify": null,
                        "matsmallclassify": null,
                        "maxNum": 300.0,
                        "memo": null,
                        "minNum": 50.0,
                        "mtlsgrt": null,
                        "mtltmrk": "23",
                        "mustCheck": 0,
                        "newGoodsName": null,
                        "newSpecifications": null,
                        "numAcc": null,
                        "onthewayQuantity": 0.0,
                        "partLink": null,
                        "piNo": null,
                        "price": null,
                        "priority": null,
                        "prtType": "零件",
                        "prtrevedit": null,
                        "prtstd": null,
                        "prtwt": 0.0,
                        "purchaseQuantity": 100.0,
                        "releaseno": null,
                        "releasenoTime": null,
                        "remark": null,
                        "rlsId": null,
                        "singlePieceQuota": null,
                        "source": null,
                        "special": null,
                        "specifications": "100克/瓶",
                        "syQuantity": null,
                        "trademark": null,
                        "unitName": "每克",
                        "updateTime": "2023-07-15 16:18:30",
                        "used": true
                    },
                    "coStorehouse": {
                        "codeAndName": null,
                        "createTime": "2023-12-25 10:09:44",
                        "deleted": false,
                        "factoryId": 41,
                        "memo": null,
                        "saveUser": {
                            "accountId": null,
                            "card": null,
                            "createTime": "2023-02-08",
                            "curStatus": 1,
                            "deleted": false,
                            "deptName": null,
                            "dimissionTime": null,
                            "factoryId": 41,
                            "head": 0,
                            "jobName": "主任",
                            "keyValue": 453,
                            "ldapName": "00075",
                            "mail": null,
                            "mobile": null,
                            "pfDepartment": {
                                "appLink": null,
                                "createTime": "2023-02-08",
                                "deleted": false,
                                "deptCode": "26",
                                "deptId": 57,
                                "deptName": "外协业务中心",
                                "deptType": 1,
                                "deptTypeTitle": "厂",
                                "keyValue": 57,
                                "memo": null,
                                "orders": "26",
                                "parentDeptId": 41,
                                "parentPath": null,
                                "ucDeptId": null,
                                "updateTime": "2023-02-08 16:38:31"
                            },
                            "ucUserId": null,
                            "updateTime": "2023-02-08 17:25:13",
                            "userCode": "00075",
                            "userId": 453,
                            "userName": "测试1",
                            "userSex": 1,
                            "userSources": "测试1",
                            "userString": "453:A:测试1",
                            "userType": "A",
                            "yearsOfService": null
                        },
                        "shCode": "RB002",
                        "shId": 184,
                        "shLevel": null,
                        "shName": "锡铂金库",
                        "toolingType": null,
                        "toolingTypeStr": null,
                        "type": 0,
                        "typeStr": "模具库",
                        "updateTime": "2023-12-25 10:09:58"
                    },
                    "createTime": "2023-12-25 10:28:24",
                    "facType": 0,
                    "factoryId": 41,
                    "goodsCodeAndGoodsName": null,
                    "goodsId": null,
                    "goodsStatus": 0,
                    "inStoreDay": 665,
                    "isApplyFor": false,
                    "keeper": null,
                    "memo": null,
                    "modelOrBrandStr": "23/null",
                    "moldBaseMaterial": false,
                    "moldStock": null,
                    "outQuantity": null,
                    "piNo": "Y20231225001",
                    "quantity": 1950.0,
                    "quantityLevel": "aaa",
                    "rlsId": 223,
                    "scrapCycle": "2024-09-18 00:00:00",
                    "splyCode": null,
                    "stayMaintainNum": 0,
                    "stockSource": 0,
                    "stopUse": false,
                    "stopUseTitle": "合格",
                    "storageLocation": {
                        "coStorehouse": {
                            "codeAndName": null,
                            "createTime": "2023-12-25 10:09:44",
                            "deleted": false,
                            "factoryId": 41,
                            "memo": null,
                            "saveUser": {
                                "accountId": null,
                                "card": null,
                                "createTime": "2023-02-08",
                                "curStatus": 1,
                                "deleted": false,
                                "deptName": null,
                                "dimissionTime": null,
                                "factoryId": 41,
                                "head": 0,
                                "jobName": "主任",
                                "keyValue": 453,
                                "ldapName": "00075",
                                "mail": null,
                                "mobile": null,
                                "pfDepartment": {
                                    "appLink": null,
                                    "createTime": "2023-02-08",
                                    "deleted": false,
                                    "deptCode": "26",
                                    "deptId": 57,
                                    "deptName": "外协业务中心",
                                    "deptType": 1,
                                    "deptTypeTitle": "厂",
                                    "keyValue": 57,
                                    "memo": null,
                                    "orders": "26",
                                    "parentDeptId": 41,
                                    "parentPath": null,
                                    "ucDeptId": null,
                                    "updateTime": "2023-02-08 16:38:31"
                                },
                                "ucUserId": null,
                                "updateTime": "2023-02-08 17:25:13",
                                "userCode": "00075",
                                "userId": 453,
                                "userName": "测试1",
                                "userSex": 1,
                                "userSources": "测试1",
                                "userString": "453:A:测试1",
                                "userType": "A",
                                "yearsOfService": null
                            },
                            "shCode": "RB002",
                            "shId": 184,
                            "shLevel": null,
                            "shName": "锡铂金库",
                            "toolingType": null,
                            "toolingTypeStr": null,
                            "type": 0,
                            "typeStr": "模具库",
                            "updateTime": "2023-12-25 10:09:58"
                        },
                        "cslId": 223,
                        "deleted": false,
                        "goodsCode": "04-05-025",
                        "goodsName": null,
                        "location": "RB002XBJ01",
                        "mtltmrk": null,
                        "specifications": null
                    },
                    "stovePiNo": null,
                    "sumNum": 0,
                    "thickness": null,
                    "updateTime": null,
                    "useQuantity": 1950.0,
                    "zyQuantity": 0.0
                }
            ]
            this.page.total = this.data.length
            this.loading = false
            setTimeout(() => {
                this.selectionClear()
            }, 500)
        }
    }
}
</script>
<style lang="scss" scoped>
:root {
    --el-switch-on-color: #13ce66;
    --el-switch-off-color: #ff4949;
}
</style>