<template>
    <div>
        <el-card :body-style="cardBodyStyle">
            <el-form :inline="true">
                <el-form-item label="年度" style="margin-bottom: 5px;" prop="yearNo">
                    <el-date-picker v-model="query.yearNo" clearable type="year" style="width: 230px"
                        placeholder="请选择年度" @change="handleQueryYearChange" />
                </el-form-item>
                <el-form-item label="计划类型" style="margin-bottom: 5px; width: 295px;">
                    <el-select v-model="planType" placeholder="请选择计划类型" clearable>
                        <el-option label="年度计划" :value=1 />
                        <el-option label="季度计划" :value=2 />
                        <el-option label="月度计划" :value=3 />
                    </el-select>
                </el-form-item>
            </el-form>
        </el-card>
        <!-- <SearchBox ref="SearchBoxRef" formName="search" :formData="query" @showPop="showPop" @reset="reset"></SearchBox> -->
        <ButtonBar @search="handleSearch" @add="handleAdd" @remove="handleRemoveBatch" @edit="handleEditBatch"
            @upload="handleUpload" @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="createEmpId" label="创建人id" width="300" header-align="center"
                    align="center" show-overflow-tooltip>
                </el-table-column>
                <el-table-column v-if="false" prop="createDtm" label="创建时间" width="240" 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="70" header-align="center" align="center"
                    show-overflow-tooltip>
                </el-table-column>
                <el-table-column v-if="removePlanType != 1" prop="quartNo" label="季度" width="70" header-align="center"
                    align="center" show-overflow-tooltip>
                </el-table-column>
                <el-table-column v-if="removePlanType == 3" prop="monthNo" label="月度" width="70" header-align="center"
                    align="center" show-overflow-tooltip>
                </el-table-column>
                <el-table-column v-if="true" prop="oreQtyTtl" label="铁矿石总产量(万吨)" width="150" header-align="center"
                    align="right" show-overflow-tooltip>
                </el-table-column>
                <el-table-column v-if="true" prop="oreQtyJz" label="金召矿业产量(万吨)" width="150" header-align="center"
                    align="right" show-overflow-tooltip>
                </el-table-column>

                <el-table-column v-if="removePlanType == 1" prop="oreQltyJz" label="金召矿业铁矿石质量" width="160"
                    header-align="center" align="right" show-overflow-tooltip>
                </el-table-column>

                <el-table-column v-if="true" prop="oreQtyJd" label="金鼎公司产量(万吨)" width="150" header-align="center"
                    align="right" show-overflow-tooltip>
                </el-table-column>
                <el-table-column v-if="true" prop="oreQtyZy" label="外购矿(正元)产量(万吨)" width="180" header-align="center"
                    align="right" show-overflow-tooltip>
                </el-table-column>
                <el-table-column v-if="true" prop="oreQtyQt" label="外购矿(其他)产量(万吨)" width="180" header-align="center"
                    align="right" show-overflow-tooltip>
                </el-table-column>
                <el-table-column v-if="true" prop="ironCcttQtyTtl" label="铁精粉总产量(万吨)" width="150" header-align="center"
                    align="right" show-overflow-tooltip>
                </el-table-column>
                <el-table-column v-if="true" prop="ironCcttQtyJl" label="本部产量(万吨)" width="120" header-align="center"
                    align="right" show-overflow-tooltip>
                </el-table-column>

                <el-table-column v-if="removePlanType == 1" prop="ironCcttQltyJl" label="铁精粉质量" width="100"
                    header-align="center" align="right" show-overflow-tooltip>
                </el-table-column>

                <el-table-column v-if="true" prop="coppCcttQty" label="铜精粉产量(万吨)" width="140" header-align="center"
                    align="right" show-overflow-tooltip>
                </el-table-column>

                <el-table-column v-if="removePlanType == 1" prop="coppCcttQlty" label="铜精粉质量" width="100"
                    header-align="center" align="right" show-overflow-tooltip>
                </el-table-column>

                <el-table-column v-if="true" prop="coppMetlQty" label="铜金属产量(万吨)" width="140" header-align="center"
                    align="right" show-overflow-tooltip>
                </el-table-column>
                <el-table-column v-if="true" prop="pellQtyTtl" label="球团矿产量(万吨)" width="140" header-align="center"
                    align="right" show-overflow-tooltip>
                </el-table-column>
                <el-table-column v-if="true" prop="pellQtyKs" label="喀什产量(万吨)" width="120" header-align="center"
                    align="right" show-overflow-tooltip>
                </el-table-column>
                <el-table-column v-if="removePlanType == 1" prop="pellQltyKs" label="喀什球团矿质量" width="130"
                    header-align="center" align="right" show-overflow-tooltip>
                </el-table-column>
                <el-table-column v-if="true" prop="pellQtyTy" label="铁鹰产量(万吨)" width="120" header-align="center"
                    align="right" show-overflow-tooltip>
                </el-table-column>
                <el-table-column v-if="removePlanType == 1" prop="pellQltyTy" label="铁鹰球团矿质量" width="140"
                    header-align="center" align="right" show-overflow-tooltip>
                </el-table-column>

                <el-table-column v-if="true" prop="fsQtyTtl" label="废石总量(万吨)" width="120" header-align="center"
                    align="right" show-overflow-tooltip>
                </el-table-column>
                <el-table-column v-if="true" prop="tyfsQtl" label="铁鹰废石量(万吨)" width="140" header-align="center"
                    align="right" show-overflow-tooltip>
                </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">
            <el-tabs type="border-card" v-model="activeTab" @tab-click="handleTabClick">
                <el-tab-pane label="年度计划" name="yearPlan" v-if="dialogName == '新增'">
                    <template #label>
                        <span @click="yearPlan">年度计划</span>
                    </template>
                </el-tab-pane>
                <el-tab-pane label="季度计划" name="quartPlan" v-if="dialogName == '新增'">
                    <template #label>
                        <span @click="quartPlan">季度计划</span>
                    </template>
                </el-tab-pane>
                <el-tab-pane label="月度计划" name="monthPlan" v-if="dialogName == '新增'">
                    <template #label>
                        <span @click="monthPlan">月度计划</span>
                    </template>
                </el-tab-pane>
                <el-form :model="form" label-width="80px" label-position="right" inline ref="ruleFormRef"
                    :rules="rules">
                    <el-card style="margin-bottom: 5px;  height: 70px;" v-if="dialogName == '新增'">
                        <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="dialogPlanType == 2">
                                    <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="(dialogPlanType == 3)">
                                    <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-card>
                    <el-card style="margin-bottom: 5px;  height: 70px;" v-if="dialogName == '编辑'">
                        <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="(removePlanType == 2)">
                                    <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="(removePlanType == 3)">
                                    <!-- <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-card>
                    <el-card style="margin-bottom: 5px; height: 110px;">
                        <el-row style="margin-bottom: 5px;">
                            <el-col>
                                <div
                                    style="font-size: 18px; color: black; background-color: #f0f0f0; margin-bottom: 10px;">
                                    铁矿石总产量：{{ form.oreQtyTtl }} 万吨</div>
                            </el-col>
                        </el-row>
                        <el-row :gutter="40">
                            <el-col :span="1"></el-col>
                            <el-col :span="6">
                                <el-form-item label="金召矿业产量(万吨)" style="white-space: nowrap;" prop="oreQtyJz">
                                    <el-input v-model="form.oreQtyJz" clearable style="width: 100px"
                                        @input="oreQtyTtlValue"></el-input>
                                </el-form-item>
                            </el-col>
                            <el-col :span="6">
                                <el-form-item label="金鼎公司产量(万吨)" style="white-space: nowrap;" prop="oreQtyJd">
                                    <el-input v-model="form.oreQtyJd" clearable style="width: 100px"
                                        @input="oreQtyTtlValue"></el-input>
                                </el-form-item>
                            </el-col>
                            <el-col :span="6">
                                <el-form-item label="外购矿(正元)产量(万吨)" style="white-space: nowrap;" prop="oreQtyZy">
                                    <el-input v-model="form.oreQtyZy" clearable style="width: 100px"
                                        @input="oreQtyTtlValue"></el-input>
                                </el-form-item>
                            </el-col>
                            <el-col :span="5">
                                <el-form-item label="外购矿(其他)产量(万吨)" style="white-space: nowrap;" prop="oreQtyQt">
                                    <el-input v-model="form.oreQtyQt" clearable style="width: 100px"
                                        @input="oreQtyTtlValue"></el-input>
                                </el-form-item>
                            </el-col>
                        </el-row>
                    </el-card>
                    <el-card style="margin-bottom: 5px; height: 110px;">
                        <el-row style="margin-bottom: 5px;">
                            <el-col>
                                <div
                                    style="font-size: 18px; color: black; background-color: #f0f0f0; margin-bottom: 10px;">
                                    铁精粉总产量：{{ form.ironCcttQtyTtl }} 万吨</div>
                            </el-col>
                        </el-row>
                        <el-row :gutter="40">
                            <el-col :span="1"></el-col>
                            <el-col :span="6">
                                <el-form-item label="本部产量(万吨)" style="white-space: nowrap;" prop="ironCcttQtyJl">
                                    <el-input v-model="form.ironCcttQtyJl" clearable style="width: 100px"
                                        @input="ironCcttQtyTtlValue"></el-input>
                                </el-form-item>
                            </el-col>
                        </el-row>
                    </el-card>
                    <el-card style="margin-bottom: 5px; height: 70px;">
                        <el-row :gutter="40">
                            <el-col :span="1"></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="coppMetlQty">
                                    <el-input v-model="form.coppMetlQty" clearable style="width: 100px"></el-input>
                                </el-form-item>
                            </el-col>
                        </el-row>
                    </el-card>
                    <el-card style="margin-bottom: 5px; height: 110px;">
                        <el-row style="margin-bottom: 5px;">
                            <el-col>
                                <div
                                    style="font-size: 18px; color: black; background-color: #f0f0f0; margin-bottom: 10px;">
                                    球团矿总产量：{{ form.pellQtyTtl }} 万吨</div>
                            </el-col>
                        </el-row>
                        <el-row :gutter="40">
                            <el-col :span="1"></el-col>
                            <el-col :span="6">
                                <el-form-item label="喀什产量(万吨)" style="white-space: nowrap;" prop="pellQtyKs">
                                    <el-input v-model="form.pellQtyKs" clearable style="width: 100px"
                                        @input="pellQtyTtlValue"></el-input>
                                </el-form-item>
                            </el-col>
                            <el-col :span="6">
                                <el-form-item label="铁鹰产量(万吨)" style="white-space: nowrap;" prop="pellQtyTy">
                                    <el-input v-model="form.pellQtyTy" clearable style="width: 100px"
                                        @input="pellQtyTtlValue"></el-input>
                                </el-form-item>
                            </el-col>
                        </el-row>
                    </el-card>
                    <el-card style="margin-bottom: 5px; height: 110px;">
                        <el-row style="margin-bottom: 5px;">
                            <el-col>
                                <div
                                    style="font-size: 18px; color: black; background-color: #f0f0f0; margin-bottom: 10px;">
                                    废石总量：{{ form.fsQtyTtl }} 万吨</div>
                            </el-col>
                        </el-row>
                        <el-row :gutter="40">
                            <el-col :span="1"></el-col>
                            <el-col :span="6">
                                <el-form-item label="铁鹰废石量(万吨)" style="white-space: nowrap;" prop="tyfsQtl">
                                    <el-input v-model="form.tyfsQtl" clearable style="width: 100px"
                                        @input="fsQtyTtlValue"></el-input>
                                </el-form-item>
                            </el-col>
                        </el-row>
                    </el-card>
                    <el-card style="margin-bottom: 5px; height: 160px;"
                        v-if="((dialogPlanType == 1) && dialogName == '新增') || (dialogName == '编辑' && removePlanType == 1)">
                        <el-row style="margin-bottom: 5px;">
                            <el-col>
                                <div
                                    style="font-size: 18px; color: black; background-color: #f0f0f0; margin-bottom: 10px;">
                                    产品质量</div>
                            </el-col>
                        </el-row>
                        <el-row :gutter="40">
                            <el-col :span="2"></el-col>
                            <el-col :span="6">
                                <el-form-item label="金召矿业铁矿石质量(%)" style="white-space: nowrap;" prop="oreQltyJz">
                                    <el-input v-model="form.oreQltyJz" clearable style="width: 100px"></el-input>
                                </el-form-item>
                            </el-col>
                            <el-col :span="6">
                                <el-form-item label="铁精粉质量(%)" style="white-space: nowrap;" prop="ironCcttQltyJl">
                                    <el-input v-model="form.ironCcttQltyJl" clearable style="width: 100px"></el-input>
                                </el-form-item>
                            </el-col>
                            <el-col :span="5">
                                <el-form-item label="铜精粉质量(%)" style="white-space: nowrap;" prop="coppCcttQlty">
                                    <el-input v-model="form.coppCcttQlty" clearable style="width: 100px"></el-input>
                                </el-form-item>
                            </el-col>
                            <el-col :span="5">
                                <el-form-item label="喀什球团矿质量(%)" style="white-space: nowrap;" prop="pellQltyKs">
                                    <el-input v-model="form.pellQltyKs" clearable style="width: 100px"></el-input>
                                </el-form-item>
                            </el-col>
                        </el-row>
                        <el-row>
                            <el-col :span="2"></el-col>
                            <el-col :span="6">
                                <el-form-item label="铁鹰球团矿质量(%)" style="white-space: nowrap;" prop="pellQltyTy">
                                    <el-input v-model="form.pellQltyTy" clearable style="width: 100px"></el-input>
                                </el-form-item>
                            </el-col>
                        </el-row>
                    </el-card>
                </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>
    </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);
        form.value.yearNo = date.getFullYear().toString(); // 转换为 YYYY格式
    } else {
        form.value.yearNo = '';
    }
}
const handleQueryYearChange = (value) => {
    if (value) {
        const date = new Date(value);
        query.value.yearNo = date.getFullYear().toString(); // 转换为 YYYY格式
    } else {
        form.value.yearNo = '';
    }
}

