<template>
    <div>
        <el-card :body-style="cardBodyStyle">
            <el-tabs type="border-card">
                <el-tab-pane label="指定外矿配比">
                    <template #header>
                        <div style="font-size: 20px; color: slategray; text-align: center; width: 100%;">指定外矿配比</div>
                    </template>
                    <el-button type="primary" style="margin-bottom: 5px;" @click="handleSearch" plain>查询</el-button>
                    <el-button type="success" style="margin-bottom: 5px;" @click="handleAdd" plain>新增</el-button>
                    <el-button type="danger" style="margin-bottom: 5px;" @click="handleRemoveBatch"
                        plain>批量删除</el-button>
                    <el-table :data="tableData" border highlight-current-row @selection-change="handleSelectionChange">
                        <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="false" prop="matlProp1" label="外矿1配比" width="100" header-align="center"
                            align="right" show-overflow-tooltip>
                        </el-table-column>
                        <el-table-column v-if="false" prop="matlProp2" label="外矿2配比" width="100" header-align="center"
                            align="right" show-overflow-tooltip>
                        </el-table-column>
                        <el-table-column v-if="false" prop="matlProp3" label="外矿3配比" width="100" header-align="center"
                            align="right" show-overflow-tooltip>
                        </el-table-column>
                        <el-table-column v-if="false" prop="matlProp4" label="外矿4配比" width="100" header-align="center"
                            align="right" show-overflow-tooltip>
                        </el-table-column>
                        <el-table-column v-if="false" prop="matlProp5" label="外矿5配比" width="100" header-align="center"
                            align="right" show-overflow-tooltip>
                        </el-table-column>
                        <el-table-column v-if="false" prop="matlProp6" label="外矿6配比" width="100" header-align="center"
                            align="right" show-overflow-tooltip>
                        </el-table-column>
                        <el-table-column v-if="false" prop="matlProp7" label="外矿7配比" width="100" header-align="center"
                            align="right" show-overflow-tooltip>
                        </el-table-column>
                        <el-table-column v-if="false" prop="matlProp8" label="外矿8配比" width="100" header-align="center"
                            align="right" show-overflow-tooltip>
                        </el-table-column>
                        <el-table-column v-if="false" prop="matlProp9" label="外矿9配比" width="100" header-align="center"
                            align="right" show-overflow-tooltip>
                        </el-table-column>
                        <el-table-column v-if="false" prop="matlProp10" label="外矿10配比" width="100" header-align="center"
                            align="right" show-overflow-tooltip>
                        </el-table-column>

                        <el-table-column v-for="(column, index) in tableColumns" :key="index" :prop="column.prop"
                            :label="column.label" header-align="center" align="center" width="100"></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-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" style="margin-top: 10px;">
                    </el-pagination>
                </el-tab-pane>
            </el-tabs>
        </el-card>

        <el-card :body-style="cardBodyStyle">
            <el-tabs type="border-card">
                <el-tab-pane label="原矿化学成分">
                    <el-button type="primary" @click="chemHandleSearch" style="margin-bottom: 5px;" plain>查询</el-button>
                    <el-table :data="chemTableData" border highlight-current-row
                        @selection-change="handleSelectionChange">
                        <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="true" prop="matlNm" label="原矿名称" width="150" header-align="center"
                            align="center" show-overflow-tooltip>
                        </el-table-column>
                        <el-table-column v-if="true" prop="tfeVal" label="TFe" width="100" header-align="center"
                            align="right" show-overflow-tooltip>
                        </el-table-column>
                        <el-table-column v-if="true" prop="sVal" label="S" width="100" header-align="center"
                            align="right" show-overflow-tooltip>
                        </el-table-column>
                        <el-table-column v-if="true" prop="cuVal" label="Cu" width="100" header-align="center"
                            align="right" show-overflow-tooltip>
                        </el-table-column>
                        <el-table-column v-if="true" prop="pVal" label="P" width="100" header-align="center"
                            align="right" show-overflow-tooltip>
                        </el-table-column>
                        <el-table-column v-if="true" prop="tio2Val" label="TiO2" width="100" header-align="center"
                            align="right" show-overflow-tooltip>
                        </el-table-column>
                        <el-table-column v-if="true" prop="sio2Val" label="SiO2" width="100" header-align="center"
                            align="right" show-overflow-tooltip>
                        </el-table-column>
                        <el-table-column v-if="true" prop="mgoVal" label="MgO" width="100" header-align="center"
                            align="right" show-overflow-tooltip>
                        </el-table-column>
                        <el-table-column v-if="true" prop="caoVal" label="CaO" width="100" header-align="center"
                            align="right" show-overflow-tooltip>
                        </el-table-column>
                        <el-table-column v-if="true" prop="al2o3Val" label="Al2O3" width="100" header-align="center"
                            align="right" show-overflow-tooltip>
                        </el-table-column>
                        <el-table-column v-if="true" prop="mnVal" label="Mn" width="100" header-align="center"
                            align="right" show-overflow-tooltip>
                        </el-table-column>
                        <el-table-column v-if="true" prop="znVal" label="Zn" width="100" header-align="center"
                            align="right" show-overflow-tooltip>
                        </el-table-column>
                    </el-table>

                    <el-pagination :current-page="chemCurrentPage" :page-size="chemPageSize" :page-sizes="chemPageSizes"
                        :total="chemTotalRows" background="background" layout="total, sizes, prev, pager, next, jumper"
                        @size-change="chemHandleSizeChange" @current-change="chemHandleCurrentChange"
                        style="margin-top: 10px;">
                    </el-pagination>
                </el-tab-pane>
            </el-tabs>
        </el-card>

        <el-card :body-style="cardBodyStyle">
            <el-tabs type="border-card">
                <el-tab-pane label="外矿配矿计算结果">
                    <el-button type="primary" @click="manuChemHandleSearch" style="margin-bottom: 5px;"
                        plain>配矿计算</el-button>
                    <el-table :data="manuChemTableData" border highlight-current-row
                        @selection-change="handleSelectionChange">
                        <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="true" prop="matlNm" label="外矿名称" width="150" header-align="center"
                            align="center" show-overflow-tooltip>
                        </el-table-column>
                        <el-table-column v-if="true" prop="tfeVal" label="TFe" width="100" header-align="center"
                            align="right" show-overflow-tooltip>
                            <template v-slot="scope">
                                <div :style="{ color: getTfeFontColor(scope.row.tfeVal) }">
                                    {{ scope.row.tfeVal }}
                                </div>
                            </template>
                        </el-table-column>
                        <el-table-column v-if="true" prop="sVal" label="S" width="100" header-align="center"
                            align="right" show-overflow-tooltip>
                            <template v-slot="scope">
                                <div :style="{ color: getSFontColor(scope.row.sVal) }">
                                    {{ scope.row.sVal }}
                                </div>
                            </template>
                        </el-table-column>
                        <el-table-column v-if="true" prop="cuVal" label="Cu" width="100" header-align="center"
                            align="right" show-overflow-tooltip>
                            <template v-slot="scope">
                                <div :style="{ color: getCuFontColor(scope.row.cuVal) }">
                                    {{ scope.row.cuVal }}
                                </div>
                            </template>
                        </el-table-column>
                        <el-table-column v-if="true" prop="pVal" label="P" width="100" header-align="center"
                            align="right" show-overflow-tooltip>
                            <template v-slot="scope">
                                <div :style="{ color: getPFontColor(scope.row.pVal) }">
                                    {{ scope.row.pVal }}
                                </div>
                            </template>
                        </el-table-column>
                        <el-table-column v-if="true" prop="tio2Val" label="TiO2" width="100" header-align="center"
                            align="right" show-overflow-tooltip>
                            <template v-slot="scope">
                                <div :style="{ color: getTio2FontColor(scope.row.tio2Val) }">
                                    {{ scope.row.tio2Val }}
                                </div>
                            </template>
                        </el-table-column>
                        <el-table-column v-if="true" prop="sio2Val" label="SiO2" width="100" header-align="center"
                            align="right" show-overflow-tooltip>
                            <template v-slot="scope">
                                <div :style="{ color: getCuSiO2Color(scope.row.sio2Val) }">
                                    {{ scope.row.sio2Val }}
                                </div>
                            </template>
                        </el-table-column>
                        <el-table-column v-if="true" prop="mgoVal" label="MgO" width="100" header-align="center"
                            align="right" show-overflow-tooltip>
                            <template v-slot="scope">
                                <div :style="{ color: getMgOFontColor(scope.row.mgoVal) }">
                                    {{ scope.row.mgoVal }}
                                </div>
                            </template>
                        </el-table-column>
                        <el-table-column v-if="true" prop="caoVal" label="CaO" width="100" header-align="center"
                            align="right" show-overflow-tooltip>
                            <template v-slot="scope">
                                <div :style="{ color: getCaOFontColor(scope.row.caoVal) }">
                                    {{ scope.row.caoVal }}
                                </div>
                            </template>
                        </el-table-column>
                        <el-table-column v-if="true" prop="al2o3Val" label="Al2O3" width="100" header-align="center"
                            align="right" show-overflow-tooltip>
                            <template v-slot="scope">
                                <div :style="{ color: getAl2O3FontColor(scope.row.al2o3Val) }">
                                    {{ scope.row.al2o3Val }}
                                </div>
                            </template>
                        </el-table-column>
                        <el-table-column v-if="true" prop="mnVal" label="Mn" width="100" header-align="center"
                            align="right" show-overflow-tooltip>
                            <template v-slot="scope">
                                <div :style="{ color: getMnFontColor(scope.row.mnVal) }">
                                    {{ scope.row.mnVal }}
                                </div>
                            </template>
                        </el-table-column>
                        <el-table-column v-if="true" prop="znVal" label="Zn" width="100" header-align="center"
                            align="right" show-overflow-tooltip>
                            <template v-slot="scope">
                                <div :style="{ color: getZnFontColor(scope.row.znVal) }">
                                    {{ scope.row.znVal }}
                                </div>
                            </template>
                        </el-table-column>
                    </el-table>

                    <el-pagination :current-page="manuChemCurrentPage" :page-size="manuChemPageSize"
                        :page-sizes="manuChemPageSizes" :total="manuChemTotalRows" background="background"
                        layout="total, sizes, prev, pager, next, jumper" @size-change="manuChemHandleSizeChange"
                        @current-change="manuChemHandleCurrentChange" style="margin-top: 10px;">
                    </el-pagination>
                </el-tab-pane>
            </el-tabs>
        </el-card>

        <el-dialog :close-on-click-modal="false" draggable :title="dialogName" v-model="dialogVisible" width="900px"
            top="5vh" @open="openDialog" :before-close="handleCancelSave">
            <el-form :model="form" label-width="80px" label-position="right" inline ref="ruleFormRef" :rules="rules">
                <el-form-item label="外矿1配比" prop="matlProp1" style="white-space: nowrap;">
                    <el-input v-model="form.matlProp1" clearable style="width: 150px"></el-input>
                </el-form-item>
                <el-form-item label="外矿2配比" prop="matlProp2" style="white-space: nowrap;">
                    <el-input v-model="form.matlProp2" clearable style="width: 150px"></el-input>
                </el-form-item>
                <el-form-item label="外矿3配比" prop="matlProp3" style="white-space: nowrap;">
                    <el-input v-model="form.matlProp3" clearable style="width: 150px"></el-input>
                </el-form-item>
                <el-form-item label="外矿4配比" prop="matlProp4" style="white-space: nowrap;">
                    <el-input v-model="form.matlProp4" clearable style="width: 150px"></el-input>
                </el-form-item>
                <el-form-item label="外矿5配比" prop="matlProp5" style="white-space: nowrap;">
                    <el-input v-model="form.matlProp5" clearable style="width: 150px"></el-input>
                </el-form-item>
                <el-form-item label="外矿6配比" prop="matlProp6" style="white-space: nowrap;">
                    <el-input v-model="form.matlProp6" clearable style="width: 150px"></el-input>
                </el-form-item>
                <el-form-item label="外矿7配比" prop="matlProp7" style="white-space: nowrap;">
                    <el-input v-model="form.matlProp7" clearable style="width: 150px"></el-input>
                </el-form-item>
                <el-form-item label="外矿8配比" prop="matlProp8" style="white-space: nowrap;">
                    <el-input v-model="form.matlProp8" clearable style="width: 150px"></el-input>
                </el-form-item>
                <el-form-item label="外矿9配比" prop="matlProp9" style="white-space: nowrap;">
                    <el-input v-model="form.matlProp9" clearable style="width: 150px"></el-input>
                </el-form-item>
                <el-form-item label="外矿10配比" prop="matlProp10" style="white-space: nowrap;">
                    <el-input v-model="form.matlProp10" clearable style="width: 150px"></el-input>
                </el-form-item>
            </el-form>
            <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,
    onBeforeMount
} from 'vue'

