<template>
    <div>
        <SearchBox ref="searchBarRef" :formName="search" :formData="query" @showPopupUser="showPop" showResetButton
            @reset="reset" />
        <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="prodDt" label="生产日期" width="120" header-align="center" align="center"
                    show-overflow-tooltip>
                </el-table-column>
                <el-table-column v-if="true" prop="prodShift" label="班次" width="80" header-align="center" align="center"
                    show-overflow-tooltip>
                    <!-- <template #default="scope">
                        <span v-if="scope.row.prodShift == 1">夜班</span>
                        <span v-else-if="scope.row.prodShift == 2">白班</span>
                        <span v-else-if="scope.row.prodShift == 3">中班</span>
                    </template> -->
                </el-table-column>

                <el-table-column v-if="true" prop="ballmQty1" label="1#球磨机处理量" width="130" header-align="center"
                    align="right" show-overflow-tooltip>
                </el-table-column>
                <el-table-column v-if="true" prop="ballmQty2" label="2#球磨机处理量" width="130" header-align="center"
                    align="right" show-overflow-tooltip>
                </el-table-column>
                <el-table-column v-if="true" prop="ballmQty3" label="3#球磨机处理量" width="130" header-align="center"
                    align="right" show-overflow-tooltip>
                </el-table-column>
                <el-table-column v-if="true" prop="ballmQty4" label="4#球磨机处理量" width="130" header-align="center"
                    align="right" show-overflow-tooltip>
                </el-table-column>
                <el-table-column v-if="true" prop="ballmQty5" label="5#球磨机处理量" width="130" header-align="center"
                    align="right" show-overflow-tooltip>
                </el-table-column>
                <el-table-column v-if="true" prop="ballmQty6" label="6#球磨机处理量" width="130" header-align="center"
                    align="right" show-overflow-tooltip>
                </el-table-column>
                <el-table-column v-if="true" prop="ballmQty" label="球磨机入磨总量" width="125"
                    header-align="center" align="right" show-overflow-tooltip>
                </el-table-column>
                <el-table-column v-if="true" prop="imp1" label="1#皮带处理量" width="120" header-align="center" align="right"
                    show-overflow-tooltip>
                </el-table-column>
                <el-table-column v-if="true" prop="imp2" label="2#皮带处理量" width="120" header-align="center" align="right"
                    show-overflow-tooltip>
                </el-table-column>
                <el-table-column v-if="true" prop="imp3" label="3#皮带处理量" width="120" header-align="center" align="right"
                    show-overflow-tooltip>
                </el-table-column>
                <el-table-column label="操作" header-align="center" align="center" width="160px" 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" draggable :title="dialogName" v-model="dialogVisible" width="1200px"
            top="5vh" @open="openDialog">
            <el-form :model="form" label-width="80px" label-position="right" inline ref="ruleFormRef" :rules="rules">
                <el-card style=" margin-bottom: 10px; height: 70px;">
                    <el-row :gutter="60">
                        <el-col span="6">
                            <el-form-item label="生产日期" prop="prodDt">
                                <el-date-picker v-model="form.prodDt" type="date" style="width: 190px;"
                                    value-format="YYYY-MM-DD" format="YYYY-MM-DD" ></el-date-picker>
                            </el-form-item>
                        </el-col>
                        <el-col span="6">
                            <el-form-item label="班次" prop="prodShift">
                                <el-select v-model="form.prodShift" placeholder="请选择班次" style="width: 190px;"  >
                                    <el-option v-for="option in optionShiftList" :key="option.dicName"
                                        :label="option.dicName" :value="option.dicName" />
                                </el-select>
                            </el-form-item>
                        </el-col>
                        <el-col span="6">
                            <el-button plain type="warning" @click="queryQty">查看处理量</el-button>
                        </el-col>

                    </el-row>
                </el-card>
                <el-card style=" height: 380px;">

                    <el-row :gutter="60">
                        <el-col :span="1"></el-col>
                        <el-col :span="7">
                            <el-form-item label="1#球磨机处理量" style="white-space: nowrap;" prop="ballmQty1">
                                <el-input v-model="form.ballmQty1" clearable style="width: 120px" 
                                 @input="ballmQtyDry1Value"></el-input>
                            </el-form-item>
                        </el-col>
                        <el-col :span="7">
                            <el-form-item label="1#球磨机水分值" style="white-space: nowrap;" prop="ballmQty2">
                                <el-input v-model="form.ballmQtyS1"  style="width: 120px" disabled></el-input>
                            </el-form-item>
                        </el-col>
                        <el-col :span="7">
                            <el-form-item label="1#球磨机折干量" style="white-space: nowrap;" prop="ballmQty3">
                                <el-input v-model="form.ballmQtyDry1" disabled style="width: 120px"></el-input>
                            </el-form-item>
                        </el-col>
                    </el-row>
                    <el-row :gutter="60">
                        <el-col :span="1"></el-col>
                        <el-col :span="7">
                            <el-form-item label="2#球磨机处理量" style="white-space: nowrap;" prop="ballmQty1">
                                <el-input v-model="form.ballmQty2" clearable style="width: 120px" @input="ballmQtyDry2Value"></el-input>
                            </el-form-item>
                        </el-col>
                        <el-col :span="7">
                            <el-form-item label="2#球磨机水分值" style="white-space: nowrap;" prop="ballmQty2">
                                <el-input v-model="form.ballmQtyS2" disabled style="width: 120px"></el-input>
                            </el-form-item>
                        </el-col>
                        <el-col :span="7">
                            <el-form-item label="2#球磨机折干量" style="white-space: nowrap;" prop="ballmQty3">
                                <el-input v-model="form.ballmQtyDry2" disabled style="width: 120px"></el-input>
                            </el-form-item>
                        </el-col>
                    </el-row>
                    <el-row :gutter="60">
                        <el-col :span="1"></el-col>
                        <el-col :span="7">
                            <el-form-item label="3#球磨机处理量" style="white-space: nowrap;" prop="ballmQty1">
                                <el-input v-model="form.ballmQty3" clearable style="width: 120px" @input="ballmQtyDry3Value"></el-input>
                            </el-form-item>
                        </el-col>
                        <el-col :span="7">
                            <el-form-item label="3#球磨机水分值" style="white-space: nowrap;" prop="ballmQty2">
                                <el-input v-model="form.ballmQtyS3" disabled style="width: 120px"></el-input>
                            </el-form-item>
                        </el-col>
                        <el-col :span="7">
                            <el-form-item label="3#球磨机折干量" style="white-space: nowrap;" prop="ballmQty3">
                                <el-input v-model="form.ballmQtyDry3" disabled style="width: 120px"></el-input>
                            </el-form-item>
                        </el-col>
                    </el-row>
                    <el-row :gutter="60">
                        <el-col :span="1"></el-col>
                        <el-col :span="7">
                            <el-form-item label="4#球磨机处理量" style="white-space: nowrap;" prop="ballmQty1">
                                <el-input v-model="form.ballmQty4" clearable style="width: 120px" @input="ballmQtyDry4Value"></el-input>
                            </el-form-item>
                        </el-col>
                        <el-col :span="7">
                            <el-form-item label="4#球磨机水分值" style="white-space: nowrap;" prop="ballmQty2">
                                <el-input v-model="form.ballmQtyS4" disabled style="width: 120px"></el-input>
                            </el-form-item>
                        </el-col>
                        <el-col :span="7">
                            <el-form-item label="4#球磨机折干量" style="white-space: nowrap;" prop="ballmQty3">
                                <el-input v-model="form.ballmQtyDry4" disabled style="width: 120px"></el-input>
                            </el-form-item>
                        </el-col>
                    </el-row>
                    <el-row :gutter="60">
                        <el-col :span="1"></el-col>
                        <el-col :span="7">
                            <el-form-item label="5#球磨机处理量" style="white-space: nowrap;" prop="ballmQty1">
                                <el-input v-model="form.ballmQty5" clearable style="width: 120px" @input="ballmQtyDry5Value"></el-input>
                            </el-form-item>
                        </el-col>
                        <el-col :span="7">
                            <el-form-item label="5#球磨机水分值" style="white-space: nowrap;" prop="ballmQty2">
                                <el-input v-model="form.ballmQtyS5" disabled style="width: 120px"></el-input>
                            </el-form-item>
                        </el-col>
                        <el-col :span="7">
                            <el-form-item label="5#球磨机折干量" style="white-space: nowrap;" prop="ballmQty3">
                                <el-input v-model="form.ballmQtyDry5" disabled style="width: 120px"></el-input>
                            </el-form-item>
                        </el-col>
                    </el-row>
                    <el-row :gutter="60">
                        <el-col :span="1"></el-col>
                        <el-col :span="7">
                            <el-form-item label="6#球磨机处理量" style="white-space: nowrap;" prop="ballmQty1">
                                <el-input v-model="form.ballmQty6" clearable style="width: 120px" @input="ballmQtyDry6Value"></el-input>
                            </el-form-item>
                        </el-col>
                        <el-col :span="7">
                            <el-form-item label="6#球磨机水分值" style="white-space: nowrap;" prop="ballmQty2">
                                <el-input v-model="form.ballmQtyS6" disabled style="width: 120px"></el-input>
                            </el-form-item>
                        </el-col>
                        <el-col :span="7">
                            <el-form-item label="6#球磨机折干量" style="white-space: nowrap;" prop="ballmQty3">
                                <el-input v-model="form.ballmQtyDry6" disabled style="width: 120px"></el-input>
                            </el-form-item>
                        </el-col>
                    </el-row>
                    <el-row :gutter="60">
                        <el-col :span="1"></el-col>
                        <el-col :span="7">
                            <el-form-item label="1#皮带处理量" style="white-space: nowrap;" prop="ballmQty1">
                                <el-input v-model="form.imp1" clearable style="width: 120px" @input="ballmQtyDry6Value"></el-input>
                            </el-form-item>
                        </el-col>
                        <el-col :span="7">
                            <el-form-item label="2#皮带处理量" style="white-space: nowrap;" prop="ballmQty2">
                                <el-input v-model="form.imp2" clearable style="width: 120px"></el-input>
                            </el-form-item>
                        </el-col>
                        <el-col :span="7">
                            <el-form-item label="3#皮带处理量" style="white-space: nowrap;" prop="ballmQty3">
                                <el-input v-model="form.imp3" clearable style="width: 120px"></el-input>
                            </el-form-item>
                        </el-col>
                    </el-row>
                    <!-- <el-row :gutter="60">
                        <el-col :span="1"></el-col>
                        <el-col :span="7">
                            <el-form-item label="粉矿量" style="white-space: nowrap;" prop="ballmQty4">
                                <el-input v-model="form.fineQty" clearable style="width: 120px"></el-input>
                            </el-form-item>
                        </el-col>
                    </el-row> -->
                </el-card>
            </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
} from 'vue'

