index.vue 17 KB

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