const {
    proxy
} = getCurrentInstance()

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

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


const tableColumns = ref([
  { prop: 'matlProp1', label: '外矿1配比' },
  { prop: 'matlProp2', label: '外矿2配比' },
  { prop: 'matlProp3', label: '外矿3配比' },
  { prop: 'matlProp4', label: '外矿4配比' },
  { prop: 'matlProp5', label: '外矿5配比' },
  { prop: 'matlProp6', label: '外矿6配比' },
  { prop: 'matlProp7', label: '外矿7配比' },
  { prop: 'matlProp8', label: '外矿8配比' },
  { prop: 'matlProp9', label: '外矿9配比' },
  { prop: 'matlProp10', label: '外矿10配比' },
])



const tableColumnsValue = () => {
    console.log(chemTableData.value)
    if(chemTableData.value != null && chemTableData.value != undefined && chemTableData.value.length > 0){
        tableColumns.value = []
        chemTableData.value.forEach((item, index) => {
            if (index < 10) {
                tableColumns.value[index] = {
                    prop: 'matlProp' + (index + 1),
                    label: item.matlNm
                }
            }
        })
    }
}


//外矿配矿计算结果
const manuChemQuery = ref({
})
const manuChemTableData = ref([])
const manuChemHandleSearch = () => {
    chemCurrentPage.value = 1
    getmanuChemTableData()
    getMatlTargData()
}
const manuChemCurrentPage = ref(1)
const manuChemTotalRows = ref(0)
const manuChemPageSizes = ref([5, 10, 20, 30, 40])
const manuChemPageSize = ref(5)
const manuChemHandleSizeChange = (val) => {
    manuChemPageSize.value = val
    getmanuChemTableData()
}
const manuChemHandleCurrentChange = (val) => {
    manuChemCurrentPage.value = val
    getmanuChemTableData()

}
const getmanuChemTableData = () => {
    var url = 'pla/PropMatlManuChem/query'
    var param = {
        page: manuChemCurrentPage.value,
        rows: manuChemPageSize.value,
        params: JSON.stringify(manuChemQuery.value)
    }
    proxy.$axios.get(url, param).then(response => {
        if (response.data.code == '0') {
            manuChemTableData.value = response.data.data.records
            manuChemTotalRows.value = response.data.data.total
        } else {
            ElMessage.error('操作失败！' + response.data.msg)
        }
    })
}