const removePlanType = ref(1)
const planType = ref(1)
const dialogName = ref('')
const dialogPlanType = ref(1)
const yearPlan = () => {
    dialogPlanType.value = 1
}
const quartPlan = () => {
    dialogPlanType.value = 2
}
const monthPlan = () => {
    dialogPlanType.value = 3
}
const pellQtyTtlValue = () => {
    var pellQtyTy = parseFloat(form.value.pellQtyTy)
    var pellQtyKs = parseFloat(form.value.pellQtyKs)
    if (isNaN(pellQtyTy)) { pellQtyTy = 0 }
    if (isNaN(pellQtyKs)) { pellQtyKs = 0 }
    var a = pellQtyTy + pellQtyKs
    form.value.pellQtyTtl = parseFloat(a.toFixed(13))
}
const ironCcttQtyTtlValue = () => {
    var ironCcttQtyJl = parseFloat(form.value.ironCcttQtyJl)
    if (isNaN(ironCcttQtyJl)) { ironCcttQtyJl = 0 }
    // form.value.ironCcttQtyTtl = ironCcttQtyJl
    form.value.ironCcttQtyTtl = parseFloat(ironCcttQtyJl.toFixed(13))
}
const fsQtyTtlValue = () => {
    var tyfsQtl = parseFloat(form.value.tyfsQtl)
    if (isNaN(tyfsQtl)) { tyfsQtl = 0 }
    form.value.fsQtyTtl = parseFloat(tyfsQtl.toFixed(13))
}
const oreQtyTtlValue = () => {
    var oreQtyJz = parseFloat(form.value.oreQtyJz)
    var oreQtyJd = parseFloat(form.value.oreQtyJd)
    var oreQtyZy = parseFloat(form.value.oreQtyZy)
    var oreQtyQt = parseFloat(form.value.oreQtyQt)

    if (isNaN(oreQtyJz)) { oreQtyJz = 0 }
    if (isNaN(oreQtyJd)) { oreQtyJd = 0 }
    if (isNaN(oreQtyZy)) { oreQtyZy = 0 }
    if (isNaN(oreQtyQt)) { oreQtyQt = 0 }
    // form.value.oreQtyTtl = oreQtyJz + oreQtyJd + oreQtyZy + oreQtyQt
    var a = oreQtyJz + oreQtyJd + oreQtyZy + oreQtyQt
    form.value.oreQtyTtl = parseFloat(a.toFixed(13));
}
/**
 *   查询
 */