const {
    proxy
} = getCurrentInstance()

import SearchBox from '@/components/SearchBox.vue'
const searchBarRef = ref(null)


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

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

// 数据字典
const optionShiftList = ref([])
const getDic = () => {
    var url = 'framework/Common/querySelector'
    var param = {
        type: 'PRD_OPER_SHIFT'
    }
    proxy.$axios.get(url, param).then(response => {
        if (response.data.code == '0') {
            optionShiftList.value = response.data.data
        } else {
            ElMessage.error('操作失败！' + response.data.msg)
        }
    })
}

//根据生产日期，班次查询处理量
const queryQty = () => {
    if (form.value.prodDt != '' && form.value.prodDt != null
        && form.value.prodDt != undefined && form.value.prodShift != ''
        && form.value.prodShift != null && form.value.prodShift != undefined) {
        console.log(form.value)
        var url = 'prd/ReptDaily/queryQty'
        var param = {
            prodDt: form.value.prodDt,
            prodShift: form.value.prodShift
        }
        proxy.$axios.get(url, param).then(response => {
            if (response.data.code == '0') {
                if(response.data.data == '' || response.data.data == null || response.data.data == undefined || response.data.data.length == 0){
                        console.log('查询失败！')
                        ElMessage.error('未查询到数据！' )
                }else{
                    let id = form.value.id
                    form.value.ballmQty1 = response.data.data[0].ballmQty1
                    form.value.ballmQty2 = response.data.data[0].ballmQty2
                    form.value.ballmQty3 = response.data.data[0].ballmQty3
                    form.value.ballmQty4 = response.data.data[0].ballmQty4
                    form.value.ballmQty5 = response.data.data[0].ballmQty5
                    form.value.ballmQty6 = response.data.data[0].ballmQty6
                    form.value.imp1 = response.data.data[0].imp1
                    form.value.imp2 = response.data.data[0].imp2
                    form.value.imp3 = response.data.data[0].imp3
                    form.value.id = id
                    ballmQtyDry1Value()
                    ballmQtyDry2Value()
                    ballmQtyDry3Value()
                    ballmQtyDry4Value()
                    ballmQtyDry5Value()
                    ballmQtyDry6Value()
                }
            } else {
                ElMessage.error('查询失败！' + response.data.msg)
            }
        })
    }else{
        ElMessage.error('查询失败！请选择生产日期和班次')
    }

}

