<template>
|
<div class="app-container">
|
<el-form :model="queryParams" ref="queryRef" :inline="true">
|
<el-form-item label="水价标准名称" prop="name">
|
<el-input
|
v-model="queryParams.name"
|
placeholder="请输入水价标准名称"
|
clearable
|
style="width: 200px"
|
@keyup.enter="handleQuery"
|
/>
|
</el-form-item>
|
<el-form-item>
|
<el-button type="primary" icon="Search" @click="handleQuery">搜索</el-button>
|
<el-button icon="Refresh" @click="resetQuery">重置</el-button>
|
</el-form-item>
|
</el-form>
|
|
<el-row :gutter="10" class="mb8">
|
<el-col :span="1.5">
|
<el-button
|
type="primary"
|
plain
|
icon="Plus"
|
@click="handleAdd"
|
>新增</el-button>
|
</el-col>
|
</el-row>
|
<!--表格及分页-->
|
<el-table v-loading="loading" :data="tableData">
|
<el-table-column
|
v-for="(item, key, index) of tableHeader"
|
:prop="key.toString()"
|
:label="item"
|
:key="index"
|
align="center"
|
>
|
</el-table-column>
|
<el-table-column label="操作" width="180" align="center" class-name="small-padding fixed-width">
|
<template #default="scope">
|
<el-button link type="primary" icon="Edit" @click="handleUpdate(scope.row)">修改</el-button>
|
<el-button link type="primary" icon="Delete" @click="handleDelete(scope.row)">删除</el-button>
|
</template>
|
</el-table-column>
|
</el-table>
|
<pagination
|
:total="pageParam.total"
|
v-model:page="pageParam.page"
|
v-model:limit="pageParam.limit"
|
:page-sizes="[10,20,30]"
|
@pagination="getList"
|
/>
|
<!-- 添加或修改对话框 -->
|
<el-dialog :title="title" v-model="open" append-to-body center>
|
<el-form class="price-form" ref="formRef" :model="form" :rules="rules" label-width='auto'>
|
<el-row>
|
<el-col :span="12">
|
<el-form-item label="水价标准名称" prop="name">
|
<el-input v-model="form.name" placeholder="请输入水价标准名称"/>
|
</el-form-item>
|
</el-col>
|
</el-row>
|
<!-- 循环阶梯水价 -->
|
<div class="fee-box">
|
<div v-for="(item,index) in form.feeContent" class="fee-item">
|
<div class="item-title" v-if="form.feeContent.length == 1">标准水价</div>
|
<div class="item-title" v-else>第{{ index + 1 }}阶梯 :</div>
|
<el-form-item :label="index + 1 == form.feeContent.length && form.feeContent.length > 1 ? '最高用水量(m³)' : '用水量(m³)' " prop="maxUse">
|
<el-input
|
:disabled="form.feeContent.length > 1 && index + 1 == form.feeContent.length && form.feeContent[index-1].maxUse == '' "
|
v-model="item.maxUse"
|
@blur="maxUseChange(index)"
|
placeholder="用水量"/>
|
<span v-if="maxUseValid && !form.feeContent[index].maxUse && index + 1 != form.feeContent.length " class="message">请输入用水量</span>
|
</el-form-item>
|
|
<el-form-item label="水价(元)" prop = 'price'>
|
<el-input v-model="item.price" @blur="priceChange(index)" placeholder="请输入水价" />
|
<span v-if="priceValid && !form.feeContent[index].price" class="message">请输入水价</span>
|
</el-form-item>
|
<el-form-item label="备注" prop="comment">
|
<el-input v-model="item.comment" placeholder="请输入备注" />
|
</el-form-item>
|
<div class="item-delete">
|
<el-button v-if="form.feeContent.length > 1" type="danger" size="small" @click="deleteFee(index)">删 除</el-button>
|
</div>
|
</div>
|
</div>
|
<div class="fee-add">
|
<el-button type="primary" @click="addFee"> + 添加阶梯水费</el-button>
|
</div>
|
<el-row>
|
<el-col :span="12">
|
<el-form-item label="备注" prop="comment">
|
<el-input v-model="form.comment" placeholder="请输入备注" />
|
</el-form-item>
|
</el-col>
|
<el-col :span="12">
|
<el-form-item label="显示排序" prop="sort">
|
<el-input-number v-model="form.sort" controls-position="right" :min="1" />
|
</el-form-item>
|
</el-col>
|
</el-row>
|
</el-form>
|
<template #footer>
|
<div class="dialog-footer">
|
<el-button type="primary" @click="submitForm">确 定</el-button>
|
<el-button @click="cancel">取 消</el-button>
|
</div>
|
</template>
|
</el-dialog>
|
</div>
|
</template>
|
|
<script setup name="Menu">
|
import TieredCharging from "@/api/configuration/waterPrice";
|
import setPostParams from "../../../utils/searchParams.js";
|
const { proxy } = getCurrentInstance();
|
|
/**
|
* 搜索相关
|
*/
|
/** 搜索按钮操作 */
|
function handleQuery() {
|
getList({keywords:queryParams.value.name,page:1})
|
}
|
|
/** 重置按钮操作 */
|
function resetQuery() {
|
proxy.resetForm("queryRef");
|
handleQuery();
|
}
|
/**
|
* Table表格权限数据列表相关
|
*/
|
const pageParam = ref({
|
total:0,
|
limit:0,
|
page:0,
|
})
|
const tableData = ref([]);
|
let tableHeader = ref({
|
name: '水价标准名称',
|
comment: '备注',
|
sort:'排序值',
|
})
|
/** 获取列表 */
|
async function getList(val) {
|
loading.value = true;
|
|
let postParam = setPostParams(val)
|
await TieredCharging().search(postParam).then((res) =>{
|
let list = res.data.list.map(obj => {
|
const { content, ...rest } = obj;
|
return {
|
...rest,
|
feeContent: content,
|
};
|
});
|
console.log('reslist',list,res.data.list);
|
tableData.value = list
|
pageParam.value.total = res.data.total
|
pageParam.value.limit = res.data.limit
|
pageParam.value.page = res.data.page
|
})
|
loading.value = false;
|
}
|
|
/** 新增按钮操作 */
|
async function handleAdd() {
|
reset();
|
open.value = true;
|
title.value = "新增用户水价标准";
|
}
|
|
/** 修改按钮操作 */
|
async function handleUpdate(row) {
|
reset();
|
form.value = Object.assign({},row)
|
await TieredCharging().get(row.id).then((res) =>{
|
form.value.feeContent = res.data.contentView;
|
})
|
open.value = true;
|
title.value = "修改用户水价标准";
|
console.log('123.',form.value)
|
}
|
|
/** 删除按钮操作 */
|
function handleDelete(row) {
|
proxy.$modal.confirm('是否确认删除名称为"' + row.name + '"的数据项?').then(function() {
|
return TieredCharging().remove(row.id);
|
}).then(() => {
|
getList();
|
proxy.$modal.msgSuccess("删除成功");
|
}).catch(() => {});
|
}
|
|
/**
|
* 新增/修改弹窗Form表单相关
|
*/
|
const open = ref(false);
|
const loading = ref(false);
|
const title = ref("");
|
|
const data = reactive({
|
form:{
|
name: '',
|
comment: '',
|
feeContent:[
|
{
|
maxUse:'',
|
price:'',
|
comment:''
|
}
|
],
|
sort:1,
|
},
|
queryParams: {
|
name: undefined,
|
},
|
rules: {
|
name: [{ required: true, message: "请输入水价标准名称", trigger: "blur" }],
|
},
|
});
|
const { queryParams, form, rules } = toRefs(data);
|
//添加水表阶梯
|
const addFee = () =>{
|
form.value.feeContent.push(
|
{
|
maxUse:'',
|
price:'',
|
comment:''
|
})
|
}
|
//删除指定水表阶梯
|
const deleteFee = (index) =>{
|
if(form.value.feeContent.length > 1){
|
form.value.feeContent.splice(index,1)
|
}
|
}
|
//校验
|
const maxUseValid =ref(false)
|
const priceValid =ref(false)
|
//用水量校验
|
const maxUseChange = (index) =>{
|
if(!form.value.feeContent[index].maxUse){
|
maxUseValid.value = true
|
}
|
if(form.value.feeContent.length > 1 && index > 0){
|
if(form.value.feeContent[index].maxUse <= form.value.feeContent[index - 1].maxUse){
|
proxy.$modal.msgError(`请输入大于第${index}阶梯用水量"${form.value.feeContent[index-1].maxUse}"的值`);
|
form.value.feeContent[index].maxUse = ''
|
maxUseValid.value = true
|
}
|
}
|
}
|
//水价校验
|
const priceChange = (index) =>{
|
if(!form.value.feeContent[index].price){
|
priceValid.value = true
|
}
|
}
|
|
/** 提交按钮 */
|
function submitForm() {
|
proxy.$refs["formRef"].validate(valid => {
|
if (valid) {
|
if (form.value.id != undefined) {
|
TieredCharging().modify(form.value).then(res => {
|
proxy.$modal.msgSuccess("修改成功");
|
open.value = false;
|
getList();
|
}).catch(() =>{
|
open.value = false;
|
proxy.$modal.msgError("修改失败");
|
});
|
} else {
|
TieredCharging().create(form.value).then(res => {
|
proxy.$modal.msgSuccess("新增成功");
|
open.value = false;
|
getList();
|
}).catch(() =>{
|
open.value = false;
|
proxy.$modal.msgError("新增失败");
|
});;
|
}
|
}
|
});
|
}
|
|
/** 取消按钮 */
|
function cancel() {
|
open.value = false;
|
reset();
|
}
|
|
/** 表单重置 */
|
function reset() {
|
form.value = {
|
name: '',
|
comment: '',
|
feeContent:[
|
{
|
maxUse:'',
|
price:'',
|
comment:''
|
}
|
],
|
sort:1,
|
};
|
proxy.resetForm("formRef");
|
}
|
getList();
|
</script>
|
<style lang="scss">
|
.price-form{
|
padding: 20px 0;
|
background:#fff;
|
border-radius: 10px;
|
}
|
.fee-box{
|
display: flex;
|
flex-wrap: wrap;
|
.fee-item{
|
// background-color: rgb(255, 255, 255);
|
border: 1px solid #cfd5dd;
|
padding: 10px;
|
margin-left: 20px;
|
margin-bottom: 20px;
|
border-radius: 10px;
|
height: 250px;
|
width:420px;
|
.item-title{
|
font-size: 18px;
|
font-weight:600;
|
width: 100px;
|
margin: 10px auto;
|
}
|
.item-delete{
|
display: flex;
|
justify-content: center;
|
}
|
}
|
}
|
.fee-add{
|
display: flex;
|
margin-bottom: 20px;
|
margin-left: 19%;
|
}
|
.message{
|
position:absolute;
|
top: 80%;
|
z-index: 100;
|
color: var(--el-color-danger);
|
font-size: 12px;
|
}
|
|
</style>
|
|