<template> <!-- 地表水体水质达标 --> <div class="publicContainer" v-if="back"> <el-form :model="queryParams" ref="queryRef" :inline="true" v-show="showSearch"> <el-form-item label="考核水体:" prop="riverId"> <el-select clearable v-model="queryParams.riverId" class="m-2" placeholder="请选择" size="mini"> <el-option v-for="item in responseAA" :key="item.id" :label="item.riverName" :value="Number(item.id)" /> </el-select> </el-form-item> <el-form-item label="采样年份:" prop="sampleYear"> <el-date-picker v-model="queryParams.sampleYear" type="year" placeholder="请选择" format="YYYY" value-format="YYYY" @change="change" /> </el-form-item> <el-form-item label="评价结果:" prop="blackOdor"> <el-select clearable v-model="queryParams.blackOdor" class="m-2" placeholder="请选择" size="mini"> <el-option v-for="item in black_odor_level" :key="item.value" :label="item.label" :value="item.value" /> </el-select> </el-form-item> <el-form-item> <el-button type="primary" icon="Search" @click="searchData">搜索</el-button> <el-button icon="Refresh" @click="resetData">重置</el-button> <el-button icon="CaretLeft" @click="resect" class="zbBtn"> 返回</el-button> <el-button icon="Plus" type="success" @click="addData">新增</el-button> </el-form-item> </el-form> <!-- 表格 --> <el-table :data="tableData" v-loading="tableLoading" :max-height="650"> <el-table-column type="index" width="55" label="序号" /> <el-table-column v-for="item in informationDate" :label="item.value" :prop="item.key"> <template #default="scope" v-if="item.key == 'blackOdorName'"> <span :style="{ color: scope.row.blackOdorName == '无黑臭' ? 'greenyellow' : scope.row.blackOdorName == '轻度黑臭' ? ' #419fff' : scope.row.blackOdorName == '中度黑臭' ? 'orange' : scope.row.blackOdorName == '重度黑臭' ? 'red' : '', }" > {{ scope.row.blackOdorName == '无黑臭' ? '无黑臭' : scope.row.blackOdorName == '轻度黑臭' ? '轻度黑臭' : scope.row.blackOdorName == '中度黑臭' ? '中度黑臭' : scope.row.blackOdorName == '重度黑臭' ? '重度黑臭' : '' }} </span> </template> </el-table-column> <el-table-column label="操作" show-overflow-tooltip width="200"> <template #default="{ row }"> <el-button type="primary" link @click="checkDetail(row)">详情</el-button> <el-button type="primary" link @click="editData(row)">修改</el-button> <el-button type="danger" link @click="deleteData(row)">删除</el-button> </template> </el-table-column> </el-table> <!-- 分页 --> <pagination v-show="total > 0" :total="total" v-model:page="queryParams.pageNum" v-model:limit="queryParams.pageSize" @pagination="getDataList" /> <!-- 添加 修改 查看彈框 --> <el-dialog :title="dialogTitle" v-model="showDialog" width="70%" :close-on-click-modal="false"> <el-form ref="ruleForm" :model="formData" :rules="formRules" label-width="auto" :disabled="isDisab"> <el-row> <el-form-item label="考核水体:" prop="riverId" style="width: 45%"> <el-select clearable v-model="formData.riverId" class="m-2" placeholder="请选择" size="mini" style="width: 100%"> <el-option v-for="item in responseAA" :key="item.id" :label="item.riverName" :value="Number(item.id)" /> </el-select> </el-form-item> <el-form-item label="采样时间:" prop="sampleTime" style="width: 45%"> <el-date-picker style="width: 100%" clearable format="YYYY-MM-DD" value-format="YYYY-MM-DD" v-model="formData.sampleTime" type="date" /> </el-form-item> <el-form-item label="采样点:" prop="sampleLocation" style="width: 45%"> <el-input v-model="formData.sampleLocation" placeholder="请输入" style="width: 100%" clearable /> </el-form-item> <el-form-item v-for="item in Dbssz" :label="item.sampleFactorName" :prop="item.sampleFactor" style="width: 45%"> <el-input-number v-model="formData[item.sampleFactor]" placeholder="请输入" clearable controls-position="right" style="width: 400px" /> </el-form-item> <el-form-item label="黑臭程度:" prop="blackOdorName" style="width: 45%" v-if="hiddentext"> <div :style="{ color: formData.blackOdorName == '无黑臭' ? 'greenyellow' : formData.blackOdorName == '轻度黑臭' ? ' #419fff' : formData.blackOdorName == '中度黑臭' ? 'orange' : formData.blackOdorName == '重度黑臭' ? 'red' : '', }" > {{ formData.blackOdorName == '无黑臭' ? '无黑臭' : formData.blackOdorName == '轻度黑臭' ? '轻度黑臭' : formData.blackOdorName == '中度黑臭' ? '中度黑臭' : formData.blackOdorName == '重度黑臭' ? '重度黑臭' : '' }} </div> </el-form-item> </el-row> </el-form> <template #footer> <div class="dialog-footer"> <el-button type="primary" @click="submitForm" v-show="!isDisab">保 存</el-button> <el-button @click="cancel">关闭</el-button> </div> </template> </el-dialog> </div> <waterquality v-else /> </template> <script setup> import { blackOdorUserId, riverInfoWater, blackOdorAdd, blackOdorDelete, sampleConfigconfiguration, blackOdorinformation, blackOdorpaging, blackOdorEdit, } from '@/api/spongePerformance/surfaceWater'; const { proxy } = getCurrentInstance(); const { hc_sample_factor, sample_type, black_odor_level } = proxy.useDict('hc_sample_factor', 'sample_type', 'black_odor_level'); import { defineEmits } from 'vue'; const isDisab = ref(false); const isDisatext = ref(false); const showDialog = ref(false); const showSearch = ref(true); const tableLoading = ref(true); const hiddentext = ref(false); const back = ref(true); const responseAA = ref([]); const total = ref(0); const dialogTitle = ref(''); const tableData = ref([]); const Dbssz = ref([]); const informationDate = ref([]); const emits = defineEmits(); const { paramsData } = defineProps(['paramsData']); const AllData = reactive({ formData: { configs: [], }, queryParams: { pageNum: 1, pageSize: 10, sampleTime: '', riverId: '', blackOdor: '', sampleYear: '', sampleLocation: '', }, formRules: { riverId: [{ required: true, message: '请选择', trigger: 'blur' }], sampleTime: [{ required: true, message: '请选择', trigger: 'blur' }], }, }); const { queryParams, formData, formRules } = toRefs(AllData); /** 表单重置 */ function resetForm() { formData.value = { riverId: undefined, sampleYear: undefined, sampleTime: undefined, blackOdor: undefined, sampleLocation: undefined, riverType: 'black_odor', }; proxy.resetForm('ruleForm'); } function resect() { emits('searchClick', 0); } /** 新增按钮操作 */ function addData() { resetForm(); hiddentext.value = false; isDisab.value = false; showDialog.value = true; dialogTitle.value = '新增检测记录'; } //搜索 function searchData() { queryParams.value.pageNum = 1; getDataList(); } //重置 function resetData() { proxy.resetForm('queryRef'); searchData(); } // 获取下拉框数据 const getSelData = async () => { let params = { riverType: 'black_odor', }; riverInfoWater(params).then(response => { if (response.code == 200) { responseAA.value = response.data; } }); }; // 新增中的 动态数据 const Dbsszconfiguration = async () => { let params = { sampleType: 'hcst', }; sampleConfigconfiguration(params).then(response => { if (response.code == 200) { Dbssz.value = response.data; Dbssz.value.forEach(item => { formRules.value[item.sampleFactor] = [{ required: true, message: '请输入', trigger: 'blur', type: 'number' }]; }); console.log(formRules.value); } }); }; //地水质采样信息动态表头 const information = async () => { blackOdorinformation().then(res => { if (res.code == 200) { informationDate.value = res.data; } }); }; /** 查询列表 */ const getDataList = async () => { tableLoading.value = true; const res = await blackOdorpaging(queryParams.value); tableData.value = res.data.records; total.value = res.data.total || 0; tableLoading.value = false; }; /** 新增弹框 修改弹框 提交按钮 */ async function submitForm() { proxy.$refs['ruleForm'].validate(valid => { if (valid) { formData.value.configs = []; let obj = []; Dbssz.value.forEach(k => { obj.push(k.sampleFactor); }); obj.forEach(element => { formData.value.configs.push({ factor: element, value: formData.value[element], }); delete formData.value[element]; }); console.log(formData.value, 'formData.value.configs'); if (formData.value.id != undefined) { blackOdorEdit(formData.value).then(() => { console.log(formData.value, 'formData.value'); proxy.$modal.msgSuccess('修改成功'); showDialog.value = false; getDataList(); }); } else { blackOdorAdd(formData.value).then(() => { console.log(formData.value, 'formData.valueformData.valueformData.value'); proxy.$modal.msgSuccess('新增成功'); showDialog.value = false; getDataList(); }); } } }); } //表格修改 function editData(row) { formData.value = { ...row }; isDisab.value = false; isDisatext.value = true; showDialog.value = true; dialogTitle.value = '修改检测记录'; hiddentext.value = true; console.log(row, 'row'); } // 表格删除 function deleteData(row) { proxy.$modal .confirm('是否确认删除?') .then(async () => { const res = await blackOdorDelete(row.id); if (res?.code !== 200) return; proxy.$modal.msgSuccess('操作成功!'); getDataList(); }) .catch(() => {}); } //详情按钮 function checkDetail(row) { dialogTitle.value = '查看检测记录'; isDisab.value = true; showDialog.value = true; isDisatext.value = true; hiddentext.value = true; formData.value = { ...row }; } /** 取消按钮 */ function cancel() { showDialog.value = false; resetForm(); } function change(val) { console.log(val, 'val'); queryParams.value.sampleYear = val; } onMounted(() => { queryParams.value.sampleYear = paramsData?.examineYear || ''; getDataList(); getSelData(); Dbsszconfiguration(); information(); }); </script> <style scoped lang="scss"></style>