<template>
    <div>
        <SearchBox ref="SearchBoxRef" formName="search" :formData="query" @showPop="showPop" @reset="reset"></SearchBox>
        <ButtonBar @search="handleSearch" @add="handleAdd" @remove="handleRemoveBatch" @edit="handleEditBatch"
            @download="handleDownload" @import="handleImport" @export="handleExport">
        </ButtonBar>

        <el-card :body-style="cardBodyStyle">
            <el-table :data="tableData" border highlight-current-row @selection-change="handleSelectionChange" style="height: 500px;">
                <el-table-column type="selection" fixed></el-table-column>
                <el-table-column type="index" label="序号" align="center" width="60">
                    <template #default="scope">
                        <span>{{ scope.$index + (currentPage - 1) * pageSize + 1 }}</span>
                    </template>
                </el-table-column>
                <el-table-column v-if="false" prop="" label="ID" width="120" header-align="center" align="center"
                    show-overflow-tooltip>
                </el-table-column>
                <el-table-column v-if="false" prop="modifyEmpId" label="修改人id" width="300" header-align="center"
                    align="center" show-overflow-tooltip>
                </el-table-column>
                <el-table-column v-if="false" prop="modifyDtm" label="修改时间" width="240" header-align="center"
                    align="center" show-overflow-tooltip>
                </el-table-column>
                <el-table-column v-if="false" prop="cancleEmpId" label="删除人ID" width="300" header-align="center"
                    align="center" show-overflow-tooltip>
                </el-table-column>
                <el-table-column v-if="false" prop="cancleDtm" label="删除时间" width="240" header-align="center"
                    align="center" show-overflow-tooltip>
                </el-table-column>
                <el-table-column v-if="false" prop="cancleYn" label="删除标记" width="240" header-align="center"
                    align="center" show-overflow-tooltip>
                </el-table-column>
                <el-table-column v-if="true" prop="yearNo" label="年度" width="60" header-align="center" align="center"
                    show-overflow-tooltip>
                </el-table-column>

                <el-table-column v-if="quartDelete" prop="quartNo" label="季度" width="60" header-align="center"
                    align="center" show-overflow-tooltip>
                </el-table-column>
                <el-table-column v-if="monthDelete" prop="monthNo" label="月度" width="60" header-align="center"
                    align="center" show-overflow-tooltip>
                </el-table-column>
                <el-table-column v-if="true" prop="oreQty" label="入选矿量(吨)" width="120" header-align="center"
                    align="right" show-overflow-tooltip>
                </el-table-column>
                <el-table-column v-if="true" prop="ballmQty" label="入磨矿量(吨)" width="120" header-align="center"
                    align="right" show-overflow-tooltip>
                </el-table-column>
                <el-table-column v-if="true" prop="ironCcttQty" label="铁精粉产品产量(吨)" width="150" header-align="center"
                    align="right" show-overflow-tooltip>
                </el-table-column>
                <el-table-column v-if="true" prop="coppCcttQty" label="铜精粉产品产量(吨)" width="150" header-align="center"
                    align="right" show-overflow-tooltip>
                </el-table-column>
                <el-table-column v-if="true" prop="coppMeltQty" label="铜金属产品产量(吨)" width="150" header-align="center"
                    align="right" show-overflow-tooltip>
                </el-table-column>
                <el-table-column v-if="true" prop="wstonQty" label="废石量(吨)" width="100" header-align="center"
                    align="right" show-overflow-tooltip>
                </el-table-column>
                <el-table-column v-if="true" prop="tailQty" label="尾矿量(吨)" width="100" header-align="center"
                    align="right" show-overflow-tooltip>
                </el-table-column>
                <el-table-column v-if="true" prop="ironCcttGrd" label="铁精粉品位(%)" width="130" header-align="center"
                    align="right" show-overflow-tooltip>
                </el-table-column>
                <el-table-column v-if="true" prop="coppCcttGrd" label="铜精粉品位(%)" width="130" header-align="center"
                    align="right" show-overflow-tooltip>
                </el-table-column>
                <el-table-column v-if="true" prop="rcvyIronDry" label="铁金属回收率(%)" width="140" header-align="center"
                    align="right" show-overflow-tooltip>
                </el-table-column>
                <el-table-column v-if="true" prop="rcvyIronWet" label="湿铁金属回收率(%)" width="150" header-align="center"
                    align="right" show-overflow-tooltip>
                </el-table-column>
                <el-table-column v-if="true" prop="rcvyCoppDry" label="铜金属回收率(%)" width="140" header-align="center"
                    align="right" show-overflow-tooltip>
                </el-table-column>
                <el-table-column v-if="true" prop="rcvyCoppWet" label="湿铜金属回收率(%)" width="150" header-align="center"
                    align="right" show-overflow-tooltip>
                </el-table-column>
                <el-table-column v-if="true" prop="ccttRatiBallm" label="入磨矿选矿比(倍)" width="140" header-align="center"
                    align="right" show-overflow-tooltip>
                </el-table-column>
                <el-table-column v-if="true" prop="ccttRatiOre" label="入选矿选矿比(倍)" width="140" header-align="center"
                    align="right" show-overflow-tooltip>
                </el-table-column>
                <el-table-column v-if="!quartDelete" prop="foreIronGrd" label="粉矿铁品位(%)" width="130"
                    header-align="center" align="right" show-overflow-tooltip>
                </el-table-column>
                <el-table-column v-if="!quartDelete" prop="foreCoppGrd" label="粉矿铜品位(%)" width="130"
                    header-align="center" align="right" show-overflow-tooltip>
                </el-table-column>
                <el-table-column v-if="!quartDelete" prop="oreIronGrd" label="原矿铁品位(%)" width="130"
                    header-align="center" align="right" show-overflow-tooltip>
                </el-table-column>
                <el-table-column v-if="!quartDelete" prop="oreCoppGrd" label="原矿铜品位(%)" width="130"
                    header-align="center" align="right" show-overflow-tooltip>
                </el-table-column>
                <el-table-column v-if="false" prop="createEmpId" label="创建人id" width="90" header-align="center"
                    align="center" show-overflow-tooltip>
                </el-table-column>
                <el-table-column v-if="false" prop="createDtm" label="创建时间" width="170" header-align="center"
                    align="center" show-overflow-tooltip>
                </el-table-column>


                <!-- <el-table-column v-if="true" prop="workModel.flowStatusName" label="流程状态" width="120"
                    header-align="center" align="center" show-overflow-tooltip fixed="right">
                    <template #default="{ row }">
                        <div>
                            <el-tag v-if="row.workId !== undefined && row.workModel.flowStatus === '110'">
                                {{ row.workModel.flowStatusName }}
                            </el-tag>
                            <el-tag type="success"
                                v-else-if="row.workId !== undefined && row.workModel.flowStatus === '170'">
                                {{ row.workModel.flowStatusName }}
                            </el-tag>
                            <el-tag type="danger"
                                v-else-if="row.workId !== undefined
                                    && (row.workModel.flowStatus === '130' || row.workModel.flowStatus === '180' || row.workModel.flowStatus === '190')">
                                {{ row.workModel.flowStatusName }}
                            </el-tag>
                            <el-tag type="warning" v-else>'---'</el-tag>
                        </div>

                    </template>
                </el-table-column>
                <el-table-column v-if="true" prop="workModel.flowNode" label="当前节点" width="120" header-align="center"
                    align="center" show-overflow-tooltip fixed="right">
                    <template #default="{ row }">
                        <div>
                            <el-tag v-if="row.workId !== undefined && row.workModel.flowStatus === '110'">
                                {{ row.workModel.flowNode }}
                            </el-tag>
                            <el-tag type="success"
                                v-else-if="row.workId !== undefined && row.workModel.flowStatus === '170'">
                                {{ row.workModel.flowNode }}
                            </el-tag>
                            <el-tag type="danger" v-else-if="row.workId !== undefined
                                && (row.workModel.flowStatus === '130'
                                    || row.workModel.flowStatus === '180'
                                    || row.workModel.flowStatus === '190')">
                                {{ row.workModel.flowNode }}
                            </el-tag>
                            <el-tag type="warning" v-else>'---'</el-tag>
                        </div>
                    </template>
                </el-table-column> -->
                <!-- <el-table-column label="操作" header-align="center" align="center" width="260px" fixed="right">
                    <template #default="scope">
                        <el-button plain type="warning" @click="handleEdit(scope.row)"
                            v-show="scope.row.workId === '' || scope.row.workModel.opType === '1'">编辑
                        </el-button>
                        <el-button plain type="danger" @click="handleDelete(scope.row)"
                            v-show="scope.row.workId === '' || scope.row.workModel.opType === '1'">删除
                        </el-button>
                        <el-button plain type="success" @click="handleSubmit(scope.row)"
                            v-show="scope.row.workId === '' || scope.row.workModel.opType === '1'">发起
                        </el-button>
                        <el-button plain type="primary" @click="handleDetail(scope.row)"
                            v-show="scope.row.workId !== ''">详情</el-button>
                        <el-button plain type="info" @click="handleCancel(scope.row)"
                            v-show="scope.row.workId !== '' && scope.row.workModel.opType !== '1' && scope.row.workModel.flowStatus !== '170'">撤回</el-button>
                    </template>
                </el-table-column> -->
                <el-table-column label="操作" header-align="center" align="center" width="200px" fixed="right">
                    <template #default="scope">
                        <el-button plain type="warning" @click="handleEdit(scope.row)">编辑</el-button>
                        <el-button plain type="danger" @click="handleDelete(scope.row)">删除</el-button>
                    </template>
                </el-table-column>
            </el-table>
        </el-card>
        <el-card :body-style="cardBodyStyle">
            <el-pagination :current-page="currentPage" :page-size="pageSize" :page-sizes="pageSizes" :total="totalRows"
                background="background" layout="total, sizes, prev, pager, next, jumper" @size-change="handleSizeChange"
                @current-change="handleCurrentChange">
            </el-pagination>
        </el-card>

        <el-dialog :close-on-click-modal="false"  :title="dialogName" v-model="dialogVisible" width="1200px"
            top="5vh" @open="openDialog" :before-close="handleCancelSave">
            <el-tabs type="border-card" v-model="activeTab" @tab-click="handleTabClick">
                <el-tab-pane label="年度计划" name="yearPlan" v-if="PlanOr">
                    <template #label>
                        <span @click="yearPlan">年度计划</span>
                    </template>
                </el-tab-pane>
                <el-tab-pane label="季度计划" name="quartPlan" v-if="PlanOr">
                    <template #label>
                        <span @click="quartPlan">季度计划</span>
                    </template>
                </el-tab-pane>
                <el-tab-pane label="月度计划" name="monthPlan" v-if="PlanOr">
                    <template #label>
                        <span @click="monthPlan">月度计划</span>
                    </template>
                </el-tab-pane>

                <el-row>
                    <div>&nbsp;</div>
                </el-row>

                <el-form :model="form" label-width="80px" label-position="right" inline ref="ruleFormRef"
                    :rules="rules">
                    <el-row>
                        <el-col :span="1"></el-col>
                        <el-col :span="6">
                            <el-form-item label="年度" prop="yearNo">
                                <el-date-picker v-model="form.yearNo" clearable type="year" style="width: 100px"
                                    placeholder="请选择" @change="handleYearChange" />
                            </el-form-item>
                        </el-col>
                        <el-col :span="6">
                            <el-form-item label="季度" prop="quartNo" v-if="quart">
                                <!-- <el-input v-model="form.quartNo" clearable style="width: 100px"></el-input> -->
                                <el-select v-model="form.quartNo" placeholder="请选择" clearable style="width: 100px">
                                    <el-option v-for="n in 4" :key="n" :label="n" :value="n" />
                                </el-select>
                            </el-form-item>

                            <el-form-item label="月度" prop="monthNo" v-if="month">
                                <!-- <el-input v-model="form.monthNo" clearable style="width: 100px"></el-input> -->
                                <el-select v-model="form.monthNo" placeholder="请选择" clearable style="width: 100px">
                                    <el-option v-for="n in 12" :key="n" :label="n" :value="n" />
                                </el-select>
                            </el-form-item>
                        </el-col>
                    </el-row>
                    <el-row>
                        <el-col :span="1"></el-col>
                        <el-col :span="6">
                            <el-form-item label="入选矿量(吨)" style="white-space: nowrap;" prop="oreQty">
                                <el-input v-model="form.oreQty" clearable style="width: 100px"></el-input>
                            </el-form-item>
                        </el-col>
                        <el-col :span="6">
                            <el-form-item label="入磨矿量(吨)" style="white-space: nowrap;" prop="ballmQty">
                                <el-input v-model="form.ballmQty" clearable style="width: 100px"></el-input>
                            </el-form-item>
                        </el-col>
                    </el-row>
                    <div style="font-size: 18px; color: black; background-color: #f0f0f0; margin-bottom: 10px;">
                        &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;产品产量</div>
                    <el-row> </el-row>
                    <el-row>
                        <el-col :span="1"></el-col>
                        <el-col :span="6">
                            <el-form-item label="铁精粉产品产量(吨)" style="white-space: nowrap;" prop="ironCcttQty">
                                <el-input v-model="form.ironCcttQty" clearable style="width: 100px"></el-input>
                            </el-form-item>
                        </el-col>
                        <el-col :span="6">
                            <el-form-item label="铜精粉产品产量(吨)" style="white-space: nowrap;" prop="coppCcttQty">
                                <el-input v-model="form.coppCcttQty" clearable style="width: 100px"></el-input>
                            </el-form-item>
                        </el-col>
                        <el-col :span="6">
                            <el-form-item label="铜金属产品产量(吨)" style="white-space: nowrap;" prop="coppMeltQty">
                                <el-input v-model="form.coppMeltQty" clearable style="width: 100px"></el-input>
                            </el-form-item>
                        </el-col>
                    </el-row>
                    <el-row>
                        <el-col :span="1"></el-col>
                        <el-col :span="6">
                            <el-form-item label="废石量(吨)" style="white-space: nowrap;" prop="wstonQty">
                                <el-input v-model="form.wstonQty" clearable style="width: 100px"></el-input>
                            </el-form-item>
                        </el-col>
                        <el-col :span="5">
                            <el-form-item label="尾矿量(吨)" style="white-space: nowrap;" prop="tailQty">
                                <el-input v-model="form.tailQty" clearable style="width: 100px"></el-input>
                            </el-form-item>
                        </el-col>
                    </el-row>
                    <div style="font-size: 18px; color: black; background-color: #f0f0f0; margin-bottom: 10px;">
                        &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;产品质量</div>
                    <el-row>
                        <el-col :span="1"></el-col>
                        <el-col :span="6">
                            <el-form-item label="铁精粉品位(%)" style="white-space: nowrap;" prop="ironCcttGrd">
                                <el-input v-model="form.ironCcttGrd" clearable style="width: 100px"></el-input>
                            </el-form-item>
                        </el-col>
                        <el-col :span="6">
                            <el-form-item label="铜精粉品位(%)" style="white-space: nowrap;" prop="coppCcttGrd">
                                <el-input v-model="form.coppCcttGrd" clearable style="width: 100px"></el-input>
                            </el-form-item>
                        </el-col>
                    </el-row>
                    <div style="font-size: 18px; color: black; background-color: #f0f0f0; margin-bottom: 10px;">
                        &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;金属回收率</div>
                    <el-row>
                        <el-col :span="1"></el-col>
                        <el-col :span="6">
                            <el-form-item label="铁金属回收率(%)" style="white-space: nowrap;" prop="rcvyIronDry">
                                <el-input v-model="form.rcvyIronDry" clearable style="width: 100px"></el-input>
                            </el-form-item>
                        </el-col>
                        <el-col :span="6">
                            <el-form-item label="湿铁金属回收率(%)" style="white-space: nowrap;" prop="rcvyIronWet">
                                <el-input v-model="form.rcvyIronWet" clearable style="width: 100px"></el-input>
                            </el-form-item>
                        </el-col>
                        <el-col :span="6">
                            <el-form-item label="铜金属回收率(%)" style="white-space: nowrap;" prop="rcvyCoppDry">
                                <el-input v-model="form.rcvyCoppDry" clearable style="width: 100px"></el-input>
                            </el-form-item>
                        </el-col>
                        <el-col :span="5">
                            <el-form-item label="湿铜金属回收率(%)" style="white-space: nowrap;" prop="rcvyCoppWet">
                                <el-input v-model="form.rcvyCoppWet" clearable style="width: 100px"></el-input>
                            </el-form-item>
                        </el-col>
                    </el-row>
                    <div style="font-size: 18px; color: black; background-color: #f0f0f0; margin-bottom: 10px;">
                        &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;选矿比</div>
                    <el-row>
                        <el-col :span="1"></el-col>
                        <el-col :span="6">
                            <el-form-item label="入磨矿选矿比(倍)" style="white-space: nowrap;" prop="ccttRatiBallm">
                                <el-input v-model="form.ccttRatiBallm" clearable style="width: 100px"></el-input>
                            </el-form-item>
                        </el-col>
                        <el-col :span="6">
                            <el-form-item label="入选矿选矿比(倍)" style="white-space: nowrap;" prop="ccttRatiOre">
                                <el-input v-model="form.ccttRatiOre" clearable style="width: 100px"></el-input>
                            </el-form-item>
                        </el-col>
                    </el-row>
                    <div style="font-size: 18px; color: black; background-color: #f0f0f0; margin-bottom: 10px;"
                        v-if="!quart">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;粉矿品位</div>
                    <el-row v-if="!quart">
                        <el-col :span="1"></el-col>
                        <el-col :span="6">
                            <el-form-item label="粉矿铁品位(%)" style="white-space: nowrap;" prop="foreIronGrd">
                                <el-input v-model="form.foreIronGrd" clearable style="width: 100px"></el-input>
                            </el-form-item>
                        </el-col>
                        <el-col :span="6">
                            <el-form-item label="粉矿铜品位(%)" style="white-space: nowrap;" prop="foreCoppGrd">
                                <el-input v-model="form.foreCoppGrd" clearable style="width: 100px"></el-input>
                            </el-form-item>
                        </el-col>
                    </el-row>
                    <div style="font-size: 18px; color: black; background-color: #f0f0f0; margin-bottom: 10px;"
                        v-if="!quart">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;原矿品位</div>
                    <el-row v-if="!quart">
                        <el-col :span="1"></el-col>
                        <el-col :span="6">
                            <el-form-item label="原矿铁品位(%)" style="white-space: nowrap;" prop="oreIronGrd">
                                <el-input v-model="form.oreIronGrd" clearable style="width: 100px"></el-input>
                            </el-form-item>
                        </el-col>
                        <el-col :span="6">
                            <el-form-item label="原矿铜品位(%)" style="white-space: nowrap;" prop="oreCoppGrd">
                                <el-input v-model="form.oreCoppGrd" clearable style="width: 100px"></el-input>
                            </el-form-item>
                        </el-col>
                    </el-row>
                </el-form>
            </el-tabs>
            <template #footer>
                <div class="dialog-footer">
                    <el-button type="success" @click="handleSave(ruleFormRef)">保存</el-button>
                    <el-button type="danger" @click="handleCancelSave">取消</el-button>
                </div>
            </template>
        </el-dialog>

        <ImportExcel ref="ImportExcelRef" :url="importUrl" :formData="importExcelformData"
            @importSuccess="importSuccess">
        </ImportExcel>
    </div>