const getWaterData = () => {
    var url = 'pla/PropWkSet/query'
    var param = {
        page: 1,
        rows: 99999,
        params: JSON.stringify({itemCd: 'XKC_'})
    }
    proxy.$axios.get(url, param).then(response => {
        if (response.data.code == '0') {
            const a = response.data.data.records
            const map = new Map();
            a.forEach(item => {
                map.set(item.itemCd, item.mois)
            })
            form.value.ballmQtyS1 = map.get('XKC_001')
            form.value.ballmQtyS2 = map.get('XKC_002')
            form.value.ballmQtyS3 = map.get('XKC_003')
            form.value.ballmQtyS4 = map.get('XKC_004')
            form.value.ballmQtyS5 = map.get('XKC_005')
            form.value.ballmQtyS6 = map.get('XKC_006')

        } else {
            ElMessage.error('操作失败！' + response.data.msg)
        }
    })
}
const ballmQtyDry1Value = () => {
    let s = 0
    if(form.value.ballmQtyS1 != '' && form.value.ballmQtyS1 != null && form.value.ballmQtyS1 != undefined){
        s = parseFloat(form.value.ballmQtyS1)
    }
    if(form.value.ballmQty1 != '' && form.value.ballmQty1 != null && form.value.ballmQty1 != undefined){
        form.value.ballmQtyDry1 = Number((parseFloat(form.value.ballmQty1) * (1-s*0.01)).toFixed(7))
    }else{
        form.value.ballmQtyDry1 = 0
    }
}

