jsy-app/pages/work/user/device.vue

331 lines
9.2 KiB
Vue
Raw Normal View History

2024-11-22 17:32:06 +08:00
<template>
<view class="index-container">
2024-11-25 18:21:25 +08:00
<z-paging class="paging" ref="paging" use-virtual-list bg-color="#F6F3F3" :loading-more-enabled="false">
2024-11-22 17:32:06 +08:00
<template #top>
<view class="search">
2024-11-25 18:21:25 +08:00
<u-search placeholder="请输入出水口编号" @search="onSearchValue" @custom="onSearchValue"
2024-11-22 17:32:06 +08:00
@clear="onSearchValue(null)" shape="square"></u-search>
</view>
</template>
<view class="tips">
<text style="color: red">注意</text>
2024-11-25 10:37:57 +08:00
<text>1.选中的开关为有控制权限;</text>
2024-11-22 17:32:06 +08:00
<view style="float: right;margin-right: 15px;border: 1px solid;">
<u-button style="height: 25px;" type="primary" size="small" :plain="true" :hairline="true"
2024-11-25 18:21:25 +08:00
@click="handleChangeAllRow">
2024-11-22 17:32:06 +08:00
{{ selectAll ? '反选':'全选' }}
</u-button>
</view>
</view>
<template #cell="{ item }">
2024-11-25 10:37:57 +08:00
<view class="item-container">
<view class="flex-text" style="padding: 10px;">
<view class="flex-text-one">出水口</view>
<view>
2024-11-25 18:21:25 +08:00
<text>{{ item.showName }}</text>
2024-11-25 10:37:57 +08:00
</view>
<view style="margin-left: 50px;height: 25px;">
<u-checkbox-group class="checkBox" style="margin: 0;" iconPlacement="left" placement="row"
2024-11-26 17:42:53 +08:00
@change="handleChangeRow($event, item)">
2024-11-25 10:37:57 +08:00
<u-checkbox activeColor="#35842E" label="全选"
2024-11-25 18:21:25 +08:00
v-if="item.landWaterOutletPermissionVo.deviceTypeKey == 'valve'"
:checked="item.landWaterOutletPermissionVo.valveClose==0 && item.landWaterOutletPermissionVo.valveOpen==0 && item.landWaterOutletPermissionVo.valveOneOpen==0 && item.landWaterOutletPermissionVo.valveTwoOpen==0"
:name="'all_'+item.id"></u-checkbox>
<u-checkbox activeColor="#35842E" label="全选"
v-if="item.landWaterOutletPermissionVo.deviceTypeKey == 'fiveValve'"
:checked="item.landWaterOutletPermissionVo.valveOneOpen==0 && item.landWaterOutletPermissionVo.valveTwoOpen==0 && item.landWaterOutletPermissionVo.valveThreeOpen==0 && item.landWaterOutletPermissionVo.valveFourOpen==0"
:name="'all_'+item.id"></u-checkbox>
2024-11-25 10:37:57 +08:00
</u-checkbox-group>
</view>
</view>
<u-gap height="1" bgColor="#D2D2D2"></u-gap>
2024-11-25 18:21:25 +08:00
<view v-if="item.landWaterOutletPermissionVo.deviceTypeKey == 'valve'">
2024-11-26 17:42:53 +08:00
<u-checkbox-group class="checkBox" iconPlacement="left" placement="row"
@change="handleChange($event, item)">
2024-11-25 18:21:25 +08:00
<u-checkbox activeColor="#35842E" label="全关"
:checked="item.landWaterOutletPermissionVo.valveClose==0"
2024-11-26 17:42:53 +08:00
name="valveClose"></u-checkbox>
2024-11-25 18:21:25 +08:00
<u-checkbox activeColor="#35842E" label="全开"
2024-11-26 17:42:53 +08:00
:checked="item.landWaterOutletPermissionVo.valveOpen==0" name="valveOpen"></u-checkbox>
2024-11-25 18:21:25 +08:00
<u-checkbox activeColor="#35842E" label="①开 "
:checked="item.landWaterOutletPermissionVo.valveOneOpen==0"
2024-11-26 17:42:53 +08:00
name="valveOneOpen"></u-checkbox>
2024-11-25 18:21:25 +08:00
<u-checkbox activeColor="#35842E" label="②开"
:checked="item.landWaterOutletPermissionVo.valveTwoOpen==0"
2024-11-26 17:42:53 +08:00
name="valveTwoOpen"></u-checkbox>
2024-11-25 10:37:57 +08:00
</u-checkbox-group>
</view>
2024-11-25 18:21:25 +08:00
<view v-if="item.landWaterOutletPermissionVo.deviceTypeKey == 'fiveValve'">
2024-11-26 17:42:53 +08:00
<u-checkbox-group class="checkBox" iconPlacement="left" placement="row"
@change="handleChange($event, item)">
2024-11-25 18:21:25 +08:00
<u-checkbox activeColor="#35842E" label="①开"
:checked="item.landWaterOutletPermissionVo.valveOneOpen==0"
2024-11-26 17:42:53 +08:00
name="valveOneOpen"></u-checkbox>
2024-11-25 18:21:25 +08:00
<u-checkbox activeColor="#35842E" label="②开"
:checked="item.landWaterOutletPermissionVo.valveTwoOpen==0"
2024-11-26 17:42:53 +08:00
name="valveTwoOpen"></u-checkbox>
2024-11-25 18:21:25 +08:00
<u-checkbox activeColor="#35842E" label="③开 "
:checked="item.landWaterOutletPermissionVo.valveThreeOpen==0"
2024-11-26 17:42:53 +08:00
name="valveThreeOpen"></u-checkbox>
2024-11-25 18:21:25 +08:00
<u-checkbox activeColor="#35842E" label="④开"
:checked="item.landWaterOutletPermissionVo.valveFourOpen==0"
2024-11-26 17:42:53 +08:00
name="valveFourOpen"></u-checkbox>
2024-11-25 10:37:57 +08:00
</u-checkbox-group>
</view>
</view>
2024-11-22 17:32:06 +08:00
</template>
<template #bottom>
<view class="button">
<u-button style="width: 200px; height: 40px; border-radius: 4px" type="success" text="设 置"
@click="submit" :disabled="disabled"></u-button>
</view>
</template>
</z-paging>
</view>
</template>
2024-11-25 10:37:57 +08:00
<script>
2024-11-22 17:32:06 +08:00
import plugin from "@/plugins"
2024-11-25 18:21:25 +08:00
import {
getLandWaterOutletPermissionList,
saveLandWaterOutletPermission
} from "@/api/system/landWaterOutletPermission"
2024-11-25 10:37:57 +08:00
export default {
data() {
return {
landId: null,
dataList: [],
2024-11-25 18:21:25 +08:00
selectItem: {},
2024-11-25 10:37:57 +08:00
tempValveData: {
valveClose: true,
valveOneOpen: true,
valveOpen: true,
valveTwoOpen: true,
valveThreeOpen: true,
valveFourOpen: true
},
selectAll: false,
query: {
2024-11-25 18:21:25 +08:00
landId: null,
2024-11-26 17:42:53 +08:00
showName: null,
2024-11-25 18:21:25 +08:00
userId: null
2024-11-25 10:37:57 +08:00
},
disabled: false
}
},
onLoad(options) {
this.landId = options.landId
this.query.landId = options.landId
this.query.userId = options.userId
this.queryList();
},
methods: {
queryList() {
2024-11-25 18:21:25 +08:00
if (!this.query.landId) {
2024-11-25 10:37:57 +08:00
return;
2024-11-22 17:32:06 +08:00
}
2024-11-25 10:37:57 +08:00
this.dataList = []
2024-11-25 18:21:25 +08:00
getLandWaterOutletPermissionList(this.query)
2024-11-25 10:37:57 +08:00
.then(res => {
2024-11-25 18:21:25 +08:00
this.dataList = res.data;
this.$refs.paging.complete(this.dataList)
2024-11-25 10:37:57 +08:00
})
},
onSearchValue(e) {
2024-11-26 17:42:53 +08:00
this.query.showName = e;
2024-11-25 10:37:57 +08:00
this.queryList();
},
//提交
submit() {
2024-11-25 18:21:25 +08:00
let saveObj = {
landWaterOutlets: this.dataList
2024-11-25 10:37:57 +08:00
}
plugin.modal.loading("设置中...")
this.disabled = true;
//获取该用户地块列表
2024-11-25 18:21:25 +08:00
saveLandWaterOutletPermission(saveObj)
2024-11-26 17:42:53 +08:00
.then(res => {
plugin.modal.msgSuccess("设置成功!")
//刷新列表
this.queryList();
this.disabled = false;
})
2024-11-25 10:37:57 +08:00
},
//全选
2024-11-25 18:21:25 +08:00
handleChangeAllRow() {
2024-11-25 10:37:57 +08:00
this.selectAll = !this.selectAll;
2024-11-26 19:11:01 +08:00
const selectAll = this.selectAll;
const valveDefaults = {
valveClose: 1,
valveOpen: 1,
valveOneOpen: 1,
valveTwoOpen: 1,
valveThreeOpen: 1,
valveFourOpen: 1
};
const valveSettings = {
valve: {
true: {
valveClose: 0,
valveOpen: 0,
valveOneOpen: 0,
valveTwoOpen: 0,
valveThreeOpen: 1,
valveFourOpen: 1
},
false: {}
},
fiveValve: {
true: {
valveClose: 1,
valveOpen: 1,
valveOneOpen: 0,
valveTwoOpen: 0,
valveThreeOpen: 0,
valveFourOpen: 0
},
false: {}
2024-11-25 10:37:57 +08:00
}
2024-11-26 19:11:01 +08:00
};
this.dataList.forEach(item => {
const deviceType = item.landWaterOutletPermissionVo.deviceTypeKey;
const settings = valveSettings[deviceType][selectAll];
Object.assign(item.landWaterOutletPermissionVo, valveDefaults, settings);
2024-11-25 10:37:57 +08:00
});
},
2024-11-25 18:21:25 +08:00
//单行全选
2024-11-26 17:42:53 +08:00
handleChangeRow(e, row) {
2024-11-26 19:11:01 +08:00
const index = this.dataList.findIndex(x => x.id === row.id);
if (index === -1) return; // 如果没有找到对应的行,直接返回
const item = this.dataList[index];
const permissions = item.landWaterOutletPermissionVo;
const valveDefaults = {
valveClose: 1,
valveOpen: 1,
valveOneOpen: 1,
valveTwoOpen: 1,
valveThreeOpen: 1,
valveFourOpen: 1
};
const valveSettings = {
valve: {
valveClose: 0,
valveOpen: 0,
valveOneOpen: 0,
valveTwoOpen: 0,
valveThreeOpen: 1,
valveFourOpen: 1
},
fiveValve: {
valveClose: 1,
valveOpen: 1,
valveOneOpen: 0,
valveTwoOpen: 0,
valveThreeOpen: 0,
valveFourOpen: 0
2024-11-25 18:21:25 +08:00
}
2024-11-26 19:11:01 +08:00
};
const deviceType = item.landWaterOutletPermissionVo.deviceTypeKey;
const settings = e && e.length ? valveSettings[deviceType] : {};
Object.assign(permissions, valveDefaults, settings);
2024-11-25 18:21:25 +08:00
},
2024-11-25 10:37:57 +08:00
//当用户点击权限开关之后
2024-11-26 17:42:53 +08:00
handleChange(e, obj) {
let index = this.dataList.findIndex(x => x.id == obj.id);
let item = this.dataList[index];
this.judgeValue(e, item);
2024-11-25 10:37:57 +08:00
},
2024-11-25 18:21:25 +08:00
judgeValue(e, itemSample) {
2024-11-26 19:11:01 +08:00
const valveProperties = [
'valveClose',
'valveOpen',
'valveOneOpen',
'valveTwoOpen',
'valveThreeOpen',
'valveFourOpen'
];
const permissions = itemSample.landWaterOutletPermissionVo;
valveProperties.forEach(property => {
permissions[property] = e.includes(property) ? 0 : 1;
});
2024-11-22 17:32:06 +08:00
}
}
}
</script>
<style lang="scss" scoped>
.index-container {
background-color: #f6f3f3;
height: 100%;
.search {
background-color: white;
padding: 10px;
}
.title {
height: 50px;
display: flex;
padding: 15px 15px;
background: white;
align-items: center;
text {
font-size: 14px;
margin-right: 10px;
}
}
.list {
height: calc(100vh - 150px - env(safe-area-inset-bottom));
margin: 0px 10px;
work-user-index-item {
background-color: #f6f3f3;
}
}
.button {
padding: 10px 20px;
display: flex;
background: white;
}
2024-11-25 10:37:57 +08:00
.item-container {
margin-top: 10px;
background-color: white;
padding-bottom: 10px;
}
.flex-text {
display: flex;
align-items: center;
font-size: 16px;
.flex-text-one {
color: #939393;
font-weight: bold;
}
}
.checkBox {
// margin: 20px 0px;
margin: 10px 0px 0px 0px;
display: flex;
justify-content: space-around;
}
2024-11-22 17:32:06 +08:00
}
.tips {
padding: 10px;
line-height: 20px;
font-size: 14px;
color: gray;
// letter-spacing: 1px;
background-color: #fff;
border-top: 1px solid #eee;
}
::v-deep.zp-paging-container {
background: #f3f3f3 !important;
}
</style>