const query = ref({
    yearNo: ''
})
const tableData = ref([])
const handleSearch = () => {
    removePlanType.value = 3
    if (planType.value == 1) {
        removePlanType.value = 1
    } else if (planType.value == 2) {
        removePlanType.value = 2
    }
    currentPage.value = 1
    getTableData()
    console.log(removePlanType.value)
    console.log(planType.value)
    console.log(dialogPlanType.value)
}
const getTableData = () => {
    var url = 'pla/ProdMastMonth/query'
    if (planType.value == 1) {
        url = 'pla/ProdMastYear/query'
    } else if (planType.value == 2) {
        url = 'pla/ProdMastQuart/query'
    }
    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') {
            tableData.value = response.data.data.records
            totalRows.value = response.data.data.total
        } else {
            ElMessage.error('操作失败！' + response.data.msg)
        }
    })
}
/**
 *   查询
 */

/**
 * 分页
 */
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: '',
    quartNo: '',
    monthNo: '',
    oreQtyTtl: '',
    oreQtyJz: '',
    oreQtyJd: '',
    oreQtyZy: '',
    oreQtyQt: '',
    ironCcttQtyTtl: '',
    ironCcttQtyJl: '',
    coppCcttQty: '',
    coppMetlQty: '',
    pellQtyTtl: '',
    pellQtyKs: '',
    pellQtyTy: '',
    fsQtyTtl:'',
    tyfsQtl:''

})
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'
    }],
    oreQtyJz: [{ pattern: /^[0-9]{1,19}(\.[0-9]{1,14})?$/, message: '请输入有效的数字', trigger: 'blur' | 'change' }],
    oreQtyJd: [{ pattern: /^[0-9]{1,19}(\.[0-9]{1,14})?$/, message: '请输入有效的数字', trigger: 'blur' | 'change' }],
    oreQtyZy: [{ pattern: /^[0-9]{1,19}(\.[0-9]{1,14})?$/, message: '请输入有效的数字', trigger: 'blur' | 'change' }],
    oreQtyQt: [{ pattern: /^[0-9]{1,19}(\.[0-9]{1,14})?$/, message: '请输入有效的数字', trigger: 'blur' | 'change' }],
    ironCcttQtyJl: [{ pattern: /^[0-9]{1,19}(\.[0-9]{1,14})?$/, message: '请输入有效的数字', trigger: 'blur' | 'change' }],
    coppCcttQty: [{ pattern: /^[0-9]{1,19}(\.[0-9]{1,14})?$/, message: '请输入有效的数字', trigger: 'blur' | 'change' }],
    coppMetlQty: [{ pattern: /^[0-9]{1,19}(\.[0-9]{1,14})?$/, message: '请输入有效的数字', trigger: 'blur' | 'change' }],
    pellQtyTtl: [{ pattern: /^[0-9]{1,19}(\.[0-9]{1,14})?$/, message: '请输入有效的数字', trigger: 'blur' |'change' }],
    pellQtyKs: [{ pattern: /^[0-9]{1,19}(\.[0-9]{1,14})?$/, message: '请输入有效的数字', trigger: 'blur' | 'change' }],
    pellQtyTy: [{ pattern: /^[0-9]{1,19}(\.[0-9]{1,14})?$/, message: '请输入有效的数字', trigger: 'blur' | 'change' }],
    oreQltyJz: [{ pattern: /^[0-9]{1,19}(\.[0-9]{1,14})?$/, message: '请输入有效的数字', trigger: 'blur' | 'change' }],
    ironCcttQltyJl: [{ pattern: /^[0-9]{1,19}(\.[0-9]{1,14})?$/, message: '请输入有效的数字', trigger: 'blur' | 'change' }],
    coppCcttQlty: [{ pattern: /^[0-9]{1,19}(\.[0-9]{1,14})?$/, message: '请输入有效的数字', trigger: 'blur' | 'change' }],
    pellQltyKs: [{ pattern: /^[0-9]{1,19}(\.[0-9]{1,14})?$/, message: '请输入有效的数字', trigger: 'blur' | 'change' }],
    pellQltyTy: [{ pattern: /^[0-9]{1,19}(\.[0-9]{1,14})?$/, message: '请输入有效的数字', trigger: 'blur' | 'change' }],
    tyfsQtl: [{ pattern: /^[0-9]{1,19}(\.[0-9]{1,14})?$/, message: '请输入有效的数字', trigger: 'blur' | 'change' }],
})