const ballmQtyDry2Value = () => {
    let s = 0
    if(form.value.ballmQtyS2 != '' && form.value.ballmQtyS2 != null && form.value.ballmQtyS2 != undefined){
        s = parseFloat(form.value.ballmQtyS2)
    }
    if(form.value.ballmQty2 != '' && form.value.ballmQty2 != null && form.value.ballmQty2 != undefined){
        form.value.ballmQtyDry2 = Number((parseFloat(form.value.ballmQty2) * (1-s*0.01)).toFixed(7))
    }else{
        form.value.ballmQtyDry2 = 0
    }
}
const ballmQtyDry3Value = () => {
    let s = 0
    if(form.value.ballmQtyS3 != '' && form.value.ballmQtyS3 != null && form.value.ballmQtyS3 != undefined){
        s = parseFloat(form.value.ballmQtyS3)
    }
    if(form.value.ballmQty3 != '' && form.value.ballmQty3 != null && form.value.ballmQty3 != undefined){
        form.value.ballmQtyDry3 = Number((parseFloat(form.value.ballmQty3) * (1-s*0.01)).toFixed(7))
    }else{
        form.value.ballmQtyDry3 = 0
    }
}
const ballmQtyDry4Value = () => {
    let s = 0
    if(form.value.ballmQtyS4 != '' && form.value.ballmQtyS4 != null && form.value.ballmQtyS4 != undefined){
        s = parseFloat(form.value.ballmQtyS4)
    }
    if(form.value.ballmQty4 != '' && form.value.ballmQty4 != null && form.value.ballmQty4 != undefined){
        form.value.ballmQtyDry4 = Number((parseFloat(form.value.ballmQty4) * (1-s*0.01)).toFixed(7))
    }else{
        form.value.ballmQtyDry4 = 0
    }
}
const ballmQtyDry5Value = () => {
    let s = 0
    if(form.value.ballmQtyS5 != '' && form.value.ballmQtyS5 != null && form.value.ballmQtyS5 != undefined){
        s = parseFloat(form.value.ballmQtyS5)
    }
    if(form.value.ballmQty5 != '' && form.value.ballmQty5 != null && form.value.ballmQty5 != undefined){
        form.value.ballmQtyDry5 = Number((parseFloat(form.value.ballmQty5) * (1-s*0.01)).toFixed(7))
    }else{
        form.value.ballmQtyDry5 = 0
    }
}
const ballmQtyDry6Value = () => {
    let s = 0
    if(form.value.ballmQtyS6 != '' && form.value.ballmQtyS6 != null && form.value.ballmQtyS6 != undefined){
        s = parseFloat(form.value.ballmQtyS6)
    }
    if(form.value.ballmQty6 != '' && form.value.ballmQty6 != null && form.value.ballmQty6 != undefined){
        form.value.ballmQtyDry6 = Number((parseFloat(form.value.ballmQty6) * (1-s*0.01)).toFixed(7))
    }else{
        form.value.ballmQtyDry6 = 0
    }
}


