350 lines
9.5 KiB
Vue
350 lines
9.5 KiB
Vue
<template>
|
||
<view class="index-container">
|
||
<z-paging class="paging" ref="paging" use-virtual-list @query="queryList" bg-color="#F6F3F3"
|
||
:loading-more-enabled="false">
|
||
<template #top>
|
||
<view class="search">
|
||
<u-search placeholder="请输入设备编号" @search="onSearchValue" @custom="onSearchValue"
|
||
@clear="onSearchValue(null)" shape="square"></u-search>
|
||
</view>
|
||
</template>
|
||
<view class="tips">
|
||
<text style="color: red">注意:</text>
|
||
<text>1.选中的开关为有控制权限;</text>
|
||
<view style="float: right;margin-right: 15px;border: 1px solid;">
|
||
<u-button style="height: 25px;" type="primary" size="small" :plain="true" :hairline="true"
|
||
@click="handleChangeAll">
|
||
{{ selectAll ? '反选':'全选' }}
|
||
</u-button>
|
||
</view>
|
||
</view>
|
||
<template #cell="{ item }">
|
||
<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">
|
||
<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>
|
||
|
||
<script>
|
||
import store from "@/store"
|
||
import plugin from "@/plugins"
|
||
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;
|
||
}
|
||
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[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]) {
|
||
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
|
||
}
|
||
}
|
||
}
|
||
</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;
|
||
}
|
||
|
||
.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 {
|
||
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> |