</template>

<script setup>
    import ButtonBar from '@/components/ButtonBar.vue'

    import {
        ref,
        reactive,
        onMounted,
        getCurrentInstance
    } from 'vue'

    const {
        proxy
    } = getCurrentInstance()

    import tools from '@/tools'
    const cardBodyStyle = ref(tools.style.card)
    const inputStyle = ref(tools.style.input)

    onMounted(() => {
        handleSearch()
    })

    const handleYearChange = (value) => {  
        if (value) {
        const date = new Date(value);
        date.setDate(date.getDate() + 1); // 给日期加一天
        form.value.yearNo = date.getFullYear().toString(); // 转换为 YYYY格式
      } else {
        form.value.yearNo = '';
      }
    }


    /**
     *   查询
     */




    const query = ref({
   })
   const quartDelete = ref(false)
   const monthDelete = ref(false)
   const planType = ref()
   const tableData = ref([])
   const handleSearch = () => {
       currentPage.value = 1
       getTableData()
       if(planType.value == 'month'){
        quartDelete.value = false
        monthDelete.value = true
       }else if(planType.value == 'quart'){
        quartDelete.value = true
        monthDelete.value = false
       }else{
        quartDelete.value = false
        monthDelete.value = false
       }
   }
   const getTableData = () => {
       var url = 'pla/ProdPlan/queryAll'
       planType.value = query.value.planType
       var param = {
           page: currentPage.value,
           rows: pageSize.value,
           params: JSON.stringify(query.value)
       }
       proxy.$axios.get(url, param).then(response => {
            if (response.data.code == '0') {
                console.log(response.data.data)
                tableData.value = response.data.data.records
                totalRows.value = response.data.data.total
            } else {
                ElMessage.error('操作失败！' + response.data.msg)
            }
        })
    }

    // const year = ref()
    const quart = ref(false)
    const month = ref(false)
    const yearPlan = () => {
        console.log(planType.value)
        dialogName.value = "新增年度计划"
        quart.value = false
        month.value = false
    }
    const quartPlan = () => {
        console.log(planType.value)
        dialogName.value = "新增季度计划"
        quart.value = true
        month.value = false
    }
    const monthPlan = () => {
        console.log(planType.value)
        dialogName.value = "新增月度计划"
        quart.value = false
        month.value = true
    }
    /**
     *   查询
     */

    /**
     * 分页
     */
    const currentPage = ref(1)
    const totalRows = ref(0)
    const pageSizes = ref([5, 10, 20, 30, 40])
    const pageSize = ref(5)
    const handleSizeChange = (val) => {
        pageSize.value = val
        getTableData()
    }
    const handleCurrentChange = (val) => {
        currentPage.value = val
        getTableData()
    }
    /**
     * 分页
     */


    /**
     * 新增
     */
    const dialogVisible = ref(false)
    const form = ref({
        yearNo: '',
        oreQty: '', 
        ballmQty: '', 
        ironCcttQty: '', 
        coppCcttQty: '', 
        coppMeltQty: '', 
        wstonQty: '', 
        tailQty: '', 
        ironCcttGrd: '', 
        coppCcttGrd: '', 
        rcvyIronDry: '', 
        rcvyIronWet: '', 
        rcvyCoppDry: '', 
        rcvyCoppWet: '', 
        ccttRatiBallm: '', 
        ccttRatiOre: '', 
        foreIronGrd: '', 
        foreCoppGrd: '', 
        oreIronGrd: '', 
        oreCoppGrd: ''
    })
    const ruleFormRef = ref()
    const rules = reactive({
        yearNo: [{
            required: true,
            message: '请输入年度',
            trigger: 'change' | 'blur'
        }], 
        quartNo: [{
            required: true,
            message: '请输入季度',
            trigger: 'change' | 'blur'
        }],
        monthNo: [{
            required: true,
            message: '请输入月度',
            trigger: 'change' | 'blur'
        }],
        oreQty: [{ pattern: /^[0-9]{1,15}(\.[0-9]{1,10})?$/, message: '请输入有效的数字', trigger: 'blur' | 'change'}],
        ballmQty: [{ pattern: /^[0-9]{1,15}(\.[0-9]{1,10})?$/, message: '请输入有效的数字', trigger: 'blur' | 'change' }],
        ironCcttQty: [{ pattern: /^[0-9]{1,15}(\.[0-9]{1,10})?$/, message: '请输入有效的数字', trigger: 'blur' | 'change' }],
        coppCcttQty: [{ pattern: /^[0-9]{1,15}(\.[0-9]{1,10})?$/, message: '请输入有效的数字', trigger: 'blur' | 'change' }],
        coppMeltQty: [{ pattern: /^[0-9]{1,15}(\.[0-9]{1,10})?$/, message: '请输入有效的数字', trigger: 'blur' | 'change' }],
        wstonQty: [{ pattern: /^[0-9]{1,15}(\.[0-9]{1,10})?$/, message: '请输入有效的数字', trigger: 'blur' | 'change' }],
        tailQty: [{ pattern: /^[0-9]{1,15}(\.[0-9]{1,10})?$/, message: '请输入有效的数字', trigger: 'blur' | 'change' }],
        ironCcttGrd: [{ pattern: /^[0-9]{1,15}(\.[0-9]{1,10})?$/, message: '请输入有效的数字', trigger: 'blur' | 'change' }],
        coppCcttGrd: [{ pattern: /^[0-9]{1,15}(\.[0-9]{1,10})?$/, message: '请输入有效的数字', trigger: 'blur' | 'change' }],
        rcvyIronDry: [{ pattern: /^[0-9]{1,15}(\.[0-9]{1,10})?$/, message: '请输入有效的数字', trigger: 'blur' | 'change' }],
        rcvyIronWet: [{ pattern: /^[0-9]{1,15}(\.[0-9]{1,10})?$/, message: '请输入有效的数字', trigger: 'blur' | 'change' }],
        rcvyCoppDry: [{ pattern: /^[0-9]{1,15}(\.[0-9]{1,10})?$/, message: '请输入有效的数字', trigger: 'blur' | 'change' }],
        rcvyCoppWet: [{ pattern: /^[0-9]{1,15}(\.[0-9]{1,10})?$/, message: '请输入有效的数字', trigger: 'blur' | 'change' }],
        ccttRatiBallm: [{ pattern: /^[0-9]{1,15}(\.[0-9]{1,10})?$/, message: '请输入有效的数字', trigger: 'blur' | 'change' }],
        ccttRatiOre: [{ pattern: /^[0-9]{1,15}(\.[0-9]{1,10})?$/, message: '请输入有效的数字', trigger: 'blur' | 'change' }],
        foreIronGrd: [{ pattern: /^[0-9]{1,15}(\.[0-9]{1,10})?$/, message: '请输入有效的数字', trigger: 'blur' | 'change' }],
        foreCoppGrd: [{ pattern: /^[0-9]{1,15}(\.[0-9]{1,10})?$/, message: '请输入有效的数字', trigger: 'blur' | 'change' }],
        oreIronGrd: [{ pattern: /^[0-9]{1,15}(\.[0-9]{1,10})?$/, message: '请输入有效的数字', trigger: 'blur' | 'change' }],
        oreCoppGrd: [{ pattern: /^[0-9]{1,15}(\.[0-9]{1,10})?$/, message: '请输入有效的数字', trigger: 'blur' | 'change' }],
    })
    const dialogName = ref()
    const handleAdd = () => {
        form.value = {
            yearNo: '', 
            oreQty: '', 
            ballmQty: '', 
            ironCcttQty: '', 
            coppCcttQty: '', 
            coppMeltQty: '', 
            wstonQty: '', 
            tailQty: '', 
            ironCcttGrd: '', 
            coppCcttGrd: '', 
            rcvyIronDry: '', 
            rcvyIronWet: '', 
            rcvyCoppDry: '', 
            rcvyCoppWet: '', 
            ccttRatiBallm: '', 
            ccttRatiOre: '', 
            foreIronGrd: '', 
            foreCoppGrd: '', 
            oreIronGrd: '', 
            oreCoppGrd: ''
        }
        dialogVisible.value = true
        dialogName.value = "新增年度计划"
    }
    /**
     * 新增
     */


    /**
     * 保存、修改、删除
     */

    const openDialog=()=>{
    }

    const handleSave = (ruleFormRef) => {
        ruleFormRef.validate((valid, fields) => {
            if (valid) {
                if(quart.value){
                    var url = 'pla/QuartProdPlan/save'
                    console.log(url)
                }else if(month.value){
                    var url = 'pla/MonthProdPlan/save'
                    console.log(url)
                }else{
                    var url = 'pla/ProdPlan/save'
                    console.log(url)
                }
                var param = {
                    json: JSON.stringify(form.value),
                }
                proxy.$axios.post(url, param).then(response => {
                    if (response.data.code == 0) {
                        form.value = response.data.data
                        ElMessage({
                            message: '保存成功',
                            type: 'success',
                        })
                        getTableData()
                        dialogVisible.value = false
                        quart.value = false
                        month.value = false
                    } else {
                        // ElMessage.error('操作失败！' + response.data.msg)
                        ElMessage({
                            message: '操作失败' + response.data.msg,
                            type: 'error'
                        })
                    }
                })

            } else {
                console.log('error submit!', fields)
                ElMessage.error('请输入有效数据')
            }
        })
    }
    const handleCancelSave = () => {
        dialogVisible.value = false
        PlanOr.value = true
        quart.value = false
        month.value = false
    }
    //计划按钮是否展示
    const PlanOr = ref(true)
    const handleEdit = (row) => {
        dialogVisible.value = true
        form.value = row
        if(form.value.monthNo){
            quart.value = false
            month.value = true
        }else if(form.value.quartNo){
            quart.value = true
            month.value = false
        }else{
            quart.value = false
            month.value = false
        }
        dialogName.value = "编辑计划"
        PlanOr.value = false
    }
    const handleDelete = (row) => {
        ElMessageBox.confirm(
            '确定删除本条记录?',
            '提示', {
                confirmButtonText: '确认',
                cancelButtonText: '取消',
                type: 'warning',
                draggable: true,
            }
        )
            .then(() => {
                if(row.monthNo){
                    var url = 'pla/MonthProdPlan/remove'
                }else if(row.quartNo){
                    var url = 'pla/QuartProdPlan/remove'
                }else{
                    var url = 'pla/ProdPlan/remove'
                }
                
                var param = {
                    id: row.id
                }
                proxy.$axios.post(url, param).then(response => {
                    if (response.data.code == 0) {
                        ElMessage({
                            type: 'success',
                            message: '删除成功',
                        })
                        getTableData()
                    } else {
                        ElMessage({
                            type: 'error',
                            message: '删除失败' + response.data.msg
                        });
                    }
                });
            })
            .catch(() => {
                ElMessage({
                    type: 'info',
                    message: '已取消',
                })
            })
    }

    /**
     * 保存、修改、删除
     */

    const multipleSelection = ref([])
    const handleSelectionChange = (val) => {
        multipleSelection.value = val
    }

    const handleRemoveBatch = () => {
        console.log('handleRemoveBatch')

        if (multipleSelection.value.length < 1) {
            ElMessage({
                type: 'warning',
                message: '请选择要删除的数据!'
            })
            return
        }

        ElMessageBox.confirm('此操作将删除该数据, 是否继续?', '提示', {
            confirmButtonText: '确定',
            cancelButtonText: '取消',
            type: 'warning'
        }).then(() => {
            var ids = []
            multipleSelection.value.forEach((item, index) => {
                ids.push(item.id)
            })
            if(monthDelete.value){
                var url = 'pla/MonthProdPlan/removeBatch'
            }else if(quartDelete.value){
                var url = 'pla/QuartProdPlan/removeBatch'
            }else{
                var url = 'pla/ProdPlan/removeBatch'
            }
            var param = {
                ids: JSON.stringify(ids)
            }
            proxy.$axios.post(url, param).then(response => {
                if (response.data.code == '0') {
                    ElMessage({
                        type: 'success',
                        message: '操作成功!',
                    });
                    getTableData()
                    dialogVisible.value = false
                } else {
                    ElMessage({
                        type: 'error',
                        message: '操作失败!' + response.data.msg
                    });
                }
            })
        }).catch(() => {
            ElMessage({
                type: 'info',
                message: '已取消删除'
            })
        })
    }

    const handleEditBatch = () => {
        console.log('handleEditBatch')
        if (multipleSelection.value.length != 1) {
            ElMessage({
                type: 'warning',
                message: '请选择一条数据编辑!'
            })
            return
        }
        handleEdit(multipleSelection.value[0])
    }

    const handleUpload = () => {
        console.log('handleUpload')
    }

    const handleDownload = (row) => {
        // console.log('handleDownload')
        location.href = import.meta.env.VITE_BASE_API +
        '/framework/Common/downloadFileFtpByName?fId=TEMPLATES&fileName=' + '选矿生产计划.xlsx'
    }


    
