<template>
    <div>
        <el-row style="margin-top: 5px;">
            <el-button type="primary" plain @click="handleSearch">查询</el-button>
        </el-row>
        <el-table :data="tableData" border highlight-current-row @selection-change="handleSelectionChange"
            style="margin-top: 5px;">
            <!-- <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="id" label="ID" width="120" header-align="center" align="center"
                    show-overflow-tooltip>
                </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="80" header-align="center" align="right"
                show-overflow-tooltip>
            </el-table-column>
            <el-table-column v-if="true" prop="sVal" label="S" width="80" header-align="center" align="right"
                show-overflow-tooltip>
            </el-table-column>
            <el-table-column v-if="true" prop="cuVal" label="Cu" width="80" header-align="center" align="right"
                show-overflow-tooltip>
            </el-table-column>
            <el-table-column v-if="true" prop="pVal" label="P" width="80" header-align="center" align="right"
                show-overflow-tooltip>
            </el-table-column>
            <el-table-column v-if="true" prop="tio2Val" label="TiO2" width="80" header-align="center" align="right"
                show-overflow-tooltip>
            </el-table-column>
            <el-table-column v-if="true" prop="sio2Val" label="SiO2" width="80" header-align="center" align="right"
                show-overflow-tooltip>
            </el-table-column>
            <el-table-column v-if="true" prop="mgoVal" label="MgO" width="80" header-align="center" align="right"
                show-overflow-tooltip>
            </el-table-column>
            <el-table-column v-if="true" prop="caoVal" label="CaO" width="80" header-align="center" align="right"
                show-overflow-tooltip>
            </el-table-column>
            <el-table-column v-if="true" prop="al2o3Val" label="Al2O3" width="80" header-align="center" align="right"
                show-overflow-tooltip>
            </el-table-column>
            <el-table-column v-if="true" prop="feoVal" label="FeO" width="80" header-align="center" align="right"
                show-overflow-tooltip>
            </el-table-column>
            <el-table-column v-if="true" prop="mnVal" label="Mn" width="80" header-align="center" align="right"
                show-overflow-tooltip>
            </el-table-column>
            <el-table-column v-if="true" prop="znVal" label="Zn" width="80" header-align="center" align="right"
                show-overflow-tooltip>
            </el-table-column>
            <el-table-column v-if="true" prop="kVal" label="K" width="80" header-align="center" align="right"
                show-overflow-tooltip>
            </el-table-column>
            <el-table-column v-if="true" prop="naVal" label="Na" width="80" header-align="center" align="right"
                show-overflow-tooltip>
            </el-table-column>
            <el-table-column v-if="true" prop="selfMelt" label="自熔度" width="80" header-align="center" align="right"
                show-overflow-tooltip>
            </el-table-column>
            <el-table-column v-if="true" prop="prodRati" label="产率" width="90" header-align="center" align="right"
                show-overflow-tooltip>
            </el-table-column>
            <el-table-column v-if="true" prop="magnRati" label="磁选管产率" width="100" header-align="center" align="right"
                show-overflow-tooltip>
            </el-table-column>
            <el-table-column v-if="true" prop="tfeRcvy" label="Fe回收率" width="90" header-align="center" align="right"
                show-overflow-tooltip>
            </el-table-column>
            <el-table-column v-if="true" prop="sRcvy" label="S回收率" width="90" header-align="center" align="right"
                show-overflow-tooltip>
            </el-table-column>
            <el-table-column v-if="true" prop="cuRcvy" label="Cu回收率" width="90" header-align="center" align="right"
                show-overflow-tooltip>
            </el-table-column>
            <el-table-column v-if="true" prop="beneRati" label="选比" width="90" header-align="center" align="right"
                show-overflow-tooltip>
            </el-table-column>


            <el-table-column label="操作" header-align="center" align="center" width="170px" fixed="right">
                <template #default="scope">
                    <el-button plain type="warning" @click="addHandleEdit(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: 5px;">
        </el-pagination>

        
    </div>
</template>

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

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

const {
    proxy
} = getCurrentInstance()

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


const addHandleEdit = (row) => {
    if(row.beneRati == '' || row.beneRati == null || row.beneRati == undefined || row.beneRati == 0){
        emit('handleSave', row);
    }else{
        var a = row;
        a.tfeVal = parseFloat((a.tfeVal/a.beneRati).toFixed(3))
        a.sVal = parseFloat((a.sVal/a.beneRati).toFixed(3))
        a.cuVal = parseFloat((a.cuVal/a.beneRati).toFixed(3))
        a.pVal = parseFloat((a.pVal/a.beneRati).toFixed(3))
        a.tio2Val = parseFloat((a.tio2Val/a.beneRati).toFixed(3))
        a.sio2Val = parseFloat((a.sio2Val/a.beneRati).toFixed(3))
        a.mgoVal = parseFloat((a.mgoVal/a.beneRati).toFixed(3))
        a.caoVal = parseFloat((a.caoVal/a.beneRati).toFixed(3))
        a.al2o3Val = parseFloat((a.al2o3Val/a.beneRati).toFixed(3))
        a.feoVal = parseFloat((a.feoVal/a.beneRati).toFixed(3))
        a.mnVal = parseFloat((a.mnVal/a.beneRati).toFixed(3))
        a.znVal = parseFloat((a.znVal/a.beneRati).toFixed(3))
        a.kVal = parseFloat((a.kVal/a.beneRati).toFixed(3))
        a.naVal = parseFloat((a.naVal/a.beneRati).toFixed(3))
        console.log(a)
        emit('handleSave', a);
    }
}
const emit = defineEmits(['handleSave']);

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

const props = defineProps({
    tabsValue: {
        type: Array,
    },
})


/**
 *   查询
 */




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

const getTableData = () => {
    // if (props.tabsValue.length != 1) {
    //     ElMessage({
    //         type: 'warning',
    //         message: '请选择一条外矿试验数据!'
    //     })
    //     return
    // }
    // query.value.pid = props.tabsValue[0].id
    var url = 'pla/OreTestFmbeRslt2/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') {
            console.log(response.data.data.records)
            tableData.value = response.data.data.records
            console.log(tableData.value)
            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()
}
/**
 * 分页
 */



</script>

<style></style>