handsontable.vue 30 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929
  1. <template>
  2. <div id="handsontable" v-loading="isLoading">
  3. <el-row class="left">
  4. <!-- <div style="display: inline-block" v-show="zoneCode === 'OtherZone'">
  5. <el-button @click="addZoneBtn" type="primary">添加分区</el-button>
  6. <el-select v-model="OtherValue" placeholder="请选择分区类型" @change="changeOtherZone">
  7. <el-option v-for="item in OtherList" :key="item.value" :label="item.label" :value="item.value">
  8. </el-option>
  9. </el-select>
  10. &nbsp;&nbsp; | &nbsp;&nbsp;
  11. </div> -->
  12. <el-select v-model="onlyRead" @change="getData(false)"
  13. style="width:100px;margin-right:20px;vertical-align:bottom;">
  14. <el-option v-for="item in options" :key="item.value" :label="item.label" :value="item.value"></el-option>
  15. </el-select>
  16. <el-select v-model="showType" @change="initHot" style="width:100px;margin-right:10px;vertical-align:bottom;">
  17. <el-option v-for="item in showTypes" :key="item.value" :label="item.label" :value="item.value"></el-option>
  18. </el-select>
  19. <el-button v-show="!onlyRead" @click="addSp">添加</el-button>
  20. <el-button @click="reset">刷新</el-button>
  21. <el-button v-show="!onlyRead" @click="undo">撤销</el-button>
  22. <el-input v-model="zoneItemID" placeholder="请输入业务空间id" @keyup.enter.native="getData"
  23. style="display:inline-block;width:500px;margin-left:20px;">
  24. <i slot="suffix" class="el-input__icon el-icon-search" @click="getData"></i>
  25. </el-input>
  26. </el-row>
  27. <div v-show="main &&main.length" :id="id"></div>
  28. <div class="center" v-show="!main || !main.length" style="height: 400px;padding-top:140px;box-sizing:border-box;">
  29. <i class="icon-wushuju iconfont"></i>
  30. 暂无数据
  31. </div>
  32. <!-- <add-business :buildMess="buildMess" :dialog="dialog"></add-business> -->
  33. <el-pagination class="right" v-show="main && main.length" @size-change="handleSizeChange"
  34. @current-change="handleCurrentChange"
  35. :current-page="page.pageNumber" :page-sizes="page.pageSizes" :page-size="page.pageSize"
  36. layout="total, sizes, prev, pager, next, jumper"
  37. :total="page.total">
  38. </el-pagination>
  39. <!-- <div class="right" v-show="main && main.length">
  40. <my-pagination :page="page" @change="pageChange"></my-pagination>
  41. </div> -->
  42. <!-- 二维码弹窗 -->
  43. <qrcode :dialog="dialog" :qrcodeUrl="qrcodeUrl" :addBody="true" ref="qrcode"></qrcode>
  44. <!-- 上传图片-->
  45. <upload-img-dialog :read="onlyRead" @changeFile="imgChange" :keysArr="imgsArr" :dialog="myDialog"/>
  46. <dialogZone ref="zone" @createSuccess="getOtherType"/>
  47. <!-- 不支持的输入方式 -->
  48. <el-dialog title="临时维护信息点" :visible.sync="myDialog.update" @close="handleCloseUpdate" width="670px">
  49. <el-row>
  50. 该信息点未定义对应组件,现在维护数据不确定后续是否可用。如确实需要维护,请点击
  51. <el-link @click="updateInputShow = true" type="primary" :underline="false">继续维护</el-link>
  52. </el-row>
  53. <el-row style="margin-top:20px;" v-show="updateInputShow">
  54. <el-input type="textarea" :autosize="{ minRows: 4, maxRows: 8}" placeholder="请输入内容"
  55. v-model="updateInput"></el-input>
  56. </el-row>
  57. <span slot="footer" class="dialog-footer">
  58. <el-button @click="myDialog.update = false">取 消</el-button>
  59. <el-button type="primary" @click="handleClickUpdate">确 认</el-button>
  60. </span>
  61. </el-dialog>
  62. <!-- 新增业务空间 -->
  63. <el-dialog title="确定新增业务空间的分区类型" :visible.sync="myDialog.addSpace" width="670px">
  64. <el-row>
  65. <space-cascader ref="cascader" @change="changeAddType"></space-cascader>
  66. </el-row>
  67. <span slot="footer" class="dialog-footer">
  68. <el-button type="primary" @click="toAddSpace">下 一 步</el-button>
  69. </span>
  70. </el-dialog>
  71. </div>
  72. </template>
  73. <script>
  74. // 引用handsontable插件
  75. import "@/assets/js/chosen.jquery.min";
  76. import tools from "@/utils/scan/tools";
  77. import "@/assets/js/handsontable-chosen-editor";
  78. import lStorage from '@/utils/localStorage'
  79. import myPagination from "@/components/common/myPagination";
  80. import showTools from "@/utils/handsontable/notShow"
  81. import handsonUtils from "@/utils/hasontableUtils"
  82. import Handsontable from "handsontable-pro"
  83. import buildFloor from '@/utils/handsontable/buildFloorData'
  84. import spaceCascader from '@/components/ledger/lib/spaceSelect'
  85. import 'handsontable-pro/dist/handsontable.full.css'
  86. import uploadImgDialog from "@/components/business_space/dialogs/list/uploadImgDialog"
  87. import qrcode from "@/components/ledger/lib/qrcode";
  88. import {
  89. BeatchQueryParam,
  90. handleZoneUpdateBd,
  91. queryAllZoneType,
  92. zoneCreate,
  93. zoneDelete,
  94. zoneQuery,
  95. zoneUpdate
  96. } from "@/api/scan/request";
  97. import { mapGetters } from "vuex";
  98. import dialogZone from "../../ledger/addDialog/dialogZone";
  99. export default {
  100. props: {
  101. id: {},
  102. zoneCode: {},
  103. otherType: String
  104. },
  105. components: {
  106. qrcode, //二维码页面
  107. myPagination,
  108. uploadImgDialog,
  109. dialogZone,
  110. spaceCascader,
  111. },
  112. computed: {
  113. ...mapGetters("layout", ["projectId", "secret", "userId"]),
  114. showTypes() {
  115. return this.onlyRead ?
  116. [{ value: "Visible", label: '只看采集信息' }, { value: "all", label: '全部' }] :
  117. [{ value: "Visible", label: '只看采集信息' }, { value: "all", label: '全部' }]
  118. }
  119. },
  120. data() {
  121. return {
  122. dialog: {
  123. qrcode: false, //二维码弹窗
  124. addDevice: false
  125. },
  126. qrcodeUrl: "",//二维码图片地址
  127. headers: null,
  128. main: [],
  129. hot: null,
  130. isLoading: true,
  131. options: [{
  132. value: true,
  133. label: '只读模式'
  134. }, {
  135. value: false,
  136. label: '编辑模式'
  137. }],
  138. onlyRead: true,
  139. showType: "",
  140. page: {
  141. pageSize: 50,
  142. pageSizes: [10, 20, 50, 100],
  143. pageNumber: 1,
  144. total: 0
  145. },
  146. param: {
  147. ProjId: this.projectId, //项目id
  148. UserId: this.userId, //用户id
  149. secret: this.secret
  150. },
  151. buildMess: null,
  152. filtersArr: [], //表格数据被过滤后的下标
  153. copyMain: [], //深拷贝数组
  154. buildFloorData: [], //楼层数据
  155. zoneItemID: '',
  156. inputMap: {
  157. flowBuild: {
  158. editable:true,
  159. code:"flowBuild",
  160. name:"建筑楼层",
  161. path:"flowBuild",
  162. category: 'STATIC',
  163. dataType: "ENUM"
  164. }
  165. }, //信息点和输入方式映射表
  166. updateInputShow: false, //是否显示临时维护输入框
  167. updateInfoPoint: '',//临时维护信息点
  168. updateInput: '', //临时维护信息点值
  169. myDialog: {
  170. uploadImgs: false, //上传图片弹窗
  171. update: false,//临时维护信息点
  172. addSpace: false, //批量添加业务空间
  173. },
  174. imgsArr: [], //空间图片
  175. OtherList: [],//其他分区筛选框
  176. OtherValue: '',
  177. addData: {},
  178. };
  179. },
  180. created() {
  181. this.setData()
  182. buildFloor.getData(this.buildFloorData)
  183. },
  184. mounted() {
  185. },
  186. methods: {
  187. setData() {
  188. this.param.ProjId = this.projectId
  189. this.param.UserId = this.userId
  190. this.param.secret = this.secret
  191. },
  192. //获取表格数据
  193. getHeader(headers, buildFloorSelectd) {
  194. this.headers = headers
  195. this.codeToDataSource = {}
  196. this.headers.forEach(item => {
  197. if (item.path) {
  198. this.inputMap[item.path] = item
  199. }
  200. if (item.dataSource) {
  201. try {
  202. this.codeToDataSource[item.code] = {}
  203. item.dataSource.forEach(dic => {
  204. this.codeToDataSource[item.code][dic.code] = dic.name;
  205. })
  206. } catch (e) {
  207. console.log(e);
  208. }
  209. }
  210. })
  211. this.buildFloorSelectd = buildFloorSelectd
  212. this.page.pageNumber = 1
  213. this.getData()
  214. },
  215. getData() {
  216. this.zoneParam = {
  217. zoneType: this.zoneCode,
  218. pageNumber: this.page.pageNumber,
  219. pageSize: this.page.pageSize,
  220. orders: "createTime desc, localName desc, localId desc, id asc"
  221. }
  222. if (this.buildFloorSelectd.length === 1) {
  223. switch (this.buildFloorSelectd[0]) {
  224. case 'noKnow':
  225. this.zoneParam.BuildingId = 'isnull';
  226. break;
  227. case 'all':
  228. // params.BuildingId = '';
  229. break
  230. }
  231. } else if (this.buildFloorSelectd.length === 2) {
  232. switch (this.buildFloorSelectd[1]) {
  233. case 'noKnow':
  234. this.zoneParam.buildingId = this.buildFloorSelectd[0];
  235. this.zoneParam.floorId = 'isnull';
  236. break;
  237. case 'all':
  238. this.zoneParam.buildingId = this.buildFloorSelectd[0];
  239. // params.FloorId = '';
  240. break;
  241. default:
  242. this.zoneParam.buildingId = this.buildFloorSelectd[0];
  243. this.zoneParam.floorId = this.buildFloorSelectd[1]
  244. }
  245. }
  246. if (this.zoneItemID) {
  247. this.zoneParam.Filters = `id="${this.zoneItemID}"`
  248. }
  249. if (this.zoneCode != 'OtherZone') {
  250. this.isLoading = true
  251. this.getZoneMessage(this.zoneParam)
  252. } else {
  253. // 其他分区类型查询表数据接口
  254. // if (localStorage.getItem('otherZone')) {
  255. // // this.OtherValue = (localStorage.getItem('otherZone'))
  256. // localStorage.removeItem('otherZone')
  257. // }
  258. if (this.OtherValue) {
  259. this.zoneParam.ZoneType = this.OtherValue;
  260. this.getZoneMessage(this.zoneParam)
  261. } else {
  262. this.main = []
  263. }
  264. this.isLoading = false
  265. // this.getOtherType();
  266. }
  267. },
  268. //查询空间信息
  269. getZoneMessage(param) {
  270. let params = param
  271. params.orders = "createTime desc,sort asc,localName desc,id desc"
  272. zoneQuery(params, res => {
  273. this.page.total = res.total;
  274. this.main = res.content.map((item) => {
  275. if (item.hasOwnProperty("buildingId") && item.hasOwnProperty("floorId")) {
  276. item.flowBuild = item.buildingId + "-" + item.floorId
  277. } else if (item.hasOwnProperty("buildingId") && !item.hasOwnProperty("floorId")) {
  278. item.flowBuild = item.buildingId
  279. }
  280. // if (item.outline) {
  281. // item.outline = JSON.stringify(item.outline)
  282. // }
  283. return item
  284. });
  285. if (this.main && this.main.length && this.main[0].id) {
  286. this.copyMain = tools.deepCopy(this.main);
  287. if (this.onlyRead) {
  288. this.getBatch(this.main)
  289. }
  290. }
  291. this.isLoading = false;
  292. this.getMain()
  293. })
  294. },
  295. //获取表格主体内容
  296. getMain() {
  297. if (!!this.hot) {
  298. this.hot.destroy();
  299. this.hot = null;
  300. }
  301. this.$nextTick(() => {
  302. this.initHot();
  303. });
  304. },
  305. //初始化handsontable组件
  306. initHot() {
  307. var container = document.getElementById(this.id);
  308. let winHeight = document.documentElement.clientHeight;
  309. this.hot = new Handsontable(container, {
  310. data: this.main,
  311. colHeaders: this.delHeader(this.headers), //表头文案
  312. columns: this.getType(this.headers), //数据显示格式
  313. filters: true,
  314. fixedColumnsLeft: 4,
  315. maxRows: this.main ? this.main.length : '',
  316. height: winHeight - 100 - 50 - 176,
  317. columnSorting: true, //添加排序
  318. sortIndicator: true, //添加排序
  319. renderAllRows: true,
  320. autoColumnSize: true,
  321. observeChanges: false,
  322. language: "zh-CN",
  323. manualColumnResize: true,
  324. manualColumnMove: true,
  325. dropdownMenu: [
  326. "filter_by_condition",
  327. "filter_by_value",
  328. "filter_action_bar"
  329. ],
  330. contextMenu: this.onlyRead ? false : {
  331. items: {
  332. remove_row: {
  333. name: "删除该业务空间"
  334. }
  335. }
  336. },
  337. // 事件
  338. afterChange: this.tdChange, //修改后
  339. afterFilter: this.trimmedRows, //排序前
  340. afterRemoveRow: this.romoveFm, //右键删除
  341. afterOnCellMouseDown: this.eventClick //鼠标点击
  342. });
  343. let pro = document.getElementById("hot-display-license-info");
  344. if (!!pro) {
  345. pro.parentNode.removeChild(pro);
  346. }
  347. },
  348. //表格中的查看详情
  349. eventClick(el, rowArr) {
  350. let filter = this.filtersArr;
  351. //被筛选过后的数组
  352. let trimmedArr = this.trimmedRows();
  353. //是否启用了排序
  354. let isSort = this.hot.getPlugin("columnSorting").isSorted();
  355. //
  356. if (trimmedArr.length && isSort) {
  357. let sortArr = this.myHotArr.getPlugin("columnSorting").rowsMapper
  358. .__arrayMap;
  359. let infos = this.main[trimmedArr[sortArr[rowArr.row]]];
  360. this.getInfors(infos, rowArr);
  361. } else if (isSort) {
  362. //排序后的数组
  363. let sortArr = this.hot.getPlugin("columnSorting").rowsMapper.__arrayMap;
  364. let infos = this.main[sortArr[rowArr.row]];
  365. this.getInfors(infos, rowArr);
  366. } else if (trimmedArr.length) {
  367. let infos = this.main[trimmedArr[rowArr.row]];
  368. this.getInfors(infos, rowArr);
  369. } else {
  370. let infos = this.main[rowArr.row];
  371. this.getInfors(infos, rowArr);
  372. }
  373. },
  374. getInfors(infos, row) {
  375. let val = this.hot.colToProp(row.col);
  376. this.row = row.row;
  377. let inputData = this.inputMap[val];
  378. lStorage.set('screen_data', {path: this.$route.path, data: {RoomID: infos.id, zone: this.zoneCode}})
  379. if (val == "point") {
  380. let query = {
  381. RoomID: infos.id,
  382. zone: this.zoneCode,
  383. isMyTab: 2,
  384. buildFloorSelectd: this.buildFloorSelectd
  385. }
  386. this.$router.push({
  387. path: "/ledger/spaceDetail",
  388. query: query
  389. })
  390. } else if (val == "RoomQRCode") {
  391. this.qrcodeUrl = this.main[row.row].RoomQRCode
  392. if (!!this.qrcodeUrl) {
  393. this.dialog.qrcode = true;
  394. } else {
  395. this.$message("此空间没有二维码")
  396. }
  397. } else if (val == "pic") {
  398. let Picdata = tools.dataForKey(this.main[row.row], val);
  399. this.imgsArr = Picdata ? Picdata : [];
  400. if (!this.onlyRead || this.imgsArr.length) {
  401. this.myDialog.uploadImgs = true;
  402. }
  403. }
  404. if (!this.onlyRead && !inputData.editable) {
  405. this.$message("该信息点的值为自动生成,不可人工维护!");
  406. return false;
  407. }
  408. if (!this.onlyRead && showTools.inputModeArr.indexOf(inputData.dataType) == '-1') {
  409. this.updateInfoPoint = val;
  410. this.updateInput = tools.dataForKey(this.tableData[row.row], val);
  411. this.myDialog.update = true;
  412. return false;
  413. }
  414. },
  415. //关闭临时维护弹窗回调
  416. handleCloseUpdate() {
  417. this.updateInputShow = false
  418. this.updateInfoPoint = ''
  419. this.updateInput = ''
  420. },
  421. //更新临时维护信息点
  422. handleClickUpdate() {
  423. tools.setDataForKey(this.tableData[this.row], this.updateInfoPoint, this.updateInput)
  424. this.tdChange([[this.row, this.updateInfoPoint, null, this.updateInput]], "edit")
  425. this.updateInputShow = false
  426. this.myDialog.update = false
  427. this.updateInput = ''
  428. },
  429. //表格发生更改
  430. tdChange(changeData, source) {
  431. if (!this.onlyRead) {
  432. if (changeData) {
  433. let trimmedArr = this.trimmedRows();
  434. let param = handsonUtils.getParam(changeData, source, this.hot, trimmedArr);
  435. let data = []
  436. for (let i = 0; i < param.length; i++) {
  437. if (param[i].id) {
  438. data.push(param[i])
  439. } else {
  440. this.handleCreateZone(param[i])
  441. }
  442. }
  443. //如果data中包含/且data长度为1,将其转换成.
  444. if (changeData.length == 1 && changeData[0][1].indexOf("/") > 0) {
  445. changeData[0][1] = changeData[0][1].split("/").join(".")
  446. }
  447. // 存在data进行修改请求
  448. if (data && data.length) {
  449. this.updateBusiness(data, changeData)
  450. }
  451. }
  452. }
  453. },
  454. //右键删除
  455. romoveFm() {
  456. let params = tools.differenceArr(this.main, this.copyMain)
  457. if (params.length < 1 || this.main > this.copyMain) {
  458. return
  459. }
  460. let param = []
  461. params.map(item => {
  462. if (item.id)
  463. param.push({ id: item.id })
  464. })
  465. params.map(i => i.ObjectType = this.zoneParam.ZoneType ? this.zoneParam.ZoneType : i.ObjectType);
  466. this.$confirm("此操作将删除业务空间,是否继续?", "提示", {
  467. confirmButtonText: '确定',
  468. cancelButtonText: '取消',
  469. type: 'warning'
  470. }).then(() => {
  471. zoneDelete(param, res => {
  472. this.$message.success("删除成功!")
  473. this.getData()
  474. })
  475. }).catch(() => {
  476. this.getData()
  477. this.$message("取消删除")
  478. })
  479. },
  480. //创建业务空间
  481. handleCreateZone(param) {
  482. let keys = Object.keys(param)
  483. keys.map((key) => { //将值为空字符串的属性删除
  484. if (param[key] == "") {
  485. delete param[key]
  486. }
  487. })
  488. if (!param.localName) {
  489. this.$message("新增业务空间本地名称不能为空!")
  490. return
  491. }
  492. if (!Object.keys(param).length) {
  493. this.$message("新添加业务空间内容不能为空!")
  494. return
  495. }
  496. if (param.flowBuild) {
  497. param.buildingId = param.flowBuild.split('-')[0]
  498. param.floorId = param.flowBuild.split('-')[1] || null
  499. } else {
  500. if (this.buildFloorSelectd) {
  501. if (this.buildFloorSelectd[0] != 'all' && this.buildFloorSelectd[0] != 'noKnow') {
  502. param.buildingId = this.buildFloorSelectd[0]
  503. }
  504. if (this.buildFloorSelectd[1] && this.buildFloorSelectd[1] != 'all' && this.buildFloorSelectd[1] != 'noKnow') {
  505. param.floorId = this.buildFloorSelectd[1]
  506. }
  507. }
  508. }
  509. param.classCode = this.zoneParam.ZoneType ? this.zoneParam.ZoneType : this.zoneCode;
  510. let params = {
  511. content: [param]
  512. };
  513. zoneCreate(params, res => {
  514. this.$message.success("添加成功!")
  515. this.getData()
  516. })
  517. },
  518. // 修改
  519. updateBusiness(data, change) {
  520. let param = {
  521. data: {
  522. Content: [],
  523. Projection: []
  524. },
  525. zone: this.zoneCode
  526. };
  527. let keyList = [];
  528. //生成要修改字段列表
  529. change.map((item) => {
  530. let key = item[1].split(".")[0]
  531. if (key == "flowBuild" && keyList.indexOf(key) == -1) {
  532. keyList.push("BuildingId", "FloorId")
  533. param.data.Projection.push("BuildingId", "FloorId")
  534. }
  535. if (item[1] && keyList.indexOf(key) == -1) {
  536. keyList.push(key)
  537. }
  538. if (item[1] && item[3] == "" && param.data.Projection.indexOf(key) == -1) {
  539. param.data.Projection.push(key)
  540. }
  541. })
  542. //生成对应修改数据
  543. data.map((item, index) => {
  544. keyList.map(value => {
  545. if (value == "BuildingId") {
  546. let itemData = tools.dataForKey(item, "flowBuild")
  547. if (itemData == "") {
  548. tools.setDataForKey(item, "BuildingId", null)
  549. tools.setDataForKey(item, "FloorId", null)
  550. } else {
  551. let BuildingId = itemData.split("-")[0]
  552. let FloorId = itemData.split("-")[1]
  553. if (BuildingId && FloorId) {
  554. tools.setDataForKey(item, "BuildingId", BuildingId)
  555. tools.setDataForKey(item, "FloorId", FloorId)
  556. } else if (BuildingId && !FloorId) {
  557. tools.setDataForKey(item, "BuildingId", BuildingId)
  558. tools.setDataForKey(item, "FloorId", null)
  559. }
  560. }
  561. } else {
  562. let itemData = tools.dataForKey(item, value)
  563. tools.setDataForKey(item, value, itemData == "" ? null : itemData)
  564. }
  565. })
  566. param.data.Content.push(item);
  567. })
  568. if (param.data.Projection.indexOf('BuildingId') > -1) {
  569. let pa = param.data.Content.map(t => {
  570. return {
  571. type: this.zoneCode,
  572. spaceId: t.id,
  573. id: t.FloorId || t.BuildingId || null,
  574. }
  575. })
  576. handleZoneUpdateBd(pa, res => {
  577. this.$message.success('修改成功')
  578. })
  579. // Orders: "createTime desc, EquipLocalName desc, EquipLocalID desc, EquipID desc"
  580. // updateRelateInSpAndBuild(pa, res => {
  581. // this.$message.success('修改成功')
  582. // })
  583. } else {
  584. // updateZone(param, (res) => {
  585. // })
  586. let obj = param.data.Content.map(i => {
  587. i.Outline = typeof i.Outline == 'string' ? JSON.parse(i.Outline) : i.Outline
  588. return {
  589. ...i,
  590. ObjectType: this.zoneParam.ZoneType || i.ObjectType
  591. }
  592. })
  593. let updateParam = {
  594. content: obj,
  595. // projection: param.data.Projection
  596. };
  597. zoneUpdate(updateParam, res => {
  598. this.$message.success('更新成功')
  599. })
  600. }
  601. },
  602. //获取被筛选掉的行号
  603. trimmedRows() {
  604. // var plugin = hot.getPlugin('trimRows').trimmedRows;//获取被筛选掉的行号
  605. var plugin = this.hot.getPlugin("trimRows").trimmedRows;
  606. let dataLength = this.main.length;
  607. let dataArr = new Array();
  608. for (let i = 0; i < dataLength; i++) {
  609. dataArr.push(i);
  610. }
  611. if (plugin.length <= 0) {
  612. dataArr = undefined;
  613. } else {
  614. dataArr = this.array_diff(dataArr, plugin);
  615. }
  616. this.filtersArr = dataArr;
  617. return dataArr || [];
  618. // var DataArray = new Array();
  619. // for (var i = 0; i < plugin.length; i++) {
  620. // // 通过行号获取数据
  621. // DataArray.push(this.hot.getSourceDataAtRow(plugin[i]));
  622. // }
  623. },
  624. //去除数组中相同的元素
  625. array_diff(a, b) {
  626. for (var i = 0; i < b.length; i++) {
  627. for (var j = 0; j < a.length; j++) {
  628. if (a[j] == b[i]) {
  629. a.splice(j, 1);
  630. j = j - 1;
  631. }
  632. }
  633. }
  634. return a;
  635. },
  636. //获取动态参数
  637. getBatch(data) {
  638. let param = {
  639. groupCode: "WD",
  640. appId: "datacenter",
  641. projectId: this.projectId,
  642. data: []
  643. };
  644. this.headers.map(head => {
  645. if (head.category != 'STATIC') {
  646. data.map(item => {
  647. let cur = tools.dataForKey(item, head.path);
  648. if (cur) {
  649. param.data.push({
  650. objectId: item.id,
  651. infoCode: head.code
  652. });
  653. }
  654. });
  655. }
  656. });
  657. if (param.data.length) {
  658. BeatchQueryParam(param, res => {
  659. if (!this.onlyRead) {
  660. return false
  661. }
  662. this.main = data.map(item => {
  663. res.data.map(child => {
  664. if (item.id == child.objectId) {
  665. if (child.data || child.data == 0) {
  666. this.headers.map(head => {
  667. if (head.code == child.infoCode) {
  668. let contentVal = child.data
  669. if (this.codeToDataSource[child.infoCode]) {
  670. contentVal = this.codeToDataSource[child.infoCode][child.data]
  671. }
  672. tools.setDataForKey(item, head.path, contentVal);
  673. }
  674. });
  675. } else {
  676. this.headers.map(head => {
  677. if (head.code == child.infoCode) {
  678. tools.setDataForKey(
  679. item,
  680. head.path,
  681. child.error
  682. // child.error ? child.value ? "表号功能号格式错误" : "表号功能号不存在" : "暂未采集到实时数据"
  683. );
  684. }
  685. });
  686. }
  687. }
  688. });
  689. return item;
  690. });
  691. this.hot.loadData(this.main);
  692. });
  693. }
  694. },
  695. /**
  696. * 表头文案处理函数
  697. * @param list header数组数据
  698. *
  699. * @return 处理好的文案
  700. */
  701. delHeader(list) {
  702. let arr = tools.copyArr(list)
  703. let data = showTools.headerTextFilter(arr, "space", this.onlyRead, this.showType)
  704. data.unshift("是否关联平面图", "与空间相关联的设备");
  705. if (this.showType == "all") {
  706. data.splice(4, 0, "所属建筑楼层")
  707. }
  708. return data;
  709. },
  710. /**
  711. * 表头数据处理函数
  712. * @param arr header数组数据
  713. *
  714. * @return 处理好的数据格式
  715. */
  716. getType(list) {
  717. let arr = tools.copyArr(list)
  718. let data = showTools.headerTypeFilter(arr, "space", this.onlyRead, this.showType)
  719. data.unshift({
  720. data: "outline",
  721. renderer: this.myRenderer,
  722. readOnly: true
  723. }, {
  724. data: "point",
  725. renderer: this.facilityRender,
  726. readOnly: true
  727. });
  728. if (this.showType == "all") {
  729. data.splice(4, 0, {
  730. data: "flowBuild",
  731. renderer: tools.customDropdownRenderer,
  732. editor: "chosen",
  733. chosenOptions: {
  734. data: this.buildFloorData
  735. },
  736. readOnly: this.onlyRead
  737. })
  738. }
  739. return data;
  740. },
  741. myRenderer(instance, td, row, col, prop, value, cellProperties) {
  742. if (value && value.length && value[0]) {
  743. td.innerHTML = "已关联"
  744. } else {
  745. td.innerHTML = "未关联"
  746. }
  747. return td;
  748. },
  749. facilityRender(instance, td, row, col, prop, value, cellProperties) {
  750. td.style.color = "#409EFF"
  751. td.style.cursor = "pointer"
  752. td.innerHTML = "点击查看"
  753. return td;
  754. },
  755. /** 页面中的按钮事件--------------------------- */
  756. addSp() {
  757. this.myDialog.addSpace = true;
  758. // 其他分区 已删除在其他分区下添加子分区
  759. // if (this.zoneCode && this.zoneCode != 'OtherZone') {
  760. this.$nextTick(() => {
  761. this.$refs.cascader.setValue([this.zoneCode])
  762. })
  763. // } else if (this.zoneCode == 'OtherZone' && this.OtherValue) {
  764. // this.$nextTick(() => {
  765. // this.$refs.cascader.setValue([this.zoneCode, this.OtherValue])
  766. // })
  767. // }
  768. // 以下是直接在列表中添加的方法
  769. // if (this.main && this.main.length && this.main[0].RoomID) {
  770. // this.hot.destroy()
  771. // this.hot = null
  772. // this.main.unshift({})
  773. // this.getMain()
  774. // } else {
  775. // if (this.main && this.main.length) {
  776. // this.$message("请添加完成后继续添加")
  777. // } else {
  778. // this.main.unshift({})
  779. // this.getMain()
  780. // }
  781. // }
  782. },
  783. //下一步
  784. toAddSpace() {
  785. if (this.addData.spaceType) {
  786. this.$router.push({
  787. path: "/ledger/spaceadd",
  788. query: this.addData
  789. });
  790. } else {
  791. this.$message("请选择要添加的业务空间类型!")
  792. }
  793. },
  794. //选择业务空间类型-添加业务空间
  795. changeAddType(val, item, value) {
  796. // if (value.length == 2 && value[0] == "OtherZone") {
  797. // this.addData.spaceType = val;
  798. // this.addData.otherType = value[0]
  799. // this.addData.spaceName = `其他分区-${item.name}`;
  800. // this.addData.showType = this.showType;
  801. // this.addData.buildFloorSelectd = this.buildFloorSelectd;
  802. // } else {
  803. this.addData.spaceType = val;
  804. this.addData.spaceName = item.name;
  805. this.addData.showType = this.showType;
  806. this.addData.buildFloorSelectd = this.buildFloorSelectd;
  807. // }
  808. },
  809. //刷新
  810. reset() {
  811. this.getData()
  812. },
  813. //撤回操作
  814. undo() {
  815. this.hot.undo()
  816. },
  817. /** 分页事件------------------------ */
  818. //切换每页显示多少条数据
  819. handleSizeChange(val) {
  820. this.page.pageSize = val
  821. this.page.pageNumber = 1
  822. this.getData()
  823. },
  824. //切换页数
  825. handleCurrentChange(val) {
  826. this.page.pageNumber = val
  827. this.getData()
  828. },
  829. //上传图片弹窗触发事件
  830. imgChange(keys) {
  831. this.setDataToMain(keys, 'pic', this.row);
  832. },
  833. //判断是否有值,有值赋值
  834. setDataToMain(data, key, row) {
  835. if (!!data && data != '--') {
  836. if (!!this.main[row]) {
  837. tools.setDataForKey(this.main[row], key, data);
  838. this.tdChange([[row, key, null, data]], "edit");
  839. } else {
  840. this.main[row] = {};
  841. tools.setDataForKey(this.main[row], key, data);
  842. }
  843. } else {
  844. tools.setDataForKey(this.main[row], key, "");
  845. }
  846. this.hot.render()
  847. },
  848. addZoneBtn() {
  849. this.$refs.zone.dialogFormVisible = true
  850. },
  851. // 其他分区类型查询
  852. getOtherType() {
  853. let param = {
  854. cascade: [{ name: 'zoneType', filters: `projectId='${this.projectId}'` }],
  855. filters: `code="otherZone"`
  856. }
  857. queryAllZoneType(param, res => {
  858. if (res.content[0].zoneType && res.content[0].zoneType.length) {
  859. this.OtherList = res.content[0].zoneType.map(t => {
  860. t.value = t.code
  861. t.label = t.name
  862. return t
  863. })
  864. } else {
  865. this.OtherList = []
  866. }
  867. if (this.otherType) {
  868. this.OtherValue = this.otherType
  869. this.changeOtherZone(this.otherType)
  870. }
  871. })
  872. },
  873. // 其他类型下拉change
  874. changeOtherZone(val) {
  875. this.zoneParam.ZoneType = val;
  876. this.getZoneMessage(this.zoneParam);
  877. // if (localStorage.getItem('otherZone')) {
  878. // localStorage.setItem('otherZone', val)
  879. // } else {
  880. // localStorage.setItem('otherZone', val)
  881. // }
  882. console.log(val)
  883. },
  884. },
  885. watch: {
  886. projectId() {
  887. this.buildFloorData = []
  888. buildFloor.getData(this.buildFloorData)
  889. this.setData()
  890. this.main = null
  891. },
  892. showTypes: {
  893. handler(newName, oldName) {
  894. if (newName && newName[0] && newName[0].value) {
  895. this.showType = newName[0].value
  896. } else {
  897. this.showType = ""
  898. }
  899. },
  900. immediate: true,
  901. deep: true
  902. }
  903. }
  904. };
  905. </script>
  906. <style lang="less" scoped>
  907. #handsontable {
  908. padding: 0 10px;
  909. .left {
  910. padding: 0;
  911. margin-bottom: 10px;
  912. }
  913. .no-data {
  914. height: 150px;
  915. line-height: 150px;
  916. text-align: center;
  917. color: gray;
  918. }
  919. }
  920. </style>