/**
 *   查询
 */


const query = ref({
    // prodDt: proxy.$dayjs().format('YYYY-MM-DD'),
    prodDt: ['', ''],
    prodShift: '',
    prodGrp: ''
})
const tableData = ref([])
const handleSearch = () => {
    currentPage.value = 1
    getTableData()
}

const getTableData = () => {
    var url = 'prd/ReptDaily/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(20)
const handleSizeChange = (val) => {
    pageSize.value = val
    getTableData()
}
const handleCurrentChange = (val) => {
    currentPage.value = val
    getTableData()
}
/**
 * 分页
 */


/**
 * 新增
 */
const dialogVisible = ref(false)
const form = ref({
    prodDt: '',
    prodShift: '',
    // prodGrp: '',
    // wstonQty: '',
    // fstonQty: '',
    ballmQty: '',
    ballmQty1: '',
    ballmQty2: '',
    ballmQty3: '',
    ballmQty4: '',
    ballmQty5: '',
    ballmQty6: '',
    // crusQty: '',
    fineQty: ''
})
const ruleFormRef = ref()
const rules = reactive({
    prodDt: [{ required: true, message: '请输入生产日期', trigger: 'change' | 'blur' }],
    prodShift: [{ required: true, message: '请输入班次', trigger: 'change' | 'blur' }],
    // prodGrp: [{ required: true, message: '请输入班组', trigger: 'change' | 'blur' }],
    // wstonQty:[{ pattern: /^[0-9]{1,15}(\.[0-9]{1,10})?$/, message: '请输入有效的数字', trigger: 'blur' | 'change'}],
    // fstonQty:[{ pattern: /^[0-9]{1,15}(\.[0-9]{1,10})?$/, message: '请输入有效的数字', trigger: 'blur' | 'change'}],
    ballmQty1: [{ pattern: /^[0-9]{1,15}(\.[0-9]{1,10})?$/, message: '请输入有效的数字', trigger: 'blur' | 'change' }],
    ballmQty2: [{ pattern: /^[0-9]{1,15}(\.[0-9]{1,10})?$/, message: '请输入有效的数字', trigger: 'blur' | 'change' }],
    ballmQty3: [{ pattern: /^[0-9]{1,15}(\.[0-9]{1,10})?$/, message: '请输入有效的数字', trigger: 'blur' | 'change' }],
    ballmQty4: [{ pattern: /^[0-9]{1,15}(\.[0-9]{1,10})?$/, message: '请输入有效的数字', trigger: 'blur' | 'change' }],
    ballmQty5: [{ pattern: /^[0-9]{1,15}(\.[0-9]{1,10})?$/, message: '请输入有效的数字', trigger: 'blur' | 'change' }],
    ballmQty6: [{ pattern: /^[0-9]{1,15}(\.[0-9]{1,10})?$/, message: '请输入有效的数字', trigger: 'blur' | 'change' }],
})

const dialogName = ref('')
const handleAdd = () => {
    form.value = {
        prodDt: '',
        prodShift: '',
        // prodGrp: '',
        // wstonQty: '',
        // fstonQty: '',
        ballmQty: '',
        ballmQty1: '',
        ballmQty2: '',
        ballmQty3: '',
        ballmQty4: '',
        ballmQty5: '',
        ballmQty6: '',
        // crusQty: '',
        fineQty: ''
    }
    if (ruleFormRef.value) {
        ruleFormRef.value.resetFields()
    }
    dialogName.value = '新增'
    dialogVisible.value = true
}
/**
 * 新增
 */


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

const openDialog = () => {
    getWaterData()
}

const handleSave = (ruleFormRef) => {
    ruleFormRef.validate((valid, fields) => {
        if (valid) {
            var url = 'prd/ReptDaily/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 = 'prd/ReptDaily/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 = 'prd/ReptDaily/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 = () => {
    console.log('handleExport')
}

</script>

<style></style>