index.vue 41 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169
  1. <template>
  2. <div class="app-container">
  3. <el-row :gutter="20">
  4. <el-col :span="4" :xs="24">
  5. <div v-if="activeTab === 'area'">
  6. <div class="head-container">
  7. <el-input v-model="areaName" placeholder="请输入区块名称" clearable size="small" prefix-icon="el-icon-search"
  8. style="margin-bottom: 20px" />
  9. </div>
  10. <div class="head-container">
  11. <el-tree :data="areaList" :props="defaultProps" :expand-on-click-node="false" :filter-node-method="filterNode" ref="tree"
  12. node-key="id" default-expand-all highlight-current @node-click="handleNodeClick"/>
  13. </div>
  14. </div>
  15. <div v-if="activeTab === 'organ'">
  16. <div class="head-container">
  17. <el-input v-model="deptName" placeholder="请输入区块名称" clearable size="small" prefix-icon="el-icon-search"
  18. style="margin-bottom: 20px" />
  19. </div>
  20. <div class="head-container">
  21. <el-tree :key="treeKey" :data="deptList" :props="defaultDeptProps" :expand-on-click-node="false" :filter-node-method="filterNode" ref="tree"
  22. node-key="deptId" default-expand-all highlight-current @node-click="handleDeptNodeClick"/>
  23. </div>
  24. </div>
  25. <div v-if="activeTab === 'facs'">
  26. <div class="head-container">
  27. <el-input v-model="areaName" placeholder="请输入区块名称" clearable size="small" prefix-icon="el-icon-search"
  28. style="margin-bottom: 20px"
  29. />
  30. </div>
  31. <div class="head-container">
  32. <el-tree :key="tableKey" :data="facsOptions" :props="defaultFacsProps" :expand-on-click-node="false"
  33. :filter-node-method="filterNode" ref="tree"
  34. node-key="id" default-expand-all highlight-current @node-click="handleFacsNodeClick"
  35. />
  36. </div>
  37. </div>
  38. <div v-if="activeTab === 'device'">
  39. <div class="head-container">
  40. <el-input v-model="areaName" placeholder="请输入区块名称" clearable size="small" prefix-icon="el-icon-search"
  41. style="margin-bottom: 20px"
  42. />
  43. </div>
  44. <div class="head-container">
  45. <el-tree :key="tableKey" :data="deviceOptions" :props="defaultFacsProps" :expand-on-click-node="false"
  46. :filter-node-method="filterNode" ref="tree"
  47. node-key="id" default-expand-all highlight-current @node-click="handleDeviceNodeClick"
  48. />
  49. </div>
  50. </div>
  51. </el-col>
  52. <el-tabs v-model="activeTab" @tab-click="handleTabClick">
  53. <el-tab-pane label="地理位置" name="area"></el-tab-pane>
  54. <el-tab-pane label="组织机构" name="organ"></el-tab-pane>
  55. <el-tab-pane label="设施" name="facs"></el-tab-pane>
  56. <el-tab-pane label="设备" name="device"></el-tab-pane>
  57. </el-tabs>
  58. <el-col :span="20" :xs="24">
  59. <!-- 地理位置 -->
  60. <div v-if="activeTab === 'area'">
  61. <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="68px">
  62. <el-form-item label="区域名称" prop="areaName">
  63. <el-input
  64. v-model="queryParams.areaName"
  65. placeholder="请输入区域名称"
  66. clearable
  67. @keyup.enter.native="handleQuery"
  68. />
  69. </el-form-item>
  70. <el-form-item>
  71. <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
  72. <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
  73. </el-form-item>
  74. </el-form>
  75. <el-table
  76. :key="tableKey"
  77. v-if="refreshTable"
  78. v-loading="loading"
  79. :data="areaOptions"
  80. :default-expand-all="isExpandAll"
  81. row-key="areaCode"
  82. :tree-props="{children: 'children', hasChildren: 'hasChildren'}"
  83. >
  84. <el-table-column label="区域名称" align="left" prop="areaName" />
  85. <el-table-column label="区域简称" align="left" prop="shortName" />
  86. <el-table-column label="区域编码" align="left" prop="areaCode" />
  87. <el-table-column label="区域状态" align="center" >
  88. <template slot-scope="scope">
  89. {{ objStatusMapping[scope.row.status] }}
  90. </template>
  91. </el-table-column>
  92. <el-table-column label="区块标签" align="center">
  93. <template slot-scope="scope">
  94. <span v-for="tag in (scope.row.tagNames && scope.row.tagNames.split(',')) || []" :key="tag" :style="getTagStyle(tag.trim())" class="tag-label">
  95. {{ tag.trim() }}
  96. </span>
  97. </template>
  98. </el-table-column>
  99. <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
  100. <template slot-scope="scope">
  101. <el-button
  102. size="mini"
  103. type="text"
  104. icon="el-icon-reading"
  105. @click="handleDevice(scope.row)"
  106. v-hasPermi="['ems:area:edit']"
  107. >计量设备</el-button>
  108. </template>
  109. </el-table-column>
  110. </el-table>
  111. </div>
  112. <!-- 组织机构 -->
  113. <div v-if="activeTab === 'organ'">
  114. <el-form :model="DeptQueryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch">
  115. <el-form-item label="部门名称" prop="deptName">
  116. <el-input
  117. v-model="DeptQueryParams.deptName"
  118. placeholder="请输入部门名称"
  119. clearable
  120. @keyup.enter.native="handleDeptQuery"
  121. />
  122. </el-form-item>
  123. <el-form-item label="状态" prop="status">
  124. <el-select v-model="DeptQueryParams.status" placeholder="部门状态" clearable>
  125. <el-option
  126. v-for="dict in dict.type.sys_normal_disable"
  127. :key="dict.value"
  128. :label="dict.label"
  129. :value="dict.value"
  130. />
  131. </el-select>
  132. </el-form-item>
  133. <el-form-item>
  134. <el-button type="primary" icon="el-icon-search" size="mini" @click="handleDeptQuery">搜索</el-button>
  135. <el-button icon="el-icon-refresh" size="mini" @click="resetDeptQuery">重置</el-button>
  136. </el-form-item>
  137. </el-form>
  138. <el-table
  139. v-if="refreshTable"
  140. v-loading="loading"
  141. :data="organOptions"
  142. row-key="deptId"
  143. :default-expand-all="isExpandAll"
  144. :tree-props="{children: 'children', hasChildren: 'hasChildren'}"
  145. >
  146. <el-table-column prop="deptName" label="部门名称" width="260"></el-table-column>
  147. <el-table-column prop="orderNum" label="排序" width="200"></el-table-column>
  148. <el-table-column prop="status" label="状态" width="100">
  149. <template slot-scope="scope">
  150. <dict-tag :options="dict.type.sys_normal_disable" :value="scope.row.status"/>
  151. </template>
  152. </el-table-column>
  153. <el-table-column label="创建时间" align="center" prop="createTime" width="200">
  154. <template slot-scope="scope">
  155. <span>{{ parseTime(scope.row.createTime) }}</span>
  156. </template>
  157. </el-table-column>
  158. <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
  159. <template slot-scope="scope">
  160. <el-button
  161. size="mini"
  162. type="text"
  163. icon="el-icon-reading"
  164. @click="handleDeptDevice(scope.row)"
  165. v-hasPermi="['ems:area:edit']"
  166. >计量设备</el-button>
  167. </template>
  168. </el-table-column>
  169. </el-table>
  170. </div>
  171. <!-- 设施 -->
  172. <div v-if="activeTab === 'facs'">
  173. <el-tabs v-model="FacsQueryParams.facsCategory" @tab-click="facsCategoryChange">
  174. <el-tab-pane label="产能设施" name="E"></el-tab-pane>
  175. <el-tab-pane label="储能设施" name="C"></el-tab-pane>
  176. <el-tab-pane label="输能设施" name="W"></el-tab-pane>
  177. <el-tab-pane label="用能设施" name="Z"></el-tab-pane>
  178. </el-tabs>
  179. <el-form :model="FacsQueryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch"
  180. label-width="68px"
  181. >
  182. <el-form-item label="设施子类" prop="facsSubtype">
  183. <el-select v-model="FacsQueryParams.facsSubCategory">
  184. <el-option v-for="item in facsSubCategoryOptions" :label="item.name" :value="item.code" :key="item.code"/>
  185. </el-select>
  186. </el-form-item>
  187. <el-form-item label="设施名称" prop="facsName">
  188. <el-input v-model="FacsQueryParams.facsName" placeholder="请输入设施名称" clearable
  189. @keyup.enter.native="handleFacsQuery"
  190. />
  191. </el-form-item>
  192. <el-form-item>
  193. <el-button type="primary" icon="el-icon-search" size="mini" @click="handleFacsQuery">搜索</el-button>
  194. <el-button icon="el-icon-refresh" size="mini" @click="resetFacsQuery">重置</el-button>
  195. </el-form-item>
  196. </el-form>
  197. <el-table :key="tableKey" v-loading="loading" :data="facsList" @selection-change="handleSelectionChange">
  198. <el-table-column type="selection" width="55" align="center"/>
  199. <el-table-column label="设施代码" align="center" prop="facsCode"/>
  200. <el-table-column label="设施名称" align="center" prop="facsName"/>
  201. <el-table-column label="设施分类" align="center" prop="facsCategoryName"/>
  202. <el-table-column label="设施子类" align="center" prop="facsSubCategoryName"/>
  203. <el-table-column label="启用状态" align="center" prop="enable">
  204. <template slot-scope="scope">
  205. <span
  206. :style="{
  207. padding: '6px 12px',
  208. borderRadius: '4px',
  209. display: 'inline-block',
  210. textAlign: 'center',
  211. cursor: 'pointer',
  212. color: scope.row.enable === 0 ? 'rgb(255,159,159)' : 'rgb(117,186,255)',
  213. backgroundColor: scope.row.enable === 0 ? 'rgb(255,235,235)' : 'rgb(232,244,255)'
  214. }"
  215. >
  216. {{ scope.row.enable === 0 ? '关闭' : '启用' }}
  217. </span>
  218. </template>
  219. </el-table-column>
  220. <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
  221. <template slot-scope="scope">
  222. <el-button
  223. size="mini"
  224. type="text"
  225. icon="el-icon-reading"
  226. @click="handleFacsDevice(scope.row)"
  227. v-hasPermi="['ems:area:edit']"
  228. >计量设备</el-button>
  229. </template>
  230. </el-table-column>
  231. </el-table>
  232. </div>
  233. <!--设备 -->
  234. <div v-if="activeTab === 'device'">
  235. <el-tabs v-model="DeviceQueryParams.deviceCategory" @tab-click="deviceCategoryChange">
  236. <el-tab-pane label="产能设备" name="E"></el-tab-pane>
  237. <el-tab-pane label="储能设备" name="C"></el-tab-pane>
  238. <el-tab-pane label="输能设备" name="W"></el-tab-pane>
  239. <el-tab-pane label="用能设备" name="Z"></el-tab-pane>
  240. </el-tabs>
  241. <el-form :model="DeviceQueryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch"
  242. label-width="68px"
  243. >
  244. <el-form-item label="设备分类" prop="deviceSubCategory">
  245. <el-select v-model="DeviceQueryParams.deviceSubCategory">
  246. <el-option v-for="item in subCategoryOptions" placeholder="设备分类" :label="item.name" :value="item.code"
  247. :key="item.code"
  248. />
  249. </el-select>
  250. </el-form-item>
  251. <el-form-item label="归属设施" prop="refFacs">
  252. <el-select v-model="DeviceQueryParams.refFacs">
  253. <el-option v-for="item in facsAllOptions" :label="item.facsName" :value="item.facsCode"
  254. :key="item.facsCode"
  255. />
  256. </el-select>
  257. </el-form-item>
  258. <el-form-item label="子系统" prop="subsystemCode">
  259. <el-select v-model="DeviceQueryParams.subsystemCode">
  260. <el-option v-for="item in subsystemOptions" :label="item.systemName" :value="item.systemCode"
  261. :key="item.systemCode"
  262. />
  263. </el-select>
  264. </el-form-item>
  265. <el-form-item label="设备工艺" prop="psCode" v-if="DeviceQueryParams.deviceCategory === 'W'">
  266. <el-select v-model="DeviceQueryParams.psCode">
  267. <el-option v-for="item in devOptions" :label="item.psName" :value="item.psCode" :key="item.psCode"/>
  268. </el-select>
  269. </el-form-item>
  270. <el-form-item>
  271. <el-button type="primary" icon="el-icon-search" size="mini" @click="handleDeviceQuery">搜索</el-button>
  272. <el-button icon="el-icon-refresh" size="mini" @click="resetDeviceQuery">重置</el-button>
  273. </el-form-item>
  274. </el-form>
  275. <el-table :key="tableKey" v-loading="loading" :data="deviceList" @selection-change="handleSelectionChange">
  276. <el-table-column type="selection" width="55" align="center"/>
  277. <el-table-column label="设备名称" align="left" prop="deviceName"/>
  278. <el-table-column label="安装位置" align="left" prop="areaPath" width="220px"/>
  279. <el-table-column label="归属设施" align="center" prop="refFacsName"/>
  280. <el-table-column label="设备分类" align="center" prop="deviceCategoryName"/>
  281. <el-table-column label="子系统" align="center" prop="subsystemName"/>
  282. <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
  283. <template slot-scope="scope">
  284. <el-button
  285. size="mini"
  286. type="text"
  287. icon="el-icon-reading"
  288. @click="handleAllDevice(scope.row)"
  289. v-hasPermi="['ems:area:edit']"
  290. >计量设备</el-button>
  291. </template>
  292. </el-table-column>
  293. </el-table>
  294. </div>
  295. </el-col>
  296. <!-- 计量设备弹框 -->
  297. <el-dialog :title="dialogTitle" :visible.sync="deviceDialogVisible" width="1000px" append-to-body>
  298. <el-tabs v-model="activeDeviceTab" @tab-click="handleADTabClick">
  299. <el-tab-pane label="电表" name="electricMeter"></el-tab-pane>
  300. <el-tab-pane label="水表" name="waterMeter"></el-tab-pane>
  301. </el-tabs>
  302. <!-- 水表和电表的已绑定和未绑定表格 -->
  303. <SubTitle title="已绑定列表" />
  304. <el-table v-loading="loading" :data="Bound" style="width: 100%">
  305. <el-table-column label="表计编号" align="left" prop="meterDevice" />
  306. <el-table-column label="表计名称" align="left" prop="meterDeviceName" />
  307. <el-table-column label="边界类型" align="left" prop="objType">
  308. <template slot-scope="scope">
  309. {{ getObjTypeLabel(scope.row.objType) }}
  310. </template>
  311. </el-table-column>
  312. <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
  313. <template slot-scope="scope">
  314. <el-button size="mini" type="text" icon="el-icon-arrow-down" @click="downToDevice(scope.row)">取消绑定</el-button>
  315. </template>
  316. </el-table-column>
  317. </el-table>
  318. <SubTitle title="未绑定列表" />
  319. <el-table v-loading="loading" :data="Unbound" style="width: 100%">
  320. <el-table-column label="表计编号" align="left" prop="deviceCode" />
  321. <el-table-column label="表计名称" align="left" prop="deviceName" width="200px"/>
  322. <el-table-column label="安装位置" align="left" prop="deviceLocation" width="200px"/>
  323. <el-table-column label="计量标签" align="center" prop="objTag">
  324. <template slot-scope="scope">
  325. {{formatDict(scope.row.objTag,'objTagOptions')}}
  326. </template>
  327. </el-table-column>
  328. <el-table-column label="采集方式" align="center" prop="colMode">
  329. <template slot-scope="scope">
  330. <span>{{ getColModeName(scope.row.colMode) }}</span>
  331. </template>
  332. </el-table-column>
  333. <el-table-column label="采集周期" align="center" prop="colCycle">
  334. <template slot-scope="scope">
  335. <span>{{ getColCycleName(scope.row.colCycle) }}</span>
  336. </template>
  337. </el-table-column>
  338. <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
  339. <template slot-scope="scope">
  340. <!-- 检查是否已绑定 -->
  341. <div v-if="isAlreadyBound(scope.row.deviceCode)">
  342. <span>已绑定</span>
  343. </div>
  344. <div v-else>
  345. <el-button
  346. size="mini"
  347. type="text"
  348. icon="el-icon-arrow-up"
  349. @click="moveToDevice(scope.row)"
  350. >绑定</el-button>
  351. </div>
  352. </template>
  353. </el-table-column>
  354. </el-table>
  355. <pagination v-show="total>0" :total="total" :page.sync="MeterQueryParams.pageNum" :limit.sync="MeterQueryParams.pageSize"
  356. @pagination="getMeterData" />
  357. <div slot="footer" class="dialog-footer">
  358. <el-button @click="saveByObj">保 存</el-button>
  359. <el-button @click="MeterCancel">取 消</el-button>
  360. </div>
  361. </el-dialog>
  362. </el-row>
  363. </div>
  364. </template>
  365. <script>
  366. import Treeselect from '@riophae/vue-treeselect'
  367. import '@riophae/vue-treeselect/dist/vue-treeselect.css'
  368. import { areaTreeSelect, listDetailArea } from '@/api/basecfg/area'
  369. import SubTitle from '@/components/SubTitle/index.vue'
  370. import { getDevProcess, getEmsTag } from '@/api/commonApi'
  371. import { delDevice, listDevice } from '@/api/device/meterDevice'
  372. import { addAllByObj, listByObj } from '@/api/basecfg/meterBoundary'
  373. import { listDept } from '@/api/system/dept'
  374. import { getFacsCategorygetByCode, listAllFacs, listFacs } from '@/api/basecfg/emsfacs'
  375. import { listDevRecursionByArea } from '@/api/device/device'
  376. import { listSubsystemAll } from '@/api/adapter/subsystem'
  377. export default {
  378. name: 'Device',
  379. dicts: ['sys_normal_disable'],
  380. components: { SubTitle, Treeselect },
  381. data() {
  382. return {
  383. activeTab: 'area',
  384. areaOptions: [],
  385. organOptions: [],
  386. facsOptions: undefined,
  387. facsAllOptions:undefined,
  388. deviceOptions:undefined,
  389. // 区域名称
  390. areaName: undefined,
  391. deptName:undefined,
  392. defaultProps: {
  393. children: 'children',
  394. label: 'areaName'
  395. },
  396. defaultDeptProps: {
  397. children: 'children',
  398. label: 'deptName'
  399. },
  400. defaultFacsProps: {
  401. children: 'children',
  402. label: 'label'
  403. },
  404. treeKey: 0,
  405. tableKey: 0,
  406. // 遮罩层
  407. loading: true,
  408. // 选中数组
  409. ids: [],
  410. // 非单个禁用
  411. single: true,
  412. // 非多个禁用
  413. multiple: true,
  414. // 显示搜索条件
  415. showSearch: true,
  416. // 区域对象表格数据
  417. areaList: [],
  418. deptList:[],
  419. facsList:[],
  420. deviceList:[],
  421. // 总条数
  422. total: 0,
  423. // 弹出层标题
  424. title: "",
  425. // 是否显示弹出层
  426. open: false,
  427. // 是否展开,默认全部展开
  428. isExpandAll: true,
  429. // 重新渲染表格状态
  430. refreshTable: true,
  431. // 标签选项
  432. emsTagOptions: [],
  433. tagCodeToColorMap:{},
  434. // 地理位置查询参数
  435. queryParams: {
  436. pageNum: 1,
  437. pageSize: 10,
  438. areaCode: null,
  439. parentCode: null,
  440. ancestors: null,
  441. areaName: null,
  442. shortName: null,
  443. desc: null,
  444. orderNum: null,
  445. status: null,
  446. tagNames:null,
  447. areaAttr:{}
  448. },
  449. // 组织机构查询参数
  450. DeptQueryParams: {
  451. deptName: undefined,
  452. status: undefined
  453. },
  454. // 设施 查询参数
  455. FacsQueryParams: {
  456. pageNum: 1,
  457. pageSize: 10,
  458. facsCode: null,
  459. facsName: null,
  460. facsCategory: 'E',
  461. facsSubCategory: null,
  462. enable: null,
  463. refArea: null,
  464. customAttrs: null
  465. },
  466. // 设备查询参数
  467. DeviceQueryParams: {
  468. psCode: null,
  469. pageNum: 1,
  470. pageSize: 10,
  471. deviceCode: null,
  472. deviceSubCategory: '',
  473. deviceCategory: 'E',
  474. locationRef: null,
  475. refFacs: null,
  476. customAttrs: null
  477. },
  478. // 水表、电表查询参数
  479. MeterQueryParams: {
  480. pageNum: 1,
  481. pageSize: 10,
  482. areaCode: null,
  483. bldgCode: null,
  484. deviceCode: null,
  485. meterCls: null,
  486. objTag: null,
  487. colCycle: null,
  488. colMode: null,
  489. magnification: null,
  490. specDesc: null
  491. },
  492. objStatusMapping: {
  493. 0: '正常',
  494. 1: '停用',
  495. },
  496. // 表单参数
  497. form: {
  498. areaAttr: {
  499. areaCode:null,
  500. attrOrg: null,
  501. mgrOrg: null,
  502. leader: null,
  503. phone: null,
  504. openDate: null,
  505. floorArea: null,
  506. usableArea: null,
  507. floor: null,
  508. tagCodes:null,
  509. tagNames:null,
  510. tagCodeList:[]
  511. }
  512. },
  513. // 表单校验
  514. rules: {
  515. areaCode: [
  516. { required: true, message: "区域代码不能为空", trigger: "blur" }
  517. ],
  518. areaName: [
  519. { required: true, message: "区域名称不能为空", trigger: "blur" }
  520. ],
  521. },
  522. objTagOptions: [
  523. { code: 0, name: '公摊表' },
  524. { code: 1, name: '个户表' }
  525. ],
  526. allAreaNode: {
  527. id: 'all',
  528. areaName: '全部',
  529. children: []
  530. },
  531. allDeptNode: {
  532. deptId: 'all',
  533. deptName: '全部',
  534. children: []
  535. },
  536. // 设施分类列表
  537. facsCategoryOptions: undefined,
  538. facsSubCategoryOptions: undefined,
  539. // 设备分类
  540. subCategoryOptions: undefined,
  541. subsystemOptions: undefined,
  542. subcategoryCode: '',
  543. devOptions: undefined,
  544. parentAreaCode:'',
  545. dialogTitle: '',
  546. deviceDialogVisible: false,
  547. activeDeviceTab: 'electricMeter',
  548. Bound: [], // 已绑定数据
  549. Unbound: [], // 未绑定数据
  550. }
  551. },
  552. mounted() {
  553. this.getList();
  554. this.getFacsList();
  555. this.getDeviceList();
  556. },
  557. created() {
  558. this.getDeviceSubCategorygetByCode();
  559. this.getFacsSubCategorygetByCode();
  560. this.getAreaFacsTree('0', false)
  561. this.getAreaDeviceTree('0', false)
  562. this.getAllDevProcess(this.subcategoryCode)
  563. this.getEmsTag('Area');
  564. this.getFacsOptions()
  565. this.getSubsystem()
  566. this.form.areaAttr = {};
  567. this.getList();
  568. this.getDeptList();
  569. },
  570. methods: {
  571. getAreaFacsTree(areaCode, recursion) {
  572. areaTreeSelect(areaCode, recursion).then(response => {
  573. this.facsOptions = [{
  574. id: '-1',
  575. label: '全部',
  576. children: response.data
  577. }]
  578. })
  579. },
  580. getAreaDeviceTree(areaCode, recursion) {
  581. areaTreeSelect(areaCode, recursion).then(response => {
  582. this.deviceOptions = [{
  583. id: null,
  584. label: '全部',
  585. children: response.data
  586. }]
  587. })
  588. },
  589. filterNode(value, data) {
  590. if (!value) return true
  591. return data.label.indexOf(value) !== -1
  592. },
  593. getObjTypeLabel(objType) {
  594. const typeLabels = {
  595. 1: '区域位置',
  596. 2: '设施',
  597. 3: '设备',
  598. 4: '组织'
  599. };
  600. return typeLabels[objType] || '未知类型';
  601. },
  602. formatDict(val, options, key = 'code', text = 'name') {
  603. if (!this[options] || !Array.isArray(this[options])) {
  604. console.error(`Expected an array for this[${options}], but got ${typeof this[options]}`);
  605. return '';
  606. }
  607. let name = '';
  608. this[options].forEach(item => {
  609. if (val === item[key]) {
  610. name = item[text];
  611. }
  612. });
  613. return name;
  614. },
  615. getColCycleName(colCycle) {
  616. const cycleMap = {
  617. 0: '实时',
  618. 1: '分钟',
  619. 2: '小时',
  620. 3: '天',
  621. 4: '月'
  622. }
  623. return cycleMap[colCycle] || ''
  624. },
  625. getColModeName(colMode) {
  626. const modeMap = {
  627. 0: '自动抄表',
  628. 1: '手动抄表'
  629. }
  630. return modeMap[colMode] || '未知'
  631. },
  632. /**分页*/
  633. handleTabClick(tab) {
  634. this.reset();
  635. if (tab.name === 'area') {
  636. this.showSearch = true;
  637. this.getList();
  638. } else if (tab.name === 'organ') {
  639. this.showSearch = true;
  640. this.getDeptList();
  641. } else if (tab.name === 'facs') {
  642. this.showSearch = true;
  643. this.getFacsList()
  644. }else if (tab.name === 'device') {
  645. this.showSearch = true;
  646. this.getDeviceList();
  647. }
  648. },
  649. /**电表、水表分页*/
  650. handleADTabClick(tab){
  651. this.activeDeviceTab = tab.name;
  652. this.getMeterData();
  653. },
  654. //地理位置
  655. handleNodeClick(data) {
  656. if (data.id === 'all') {
  657. this.areaOptions = this.areaList.slice(1).map(item => {
  658. const { children, ...rest } = item;
  659. return rest;
  660. });
  661. } else {
  662. // 判断是否为叶子节点
  663. if (!data.children || data.children.length === 0) {
  664. // 叶子节点,展示该节点的数据
  665. this.areaOptions = [data];
  666. } else {
  667. this.areaOptions = data.children.map(child => {
  668. const { children, ...rest } = child;
  669. return rest;
  670. });
  671. }
  672. }
  673. },
  674. //组织机构
  675. handleDeptNodeClick(data) {
  676. if (data.deptId === 'all') {
  677. this.organOptions = this.deptList.slice(1).map(item => {
  678. const { children, ...rest } = item;
  679. return rest;
  680. });
  681. } else {
  682. // 判断是否为叶子节点
  683. if (!data.children || data.children.length === 0) {
  684. this.organOptions = [data];
  685. } else {
  686. this.organOptions = data.children.map(child => {
  687. const { children, ...rest } = child;
  688. return rest;
  689. });
  690. }
  691. }
  692. },
  693. //设施
  694. handleFacsNodeClick(data) {
  695. this.FacsQueryParams.refArea = data.id
  696. this.handleFacsQuery()
  697. },
  698. //设备
  699. handleDeviceNodeClick(data) {
  700. this.DeviceQueryParams.locationRef = data.id
  701. this.handleDeviceQuery()
  702. },
  703. /** 查询区域对象列表 */
  704. getList() {
  705. this.loading = true;
  706. listDetailArea(this.queryParams).then(response => {
  707. this.areaList = this.handleTree(response.data, "areaCode", "parentCode");
  708. this.areaList = this.extractTagNames(this.areaList);
  709. this.tableKey += 1; // 改变 key 值以强制重新渲染
  710. // 将“全部”节点添加到区域列表的顶部
  711. this.areaList.unshift(this.allAreaNode);
  712. this.loading = false;
  713. this.Node();
  714. });
  715. },
  716. Node() {
  717. if (this.areaList.length > 0) {
  718. this.handleNodeClick(this.areaList[0]);}
  719. if (this.areaList[0].children && this.areaList[0].children.length > 1) {
  720. this.handleNodeClick(this.areaList[0].children[1]);
  721. }
  722. },
  723. // 递归提取 tagNames
  724. extractTagNames(list) {
  725. return list.map(item => {
  726. if (item.areaAttr && item.areaAttr.tagNames) {
  727. item.tagNames = item.areaAttr.tagNames;
  728. } else {
  729. item.tagNames = '';
  730. }
  731. if (item.children) {
  732. item.children = this.extractTagNames(item.children);
  733. }
  734. return item;
  735. });
  736. },
  737. /** 查询部门列表 */
  738. getDeptList() {
  739. this.loading = true;
  740. listDept(this.DeptQueryParams).then(response => {
  741. this.deptList = this.handleTree(response.data, "deptId");
  742. this.deptList = this.extractTagNames(this.deptList);
  743. this.treeKey += 1;
  744. this.loading = false;
  745. this.deptList.unshift(this.allDeptNode);
  746. this.deptNode();
  747. });
  748. },
  749. deptNode() {
  750. if (this.deptList.length > 0) {
  751. this.handleDeptNodeClick(this.deptList[0]);}
  752. if (this.deptList[0].children && this.deptList[0].children.length > 1) {
  753. this.handleDeptNodeClick(this.deptList[0].children[1]);
  754. }
  755. },
  756. /** 查询能源设施/系统列表 */
  757. getFacsList() {
  758. this.loading = true
  759. listFacs(this.FacsQueryParams).then(response => {
  760. this.facsList = response.rows
  761. this.total = response.total
  762. this.loading = false
  763. // 确保在数据更新后更新 key
  764. this.tableKey += 1;
  765. })
  766. },
  767. /** 查询能源设备列表 */
  768. getDeviceList() {
  769. this.loading = true
  770. listDevRecursionByArea(this.DeviceQueryParams).then(response => {
  771. this.deviceList = response.rows
  772. this.total = response.total
  773. this.loading = false
  774. this.tableKey += 1;
  775. })
  776. },
  777. // 取消按钮
  778. cancel() {
  779. this.open = false;
  780. this.reset();
  781. },
  782. MeterCancel() {
  783. this.deviceDialogVisible = false;
  784. this.reset();
  785. },
  786. // 表单重置
  787. reset() {
  788. this.form = {
  789. id: null,
  790. areaCode: null,
  791. parentCode: null,
  792. ancestors: null,
  793. areaName: null,
  794. shortName: null,
  795. desc: null,
  796. orderNum: null,
  797. status: null,
  798. areaAttr: {
  799. areaCode: null,
  800. attrOrg: null,
  801. mgrOrg: null,
  802. leader: null,
  803. phone: null,
  804. openDate: null,
  805. floorArea: null,
  806. usableArea: null,
  807. floor: null,
  808. tagCodes: null,
  809. tagNames: null,
  810. tagCodeList: []
  811. }// 确保 areaAttr 始终为一个空对象
  812. };
  813. this.resetForm("form");
  814. this.queryParams = {
  815. pageNum: 1,
  816. pageSize: 10,
  817. areaCode: null, // 确保这里也重置areaCode
  818. parentCode: null,
  819. ancestors: null,
  820. areaName: null,
  821. shortName: null,
  822. desc: null,
  823. orderNum: null,
  824. status: null,
  825. tagNames:null,
  826. areaAttr:{}
  827. };
  828. },
  829. /** 地理位置搜索按钮操作 */
  830. handleQuery() {
  831. this.loading = true;
  832. listDetailArea(this.queryParams).then(response => {
  833. this.areaOptions = this.handleTree(response.data, "areaCode", "parentCode");
  834. this.areaOptions = this.extractTagNames(this.areaOptions);
  835. this.loading = false;
  836. });
  837. },
  838. filterDataByAreaCode(list, areaCode) {
  839. let result = [];
  840. for (let i = 0; i < list.length; i++) {
  841. if (list[i].areaCode === areaCode) {
  842. if (list[i].children && list[i].children.length > 0) {
  843. list[i].children.forEach(child => {
  844. result.push(child);
  845. if (child.children && child.children.length > 0) {
  846. result = result.concat(this.filterDataByAreaCode(child.children, areaCode));
  847. }
  848. });
  849. }
  850. return result;
  851. } else if (list[i].children && list[i].children.length > 0) {
  852. const foundChildren = this.filterDataByAreaCode(list[i].children, areaCode);
  853. if (foundChildren.length > 0) {
  854. return foundChildren;
  855. }
  856. }
  857. }
  858. return result;
  859. },
  860. /** 地理位置重置按钮操作 */
  861. resetQuery() {
  862. this.resetForm("queryForm");
  863. this.handleQuery();
  864. },
  865. /** 组织机构搜索按钮操作 */
  866. handleDeptQuery() {
  867. this.getDeptList();
  868. },
  869. resetDeptQuery() {
  870. this.resetForm("queryForm");
  871. this.handleDeptQuery();
  872. },
  873. /** 设施搜索按钮操作 */
  874. handleFacsQuery() {
  875. this.FacsQueryParams.pageNum = 1
  876. this.getFacsList()
  877. },
  878. resetFacsQuery() {
  879. this.FacsQueryParams.refArea = null
  880. this.resetForm('queryForm')
  881. this.handleFacsQuery()
  882. },
  883. /**设备搜索按钮操作 */
  884. handleDeviceQuery() {
  885. this.DeviceQueryParams.pageNum = 1
  886. this.getDeviceList()
  887. },
  888. resetDeviceQuery() {
  889. this.DeptQueryParams.locationRef = null
  890. this.resetForm('queryForm')
  891. this.handleDeviceQuery()
  892. },
  893. // 多选框选中数据
  894. handleSelectionChange(selection) {
  895. this.ids = selection.map(item => item.id)
  896. this.single = selection.length !== 1
  897. this.multiple = !selection.length
  898. },
  899. /**计量设备*/
  900. handleDevice(row) {
  901. this.queryParams.areaCode = row.areaCode;
  902. if (row && row.ancestors) {
  903. const ancestorsArray = row.ancestors.split(',');
  904. if (ancestorsArray.length > 1) {
  905. // 当 ancestors 长度大于 1 时,取第二个 areaCode 作为父级 areaCode
  906. this.MeterQueryParams.areaCode= ancestorsArray[1];
  907. } else if (ancestorsArray.length === 1) {
  908. // 当 ancestors 长度等于 1 时,取该对象本身的 areaCode 作为父级 areaCode
  909. this.MeterQueryParams.areaCode = row.areaCode;
  910. }
  911. }
  912. this.dialogTitle = `计量设备 - ${row.areaName}`;
  913. this.deviceDialogVisible = true;
  914. this.getMeterData(row);
  915. },
  916. /**组织结构计量设备*/
  917. handleDeptDevice(row) {
  918. this.queryParams.areaCode = row.deptId;
  919. if (row && row.ancestors) {
  920. const ancestorsArray = row.ancestors.split(',');
  921. if (ancestorsArray.length > 1) {
  922. this.MeterQueryParams.areaCode= ancestorsArray[1];
  923. } else if (ancestorsArray.length === 1) {
  924. this.MeterQueryParams.areaCode = row.deptId;
  925. }
  926. }
  927. this.dialogTitle = `计量设备 - ${row.deptName}`;
  928. this.deviceDialogVisible = true;
  929. this.getMeterData();
  930. },
  931. /**设施计量设备*/
  932. handleFacsDevice(row) {
  933. this.queryParams.areaCode = row.facsCode;
  934. this.MeterQueryParams.areaCode = row.refArea;
  935. this.dialogTitle = `计量设备 - ${row.facsName}`;
  936. this.deviceDialogVisible = true;
  937. this.getMeterData();
  938. },
  939. /**设备计量设备*/
  940. handleAllDevice(row) {
  941. console.log("row",row)
  942. this.queryParams.areaCode = row.deviceCode;
  943. this.MeterQueryParams.areaCode = row.areaCode;
  944. this.dialogTitle = `计量设备 - ${row.deviceName}`;
  945. this.deviceDialogVisible = true;
  946. this.getMeterData();
  947. },
  948. getMeterData() {
  949. this.loading = true;
  950. let meterCls = '';
  951. if (this.activeDeviceTab === 'electricMeter') {
  952. meterCls = 45;
  953. } else if (this.activeDeviceTab === 'waterMeter') {
  954. meterCls = 70;
  955. }
  956. let objType;
  957. if (this.activeTab === 'area') {
  958. objType = 1;
  959. } else if (this.activeTab === 'organ') {
  960. objType = 4;
  961. } else if (this.activeTab === 'facs') {
  962. objType = 2;
  963. } else if (this.activeTab === 'device') {
  964. objType = 3;
  965. }
  966. listDevice({ ...this.MeterQueryParams, meterCls}).then(response => {
  967. this.Unbound = response.rows;
  968. this.total = response.total;
  969. this.loading = false;
  970. });
  971. listByObj(objType,meterCls,this.queryParams.areaCode).then(response=>{
  972. this.Bound = response.data;
  973. })
  974. },
  975. /**绑定设备*/
  976. moveToDevice(row) {
  977. let objType;
  978. if (this.activeTab === 'area') {
  979. objType = 1;
  980. } else if (this.activeTab === 'organ') {
  981. objType = 4;
  982. } else if (this.activeTab === 'facs') {
  983. objType = 2;
  984. } else if (this.activeTab === 'device') {
  985. objType = 3;
  986. }
  987. const index = this.Unbound.indexOf(row);
  988. if (index !== -1) {
  989. this.Unbound.splice(index, 1);
  990. }
  991. const boundRow = {
  992. meterDeviceName: row.deviceName,
  993. meterDevice: row.deviceCode,
  994. boundaryObj: this.queryParams.areaCode,
  995. objType: objType
  996. };
  997. this.Bound.push(boundRow);
  998. },
  999. isAlreadyBound(deviceCode) {
  1000. return this.Bound.some(boundDevice => boundDevice.meterDevice === deviceCode);
  1001. },
  1002. /**取消绑定设备*/
  1003. downToDevice(row){
  1004. const index = this.Bound.indexOf(row);
  1005. if (index !== -1) {
  1006. this.Bound.splice(index, 1);
  1007. }
  1008. this.Unbound.push(row);
  1009. delete row.boundaryObj;
  1010. delete row.meterDevice;
  1011. delete row.objType;
  1012. },
  1013. /**保存绑定的设备*/
  1014. saveByObj() {
  1015. // 构建要保存的数据数组
  1016. const dataToSave = this.Bound.map(item => {
  1017. return {
  1018. boundaryObj: item.boundaryObj,
  1019. id: item.id,
  1020. meterCls: item.meterCls || (this.activeDeviceTab === 'electricMeter' ? 45 : 70),
  1021. meterDevice: item.meterDevice,
  1022. objType: item.objType
  1023. };
  1024. });
  1025. // 构建查询参数
  1026. const RequestQueryParams = this.Bound.map(item => {
  1027. return {
  1028. objType: item.objType,
  1029. boundaryObj: item.boundaryObj,
  1030. meterCls: item.meterCls || (this.activeDeviceTab === 'electricMeter' ? 45 : 70),
  1031. };
  1032. });
  1033. const objType = RequestQueryParams.length > 0 ? RequestQueryParams[0].objType : null;
  1034. const boundaryObj = RequestQueryParams.length > 0 ? RequestQueryParams[0].boundaryObj : null;
  1035. const meterCls = RequestQueryParams.length > 0 ? RequestQueryParams[0].meterCls : null;
  1036. addAllByObj(objType, meterCls,boundaryObj, dataToSave)
  1037. .then(response => {
  1038. if (response.code === 200) {
  1039. this.$message.success('保存成功');
  1040. this.deviceDialogVisible = false;
  1041. this.getMeterData();
  1042. } else {
  1043. this.$message.error('保存失败');
  1044. }
  1045. })
  1046. .catch(error => {
  1047. console.error('保存失败:', error);
  1048. this.$message.error('保存失败');
  1049. });
  1050. },
  1051. facsCategoryChange() {
  1052. this.FacsQueryParams.facsSubCategory = ''
  1053. this.getFacsSubCategorygetByCode()
  1054. this.handleFacsQuery()
  1055. },
  1056. getFacsSubCategorygetByCode() {
  1057. getFacsCategorygetByCode(this.FacsQueryParams.facsCategory).then(response => {
  1058. this.facsSubCategoryOptions = response.data.subtypeList || []
  1059. })
  1060. },
  1061. getDeviceSubCategorygetByCode() {
  1062. getFacsCategorygetByCode(this.DeviceQueryParams.deviceCategory).then(response => {
  1063. this.subCategoryOptions = response.data.subtypeList || []
  1064. })
  1065. },
  1066. // 设施下拉框选项
  1067. getFacsOptions() {
  1068. const getFacsParams = {
  1069. facsCategory: this.DeviceQueryParams.deviceCategory,
  1070. subCategory: this.DeviceQueryParams.deviceSubCategory
  1071. }
  1072. listAllFacs(getFacsParams).then(response => {
  1073. this.facsAllOptions = response.data
  1074. })
  1075. },
  1076. deviceCategoryChange() {
  1077. this.DeviceQueryParams.deviceSubCategory = ''
  1078. //this.queryParams.psCode = null; // 重置设备工艺选择
  1079. if (this.DeviceQueryParams.deviceCategory === 'E' || this.DeviceQueryParams.deviceCategory === 'W'
  1080. || this.DeviceQueryParams.deviceCategory === 'T' || this.DeviceQueryParams.deviceCategory === 'C') {
  1081. this.getAreaDeviceTree('0', false)
  1082. } else if (this.DeviceQueryParams.deviceCategory === 'Z') {
  1083. this.getAreaDeviceTree('0', true)
  1084. }
  1085. this.getDeviceSubCategorygetByCode()
  1086. this.getFacsOptions()
  1087. this.handleDeviceQuery()
  1088. },
  1089. getSubsystem() {
  1090. listSubsystemAll().then(response => {
  1091. this.subsystemOptions = response.data
  1092. })
  1093. },
  1094. getAllDevProcess(subcategoryCode) {
  1095. getDevProcess(subcategoryCode).then(response => {
  1096. this.devOptions = response.data
  1097. })
  1098. },
  1099. getEmsTag(tagModel) {
  1100. console.log("tagModel", tagModel)
  1101. getEmsTag(tagModel).then(response => {
  1102. if (response && response.data) {
  1103. this.emsTagOptions = response.data.map(item => ({
  1104. label: item.tagName,
  1105. value: item.tagCode,
  1106. color: item.tagColor
  1107. }));
  1108. //颜色映射
  1109. this.tagCodeToColorMap = {};
  1110. this.emsTagOptions.forEach(item => {
  1111. this.tagCodeToColorMap[item.value] = item.color;
  1112. });
  1113. }
  1114. })
  1115. },
  1116. getTagStyle(tagName) {
  1117. // 从tagName找到对应的tagCode
  1118. const tagCode = this.emsTagOptions.find(tag => tag.label === tagName)?.value;
  1119. const color = this.tagCodeToColorMap[tagCode] || '#FFFFFF'; // 默认白色
  1120. return {
  1121. backgroundColor: color,
  1122. color:'#808080',
  1123. padding: '4px 8px',
  1124. borderRadius: '4px',
  1125. width: '80px',
  1126. height: '30px',
  1127. margin: '4px 8px 4px 0',
  1128. display: 'inline-block',
  1129. verticalAlign: 'top'
  1130. };
  1131. },
  1132. }
  1133. }
  1134. </script>