//配矿化学成分目标值数据
const matlTargData = ref([])
const getMatlTargData = () => {
    var url = 'pla/PropMatlTarg/query'
    var param = {
        page: 1,
        rows: 1,
        params: JSON.stringify({ useFlag: '0' })
    }
    proxy.$axios.get(url, param).then(response => {
        if (response.data.code == '0') {
            matlTargData.value = response.data.data.records
        } else {
            ElMessage.error('操作失败！' + response.data.msg)
        }
    })
}
const getTfeFontColor = (tfeVal) => {
    const min = matlTargData.value[0].tfeMin
    const max = matlTargData.value[0].tfeMax
    if ((max != 0 ? tfeVal > max : false)) {
        return 'red';
    } else if (tfeVal < min) {
        return 'green';
    }
}
const getSFontColor = (sVal) => {
    const min = matlTargData.value[0].sMin
    const max = matlTargData.value[0].sMax
    if ((max != 0 ? sVal > max : false)) {
        return 'red';
    } else if (sVal < min) {
        return 'green';
    }
}
const getCuFontColor = (cuVal) => {
    const min = matlTargData.value[0].cuMin
    const max = matlTargData.value[0].cuMax
    if (max != 0 ? cuVal > max : false) {
        return 'red';
    } else if (cuVal < min) {
        return 'green';
    }
}
const getPFontColor = (pVal) => {
    const min = matlTargData.value[0].pMin
    const max = matlTargData.value[0].pMax
    if (max != 0 ? pVal > max : false) {
        return 'red';
    } else if (pVal < min) {
        return 'green';
    }
}
const getTio2FontColor = (tio2Val) => {
    const min = matlTargData.value[0].tio2Min
    const max = matlTargData.value[0].tio2Max
    if (max != 0 ? tio2Val > max : false) {
        return 'red';
    } else if (tio2Val < min) {
        return 'green';
    }
}
const getCuSiO2Color = (sio2Val) => {
    const min = matlTargData.value[0].sio2Min
    const max = matlTargData.value[0].sio2Max
    if (max != 0 ? sio2Val > max : false) {
        return 'red';
    } else if (sio2Val < min) {
        return 'green';
    }
}
const getMgOFontColor = (mgoVal) => {
    const min = matlTargData.value[0].mgoMin
    const max = matlTargData.value[0].mgoMax
    if (max != 0 ? mgoVal > max : false) {
        return 'red';
    } else if (mgoVal < min) {
        return 'green';
    }
}
const getCaOFontColor = (caoVal) => {
    const min = matlTargData.value[0].caoMin
    const max = matlTargData.value[0].caoMax
    if (max != 0 ? caoVal > max : false) {
        return 'red';
    } else if (caoVal < min) {
        return 'green';
    }
}
const getAl2O3FontColor = (al2o3Val) => {
    const min = matlTargData.value[0].al2o3Min
    const max = matlTargData.value[0].al2o3Max
    if (max != 0 ? al2o3Val > max : false) {
        return 'red';
    } else if (al2o3Val < min) {
        return 'green';
    }
}
const getMnFontColor = (mnVal) => {
    const min = matlTargData.value[0].mnMin
    const max = matlTargData.value[0].mnMax
    if (max != 0 ? mnVal > max : false) {
        return 'red';
    } else if (mnVal < min) {
        return 'green';
    }
}
const getZnFontColor = (znVal) => {
    const min = matlTargData.value[0].znMin
    const max = matlTargData.value[0].znMax
    if (max != 0 ? znVal > max : false) {
        return 'red';
    } else if (znVal < min) {
        return 'green';
    }
}