const handleAdd = () => {
    form.value = {
        yearNo: '',
        quartNo: '',
        monthNo: '',
        oreQtyTtl: '',
        oreQtyJz: '',
        oreQtyJd: '',
        oreQtyZy: '',
        oreQtyQt: '',
        ironCcttQtyTtl: '',
        ironCcttQtyJl: '',
        coppCcttQty: '',
        coppMetlQty: '',
        pellQtyTtl: '',
        pellQtyKs: '',
        pellQtyTy: '',
        fsQtyTtl: '',
        tyfsQtl:''
    }
    dialogName.value = '新增'
    dialogVisible.value = true
}
/**
 * 新增
 */


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

const openDialog = () => {
}

const handleSave = (ruleFormRef) => {
    ruleFormRef.validate((valid, fields) => {
        if (valid) {
            var url = 'pla/ProdMastMonth/save'
            if ((dialogPlanType.value == 1 && dialogName.value == '新增') || (removePlanType.value == 1 && dialogName.value == '编辑')) {
                url = 'pla/ProdMastYear/save'
            } else if ((dialogPlanType.value == 2 && dialogName.value == '新增') || (removePlanType.value == 2 && dialogName.value == '编辑')) {
                url = 'pla/ProdMastQuart/save'
            }

            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
                } 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
}
const handleEdit = (row) => {
    dialogName.value = '编辑'
    dialogVisible.value = true
    form.value = row
}
const handleDelete = (row) => {
    ElMessageBox.confirm(
        '确定删除本条记录?',
        '提示', {
        confirmButtonText: '确认',
        cancelButtonText: '取消',
        type: 'warning',
        draggable: true,
    }
    )
        .then(() => {
            var url = 'pla/ProdMastMonth/remove'
            if (removePlanType.value == 1) {
                url = 'pla/ProdMastYear/remove'
            } else if (removePlanType.value == 2) {
                url = 'pla/ProdMastQuart/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)
        })
        var url = 'pla/ProdMastMonth/removeBatch'
        if (removePlanType.value == 1) {
            url = 'pla/ProdMastYear/removeBatch'
        } else if (removePlanType.value == 2) {
            url = 'pla/ProdMastQuart/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 = () => {
    console.log('handleDownload')
}

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

const handleExport = () => {
    if (multipleSelection.value.length < 1) {
        ElMessage({
            type: 'warning',
            message: '请选择要到导出的数据!'
        })
        return
    } else {
        var ids = []
        multipleSelection.value.forEach((item, index) => {
            ids.push(item.id)
        })
        var url = 'ProdMastMonth'
        if (removePlanType.value == 1) {
            url = 'ProdMastYear'
        } else if (removePlanType.value == 2) {
            url = 'ProdMastQuart'
        }
        console.log(url)
        location.href = import.meta.env.VITE_BASE_API +
            '/pla/'+url+'/exportExcel?params=' + encodeURIComponent(JSON.stringify(ids))
    }
}

</script>

<style></style>