//导入
    import ImportExcel from '@/components/ImportExcel.vue'
	const ImportExcelRef = ref(null)
    

    const importUrl = ref('pla/ProdPlan/importExcel')
	const importExcelformData = ref({
		fId: '',
        userId: localStorage.getItem('userId')
	})

    const importSuccess = () => {
        ImportExcelRef.value.close()
		handleSearch()
	}
    
    const handleImport = () => {
        ImportExcelRef.value.open()
    }

    const handleExport = () => {
        if (multipleSelection.value.length != 1) {
            ElMessage({
                type: 'warning',
                message: '请选择一条数据导出!'
            })
            return
        }else{
            var params = multipleSelection.value[0]
		location.href = import.meta.env.VITE_BASE_API +
			'/pla/ProdPlan/exportExcel?params=' + encodeURIComponent(JSON.stringify(params))
        }
    }

    /**
 * 工作流相关
 */

 import {workflowSubmit, workflowCancel} from "@/tools/workflow.js";


const flowId = ref('')
flowId.value = 'prodPlan'

// const handleSubmit = (row) => {
//   ElMessageBox.confirm(
//       '确定提交审批?',
//       '提示', {
//         confirmButtonText: '确认',
//         cancelButtonText: '取消',
//         type: 'warning',
//         draggable: true,
//       }
//   ).then(() => {
//     console.log(row)
//     return workflowSubmit(
//         flowId.value,
//         '测试流程请示',
//         '初始化提交',
//         JSON.stringify(row),
//         row.workId,
//         row.trackId)
//   }).then((result) => {
//     console.log(result)
//     if(result.status === 'success'){
//       // 将结果返回的workId和trackId保存
//       console.log(row)
//       console.log(row.monthNo)
//       console.log(row.quartNo)
//       var url = ''
//         if (row.monthNo) {
//             url = 'pla/MonthProdPlan/save'
//             console.log(url)
//         } else if (row.quartNo) {
//             url = 'pla/QuartProdPlan/save'
//             console.log(url)
//         } else{
//             url = 'pla/ProdPlan/save'
//             console.log(url)
//         }
//       var process = {
//         'id': row.id,
//         'workId': result.workId,
//         'trackId': result.trackId,
//         'yearNo':row.yearNo,
//         'monthNo':row.monthNo,
//         'quartNo':row.quartNo,
//       }
//       var param = {
//         json: JSON.stringify(process),
//       }
//       proxy.$axios.post(url, param).then(response => {
//         if (response.data.code === 0) {
//           form.value = response.data.data
//           ElMessage({
//             type: 'success',
//             message: '提交审批成功',
//           })
//           getTableData()
//         }
//       })
//     }
//     else{
//       ElMessage({
//         type: 'error',
//         message: '提交审批失败' + response.data.msg
//       });
//     }
//   }).catch(() => {
//     ElMessage({
//       type: 'info',
//       message: '已取消提交',
//     })
//   })
// }

