index.vue 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590
  1. <template>
  2. <div id="deviceList">
  3. <!-- <div class="search-header">
  4. <floor-cascader @change="changeFloor"></floor-cascader>
  5. </div> -->
  6. <el-row class="left">
  7. <span style="float:right;">当前筛选条件下共{{page.total || '--'}}租户</span>
  8. <el-select v-model="onlyRead" @change="getTableHeader" style="width:100px;margin-right:10px;vertical-align:bottom;">
  9. <el-option v-for="item in options" :key="item.value" :label="item.label" :value="item.value">
  10. </el-option>
  11. </el-select>
  12. <el-select v-model="showType" @change="initTable" style="width:100px;margin-right:10px;vertical-align:bottom;">
  13. <el-option v-for="item in showTypes" :key="item.value" :label="item.label" :value="item.value">
  14. </el-option>
  15. </el-select>
  16. <!-- <div v-show="onlyRead" style="width:200px;display:inline-block;text-align:left;color:gray;font-size:12px;">
  17. <span>只看要采集的信息</span>
  18. <el-checkbox v-model="allMess" @change="getTableHeader"></el-checkbox>
  19. </div> -->
  20. <el-button @click="handleCreateTableData">添加租户</el-button>
  21. <el-button @click="getTableHeader">刷新</el-button>
  22. <el-button @click="mangeTenantZone">管理租赁空间</el-button>
  23. <el-button v-show="!onlyRead" @click="undo">撤销</el-button>
  24. </el-row>
  25. <div class="tableBox">
  26. <div class="center middle_sty" style="flex:1;" v-show="tableData && !tableData.length">
  27. <p>
  28. <i class="icon-wushuju iconfont"></i>
  29. 暂无数据
  30. </p>
  31. </div>
  32. <div class="tableLeft" v-show="tableData && tableData.length">
  33. <handson-table ref="table"></handson-table>
  34. </div>
  35. </div>
  36. <el-pagination class="right" v-show="tableData && tableData.length" @size-change="handleSizeChange" @current-change="handleCurrentChange"
  37. :current-page="page.pageNumber" :page-sizes="page.pageSizes" :page-size="page.pageSize" layout="total, sizes, prev, pager, next, jumper"
  38. :total="page.total">
  39. </el-pagination>
  40. <!-- 不支持的输入方式 -->
  41. <el-dialog title="临时维护信息点" :visible.sync="myDialog.update" @close="handleCloseUpdate" width="670px">
  42. <el-row>
  43. 该信息点未定义对应组件,现在维护数据不确定后续是否可用。如确实需要维护,请点击<el-link @click="updateInputShow = true" type="primary" :underline="false">继续维护</el-link>。
  44. </el-row>
  45. <el-row style="margin-top:20px;" v-show="updateInputShow">
  46. <el-input type="textarea" :autosize="{ minRows: 4, maxRows: 8}" placeholder="请输入内容" v-model="updateInput"></el-input>
  47. </el-row>
  48. <span slot="footer" class="dialog-footer">
  49. <el-button @click="myDialog.update = false">取 消</el-button>
  50. <el-button type="primary" @click="handleClickUpdate">确 认</el-button>
  51. </span>
  52. </el-dialog>
  53. <!-- 右侧关联的业务空间抽屉 -->
  54. <roomCountDrawer ref="roomCountDrawer" :readonly="onlyRead" @refresh="getTableData"></roomCountDrawer>
  55. </div>
  56. </template>
  57. <script>
  58. import tools from "@/utils/scan/tools"
  59. import handsonUtils from "@/utils/hasontableUtils"
  60. import showTools from "@/utils/handsontable/notShow"
  61. import text from "@/utils/handsontable/mainText"
  62. import roomCountDrawer from "@/components/ledger/rentList/roomCountDrawer"
  63. import floorCascader from "@/components/ledger/lib/floorCascader"
  64. import handsonTable from "@/components/common/handsontable"
  65. import { getDataDictionary, getRentTableHeader, queryRentTableData, updataRentTableData, deleteRentTableData, saveRentRelateSpace, BeatchQueryParam } from "@/api/scan/request"
  66. import { mapGetters, mapActions } from "vuex";
  67. export default {
  68. components: {
  69. floorCascader,
  70. handsonTable,
  71. roomCountDrawer
  72. },
  73. data() {
  74. return {
  75. buildId: null,//建筑id
  76. floorId: null,//楼层id
  77. tenantID: "",//要操作的租户id
  78. isTableRightShow: false,
  79. roomId: "",//关联的空间id
  80. options: [{
  81. value: true,
  82. label: '只读模式'
  83. }, {
  84. value: false,
  85. label: '编辑模式'
  86. }],
  87. onlyRead: true,
  88. showType: "",
  89. // allMess: true,
  90. tableHeader: [],
  91. page: {
  92. pageSize: 50,
  93. pageSizes: [10, 20, 50, 100],
  94. pageNumber: 1,
  95. total: 0
  96. },
  97. tableData: [],
  98. copyTableData: [],
  99. myDialog: {
  100. update: false,//临时维护信息点
  101. },
  102. inputMap: {
  103. FloorId: 'B1'
  104. }, //信息点和输入方式映射表
  105. updateInputShow: false, //是否显示临时维护输入框
  106. updateInfoPoint: '',//临时维护信息点
  107. updateInput: '', //临时维护信息点值
  108. };
  109. },
  110. computed: {
  111. ...mapGetters("layout", ["projectId", "secret", "userId"]),
  112. showTypes() {
  113. return this.onlyRead ?
  114. [{ value: "Visible", label: '只看采集信息' }, { value: "all", label: '全部' }] :
  115. [{ value: "partInfo", label: '隐藏信息点' }, { value: "all", label: '全部' }, { value: "Visible", label: '只看采集信息' }]
  116. }
  117. },
  118. created() {
  119. this.getTableHeader()
  120. },
  121. watch: {
  122. projectId() {
  123. this.getTableHeader()
  124. },
  125. showTypes: {
  126. handler(newName, oldName) {
  127. if (newName && newName[0] && newName[0].value) {
  128. this.showType = newName[0].value
  129. } else {
  130. this.showType = ""
  131. }
  132. },
  133. immediate: true,
  134. deep: true
  135. }
  136. },
  137. methods: {
  138. // 获取表头数据(初始化表格)
  139. async getTableHeader() {
  140. let param = {
  141. data: {
  142. Orders: "sort asc",
  143. PageNumber: 1,
  144. PageSize: 500
  145. },
  146. type: 'Tenant'
  147. }
  148. await getDataDictionary(param, res => {
  149. this.tableHeader = res.Content;
  150. this.tableHeader.forEach(item => {
  151. if (item.Path && item.InputMode) {
  152. this.inputMap[item.Path] = item.InputMode
  153. }
  154. })
  155. this.getTableData()
  156. })
  157. },
  158. async getTableData() {//获取表格数据
  159. let params = {
  160. Cascade: [
  161. { Name: 'zoneTenantList', Cascade: [{ Name: 'building' }, { Name: 'floor' }] },
  162. { Name: 'zoneGeneraltList', Cascade: [{ Name: 'building' }, { Name: 'floor' }] }
  163. ],
  164. Orders: "createTime desc, TenantID asc",
  165. PageNumber: this.page.pageNumber,
  166. PageSize: this.page.pageSize
  167. }
  168. await queryRentTableData(params, (res) => {
  169. this.tableData = res.Content
  170. this.copyTableData = tools.deepCopy(res.Content)
  171. this.page.pageNumber = res.PageNumber
  172. this.page.total = res.Total
  173. if (this.tableData && this.tableData.length) {
  174. if (this.onlyRead) {
  175. this.getBatch(res.Content)
  176. }
  177. this.initTable()
  178. }
  179. })
  180. },
  181. // 修改表格内容
  182. async updateTableData(data, change) {
  183. let param = {
  184. Content: [],
  185. Projection: []
  186. }, keyList = [];
  187. //生成要修改字段列表
  188. change.map(item => {
  189. let key = item[1].split(".")[0]
  190. if (item[1] && keyList.indexOf(key) == -1) {
  191. keyList.push(key);
  192. }
  193. if (item[1] && item[3] == "" && param.Projection.indexOf(key) == -1) {
  194. param.Projection.push(key);
  195. }
  196. });
  197. //生成对应修改数据
  198. data.map((item, index) => {
  199. keyList.map(value => {
  200. let itemData = tools.dataForKey(item, value)
  201. tools.setDataForKey(item, value, itemData == "" ? null : itemData)
  202. })
  203. // let keyarr = change[index][1].split(".")
  204. // if (keyarr && keyarr.length > 1) {
  205. // item[keyarr[0]][keyarr[1]] = item[keyarr[0]][keyarr[1]] != ""? item[keyarr[0]][keyarr[1]]: null
  206. // } else {
  207. // item[keyarr[0]] = item[keyarr[0]] != ""? item[keyarr[0]]: null
  208. // }
  209. param.Content.push(item);
  210. });
  211. await updataRentTableData(param, (res) => {
  212. })
  213. },
  214. //保存元空间关联
  215. async saveSpaceList() {
  216. let params = {
  217. Tenant: this.tenantID,
  218. RoomID: this.roomId
  219. }
  220. await saveRentRelateSpace(params, (res) => {
  221. this.$message.success("关联成功!")
  222. this.getTableHeader()
  223. })
  224. },
  225. // 删除表格数据
  226. async deleteTableData(params) {
  227. await deleteRentTableData(params, (res) => {
  228. this.$message.success("删除成功")
  229. this.getTableHeader()
  230. })
  231. },
  232. // 添加租户数据
  233. handleCreateTableData() {
  234. this.$router.push({ name: 'rentadd' })
  235. },
  236. // 删除表格行
  237. handleDeleteTableRow() {
  238. let params = tools.differenceArr(this.tableData, this.copyTableData)
  239. if (params.length < 1) {
  240. return
  241. }
  242. let param = []
  243. params.map(item => {
  244. param.push({ TenantID: item.TenantID })
  245. })
  246. this.$confirm("此操作将删除租户,是否继续?", "提示", {
  247. confirmButtonText: '确定',
  248. cancelButtonText: '取消',
  249. type: 'warning'
  250. }).then(() => {
  251. this.deleteTableData(param)
  252. }).catch(() => {
  253. this.getTableHeader()
  254. this.$message("取消删除")
  255. })
  256. },
  257. //修改
  258. handleUpdataTable(changeData, source) {
  259. if (!this.onlyRead) {
  260. if (changeData) {
  261. let trimmedArr = this.trimmedRows();
  262. let param = handsonUtils.getParam(changeData, source, this.tableExample, trimmedArr);
  263. let data = [];
  264. for (let i = 0; i < param.length; i++) {
  265. data.push(param[i]);
  266. }
  267. //如果data中包含/且data长度为1,将其转换成.
  268. if (changeData.length == 1 && changeData[0][1].indexOf("/") > 0) {
  269. changeData[0][1] = changeData[0][1].split("/").join(".")
  270. }
  271. // 存在data进行修改请求
  272. if (data && data.length) {
  273. this.updateTableData(data, changeData);
  274. }
  275. }
  276. }
  277. },
  278. //撤回
  279. undo() {
  280. this.tableExample.undo();
  281. },
  282. //切换租户类型
  283. changeFloor(value) {
  284. if (value[0]) {
  285. this.buildId = value[0]
  286. }
  287. if (value[1]) {
  288. this.floorId = value[1]
  289. } else {
  290. this.floorId = null
  291. }
  292. this.getTableHeader()
  293. },
  294. //关闭右侧关联元空间输入按钮
  295. handleCloseRight() {
  296. this.isTableRightShow = false
  297. },
  298. //切换每页显示多少条数据
  299. handleSizeChange(val) {
  300. this.page.pageSize = val
  301. this.getTableHeader()
  302. },
  303. //切换页数
  304. handleCurrentChange(val) {
  305. this.page.pageNumber = val
  306. this.getTableHeader()
  307. },
  308. formatHeaderData(list) {//格式化表头显示的数据
  309. let arr = tools.copyArr(list)
  310. let data = showTools.headerTextFilter(arr, "tenant", this.onlyRead, this.showType)
  311. data.unshift("操作", "所属楼层", "租赁空间");
  312. return data;
  313. },
  314. formatHeaderType(list) {//格式化表头头映射的数据
  315. let arr = tools.copyArr(list);
  316. let data = showTools.headerTypeFilter(arr, "tenant", this.onlyRead, this.showType)
  317. data.unshift({
  318. data: "caozuo",
  319. renderer: tools.lookDetails,
  320. readOnly: true
  321. }, {
  322. data: "FloorId",
  323. readOnly: true
  324. }, {
  325. data: "RoomCount",
  326. renderer: (instance, td, row, col, prop, value, cellProperties) => {
  327. td.style.color = "#409EFF";
  328. td.style.cursor = "pointer";
  329. let num = 0;
  330. let a = instance.getDataAtRowProp(row, 'ZoneGeneraltList')
  331. let b = instance.getDataAtRowProp(row, 'ZoneTenantList')
  332. if (a && a.length) {
  333. num += a.length
  334. }
  335. if (b && b.length) {
  336. num += b.length
  337. }
  338. td.innerHTML = num;
  339. return td;
  340. },
  341. readOnly: true
  342. })
  343. return data;
  344. },
  345. initTable() {//实例化表格
  346. let settings = {
  347. data: this.tableData,
  348. colHeaders: this.formatHeaderData(this.tableHeader),
  349. columns: this.formatHeaderType(this.tableHeader),
  350. rowHeights: 30,
  351. maxRows: this.tableData.length,
  352. contextMenu: this.onlyRead ? false :{
  353. items: {
  354. remove_row: {
  355. name: "删除租户"
  356. }
  357. }
  358. },
  359. // 事件
  360. afterChange: this.handleUpdataTable, //修改后
  361. afterFilter: this.trimmedRows, //排序前
  362. afterRemoveRow: this.handleDeleteTableRow, //右键删除
  363. afterOnCellMouseDown: this.handleTdClick //鼠标点击
  364. };
  365. this.$nextTick(() => {
  366. console.log(this.$refs.table);
  367. this.tableExample = this.$refs.table.init(settings);
  368. });
  369. },
  370. //获取到了正确的信息
  371. getInfors(infos, row) {
  372. //其他的开始判断
  373. let val = this.tableExample.colToProp(row.col)
  374. let inputMode = this.inputMap[val]
  375. this.row = row.row //要操作的列号
  376. this.messKey = val //要操作的列类型
  377. this.tenantID = infos.TenantID //要操作的数据id
  378. //点击操作跳转详情
  379. if (val === "caozuo") {
  380. this.$message("开发中!")
  381. // window.open(`${process.env.BASE_URL}:8889/#/details?perjectId=${this.projectId}&secret=${this.secret}&FmId=${this.tenantID}&type=0&code=VOTn`,"_blank")
  382. return false
  383. }
  384. //点击关联的元空间
  385. if (val === "RoomCount") {
  386. // if (infos && infos.RoomID) {
  387. // this.roomId = infos.RoomID
  388. // } else {
  389. // this.roomId = ""
  390. // }
  391. // this.isTableRightShow = true;
  392. this.$refs.roomCountDrawer.showDrawer(infos)
  393. return false
  394. }
  395. if (!this.onlyRead && showTools.InputModeArr.indexOf(inputMode) == '-1') {
  396. this.updateInfoPoint = val
  397. this.updateInput = tools.dataForKey(this.tableData[row.row], val)
  398. this.myDialog.update = true
  399. }
  400. },
  401. //关闭临时维护弹窗回调
  402. handleCloseUpdate() {
  403. this.updateInputShow = false
  404. this.updateInfoPoint = ''
  405. this.updateInput = ''
  406. },
  407. //更新临时维护信息点
  408. handleClickUpdate() {
  409. tools.setDataForKey(this.tableData[this.row], this.updateInfoPoint, this.updateInput)
  410. this.handleUpdataTable([[this.row, this.updateInfoPoint, null, this.updateInput]], "edit")
  411. this.updateInputShow = false
  412. this.myDialog.update = false
  413. this.updateInput = ''
  414. },
  415. //表格点击事件
  416. handleTdClick(el, rowArr) {
  417. //点击的是表头
  418. if (rowArr.row < 0) {
  419. return;
  420. }
  421. //被筛选过后的数组
  422. let trimmedArr = this.trimmedRows();
  423. //是否启用了排序
  424. let isSort = this.tableExample.getPlugin("columnSorting").isSorted();
  425. if (trimmedArr.length && isSort) {
  426. let sortArr = this.myHotArr.getPlugin("columnSorting").rowsMapper
  427. .__arrayMap;
  428. let infos = this.tableData[trimmedArr[sortArr[rowArr.row]]];
  429. this.getInfors(infos, { row: sortArr[rowArr.row], col: rowArr.col });
  430. } else if (isSort) {
  431. //排序后的数组
  432. let sortArr = this.tableExample.getPlugin("columnSorting").rowsMapper.__arrayMap;
  433. let infos = this.tableData[sortArr[rowArr.row]];
  434. this.getInfors(infos, { row: sortArr[rowArr.row], col: rowArr.col });
  435. } else if (trimmedArr.length) {
  436. let infos = this.tableData[trimmedArr[rowArr.row]];
  437. this.getInfors(infos, { row: trimmedArr[rowArr.row], col: rowArr.col });
  438. } else {
  439. let infos = this.tableData[rowArr.row];
  440. this.getInfors(infos, rowArr);
  441. }
  442. },
  443. //获取被筛选掉的行号
  444. trimmedRows() {
  445. // var plugin = hot.getPlugin('trimRows').trimmedRows;//获取被筛选掉的行号
  446. var plugin = this.tableExample.getPlugin("trimRows").trimmedRows;
  447. let dataLength = this.tableData.length;
  448. let dataArr = new Array();
  449. for (let i = 0; i < dataLength; i++) {
  450. dataArr.push(i);
  451. }
  452. if (plugin.length <= 0) {
  453. dataArr = undefined;
  454. } else {
  455. dataArr = this.array_diff(dataArr, plugin);
  456. }
  457. return dataArr || [];
  458. // var DataArray = new Array();
  459. // for (var i = 0; i < plugin.length; i++) {
  460. // // 通过行号获取数据
  461. // DataArray.push(this.tableExample.getSourceDataAtRow(plugin[i]));
  462. // }
  463. },
  464. //去除数组中相同的元素
  465. array_diff(a, b) {
  466. for (var i = 0; i < b.length; i++) {
  467. for (var j = 0; j < a.length; j++) {
  468. if (a[j] == b[i]) {
  469. a.splice(j, 1);
  470. j = j - 1;
  471. }
  472. }
  473. }
  474. return a;
  475. },
  476. //获取动态参数
  477. getBatch(data) {
  478. let param = {
  479. secret: this.secret,
  480. ProjId: this.projectId,
  481. data: {
  482. criterias: []
  483. }
  484. };
  485. this.tableHeader.map(head => {
  486. if (
  487. head.InputMode == "L" ||
  488. head.InputMode == "L1" ||
  489. head.InputMode == "L2" ||
  490. head.InputMode == "M"
  491. ) {
  492. data.map(item => {
  493. let cur = tools.dataForKey(item, head.Path);
  494. if (cur) {
  495. param.data.criterias.push({
  496. id: item.TenantID,
  497. code: head.InfoPointCode
  498. });
  499. }
  500. });
  501. }
  502. });
  503. if (param.data.criterias.length) {
  504. BeatchQueryParam(param, res => {
  505. this.tableData = data.map(item => {
  506. res.Content.map(child => {
  507. if (item.TenantID == child.id) {
  508. if (child.data || child.data == 0) {
  509. this.tableHeader.map(head => {
  510. if (head.InfoPointCode == child.code) {
  511. tools.setDataForKey(item, head.Path, child.data);
  512. }
  513. });
  514. } else {
  515. this.tableHeader.map(head => {
  516. if (head.InfoPointCode == child.code) {
  517. tools.setDataForKey(
  518. item,
  519. head.Path,
  520. // child.error ? "表号功能号格式错误" : "表号功能号不存在"
  521. child.error ? child.value ? "表号功能号格式错误" : "表号功能号不存在" : "暂未采集到实时数据"
  522. );
  523. }
  524. });
  525. }
  526. }
  527. });
  528. return item;
  529. });
  530. this.tableExample.loadData(this.tableData);
  531. });
  532. }
  533. },
  534. // 跳转至管理租赁空间
  535. mangeTenantZone() {
  536. this.$router.push({ name: 'manageTenantZone', query: { onlyRead: this.onlyRead } })
  537. }
  538. }
  539. };
  540. </script>
  541. <style lang="less" scoped>
  542. #deviceList {
  543. overflow: hidden;
  544. height: 100%;
  545. background-color: #fff;
  546. padding: 10px;
  547. position: relative;
  548. .right {
  549. background: #fff;
  550. }
  551. .search-header {
  552. overflow: hidden;
  553. padding: 0 10px 10px 10px;
  554. border-bottom: 1px solid #bcbcbc;
  555. }
  556. .tableBox {
  557. display: flex;
  558. height: calc(100% - 95px);
  559. margin-top: 10px;
  560. .tableLeft {
  561. flex: 2;
  562. margin-right: 20px;
  563. }
  564. .tableRight {
  565. flex: 1;
  566. // display: none;
  567. border-left: 1px solid #dadada;
  568. padding: 5px 15px;
  569. margin-right: 5px;
  570. box-shadow: 0px 1px 5px 0px rgba(59, 66, 84, 0.15);
  571. .table_right_box::after {
  572. display: block;
  573. content: "";
  574. clear: both;
  575. }
  576. .close_right {
  577. float: right;
  578. cursor: pointer;
  579. }
  580. }
  581. }
  582. }
  583. .el-pagination button,
  584. .el-pagination span:not([class*="suffix"]) {
  585. vertical-align: middle;
  586. }
  587. </style>