//外矿化学成分表查询
const chemQuery = ref({
})
const chemTableData = ref([])
const chemHandleSearch = () => {
    chemCurrentPage.value = 1
    getChemTableData()
}
const chemCurrentPage = ref(1)
const chemTotalRows = ref(0)
const chemPageSizes = ref([5, 10, 20, 30, 40])
const chemPageSize = ref(5)
const chemHandleSizeChange = (val) => {
    chemPageSize.value = val
    getChemTableData()
}
const chemHandleCurrentChange = (val) => {
    chemCurrentPage.value = val
    getChemTableData()
}
const getChemTableData = () => {
    var url = 'pla/PropMatlChem/query'
    var param = {
        page: chemCurrentPage.value,
        rows: chemPageSize.value,
        params: JSON.stringify(chemQuery.value)
    }
    proxy.$axios.get(url, param).then(response => {
        if (response.data.code == '0') {
            chemTableData.value = response.data.data.records
            chemTotalRows.value = response.data.data.total
            tableColumnsValue()
        } else {
            ElMessage.error('操作失败！' + response.data.msg)
        }
    })
}


/**
 *   查询
 */




const query = ref({
})
const tableData = ref([])
const handleSearch = () => {
    currentPage.value = 1
    getTableData()
}

const getTableData = () => {
    var url = 'pla/PropMatlManu/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({
    matlProp1: '',
    matlProp2: '',
    matlProp3: '',
    matlProp4: '',
    matlProp5: '',
    matlProp6: '',
    matlProp7: '',
    matlProp8: '',
    matlProp9: '',
    matlProp10: ''
})
const ruleFormRef = ref()
const rules = reactive({
    matlProp1: [{ required: true, message: '请输入外矿1配比', trigger: 'change' | 'blur' },
    { pattern: /^[0-9]$/, message: '请输入0-9的整数', trigger: 'blur' | 'change' }],
    matlProp2: [{ required: true, message: '请输入外矿2配比', trigger: 'change' | 'blur' },
    { pattern: /^[0-9]$/, message: '请输入0-9的整数', trigger: 'blur' | 'change' }],
    matlProp3: [{ required: true, message: '请输入外矿3配比', trigger: 'change' | 'blur' },
    { pattern: /^[0-9]$/, message: '请输入0-9的整数', trigger: 'blur' | 'change' }],
    matlProp4: [{ required: true, message: '请输入外矿4配比', trigger: 'change' | 'blur' },
    { pattern: /^[0-9]$/, message: '请输入0-9的整数', trigger: 'blur' | 'change' }],
    matlProp5: [{ required: true, message: '请输入外矿5配比', trigger: 'change' | 'blur' },
    { pattern: /^[0-9]$/, message: '请输入0-9的整数', trigger: 'blur' | 'change' }],
    matlProp6: [{ required: true, message: '请输入外矿6配比', trigger: 'change' | 'blur' },
    { pattern: /^[0-9]$/, message: '请输入0-9的整数', trigger: 'blur' | 'change' }],
    matlProp7: [{ required: true, message: '请输入外矿7配比', trigger: 'change' | 'blur' },
    { pattern: /^[0-9]$/, message: '请输入0-9的整数', trigger: 'blur' | 'change' }],
    matlProp8: [{ required: true, message: '请输入外矿8配比', trigger: 'change' | 'blur' },
    { pattern: /^[0-9]$/, message: '请输入0-9的整数', trigger: 'blur' | 'change' }],
    matlProp9: [{ required: true, message: '请输入外矿9配比', trigger: 'change' | 'blur' },
    { pattern: /^[0-9]$/, message: '请输入0-9的整数', trigger: 'blur' | 'change' }],
    matlProp10: [{ required: true, message: '请输入外矿10配比', trigger: 'change' | 'blur' },
    { pattern: /^[0-9]$/, message: '请输入0-9的整数', trigger: 'blur' | 'change' }]
})

const dialogName = ref('')
const handleAdd = () => {
    form.value = {
        matlProp1: '',
        matlProp2: '',
        matlProp3: '',
        matlProp4: '',
        matlProp5: '',
        matlProp6: '',
        matlProp7: '',
        matlProp8: '',
        matlProp9: '',
        matlProp10: ''
    }
    if (ruleFormRef.value) {
        ruleFormRef.value.resetFields()
    }
    dialogName.value = '新增'
    dialogVisible.value = true
}
/**
 * 新增
 */


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

const openDialog = () => {
}

const handleSave = (ruleFormRef) => {
    ruleFormRef.validate((valid, fields) => {
        if (valid) {
            var url = 'pla/PropMatlManu/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/PropMatlManu/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/PropMatlManu/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])
}


</script>

<style></style>