smart-power-ui/src/views/iot/project/index.vue

1113 lines
30 KiB
Vue

<template>
<div class="app-container iot-project">
<component
:is="componectVal"
:sourceId="sourceId"
@linkToTable="linkToTable"
></component>
<div v-show="componectVal === ''">
<el-form
v-show="showSearch"
ref="queryForm"
:inline="true"
:model="queryParams"
class="main-search-card"
label-width="68px"
>
<el-form-item label="项目名称" prop="projectName">
<el-input
v-model="queryParams.projectName"
clearable
placeholder="请输入项目名称"
size="small"
@keyup.enter.native="handleQuery"
/>
</el-form-item>
<el-form-item label="项目类型" prop="industry">
<el-select
v-model="queryParams.industry"
clearable
placeholder="请选择项目类型"
size="small"
>
<el-option
v-for="dict in projectTypeOptions"
:key="dict.dictValue"
:label="dict.dictLabel"
:value="dict.dictValue"
></el-option>
</el-select>
</el-form-item>
<el-form-item>
<el-button
icon="el-icon-search"
size="mini"
type="primary"
@click="handleQuery"
>搜索</el-button
>
<el-button icon="el-icon-refresh" size="mini" @click="resetQuery"
>重置</el-button
>
</el-form-item>
</el-form>
<div class="main-content-card">
<el-row :gutter="10" class="mb8">
<el-col :span="1.5">
<el-button
v-hasPermi="['iot:project:add']"
icon="el-icon-plus"
plain
size="mini"
type="primary"
@click="handleAdd"
>新增</el-button
>
</el-col>
<right-toolbar
:showSearch.sync="showSearch"
:view-type="viewType"
@changeViewType="changeViewType"
@queryTable="getList"
></right-toolbar>
</el-row>
<el-table
v-if="viewType!='card'"
v-loading="loading"
:data="projectList"
:default-sort="{ prop: 'createTime', order: 'descending' }"
@sort-change="sortChange"
>
<el-table-column
:index="indexFormatter"
align="center"
label="序号"
type="index"
width="60px"
></el-table-column>
<el-table-column
align="center"
label="项目名称"
prop="projectName"
/>
<el-table-column
:formatter="statusFormat"
align="center"
label="项目类型"
prop="industry"
width="80"
/>
<el-table-column
align="center"
label="行政区划"
prop="regionalismFullName"
width="160"
/>
<el-table-column align="center" label="项目地址" prop="projectAddress">
<template slot-scope="scope">
<el-tooltip :content="scope.row.projectAddress" effect="dark" placement="top">
<span class="lay-table-textarea">{{ scope.row.projectAddress }}</span>
</el-tooltip>
</template>
</el-table-column>
<el-table-column
align="center"
label="创建时间"
prop="createTime"
sortable="custom"
width="160"
/>
<el-table-column
align="center"
class-name="small-padding fixed-width"
label="操作"
width="200"
>
<template slot-scope="scope">
<el-button
icon="el-icon-search"
size="mini"
type="text"
@click="handleDetails(scope.row)"
>详情</el-button
>
<el-button
v-hasPermi="['iot:project:edit']"
icon="el-icon-edit"
size="mini"
type="text"
@click="handleUpdate(scope.row)"
>修改</el-button
>
<el-button
v-hasPermi="['iot:project:remove']"
icon="el-icon-delete"
size="mini"
type="text"
@click="handleDelete(scope.row)"
>删除</el-button
>
</template>
</el-table-column>
</el-table>
<div v-else class="card-list-box">
<el-row :gutter="20">
<el-col v-for="(item, index) in projectList" :key="index" :lg="8" :md="12" :sm="12" :xs="24" class="card-item-col">
<div class="card-item">
<div class="card-header">
<div class="card-header-top">
<div class="device-img-box">
<el-image
:preview-src-list="[deviceImgUrl]"
:src="deviceImgUrl"
style="width: 100%; height: 100%">
</el-image>
</div>
<div class="card-item-name">{{ item.projectName }}</div>
</div>
<div class="card-item-address">项目地址:{{ item.projectAddress }}</div>
</div>
<div class="card-content">
<div class="info-item">
<span class="label">类型:</span>
<span class="value">{{ statusFormat(item) }}</span>
</div>
<div class="info-item">
<span class="label">创建时间:</span>
<el-tooltip :content="item.createTime" effect="dark" placement="top">
<span class="value">{{ item.createTime }}</span>
</el-tooltip>
</div>
</div>
<div class="card-footer">
<el-button icon="el-icon-search" type="text" @click="handleDetails(item)">查看详情</el-button>
<el-divider direction="vertical"></el-divider>
<el-button v-hasPermi="['iot:project:edit']" icon="el-icon-edit" type="text" @click="handleUpdate(item)">修改</el-button>
<el-divider direction="vertical"></el-divider>
<el-button v-hasPermi="['iot:project:remove']" icon="el-icon-delete" type="text" @click="handleDelete(item)">删除</el-button>
</div>
</div>
</el-col>
</el-row>
<el-empty v-if="total === 0"></el-empty>
</div>
<pagination
v-show="total > 0"
:limit.sync="queryParams.pageSize"
:page-sizes="[12, 24, 36, 60]"
:page.sync="queryParams.pageNum"
:total="total"
@pagination="getList"
/>
</div>
<!-- 添加或修改项目对话框 -->
<dialog-template
:title="title"
:visible="open"
class="eldialog-wrap"
width="720px"
@close="open = false"
>
<el-form
ref="form"
slot="dialog-center"
:model="form"
:rules="rules"
label-width="100px"
>
<el-row :gutter="20">
<el-col :span="12">
<el-form-item label="项目名称:" prop="projectName">
<el-input
v-model="form.projectName"
placeholder="请输入项目名称"
/>
</el-form-item>
</el-col>
<el-col :span="12">
<el-form-item label="项目类型:" prop="industry">
<el-select
v-model="form.industry"
placeholder="请选择项目类型"
style="width: 100%"
>
<el-option
v-for="dict in projectTypeOptions"
:key="dict.dictValue"
:label="dict.dictLabel"
:value="dict.dictValue"
></el-option>
</el-select>
</el-form-item>
</el-col>
</el-row>
<el-form-item label="电价合同:">
<e-dialog-table-input
v-model="form.contractName"
:refurbishFun="listContract"
:table="selectPriceTable"
fileName="contractId,contractName"
psize="small"
showFileName="contractName"
title="合同"
@change="handleProiceDialogEvent"
/>
</el-form-item>
<el-form-item label="行政区划" prop="regionalismId">
<!-- <el-input v-model="form.regionalismId" placeholder="请输入行政区划代码" /> -->
<treeselect
v-model="form.regionalismId"
:disable-branch-nodes="true"
:normalizer="normalizer"
:options="regionalismOption"
placeholder="请选择上级行政区划"
@select="regionalismChange"
/>
</el-form-item>
<el-row :gutter="20">
<el-col :span="12">
<el-form-item label="项目经度" prop="projectLng">
<el-input
v-model="form.projectLng"
disabled
placeholder="请输入项目经度"
/>
</el-form-item>
</el-col>
<el-col :span="12">
<el-form-item label="项目纬度" prop="projectLat">
<el-input
v-model="form.projectLat"
disabled
placeholder="请输入项目纬度"
/>
</el-form-item>
</el-col>
</el-row>
<el-row>
<el-col :span="24">
<el-form-item label="项目地址" prop="projectAddress">
<el-input
v-model="form.projectAddress"
placeholder="请输入项目地址"
@blur="mapAddressFromPoint"
>
<el-popover
slot="suffix"
v-model="visible"
placement="left-start"
title="地图选择坐标"
trigger="manual"
width="730"
>
<i
slot="reference"
class="el-icon-map-location"
@click="mapClick"
></i>
<!-- 地图模块选择和设置 -->
<slot>
<el-row>
<el-col :span="7">
<span>经度:{{ mapForm.lng }}</span>
</el-col>
<el-col :span="7">
<span>纬度:{{ mapForm.lat }}</span>
</el-col>
<el-col :span="10">
<span>地址:{{ mapForm.address }}</span>
</el-col>
</el-row>
<shop-location
v-if="visible === true"
:draggable="true"
:mapCenter="mapCenter"
:zoom="zoom"
style="height: 300px"
@mapEvent="mapEvent"
/>
<div
style="
width: 100%;
height: 50px;
display: flex;
align-items: center;
justify-content: flex-end;
margin-top: 5px;
"
>
<el-button type="primary" @click="mapSureClick"
>确 定</el-button
>
<el-button @click="visible = false">取 消</el-button>
</div>
</slot>
</el-popover>
</el-input>
</el-form-item>
</el-col>
</el-row>
<el-row :gutter="20">
<el-col :span="12">
<el-form-item label="联系方式1" prop="contacts1">
<el-input
v-model="form.contacts1"
placeholder="请输入联系方式1"
/>
</el-form-item>
</el-col>
<el-col :span="12">
<el-form-item label="联系方式2" prop="contacts2">
<el-input
v-model="form.contacts2"
placeholder="请输入联系方式2"
/>
</el-form-item>
</el-col>
<el-col :span="12">
<el-form-item label="联系方式3" prop="contacts3">
<el-input
v-model="form.contacts3"
placeholder="请输入联系方式3"
/>
</el-form-item>
</el-col>
</el-row>
<el-form-item label="总路设备:">
<e-dialog-table-input
v-model="form.projectDeviceName"
:refurbishFun="listDevice"
:table="selectDeviceTable"
fileName="deviceId,deviceName"
psize="small"
showFileName="deviceName"
title="设备"
@change="handleDeviceDialogEvent"
/>
</el-form-item>
</el-form>
<div slot="dialog-footer" class="dialog-footer">
<el-button size="mini" type="primary" @click="submitForm"
>确 定</el-button
>
<el-button size="mini" @click="cancel">取 消</el-button>
</div>
</dialog-template>
</div>
<!-- <div class="to-home-wrap2" @click="linkToTable" v-show="componectVal !== ''">
<el-button icon="el-icon-d-arrow-left" title="返回列表" circle>返回列表</el-button>
</div> -->
</div>
</template>
<script>
import {
listProject,
getProject,
delProject,
addProject,
updateProject,
exportProject,
} from "@/api/iot/project";
import { listDevice } from "@/api/iot/device";
import { listContract } from "@/api/iot/contract";
import { listRegionalism } from "@/api/system/regionalism";
import { initMap, gjzCode } from "@/utils/latlngFromAddress.js";
import ShopLocation from "@/components/Amap/components/shopLocation/index";
import DetailsWrap from "./profile/details";
import Treeselect from "@riophae/vue-treeselect";
import "@riophae/vue-treeselect/dist/vue-treeselect.css";
import DialogTemplate from "@/components/DialogTemplate/index";
import EDialogTableInput from "@/components/EDialogTableInput";
import deviceImgUrl from "@/assets/images/device/device-number.png";
/////、、、、、、、、、、、、、、、、、、、、
import EDetailsWrap from "./profileV2/details";
const selectDeviceTable = {
otherOption: {
tableType: "device",
},
queryOption: {
disable: false,
labelWidth: "68px",
params: {
deviceName: "",
parentId: 0,
deviceType: "10002",
},
inline: true,
queryChilds: [
{
style: "",
placeholder: "设备名称",
clearable: true,
label: "设备名称",
type: "input",
key: "deviceName",
size: "small",
value: "",
},
],
},
tableOption: {
loading: false,
rowKey: "deviceId",
selection: false,
maxHeight: "45vh",
childs: [
{
style: "",
label: "所属型号",
type: "",
prop: "modelName",
align: "left",
width: "",
"show-overflow-tooltip": false,
tempType: "span",
},
{
style: "",
label: "设备名称",
type: "",
prop: "deviceName",
align: "left",
width: "",
"show-overflow-tooltip": false,
tempType: "span",
},
{
style: "",
label: "设备Key",
type: "",
prop: "deviceKey",
align: "left",
width: "",
"show-overflow-tooltip": false,
tempType: "span",
},
{
style: "",
label: "创建时间",
type: "time",
prop: "createTime",
align: "center",
width: "160",
"show-overflow-tooltip": false,
tempType: "span",
},
],
},
};
const selectPriceTable = {
otherOption: {
tableType: "project",
},
queryOption: {
disable: false,
labelWidth: "68px",
params: {
contractName: "",
modelCode: "",
},
page: {
pageSize: 10,
pageNum: 1,
total: 0,
},
inline: true,
queryChilds: [
{
style: "",
placeholder: "合同名称",
clearable: true,
label: "合同名称",
type: "input",
key: "contractName",
size: "small",
value: "",
},
],
},
tableOption: {
loading: false,
rowKey: "deviceId",
selection: false,
maxHeight: "45vh",
childs: [
{
style: "",
label: "合同名称",
type: "",
prop: "contractName",
align: "left",
width: "",
"show-overflow-tooltip": false,
tempType: "span",
},
{
style: "",
label: "计价类型",
type: "",
prop: "contractType",
align: "left",
width: "",
"show-overflow-tooltip": false,
tempType: "strType",
option: {
PEAK_VALLEY: "峰谷时段计价",
LADDER: "阶梯计价",
},
},
{
style: "",
label: "状态",
type: "",
prop: "status",
align: "left",
width: "",
"show-overflow-tooltip": false,
tempType: "text1",
},
],
},
};
export default {
name: "Project",
components: {
ShopLocation,
Treeselect,
DetailsWrap,
EDetailsWrap,
DialogTemplate,
EDialogTableInput,
},
data() {
return {
deviceImgUrl,
//列表显示视图
viewType: "card",
selectPriceTable,
selectDeviceTable,
selectTableShow: false,
tableSelectOption: {},
selectResult: {},
// 遮罩层
loading: true,
// 选中数组
ids: [],
// 非单个禁用
single: true,
// 非多个禁用
multiple: true,
// 显示搜索条件
showSearch: true,
// 总条数
total: 0,
// 项目表格数据
projectList: [],
// 弹出层标题
title: "",
// 是否显示弹出层
open: false,
// 查询参数
queryParams: {
pageNum: 1,
pageSize: 12,
projectName: null,
industry: null,
regionalismId: null,
projectAddress: null,
projectStatus: null,
orderByColumn: "createTime",
isAsc: "desc",
},
// 表单参数
form: {},
// 表单校验
rules: {
projectName: [
{ required: true, message: "项目名称不能为空", trigger: "blur" },
],
industry: [
{ required: true, message: "项目类型不能为空", trigger: "blur" },
],
regionalismId: [
{ required: true, message: "行政区划不能为空", trigger: "change" },
],
projectAddress: [
{ required: true, message: "项目地址不能为空", trigger: "change" },
],
projectLng: [
{ required: true, message: "经度不能为空", trigger: "change" },
],
projectLat: [
{ required: true, message: "纬度不能为空", trigger: "change" },
],
},
projectTypeOptions: [],
mapCenter: {
lng: 119.459889,
lat: 25.98974,
},
baiduMapKey: "N05AG95Umzs3fouk6WpFqtGxcDlw0fRn",
zoom: 15,
BMap: null,
map: null,
visible: false,
mapForm: {},
// 行政划分树选项
regionalismOption: [],
componectVal: "",
sourceId: "",
userType: "",
};
},
created() {
if (this.$route.query["projectId"]) {
this.handleDetails(this.$route.query);
}
this.getDicts("project_industry").then((response) => {
this.projectTypeOptions = response.data;
});
this.getList();
this.getTreeselect();
},
activated() {
if (this.$route.query["projectId"]) {
this.handleDetails(this.$route.query);
}
},
methods: {
listContract,
listDevice,
handleProiceDialogEvent(e) {
this.form.contractId = e.contractId;
this.form.contractName = e.contractName;
this.$forceUpdate();
},
handleDeviceDialogEvent(e) {
this.form.projectDevice = e.deviceId;
this.form.projectDeviceName = e.deviceName;
this.$forceUpdate();
},
changeViewType(type) {
this.viewType=type;
},
sortChange(column) {
const sort = {
isAsc: column.order === "descending" ? "desc" : "asc",
orderByColumn: column.prop,
};
this.queryParams = Object.assign(this.queryParams, sort);
this.handleQuery();
},
indexFormatter(val) {
return (
val + 1 + (this.queryParams.pageNum - 1) * this.queryParams.pageSize
);
},
handleDetails(row) {
this.sourceId = row.projectId;
this.componectVal = "EDetailsWrap";
},
// 跳转详情页
linkToTable() {
if (this.$route.query["projectId"]) {
this.$router.push("/project/project");
}
this.componectVal = "";
},
// 菜单状态字典翻译
statusFormat(row, column) {
return this.selectDictLabel(this.projectTypeOptions, row.industry);
},
/** 查询行政区划下拉树结构 */
getTreeselect() {
listRegionalism().then((response) => {
this.regionalismOption = [];
const data = {
regionalismId: 0,
regionalismName: "中国",
children: [],
};
data.children = this.handleTree(
response.data,
"regionalismId",
"parentId"
);
this.regionalismOption.push(data);
});
},
/** 转换行政划分数据结构 */
normalizer(node) {
if (node.children && !node.children.length) {
delete node.children;
}
return {
id: node.regionalismId,
label: node.regionalismName,
children: node.children,
};
},
regionalismChange(val) {
this.mapCenter = {
lng: val.stationLng,
lat: val.stationLat,
};
this.form.projectLng = val.stationLng;
this.form.projectLat = val.stationLat;
},
// 地图方法
handler({ BMap, map }) {
//地图
this.BMap = BMap;
this.map = map;
this.mapLoading = false;
// this.getPointByIp()
},
mapEvent(data) {
this.mapForm.lng = data.lng;
this.mapForm.lat = data.lat;
this.mapForm.address = data.address;
this.$forceUpdate();
},
// 使用地图方式定位
mapClick() {
if (this.form.projectLng && this.form.projectLat) {
this.mapCenter.lng = this.form.projectLng;
this.mapCenter.lat = this.form.projectLat;
this.mapForm.lng = this.form.projectLng;
this.mapForm.lat = this.form.projectLat;
this.mapForm.address = this.form.projectAddress;
} else {
this.mapCenter = {
lng: 119.459889,
lat: 25.98974,
};
this.mapForm.lng = 119.459889;
this.mapForm.lat = 25.98974;
this.mapForm.address = "";
}
this.visible = !this.visible;
},
mapSureClick() {
// 确认的时候将值赋值给form表单并且关闭地图
this.form.projectAddress = this.mapForm.address
? this.mapForm.address
: this.form.projectAddress;
this.form.projectLng = this.mapForm.lng;
this.form.projectLat = this.mapForm.lat;
this.visible = false;
},
mapAddressFromPoint() {
if (this.form.projectAddress) {
// geoCode(this.form.projectAddress, this, { form: 'form', lat: 'shopLat', lng: 'shopLng' })
gjzCode(this.form.projectAddress, this, {
form: "form",
lat: "shopLat",
lng: "shopLng",
});
}
},
/** 查询项目列表 */
getList() {
this.loading = true;
listProject(this.queryParams).then((response) => {
this.projectList = response.rows;
this.total = response.total;
this.loading = false;
});
},
// 取消按钮
cancel() {
this.open = false;
this.reset();
},
// 表单重置
reset() {
this.form = {
projectName: null,
industry: null,
regionalismId: null,
projectAddress: null,
projectLng: null,
projectLat: null,
projectDevice: "",
};
this.resetForm("form");
},
/** 搜索按钮操作 */
handleQuery() {
this.queryParams.pageNum = 1;
this.getList();
},
/** 重置按钮操作 */
resetQuery() {
this.resetForm("queryForm");
this.handleQuery();
},
// 多选框选中数据
handleSelectionChange(selection) {
this.ids = selection.map((item) => item.projectId);
this.single = selection.length !== 1;
this.multiple = !selection.length;
},
/** 新增按钮操作 */
handleAdd() {
this.reset();
this.open = true;
this.title = "添加项目";
},
/** 修改按钮操作 */
handleUpdate(row) {
this.reset();
const projectId = row.projectId || this.ids;
getProject(projectId).then((response) => {
this.form = response.data;
this.open = true;
this.title = "修改项目";
});
},
/** 提交按钮 */
submitForm() {
this.$refs["form"].validate((valid) => {
if (valid) {
if (this.form.projectId != null) {
updateProject(this.form).then((response) => {
this.msgSuccess("修改成功");
this.open = false;
this.getList();
});
} else {
addProject(this.form).then((response) => {
this.msgSuccess("新增成功");
this.open = false;
this.getList();
});
}
}
});
},
/** 删除按钮操作 */
handleDelete(row) {
const projectIds = row.projectId || this.ids;
this.$confirm("是否删除该选项?", "警告", {
confirmButtonText: "确定",
cancelButtonText: "取消",
type: "warning",
})
.then(function () {
return delProject(projectIds);
})
.then(() => {
this.getList();
this.msgSuccess("删除成功");
});
},
/** 导出按钮操作 */
handleExport() {
const queryParams = this.queryParams;
this.$confirm("是否确认导出所有项目数据项?", "警告", {
confirmButtonText: "确定",
cancelButtonText: "取消",
type: "warning",
})
.then(function () {
return exportProject(queryParams);
})
.then((response) => {
this.download(response.msg);
});
},
},
};
</script>
<style lang="scss">
.iot-project {
.eldialog-wrap {
.el-dialog__header {
}
.el-dialog__body {
padding: 0px;
}
.el-form {
padding: 20px;
padding-right: 40px;
}
.el-dialog__footer {
height: 60px;
text-align: right;
width: 100%;
padding: 0px;
padding-top: 15px;
.el-button + .el-button {
margin-right: 10px;
}
.el-button {
padding-top: 8px;
}
}
}
.to-home-wrap2 {
width: 20px;
height: 20px;
position: absolute;
right: 30px;
top: 30px;
display: flex;
justify-content: center;
align-items: center;
z-index: 100;
color: #656363;
font-size: 20px;
cursor: default;
width: 100px;
.el-button--medium.is-circle {
width: 25px;
height: 20px;
padding: 0;
background: #f26a6a;
color: #fff;
font-size: 16px;
border-radius: 5px;
height: 30px;
width: 100%;
font-size: 14px;
}
}
.to-home-wrap2:hover {
color: #1890ff;
font-size: 30px;
}
}
// 卡片视图样式
.card-list-box {
.card-item-col {
margin-top: 15px;
}
.card-item {
height: 100%;
border-radius: 10px;
border: 1px solid #ebeef5;
background-color: #fff;
overflow: hidden;
color: #303133;
transition: 0.3s;
cursor: pointer;
&:hover {
box-shadow: 0 4px 16px 0 rgba(0, 0, 0, 0.2);
//border: 1px solid #409EFF;
}
.card-header {
padding: 10px 20px 0px 20px;
.card-header-top{
display: flex;
align-items: center;
.device-img-box{
width: 60px;
height: 60px;
img{
width: 100%;
height: 100%;
}
}
.card-item-name {
margin-left: 10px;
font-size: 18px;
line-height: 18px;
font-weight: bold;
white-space: nowrap;
overflow: hidden;
text-overflow: ellipsis;
max-width: calc(100% - 110px);
}
}
.card-item-address{
height: 32px;
margin-top: 6px;
font-size: 12px;
color: #999;
line-height: 16px;
display: -webkit-box;
-webkit-box-orient: vertical;
-webkit-line-clamp: 2; /* 限制显示的行数 */
overflow: hidden;
text-overflow: ellipsis;
}
}
.card-content {
padding: 10px 20px;
display: flex;
flex-wrap: wrap;
.info-item {
display: flex;
align-items: center;
margin-bottom: 5px;
font-size: 11px;
width: 50%;
.label {
color: #909399;
width: 35px;
}
.value {
width: calc(100% - 35px);
color: #606266;
white-space: nowrap;
overflow: hidden;
text-overflow: ellipsis;
}
&:nth-child(2n){
width: 50%;
.label {
width: 70px;
}
}
}
}
.card-footer {
display: flex;
justify-content: space-around;
align-items: center;
padding: 10px 15px;
border-top: 1px solid #ebeef5;
.el-button {
padding: 5px 8px;
&:hover {
color: #409EFF;
}
}
}
}
}
</style>