jdcProject_front/src/pages/demo/diceke/Precipitation.vue
吕杰刚 40b97f8a0f
Some checks failed
Build And Deploy v3-admin-vite / build-and-deploy (push) Has been cancelled
采剥量,损失和贫化
2025-05-08 21:39:47 +08:00

190 lines
5.4 KiB
Vue
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

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