2025-05-05 23:25:15 +08:00
|
|
|
|
<script>
|
|
|
|
|
import {
|
|
|
|
|
addPrecipitationApi,
|
|
|
|
|
deletePrecipitation,
|
|
|
|
|
findAllPrecipitation,
|
|
|
|
|
findPrecipitationById,
|
2025-05-08 21:39:47 +08:00
|
|
|
|
updatePrecipitationApi,
|
|
|
|
|
} from "@@/apis/tables/diceke/Precipitation.ts";
|
2025-05-05 23:25:15 +08:00
|
|
|
|
|
|
|
|
|
export default {
|
|
|
|
|
data() {
|
|
|
|
|
return {
|
|
|
|
|
precipitationQuerry: null, // 电铲平台数据
|
|
|
|
|
updateprecipitationform: false,
|
2025-05-08 21:39:47 +08:00
|
|
|
|
precipitationform: null,
|
|
|
|
|
};
|
2025-05-05 23:25:15 +08:00
|
|
|
|
},
|
|
|
|
|
created() {
|
|
|
|
|
// 页面渲染之前执行,一般调用methods定义的方法
|
2025-05-08 21:39:47 +08:00
|
|
|
|
this.getList();
|
2025-05-05 23:25:15 +08:00
|
|
|
|
},
|
|
|
|
|
methods: {
|
|
|
|
|
getList() {
|
|
|
|
|
findAllPrecipitation().then((Response) => {
|
2025-05-08 21:39:47 +08:00
|
|
|
|
console.log(Response);
|
|
|
|
|
this.precipitationQuerry = Response.data.precipitation;
|
|
|
|
|
});
|
2025-05-05 23:25:15 +08:00
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
removeDataById(id) {
|
2025-05-08 21:39:47 +08:00
|
|
|
|
ElMessageBox.confirm("此操作将永久删除降水量记录,是否继续?", "提示", {
|
|
|
|
|
confirmButtonText: "确定",
|
|
|
|
|
cancelButtonText: "取消",
|
|
|
|
|
type: "warning",
|
|
|
|
|
})
|
2025-05-05 23:25:15 +08:00
|
|
|
|
.then(() => {
|
|
|
|
|
deletePrecipitation(id).then(() => {
|
|
|
|
|
// 删除成功
|
|
|
|
|
ElMessage({
|
|
|
|
|
type: "success",
|
2025-05-08 21:39:47 +08:00
|
|
|
|
message: "删除成功!",
|
|
|
|
|
});
|
2025-05-05 23:25:15 +08:00
|
|
|
|
// 重新加载列表
|
2025-05-08 21:39:47 +08:00
|
|
|
|
this.getList();
|
|
|
|
|
});
|
2025-05-05 23:25:15 +08:00
|
|
|
|
})
|
|
|
|
|
.catch(() => {
|
|
|
|
|
ElMessage({
|
|
|
|
|
type: "info",
|
2025-05-08 21:39:47 +08:00
|
|
|
|
message: "已取消删除",
|
|
|
|
|
});
|
|
|
|
|
});
|
2025-05-05 23:25:15 +08:00
|
|
|
|
},
|
|
|
|
|
handleAdd() {
|
2025-05-08 21:39:47 +08:00
|
|
|
|
this.isEdit = false; // 设置为新增操作
|
|
|
|
|
this.precipitationform = { plateRange: "" }; // 初始化为空数据
|
|
|
|
|
this.updateprecipitationform = true; // 显示弹窗
|
2025-05-05 23:25:15 +08:00
|
|
|
|
},
|
|
|
|
|
handleEdit(id) {
|
2025-05-08 21:39:47 +08:00
|
|
|
|
this.isEdit = true;
|
|
|
|
|
findPrecipitationById(id)
|
|
|
|
|
.then((Response) => {
|
|
|
|
|
this.precipitationform = Response.data.precipitationById;
|
|
|
|
|
console.log(this.precipitationform);
|
|
|
|
|
this.updateprecipitationform = true;
|
|
|
|
|
})
|
|
|
|
|
.catch(() => {
|
|
|
|
|
ElMessage.error("查询失败,请稍后重试");
|
|
|
|
|
});
|
2025-05-05 23:25:15 +08:00
|
|
|
|
},
|
|
|
|
|
formatMonth(dateTime) {
|
2025-05-08 21:39:47 +08:00
|
|
|
|
if (!dateTime) return "-";
|
|
|
|
|
return dateTime.slice(0, 7); // 直接截取 "yyyy-MM"
|
2025-05-05 23:25:15 +08:00
|
|
|
|
// 或用 dayjs(需安装):
|
|
|
|
|
// return dayjs(dateTime).format('YYYY-MM');
|
|
|
|
|
},
|
|
|
|
|
updatePrecipitation() {
|
|
|
|
|
if (this.isEdit) {
|
2025-05-08 21:39:47 +08:00
|
|
|
|
updatePrecipitationApi(this.precipitationform)
|
|
|
|
|
.then(() => {
|
|
|
|
|
ElMessage({
|
|
|
|
|
type: "success",
|
|
|
|
|
message: "修改成功!",
|
|
|
|
|
});
|
|
|
|
|
this.updateprecipitationform = false;
|
|
|
|
|
this.getList();
|
2025-05-05 23:25:15 +08:00
|
|
|
|
})
|
2025-05-08 21:39:47 +08:00
|
|
|
|
.catch(() => {
|
|
|
|
|
ElMessage.error("修改失败,请稍后重试");
|
|
|
|
|
});
|
2025-05-05 23:25:15 +08:00
|
|
|
|
} else {
|
2025-05-08 21:39:47 +08:00
|
|
|
|
addPrecipitationApi(this.precipitationform)
|
|
|
|
|
.then(() => {
|
|
|
|
|
ElMessage({
|
|
|
|
|
type: "success",
|
|
|
|
|
message: "新增成功!",
|
|
|
|
|
});
|
|
|
|
|
this.updateprecipitationform = false;
|
|
|
|
|
this.getList();
|
2025-05-05 23:25:15 +08:00
|
|
|
|
})
|
2025-05-08 21:39:47 +08:00
|
|
|
|
.catch(() => {
|
|
|
|
|
ElMessage.error("新增失败,请稍后重试");
|
|
|
|
|
});
|
2025-05-05 23:25:15 +08:00
|
|
|
|
}
|
2025-05-08 21:39:47 +08:00
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
};
|
2025-05-05 23:25:15 +08:00
|
|
|
|
</script>
|
|
|
|
|
|
|
|
|
|
<template>
|
|
|
|
|
<div class="app-container">
|
2025-05-08 21:39:47 +08:00
|
|
|
|
<div style="margin-bottom: 20px">
|
2025-05-05 23:25:15 +08:00
|
|
|
|
<el-button type="primary" @click="handleAdd" icon="el-icon-plus">
|
|
|
|
|
新增降水量
|
|
|
|
|
</el-button>
|
|
|
|
|
</div>
|
2025-05-08 21:39:47 +08:00
|
|
|
|
<el-table
|
|
|
|
|
:cell-style="rowStyle"
|
|
|
|
|
:data="precipitationQuerry"
|
|
|
|
|
border
|
|
|
|
|
style="width: 100%"
|
|
|
|
|
:span-method="spanMethod"
|
|
|
|
|
>
|
2025-05-05 23:25:15 +08:00
|
|
|
|
<!-- 表格列定义 -->
|
2025-05-08 21:39:47 +08:00
|
|
|
|
<el-table-column align="center" prop="amount" label="降水量" />
|
|
|
|
|
<el-table-column align="center" prop="unit" label="计量单位" />
|
|
|
|
|
<el-table-column
|
|
|
|
|
align="center"
|
|
|
|
|
prop="monthDate"
|
|
|
|
|
label="月份"
|
|
|
|
|
:formatter="(row) => formatMonth(row.monthDate)"
|
|
|
|
|
/>
|
|
|
|
|
<el-table-column
|
|
|
|
|
align="center"
|
|
|
|
|
fixed="right"
|
|
|
|
|
label="操作"
|
|
|
|
|
width="300"
|
|
|
|
|
>
|
2025-05-05 23:25:15 +08:00
|
|
|
|
<template #default="scope">
|
2025-05-08 21:39:47 +08:00
|
|
|
|
<div style="display: flex; justify-content: center; gap: 8px">
|
|
|
|
|
<el-button
|
|
|
|
|
type="primary"
|
|
|
|
|
size="small"
|
|
|
|
|
@click="handleEdit(scope.row.precipID)"
|
|
|
|
|
>
|
2025-05-05 23:25:15 +08:00
|
|
|
|
修改
|
|
|
|
|
</el-button>
|
|
|
|
|
<el-button
|
|
|
|
|
type="danger"
|
2025-05-08 21:39:47 +08:00
|
|
|
|
size="small"
|
2025-05-05 23:25:15 +08:00
|
|
|
|
@click="removeDataById(scope.row.precipID)"
|
|
|
|
|
>
|
|
|
|
|
删除
|
|
|
|
|
</el-button>
|
|
|
|
|
</div>
|
|
|
|
|
</template>
|
|
|
|
|
</el-table-column>
|
|
|
|
|
</el-table>
|
2025-05-08 21:39:47 +08:00
|
|
|
|
<el-dialog
|
|
|
|
|
v-model="updateprecipitationform"
|
|
|
|
|
title="修改降水量信息"
|
|
|
|
|
width="500"
|
|
|
|
|
>
|
2025-05-05 23:25:15 +08:00
|
|
|
|
<el-form :model="precipitationform">
|
|
|
|
|
<el-form-item label="降水量" :label-width="formLabelWidth">
|
|
|
|
|
<el-input v-model="precipitationform.amount" autocomplete="off" />
|
|
|
|
|
</el-form-item>
|
|
|
|
|
<el-form-item label="计量单位" :label-width="formLabelWidth">
|
|
|
|
|
<el-input v-model="precipitationform.unit" autocomplete="off" />
|
|
|
|
|
</el-form-item>
|
|
|
|
|
<el-form-item label="月份" :label-width="formLabelWidth">
|
|
|
|
|
<el-date-picker
|
|
|
|
|
v-model="precipitationform.monthDate"
|
|
|
|
|
type="datetime"
|
|
|
|
|
placeholder="选择月份"
|
|
|
|
|
/>
|
|
|
|
|
</el-form-item>
|
|
|
|
|
</el-form>
|
|
|
|
|
<template #footer>
|
|
|
|
|
<div class="dialog-footer">
|
2025-05-08 21:39:47 +08:00
|
|
|
|
<el-button @click="updateprecipitationform = false"> 取消 </el-button>
|
2025-05-05 23:25:15 +08:00
|
|
|
|
<el-button type="primary" @click="updatePrecipitation">
|
|
|
|
|
提交
|
|
|
|
|
</el-button>
|
|
|
|
|
</div>
|
|
|
|
|
</template>
|
|
|
|
|
</el-dialog>
|
|
|
|
|
</div>
|
|
|
|
|
</template>
|