<script setup name="device">
|
import { ref, reactive, onMounted, computed, nextTick } from "vue";
|
import { storeToRefs } from "pinia";
|
import { Search, Plus } from "@element-plus/icons-vue";
|
import ycCard from "@/components/ycCard/index.vue";
|
import addEdit from "./addEdit.vue";
|
import { ElMessage } from "element-plus";
|
import useElement from "@/hooks/useElement.js";
|
import { useUserStore } from '@/store/user';
|
|
import useStation from "@/hooks/useStationList.js";
|
const { provice, city, country, stationName,
|
proviceList, cityList, countryList, stationList,
|
} = useStation();
|
|
import powerTypes from '@/utils/const/const_powerType.js';
|
import {
|
delBatt,
|
getPowerBrand,
|
getVoltageLevel,
|
} from "@/api/station";
|
|
const userStore = useUserStore();
|
const { uid, uname } = storeToRefs(userStore);
|
|
|
|
import {
|
getDevList,
|
} from "@/api/station";
|
|
const { $loading, $message, $confirm } = useElement();
|
|
const headers = [
|
{
|
prop: "provice",
|
label: "省",
|
width: "80",
|
},
|
{
|
prop: "city",
|
label: "市",
|
width: "80",
|
},
|
{
|
prop: "country",
|
label: "区县",
|
width: "80",
|
},
|
{
|
prop: "stationName",
|
label: "机房名称",
|
width: "160",
|
},
|
{
|
prop: "stationType",
|
label: "电压等级",
|
width: "80",
|
},
|
{
|
prop: "longitude",
|
label: "经度",
|
width: "80",
|
},
|
{
|
prop: "latitude",
|
label: "纬度",
|
width: "80",
|
},
|
{
|
prop: "powerName",
|
label: "电源名称",
|
width: "80",
|
},
|
{
|
prop: "powerTypeStr",
|
label: "电源类型",
|
width: "80",
|
},
|
{
|
prop: "company",
|
label: "电源品牌",
|
width: "80",
|
},
|
{
|
prop: "powerModel",
|
label: "电源型号",
|
width: "80",
|
},
|
{
|
prop: "protocol",
|
label: "电源协议",
|
width: "80",
|
},
|
{
|
prop: "powerIp",
|
label: "电源IP",
|
width: "120",
|
},
|
{
|
prop: "devName",
|
label: "设备名称",
|
width: "120",
|
},
|
{
|
prop: "devType",
|
label: "设备型号",
|
width: "120",
|
},
|
{
|
prop: "devIp",
|
label: "设备IP",
|
width: "120",
|
},
|
{
|
prop: "battgroupName",
|
label: "电池组名称",
|
width: "120",
|
},
|
{
|
prop: "moncount",
|
label: "电池单体个数",
|
width: "120",
|
},
|
{
|
prop: "monvolstd",
|
label: "电池标称电压",
|
width: "120",
|
},
|
{
|
prop: "moncapstd",
|
label: "电池标称容量",
|
width: "120",
|
},
|
{
|
prop: "monresstd",
|
label: "电池标称内阻",
|
width: "120",
|
},
|
{
|
prop: "product",
|
label: "电池品牌",
|
width: "120",
|
},
|
{
|
prop: "battModel",
|
label: "电池型号",
|
width: "120",
|
},
|
];
|
|
const company = ref("");
|
const companyList = ref([]);
|
const volLevels = ref([]);
|
const powerType = ref('');
|
const stationType = ref('');
|
const background = ref(true);
|
const disabled = ref(false);
|
const pageCurr = ref(1);
|
const pageSize = ref(10);
|
const total = ref(0);
|
const addEditVisible = ref(false);
|
const dialogTitle = ref("");
|
const currentAreaId = ref();
|
const currentAreaIds = ref([]);
|
const datas = reactive({
|
tableData: [],
|
rowData: {},
|
});
|
|
const powerTypeList = computed(() => {
|
return Object.keys(powerTypes).map(v => ({ label: powerTypes[v], value: v * 1 }));
|
});
|
|
// const tableData = reactive([]);
|
// const rowData = reactive({});
|
|
// const userStore = useUserStore();
|
// const { uid, uname } = storeToRefs(userStore);
|
|
function getList() {
|
let loading = $loading();
|
let params = {
|
provice: provice.value || undefined,
|
city: city.value || undefined,
|
country: country.value || undefined,
|
stationName: stationName.value || undefined,
|
powerType: powerType.value || undefined,
|
stationType: stationType.value || undefined,
|
pageNum: pageCurr.value,
|
pageSize: pageSize.value,
|
// powerName: "",
|
};
|
|
getDevList(params)
|
.then((res) => {
|
let { code, data, data2 } = res;
|
let list = [];
|
let _total = 0;
|
if (code && data) {
|
// console.log(data);
|
list = data2.list.map(v => ({
|
...v,
|
powerTypeStr: powerTypes[v.powerType],
|
// roleName: roles[v.role],
|
}));
|
_total = data2.total;
|
}
|
loading.close();
|
// tableData.length = 0;
|
// tableData.push(...list);
|
datas.tableData = list;
|
total.value = _total;
|
})
|
.catch((err) => {
|
console.log(err);
|
loading.close();
|
});
|
}
|
|
function getCompanyList() {
|
getPowerBrand().then((res) => {
|
let { code, data, data2 } = res;
|
let list = [];
|
if (code && data) {
|
list = data2;
|
}
|
companyList.value = list;
|
});
|
}
|
|
// 获取电压等级
|
function getVolLevels() {
|
console.log("获取电压等级");
|
getVoltageLevel().then((res) => {
|
let { code, data, data2 } = res;
|
let list = [];
|
if (code && data) {
|
list = data2;
|
}
|
volLevels.value = list;
|
});
|
}
|
|
// 展示数据数量
|
function handleSizeChange(val) {
|
pageSize.value = val;
|
getList();
|
}
|
// 翻页
|
function handleCurrentChange(val) {
|
pageCurr.value = val;
|
getList();
|
}
|
function add() {
|
dialogTitle.value = "添加设备";
|
datas.rowData = {};
|
addEditVisible.value = true;
|
}
|
function edit(record) {
|
dialogTitle.value = "编辑设备";
|
addEditVisible.value = true;
|
console.log(record, '=======edit======');
|
// if (record.ainfList.idPath) {
|
// ids = record.ainfList.idPath.split("_").map((v) => v * 1);
|
// }
|
// ids.push(record.areaId);
|
|
datas.rowData = { ...record };
|
}
|
|
function addBatt(record) {
|
dialogTitle.value = "添加电池组";
|
datas.rowData = { ...record, addBattFlag: true };
|
addEditVisible.value = true;
|
}
|
|
function confirmRemove(record) {
|
$confirm("删除", () => {
|
let { stationId, powerId, battgroupId } = record;
|
remove(stationId, powerId, battgroupId||undefined);
|
});
|
}
|
function remove(stationId, powerId, battgroupId) {
|
let loading = $loading();
|
delBatt(stationId, powerId, battgroupId)
|
.then((res) => {
|
let { code, data } = res;
|
loading.close();
|
if (code && data) {
|
$message.success("操作成功");
|
handleCurrentChange(1);
|
} else {
|
$message.success("操作失败");
|
}
|
})
|
.catch((err) => {
|
loading.close();
|
console.log(err);
|
});
|
}
|
function onOk() {
|
addEditVisible.value = false;
|
handleCurrentChange(1);
|
}
|
function onCanel() {
|
addEditVisible.value = false;
|
}
|
|
function filterChange() {
|
nextTick(() => {
|
pageCurr.value = 1;
|
getList();
|
});
|
}
|
|
|
onMounted(() => {
|
getCompanyList();
|
getVolLevels();
|
getList();
|
});
|
</script>
|
|
<template>
|
<div class="page-wrapper">
|
<!-- <div class="page-header">
|
</div> -->
|
<div class="page-content">
|
<yc-card is-full>
|
<div class="page-content-wrapper">
|
<div class="page-content-tools page-filter">
|
<div class="table-row">
|
<div class="table-cell text-right">省:</div>
|
<div class="table-cell">
|
<el-select
|
v-model="provice"
|
size="small"
|
clearable
|
@change="filterChange"
|
placeholder="请选择省"
|
>
|
<el-option
|
v-for="item in proviceList"
|
:key="'l0_' + item"
|
:label="item"
|
:value="item"
|
>
|
</el-option>
|
</el-select>
|
</div>
|
<div class="table-cell text-right">市:</div>
|
<div class="table-cell">
|
<el-select
|
v-model="city"
|
size="small"
|
clearable
|
@change="filterChange"
|
placeholder="请选择市"
|
>
|
<el-option
|
v-for="item in cityList"
|
:key="'l1_' + item"
|
:label="item"
|
:value="item"
|
>
|
</el-option>
|
</el-select>
|
</div>
|
<div class="table-cell text-right">区县:</div>
|
<div class="table-cell">
|
<el-select
|
v-model="country"
|
size="small"
|
clearable
|
@change="filterChange"
|
placeholder="请选择区县"
|
>
|
<el-option
|
v-for="item in countryList"
|
:key="'l2_' + item"
|
:label="item"
|
:value="item"
|
>
|
</el-option>
|
</el-select>
|
</div>
|
<div class="table-cell text-right">站点:</div>
|
<div class="table-cell">
|
<el-select
|
v-model="stationName"
|
size="small"
|
clearable
|
@change="filterChange"
|
placeholder="请选择站点"
|
>
|
<el-option
|
v-for="item in stationList"
|
:key="'l3_' + item.stationId"
|
:label="item.stationName"
|
:value="item.stationName"
|
>
|
</el-option>
|
</el-select>
|
</div>
|
<!-- <div class="table-cell text-right">品牌:</div>
|
<div class="table-cell">
|
<el-select
|
v-model="company"
|
size="small"
|
clearable
|
@change="filterChange"
|
placeholder="请选择品牌"
|
>
|
<el-option
|
v-for="(item, idx) in companyList"
|
:key="'list4_' + idx"
|
:label="item"
|
:value="item"
|
>
|
</el-option>
|
</el-select>
|
</div> -->
|
<div class="table-cell text-right">电源类型:</div>
|
<div class="table-cell">
|
<el-select
|
v-model="powerType"
|
size="small"
|
clearable
|
@change="filterChange"
|
placeholder="请选择品牌"
|
>
|
<el-option
|
v-for="(item, idx) in powerTypeList"
|
:key="'list4_' + idx"
|
:label="item.label"
|
:value="item.value"
|
>
|
</el-option>
|
</el-select>
|
</div>
|
<div class="table-cell text-right">电压等级:</div>
|
<div class="table-cell">
|
<el-select
|
v-model="stationType"
|
size="small"
|
clearable
|
@change="filterChange"
|
placeholder="请选择电压等级"
|
>
|
<el-option
|
v-for="(item, idx) in volLevels"
|
:key="'list5_' + idx"
|
:label="item"
|
:value="item"
|
>
|
</el-option>
|
</el-select>
|
</div>
|
</div>
|
</div>
|
<div class="page-content-table">
|
<div class="pos-rel">
|
<div class="pos-abs">
|
<el-table class="yc-table" stripe height="100%" size="small" :data="datas.tableData" style="width: 100%">
|
<el-table-column type="index" fixed="left" label="序号" width="60"></el-table-column>
|
<el-table-column v-for="header in headers" :key="header.prop" :prop="header.prop" :label="header.label"
|
:min-width="header.width" align="center">
|
<template #default="scope">{{ scope.row[header.prop] || '--' }}</template>
|
</el-table-column>
|
<el-table-column label="操作" fixed="right" width="240" align="center">
|
<template #default="scope">
|
<el-button type="primary" size="small"
|
@click="edit(scope.row)">编辑</el-button>
|
<el-button type="danger" size="small"
|
@click="confirmRemove(scope.row)">删除</el-button>
|
<el-button type="primary" size="small"
|
@click="addBatt(scope.row)">添加电池组</el-button>
|
</template>
|
</el-table-column>
|
</el-table>
|
</div>
|
</div>
|
</div>
|
<div class="page-content-page">
|
<div class="page-tool">
|
<el-button type="primary" round size="small" @click="add" :icon="Plus">添加</el-button>
|
<el-button type="primary" round size="small" @click="getList" :icon="Search">查询</el-button>
|
</div>
|
<div class="el-page-container">
|
<el-pagination v-model:current-page="pageCurr" v-model:page-size="pageSize"
|
:page-sizes="[20, 40, 60, 80, 100, 200, 300, 400]" size="small" :disabled="disabled"
|
:background="background" layout="total, sizes, prev, pager, next, jumper" :total="total"
|
@size-change="handleSizeChange" @current-change="handleCurrentChange" />
|
</div>
|
<div class="page-tool"></div>
|
</div>
|
</div>
|
</yc-card>
|
</div>
|
<div class="page-footer"></div>
|
<!-- 弹窗 -->
|
<el-dialog :title="dialogTitle" v-model="addEditVisible" top="0" :close-on-click-modal="false" class="dialog-center"
|
width="1000px" center>
|
<add-edit v-if="addEditVisible" @success="onOk" :info="datas.rowData" @cancel="onCanel"></add-edit>
|
</el-dialog>
|
</div>
|
</template>
|
|
<style scoped lang="less">
|
.page-wrapper {
|
display: flex;
|
flex-direction: row;
|
// padding: 8px;
|
height: 100%;
|
|
.page-content {
|
flex: 1;
|
}
|
}
|
|
.page-content-wrapper {
|
display: flex;
|
flex-direction: column;
|
height: 100%;
|
|
.page-content-tools {
|
padding-bottom: 8px;
|
}
|
|
.page-content-table {
|
// border-top: 1px solid var(--border-light-color);
|
box-sizing: border-box;
|
flex: 1;
|
margin-left: 26px;
|
margin-right: 26px;
|
}
|
|
.page-content-page {
|
padding: 8px 8px 0 8px;
|
text-align: center;
|
|
.el-page-container {
|
display: inline-block;
|
padding: 0 16px;
|
}
|
|
.page-tool {
|
display: inline-block;
|
}
|
}
|
}
|
|
.hdw-card-container {
|
width: 240px;
|
padding-right: 8px;
|
height: 100%;
|
}
|
|
.pos-rel {
|
position: relative;
|
width: 100%;
|
height: 100%;
|
|
.pos-abs {
|
position: absolute;
|
top: 0;
|
bottom: 0;
|
left: 0;
|
right: 0;
|
width: 100%;
|
height: 100%;
|
}
|
}
|
|
.tools-filter {
|
display: inline-block;
|
font-size: 14px;
|
|
.tools-filter-item {
|
display: inline-block;
|
margin-right: 8px;
|
|
.filter-label {
|
display: inline-block;
|
}
|
|
.filter-content {
|
display: inline-block;
|
}
|
}
|
}
|
</style>
|