添加设备权限
This commit is contained in:
parent
495b0fcefc
commit
74f7c83242
@ -10,13 +10,8 @@
|
||||
</template>
|
||||
<view class="tips">
|
||||
<text style="color: red">注意:</text>
|
||||
<text>1.选中的开关为没有控制权限;</text>
|
||||
<text> 2.不建议选择“全关”按钮;</text>
|
||||
<text>1.选中的开关为有控制权限;</text>
|
||||
<view style="float: right;margin-right: 15px;border: 1px solid;">
|
||||
<!-- <u-checkbox-group class="checkBox" style="margin: 0;" iconPlacement="left" placement="row"
|
||||
@change="handleChangeAll">
|
||||
<u-checkbox activeColor="#35842E" label="全选" :checked="false" name="all"></u-checkbox>
|
||||
</u-checkbox-group> -->
|
||||
<u-button style="height: 25px;" type="primary" size="small" :plain="true" :hairline="true"
|
||||
@click="handleChangeAll">
|
||||
{{ selectAll ? '反选':'全选' }}
|
||||
@ -24,7 +19,48 @@
|
||||
</view>
|
||||
</view>
|
||||
<template #cell="{ item }">
|
||||
<work-user-ground-device-item :item="item" @onCheckBoxChange="onCheckBoxChange" />
|
||||
<view class="item-container">
|
||||
<view class="flex-text" style="padding: 10px;">
|
||||
<view class="flex-text-one">出水口:</view>
|
||||
<view>
|
||||
<text>{{ item.waterOutletName }}</text>
|
||||
<text style="font-size: 14px">{{ ` (${item.deviceCode})` }}</text>
|
||||
</view>
|
||||
<view style="margin-left: 50px;height: 25px;">
|
||||
<u-checkbox-group class="checkBox" style="margin: 0;" iconPlacement="left" placement="row"
|
||||
@change="handleChangeRow">
|
||||
<u-checkbox activeColor="#35842E" label="全选"
|
||||
:checked="item.valveClose && item.valveOpen && item.valveOneOpen && item.valveTwoOpen"
|
||||
name="all"></u-checkbox>
|
||||
</u-checkbox-group>
|
||||
</view>
|
||||
</view>
|
||||
<u-gap height="1" bgColor="#D2D2D2"></u-gap>
|
||||
<view v-if="item.deviceTypeId == 2 || item.deviceTypeId == 3">
|
||||
<u-checkbox-group class="checkBox" iconPlacement="left" placement="row" @change="handleChange">
|
||||
<u-checkbox activeColor="#35842E" label="全关" :checked="item.valveClose"
|
||||
name="valveClose"></u-checkbox>
|
||||
<u-checkbox activeColor="#35842E" label="全开" :checked="item.valveOpen"
|
||||
name="valveOpen"></u-checkbox>
|
||||
<u-checkbox activeColor="#35842E" label="①开 " :checked="item.valveOneOpen"
|
||||
name="valveOneOpen"></u-checkbox>
|
||||
<u-checkbox activeColor="#35842E" label="②开" :checked="item.valveTwoOpen"
|
||||
name="valveTwoOpen"></u-checkbox>
|
||||
</u-checkbox-group>
|
||||
</view>
|
||||
<view v-if="item.deviceTypeId == 13">
|
||||
<u-checkbox-group class="checkBox" iconPlacement="left" placement="row" @change="handleChange">
|
||||
<u-checkbox activeColor="#35842E" label="①开" :checked="item.valveOneOpen"
|
||||
name="valveOneOpen"></u-checkbox>
|
||||
<u-checkbox activeColor="#35842E" label="②开" :checked="item.valveTwoOpen"
|
||||
name="valveTwoOpen"></u-checkbox>
|
||||
<u-checkbox activeColor="#35842E" label="③开 " :checked="item.valveThreeOpen"
|
||||
name="valveThreeOpen"></u-checkbox>
|
||||
<u-checkbox activeColor="#35842E" label="④开" :checked="item.valveFourOpen"
|
||||
name="valveFourOpen"></u-checkbox>
|
||||
</u-checkbox-group>
|
||||
</view>
|
||||
</view>
|
||||
</template>
|
||||
<template #bottom>
|
||||
<view class="button">
|
||||
@ -36,226 +72,203 @@
|
||||
</view>
|
||||
</template>
|
||||
|
||||
<script setup>
|
||||
import {
|
||||
ref
|
||||
} from "vue"
|
||||
import {
|
||||
onShow,
|
||||
onLoad,
|
||||
onReady
|
||||
} from "@dcloudio/uni-app"
|
||||
<script>
|
||||
import store from "@/store"
|
||||
import plugin from "@/plugins"
|
||||
import storage from "@/utils/storage"
|
||||
const landId = ref(0)
|
||||
const dataList = ref([])
|
||||
const tempList = ref([])
|
||||
const tempValveData = ref({
|
||||
valveClose: true,
|
||||
valveOneOpen: true,
|
||||
valveOpen: true,
|
||||
valveTwoOpen: true,
|
||||
valveThreeOpen: true,
|
||||
valveFourOpen: true
|
||||
})
|
||||
const selectAll = ref(false)
|
||||
const paging = ref(null)
|
||||
const query = ref({
|
||||
landId: 0,
|
||||
deviceCode: null,
|
||||
userId: 0
|
||||
})
|
||||
const disabled = ref(false)
|
||||
|
||||
onLoad(res => {
|
||||
landId.value = res.landId
|
||||
query.value.landId = res.landId
|
||||
query.value.userId = res.userId
|
||||
})
|
||||
|
||||
onShow(() => {
|
||||
// if (paging.value != null) {
|
||||
// paging.value.reload()
|
||||
// }
|
||||
})
|
||||
|
||||
//获取地块列表
|
||||
function queryList() {
|
||||
// plugin.modal.loading("获取权限列表...")
|
||||
dataList.value = []
|
||||
tempList.value = []
|
||||
if (query.value.deviceCode == null || query.value.deviceCode == "") {
|
||||
delete query.value["deviceCode"]
|
||||
}
|
||||
//获取该用户地块列表
|
||||
store
|
||||
.dispatch("onGetUserControlList", query.value)
|
||||
.then(res => {
|
||||
let data = res.data[0].valveControls;
|
||||
// console.error("data:", data);
|
||||
if (data && data.length) {
|
||||
data.forEach(item => {
|
||||
let sortArr = item.waterOutletName.split("-");
|
||||
switch (sortArr.length) {
|
||||
case 0:
|
||||
sortArr = [0, 0, 0, 0];
|
||||
break;
|
||||
case 1:
|
||||
sortArr = sortArr.concat([0, 0, 0]);
|
||||
break;
|
||||
case 2:
|
||||
sortArr = sortArr.concat([0, 0]);
|
||||
break;
|
||||
case 3:
|
||||
sortArr = sortArr.concat([0]);
|
||||
break;
|
||||
}
|
||||
item.sortArr = sortArr;
|
||||
});
|
||||
data = data.sort(compareData());
|
||||
} else {
|
||||
data = [];
|
||||
plugin.modal.msg("该地块还没有安装或绑定阀门!")
|
||||
export default {
|
||||
data() {
|
||||
return {
|
||||
landId: null,
|
||||
dataList: [],
|
||||
tempList: [],
|
||||
tempValveData: {
|
||||
valveClose: true,
|
||||
valveOneOpen: true,
|
||||
valveOpen: true,
|
||||
valveTwoOpen: true,
|
||||
valveThreeOpen: true,
|
||||
valveFourOpen: true
|
||||
},
|
||||
selectAll: false,
|
||||
query: {
|
||||
landId: 0,
|
||||
deviceCode: null,
|
||||
userId: 0
|
||||
},
|
||||
disabled: false
|
||||
}
|
||||
},
|
||||
created() {
|
||||
this.avatar = avatar;
|
||||
},
|
||||
onLoad(options) {
|
||||
this.landId = options.landId
|
||||
this.query.landId = options.landId
|
||||
this.query.userId = options.userId
|
||||
this.queryList();
|
||||
},
|
||||
onShow() {
|
||||
if (this.userInfo) {
|
||||
this.query.userId = this.userInfo.userId;
|
||||
}
|
||||
},
|
||||
methods: {
|
||||
queryList() {
|
||||
if (!this.query.userId) {
|
||||
return;
|
||||
}
|
||||
dataList.value = data;
|
||||
paging.value.complete(dataList.value)
|
||||
})
|
||||
.catch(error => {
|
||||
paging.value.complete([])
|
||||
plugin.modal.msgError(error)
|
||||
})
|
||||
.finally(() => {
|
||||
plugin.modal.closeLoading()
|
||||
})
|
||||
}
|
||||
//数据排序
|
||||
function compareData() {
|
||||
return function(b, a) {
|
||||
if (b.sortArr[0] < a.sortArr[0]) {
|
||||
return -1;
|
||||
} else if (b.sortArr[0] > a.sortArr[0]) {
|
||||
return 1;
|
||||
} else {
|
||||
if (b.sortArr[1] < a.sortArr[1]) {
|
||||
return -1;
|
||||
} else if (b.sortArr[1] > a.sortArr[1]) {
|
||||
return 1;
|
||||
} else {
|
||||
if (b.sortArr[2] < a.sortArr[2]) {
|
||||
this.dataList = []
|
||||
this.tempList = []
|
||||
if (this.query.deviceCode == null || this.query.deviceCode == "") {
|
||||
delete this.query["deviceCode"]
|
||||
}
|
||||
//获取该用户地块列表
|
||||
store
|
||||
.dispatch("onGetUserControlList", this.query)
|
||||
.then(res => {
|
||||
let data = res.data[0].valveControls;
|
||||
if (data && data.length) {
|
||||
data.forEach(item => {
|
||||
let sortArr = item.waterOutletName.split("-");
|
||||
switch (sortArr.length) {
|
||||
case 0:
|
||||
sortArr = [0, 0, 0, 0];
|
||||
break;
|
||||
case 1:
|
||||
sortArr = sortArr.concat([0, 0, 0]);
|
||||
break;
|
||||
case 2:
|
||||
sortArr = sortArr.concat([0, 0]);
|
||||
break;
|
||||
case 3:
|
||||
sortArr = sortArr.concat([0]);
|
||||
break;
|
||||
}
|
||||
item.sortArr = sortArr;
|
||||
});
|
||||
data = data.sort(compareData());
|
||||
} else {
|
||||
data = [];
|
||||
plugin.modal.msg("该地块还没有安装或绑定阀门!")
|
||||
}
|
||||
this.dataList= data;
|
||||
this.$refs.paging.complete(dataList.value)
|
||||
})
|
||||
.catch(error => {
|
||||
this.$refs.paging.complete([])
|
||||
plugin.modal.msgError(error)
|
||||
})
|
||||
.finally(() => {
|
||||
plugin.modal.closeLoading()
|
||||
})
|
||||
},
|
||||
onSearchValue(e) {
|
||||
this.query.landName = e;
|
||||
this.queryList();
|
||||
},
|
||||
onClickPermission(item) {
|
||||
plugin.tab.navigateTo(`/pages/work/user/device?landId=${item.landId}&userId=${item.userId}`)
|
||||
},
|
||||
//排序
|
||||
compareData() {
|
||||
return function(b, a) {
|
||||
if (b.sortArr[0] < a.sortArr[0]) {
|
||||
return -1;
|
||||
} else if (b.sortArr[2] > a.sortArr[2]) {
|
||||
} else if (b.sortArr[0] > a.sortArr[0]) {
|
||||
return 1;
|
||||
} else {
|
||||
if (b.sortArr[3] < a.sortArr[3]) {
|
||||
if (b.sortArr[1] < a.sortArr[1]) {
|
||||
return -1;
|
||||
} else if (b.sortArr[3] > a.sortArr[3]) {
|
||||
} else if (b.sortArr[1] > a.sortArr[1]) {
|
||||
return 1;
|
||||
} else {
|
||||
return 0;
|
||||
if (b.sortArr[2] < a.sortArr[2]) {
|
||||
return -1;
|
||||
} else if (b.sortArr[2] > a.sortArr[2]) {
|
||||
return 1;
|
||||
} else {
|
||||
if (b.sortArr[3] < a.sortArr[3]) {
|
||||
return -1;
|
||||
} else if (b.sortArr[3] > a.sortArr[3]) {
|
||||
return 1;
|
||||
} else {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
//提交
|
||||
submit() {
|
||||
let queryData = {
|
||||
addValveControl: this.tempList
|
||||
}
|
||||
plugin.modal.loading("设置中...")
|
||||
this.disabled = true;
|
||||
//获取该用户地块列表
|
||||
store
|
||||
.dispatch("onSetUserControlList", queryData)
|
||||
.then(res => {
|
||||
plugin.modal.msgSuccess("设置成功!")
|
||||
//刷新列表
|
||||
this.queryList();
|
||||
})
|
||||
.catch(error => {
|
||||
plugin.modal.msgError(error)
|
||||
this.disabled = false;
|
||||
})
|
||||
.finally(() => {
|
||||
plugin.modal.closeLoading()
|
||||
this.disabled = false;
|
||||
})
|
||||
},
|
||||
//全选
|
||||
handleChangeAll() {
|
||||
this.selectAll = !this.selectAll;
|
||||
this.tempList = [];
|
||||
this.dataList.forEach(item => {
|
||||
if (item.deviceTypeId == 2 || item.deviceTypeId == 3) {
|
||||
item.valveClose = this.selectAll;
|
||||
item.valveOpen = this.selectAll;
|
||||
item.valveOneOpen = this.selectAll;
|
||||
item.valveTwoOpen = this.selectAll;
|
||||
item.valveThreeOpen = false;
|
||||
item.valveFourOpen = false;
|
||||
}
|
||||
if (item.deviceTypeId == 13) {
|
||||
item.valveClose = false;
|
||||
item.valveOpen = false;
|
||||
item.valveOneOpen = this.selectAll;
|
||||
item.valveTwoOpen = this.selectAll;
|
||||
item.valveThreeOpen = this.selectAll;
|
||||
item.valveFourOpen = this.selectAll;
|
||||
}
|
||||
this.tempList.push(item);
|
||||
});
|
||||
},
|
||||
//当用户点击权限开关之后
|
||||
onCheckBoxChange(param) {
|
||||
let index = this.tempList.findIndex(x => x.id == param.item.id && x.userId == param.item.userId && x
|
||||
.deviceId == param.item.deviceId)
|
||||
if (index != -1) {
|
||||
this.tempList.splice(index, 1);
|
||||
}
|
||||
let itemSample = this.judgeValue(param.item, param.checkItem);
|
||||
this.tempList.push(itemSample);
|
||||
},
|
||||
//判断开关值属性
|
||||
judgeValue(itemSample, param) {
|
||||
itemSample.valveClose = param.indexOf("valveClose") > -1 ? true : false
|
||||
itemSample.valveOpen = param.indexOf("valveOpen") > -1 ? true : false
|
||||
itemSample.valveOneOpen = param.indexOf("valveOneOpen") > -1 ? true : false
|
||||
itemSample.valveTwoOpen = param.indexOf("valveTwoOpen") > -1 ? true : false
|
||||
itemSample.valveThreeOpen = param.indexOf("valveThreeOpen") > -1 ? true : false
|
||||
itemSample.valveFourOpen = param.indexOf("valveFourOpen") > -1 ? true : false
|
||||
return itemSample
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//查找地块
|
||||
function onSearchValue(keyword) {
|
||||
query.value.deviceCode = keyword
|
||||
paging.value.reload()
|
||||
}
|
||||
//设置控制权限
|
||||
function submit() {
|
||||
// if (tempList.value.length < 1) {
|
||||
// plugin.modal.msg("您未做任何改变!")
|
||||
// return
|
||||
// }
|
||||
let queryData = {
|
||||
addValveControl: tempList.value
|
||||
}
|
||||
plugin.modal.loading("设置中...")
|
||||
disabled.value = true;
|
||||
//获取该用户地块列表
|
||||
store
|
||||
.dispatch("onSetUserControlList", queryData)
|
||||
.then(res => {
|
||||
plugin.modal.msgSuccess("设置成功!")
|
||||
//刷新列表
|
||||
queryList();
|
||||
// queryList(1, 10, "")
|
||||
})
|
||||
.catch(error => {
|
||||
plugin.modal.msgError(error)
|
||||
disabled.value = false;
|
||||
})
|
||||
.finally(() => {
|
||||
plugin.modal.closeLoading()
|
||||
disabled.value = false;
|
||||
})
|
||||
}
|
||||
// 全选
|
||||
function handleChangeAll() {
|
||||
selectAll.value = !selectAll.value;
|
||||
tempList.value = [];
|
||||
dataList.value.forEach(item => {
|
||||
if (item.deviceTypeId == 2 || item.deviceTypeId == 3) {
|
||||
item.valveClose = selectAll.value;
|
||||
item.valveOpen = selectAll.value;
|
||||
item.valveOneOpen = selectAll.value;
|
||||
item.valveTwoOpen = selectAll.value;
|
||||
item.valveThreeOpen = false;
|
||||
item.valveFourOpen = false;
|
||||
}
|
||||
if (item.deviceTypeId == 13) {
|
||||
item.valveClose = false;
|
||||
item.valveOpen = false;
|
||||
item.valveOneOpen = selectAll.value;
|
||||
item.valveTwoOpen = selectAll.value;
|
||||
item.valveThreeOpen = selectAll.value;
|
||||
item.valveFourOpen = selectAll.value;
|
||||
}
|
||||
tempList.value.push(item);
|
||||
});
|
||||
}
|
||||
//当用户点击权限开关之后
|
||||
function onCheckBoxChange(param) {
|
||||
console.log(param)
|
||||
let index = tempList.value.findIndex(x => x.id == param.item.id && x.userId == param.item.userId && x.deviceId ==
|
||||
param.item.deviceId)
|
||||
if (index != -1) {
|
||||
tempList.value.splice(index, 1);
|
||||
}
|
||||
let itemSample = judgeValue(param.item, param.checkItem);
|
||||
tempList.value.push(itemSample);
|
||||
// //添加到提交的列表中
|
||||
// //先查找缓存列表有这个对象
|
||||
// let item = tempList.value.filter(res => {
|
||||
// return res.id == param.itemId
|
||||
// })
|
||||
// //修改属性值
|
||||
// itemSample = judgeValue(itemSample, param)
|
||||
// //如果没有这个对象则添加到缓存列表
|
||||
// if (!item.length) {
|
||||
// tempList.value.push(itemSample)
|
||||
// } else {
|
||||
// //原列表删除后重新添加
|
||||
// tempList.value = tempList.value.filter(res => {
|
||||
// return res.itemId != param.itemId
|
||||
// })
|
||||
// tempList.value.push(itemSample)
|
||||
// }
|
||||
}
|
||||
//判断开关值属性
|
||||
function judgeValue(itemSample, param) {
|
||||
itemSample.valveClose = param.indexOf("valveClose") > -1 ? true : false
|
||||
itemSample.valveOpen = param.indexOf("valveOpen") > -1 ? true : false
|
||||
itemSample.valveOneOpen = param.indexOf("valveOneOpen") > -1 ? true : false
|
||||
itemSample.valveTwoOpen = param.indexOf("valveTwoOpen") > -1 ? true : false
|
||||
itemSample.valveThreeOpen = param.indexOf("valveThreeOpen") > -1 ? true : false
|
||||
itemSample.valveFourOpen = param.indexOf("valveFourOpen") > -1 ? true : false
|
||||
return itemSample
|
||||
}
|
||||
</script>
|
||||
|
||||
<style lang="scss" scoped>
|
||||
@ -295,6 +308,30 @@
|
||||
display: flex;
|
||||
background: white;
|
||||
}
|
||||
|
||||
.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;
|
||||
}
|
||||
}
|
||||
|
||||
.tips {
|
||||
|
@ -74,7 +74,6 @@ export default {
|
||||
onShow() {
|
||||
if(this.userInfo){
|
||||
this.query.userId = this.userInfo.userId;
|
||||
|
||||
}
|
||||
},
|
||||
methods: {
|
||||
@ -112,7 +111,6 @@ export default {
|
||||
}
|
||||
}
|
||||
</script>
|
||||
|
||||
<style lang="stylus">
|
||||
.index-container{
|
||||
background-color: #F6F3F3;
|
||||
|
Loading…
Reference in New Issue
Block a user