<template>
    <div>
        <!-- 列表展示  额外计划  部分批料和未批料的数据 -->
        <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="batchMaintain()">批量提请
                </el-button>
            </template>
            <template #menu-right>

            </template>
            <template #menu="scope">
                <el-button type="text" @click="batchMaintain(scope.row)">提请</el-button>
                <!-- <el-button type="text" @click="handeExamine(scope.row)">审批</el-button> -->
            </template>

        </avue-crud>
        <processDialog :showDialog="isOpen" type="request" v-if="isOpen" :list="selectList" @closeDialog="closeDialog"></processDialog>
        <el-dialog width="30%" v-model="approveDialog" title="审批">
            <el-form :model="auditForm" :rules="auditRules" ref="auditForm">
                <el-form-item label="是否审核通过" prop="approvalResult">
                    <el-radio v-model="auditForm.approvalResult" label="1">是</el-radio>
                    <el-radio v-model="auditForm.approvalResult" label="10">否</el-radio>
                </el-form-item>
            </el-form>
            <template #footer>
                <span class="dialog-footer">
                    <el-button @click="approveDialog = false">取 消</el-button>
                    <el-button type="primary" @click="submit">确 定</el-button>
                </span>
            </template>
        </el-dialog>
    </div>
</template>
<script>
import {getList,approve} from "@/api/storeManagement/warehouseRequest"
import processDialog from './processDialog.vue'
export default {
    components: {
        processDialog
    },
    data() {
        return {
            selectionList: [],
            selectList:[],
            loading:false,
            query:{},
            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,
                viewBtn: false,
                addBtn: false,
                editBtn: false,
                delBtn: false,
                editBtnText: '修改',
                addBtnIcon: ' ',
                viewBtnIcon: ' ',
                delBtnIcon: ' ',
                editBtnIcon: ' ',
                viewBtnText: '详情',
                labelWidth: 120,
                menuWidth: 80,
                dialogWidth: 1040,
                dialogClickModal: false,
                searchEnter: true,
                excelBtn: false,
                filterBtn: true,
                searchShowBtn: false,
                columnSort: true,
                excelBtn: true,
                columnSort: true,
                index: false,
                showOverflowTooltip: true,
                searchLabelPosition: 'left',
                searchLabelWidth: 'auto',
                searchGutter: 24,
                searchSpan: 6,
                menuAlign: 'center',
                gridBtn: false,
                searchMenuPosition: 'right',
                align: 'center',
                isOpen: false,
                moldAddMore: false,
                column: [

                    // {
                    //     label: '提请单号',
                    //     prop: 'reqCode',
                    //     search: true,
                    //     sortable: true,
                    //     filter: true,
                    //     span: 12,
                    //     width: 120,
                    // },
                    {
                        label: '采购单号',
                        prop: 'boCode',
                        // bind: 'stBuyOrder.boCode',
                        search: true,
                        sortable: true,
                        filter: true,
                        span: 12,

                    },
                    {
                        label: '物料编号',
                        prop: 'goodsCode',
                        // bind: 'stBuyOrder.coGoods.goodsCode',
                        search: true,
                        sortable: true,
                        filter: true,
                        width:180,
                        span: 12,

                    },
                    {
                        label: '物料名称',
                        prop: 'goodsName',
                        // bind: 'stBuyOrder.coGoods.goodsName',
                        search: false,
                        sortable: true,
                        filter: true,
                        span: 12,

                    },
                    {
                        label: '型号/牌号',
                        prop: 'materialModel',
                        // bind: 'stBuyOrder.coGoods.mtltmrk',
                        search: false,
                        sortable: true,
                        filter: true,
                        span: 12,
                    },
                    {
                        label: '物料规格',
                        prop: 'specifications',
                        // bind: 'stBuyOrder.coGoods.specifications',
                        search: false,
                        sortable: true,
                        filter: true,
                        span: 12,
                    },
                    {
                        label: '采购数量',
                        prop: 'buyQty',
                        // bind: 'stBuyOrder.buyQty',
                        search: false,
                        sortable: true,
                        filter: true,
                        span: 12,
                    },
                    {
                        label: '已批数量',//erp已经审核通过的总数
                        prop: 'batchQuantity',
                        search: false,
                        sortable: true,
                        filter: true,
                        span: 12,

                    },
                    {
                        label: '待批数量',//已提交  erp未审批数量 
                        prop: 'pendingQty',
                        search: false,
                        sortable: true,
                        filter: true,
                        span: 12,
                    },
                    {
                        label: '已提请数量',//已提交  erp未审批数量 
                        prop: 'drawQuantity',
                        search: false,
                        sortable: true,
                        filter: true,
                        span: 12,
                    },
                    {
                        label: '生产标识',
                        prop: 'grade',
                        // bind: 'stBuyOrder.grade',
                        search: false,
                        sortable: true,
                        filter: true,
                        span: 12,

                    },
                    {
                        label: '申报日期',//额外计划的申报日期
                        prop: 'declareDate',
                        // bind: 'stBuyOrder.grade',
                        search: false,
                        sortable: true,
                        filter: true,
                        span: 12,
                        type: 'date',
                        searchRange: true,
                        startPlaceholder: '开始时间',
                        endPlaceholder: "结束时间",

                    },

                ]
            },
            form: {

            },
            page: {
                pageSize: 10,
                currentPage: 1,
                total: 0,
            },
            isOpen: false,
            approveDialog:false,
            auditForm:{},
            auditRules:{
               approvalResult:[{ required: true, message: '请选择是否通过审核', trigger: 'blur' }] 
            },
        }
    },
    methods: {
        batchMaintain(row) {
            if(row){
                this.selectList = [row]
                this.isOpen = true
            }else{
                if(this.selectionList.length == 0){
                    this.$message.error('请至少选择一条数据')
                    return
                }
                this.selectList = this.selectionList
                this.isOpen = true
            }
            
        },
        closeDialog(val) {
            this.isOpen = false
            if(val){
                this.onLoad()
            }
        },
        handleDelete() {
            if (this.selectionList.length === 0) {
                this.$message.warning('请选择至少一条数据');
                return;
            }
            this.$confirm('确定将选择数据删除?', {
                confirmButtonText: '确定',
                cancelButtonText: '取消',
                type: 'warning',
            }).then(() => {
            })
        },
        // 多选
        selectionChange(list) {
            this.selectionList = list;
        },
        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
        },
        handeExamine(row){
            this.auditForm = {}
            this.auditForm.id = row.id
            this.approveDialog = true
        },
        submit(){
            this.$refs.auditForm.validate(valid => {
                if(valid){
                    approve({...this.auditForm}).then(res =>{
                        if(res.data.code == 200){
                            this.$message.success('审批成功')
                            this.approveDialog = false
                            this.onLoad()
                        }
                    })
                }
            })
        },
        onLoad() {
            this.loading = true
            getList({
                current:this.page.currentPage,
                size:this.page.pageSize,
                ...this.query
            }).then(res =>{
                this.data = res.data.data.records
                this.page.total = res.data.data.total
                this.loading = false
            })
            // this.data = [
            //     {
            //         "bsTeamSet": null,
            //         "bsWorkCenter": {
            //             "area": 13000.0,
            //             "batchNo": null,
            //             "bigBatch": false,
            //             "bsJfCenter": {
            //                 "createMan": {
            //                     "userId": 1,
            //                     "userName": "admin"
            //                 },
            //                 "createTime": "2024-12-09 00:00:00",
            //                 "deleted": false,
            //                 "jcCode": "RBZX",
            //                 "jcId": 1,
            //                 "jcName": "热表中心",
            //                 "keyValue": 1,
            //                 "updateTime": "2024-12-09 00:00:00"
            //             },
            //             "checkout": false,
            //             "craftAbility": "化学镀镍",
            //             "createMan": {
            //                 "userId": 1,
            //                 "userName": "admin"
            //             },
            //             "createTime": "2023-02-06 12:31:36",
            //             "deleted": false,
            //             "describe": null,
            //             "endPoint": null,
            //             "keyValue": 81,
            //             "leaderUser": {
            //                 "userId": 541,
            //                 "userName": "崔殿龙"
            //             },
            //             "limitType": 0,
            //             "processes": "上挂、下挂、交检、化学镀镍、喷砂",
            //             "quantity": null,
            //             "roundCycle": null,
            //             "saturation": 85.0,
            //             "sign": "4",
            //             "startPoint": null,
            //             "team": "化学镀镍一班崔胜伟、化学镀镍一班郭家梁",
            //             "updateTime": "2023-03-06 18:42:47",
            //             "wcCode": "001",
            //             "wcId": 81,
            //             "wcName": "化学镀镍作业中心",
            //             "whetherPlate": false
            //         },
            //         "createMan": {
            //             "userId": 1,
            //             "userName": "admin"
            //         },
            //         "createTime": "2025-04-09 11:27:09",
            //         "deEquipmentCard": {
            //             "bindQty": 4,
            //             "categorys": "产线设备",
            //             "deviceCode": "9652247",
            //             "deviceIp": "192.168.43.179",
            //             "deviceName": "化学镀镍",
            //             "docking": true,
            //             "ecId": 1,
            //             "keyValue": 1,
            //             "macCode": "9652247",
            //             "macSpec": null,
            //             "memo": null,
            //             "rfId": "SYM-HCP-L4",
            //             "status": true,
            //             "typeName": "9652247",
            //             "updateTime": null,
            //             "used": 1,
            //             "usedText": "正常服役",
            //             "virtualMac": false
            //         },
            //         "keyValue": 121,
            //         "pureWater": 1.0,
            //         "quotaArea": 0.0,
            //         "tapWater": 1.0,
            //         "updateTime": "2025-04-09 11:27:09",
            //         "uqDate": "2025-04-09",
            //         "uqId": 121,
            //         "uqType": 0,
            //         "useElectric": 0.0,
            //         "workCenterId": "[81]",
            //         "workCenterName": "[\"化学镀镍作业中心\"]",
            //         "workCenterNames": "化学镀镍作业中心"
            //     }
            // ]
            // this.page.total = this.data.length
            // this.loading = false
            // setTimeout(() => {
            //     this.selectionClear()
            // }, 500)
        }
    }
}
</script>
<style lang="scss" scoped></style>