// const handleCancel = (row) => {
//   ElMessageBox.confirm(
//       '确定撤回审批?',
//       '提示', {
//         confirmButtonText: '确认',
//         cancelButtonText: '取消',
//         type: 'warning',
//         draggable: true,
//       }
//   ).then(() => {
//     return workflowCancel(row.workId, row.trackId);
//   }).then((result) => {
//     if(result.status === 'success'){
//       ElMessage({
//         type: 'success',
//         message: '撤回审批成功',
//       })
//       getTableData()
//     }else {
//       ElMessage({
//         type: 'error',
//         message: '撤回审批失败' + response.data.msg
//       });
//     }
//   }).catch(() => {
//     ElMessage({
//       type: 'info',
//       message: '已取消提交',
//     })
//   })
// }

// const handleDetail = (row) => {
//   if(row.workId === null){
//     ElMessage({
//       type: 'info',
//       message: '无法查看',
//     })
//   }else {
//     console.log(row)
//     sessionStorage.setItem('workflowQuery', JSON.stringify({
//   flowId: flowId.value,
//   workId: row.workId,
//   trackId: row.trackId,
//   date:new Date().getTime()
// }))

// proxy.$router.push({
//   path: '/workflow/detail',
// })
  
//   }
// }

</script>

<style scoped>
.el-dialog__title {
  color: rgb(79, 79, 79); /* 更改颜色 */
  font-size: 30px; /* 更改字体大小 */
}
</style>