handsontable.vue 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756
  1. <template>
  2. <div id="handsontable" v-loading="isLoading">
  3. <el-row class="left">
  4. <!-- <div style="display: inline-block">-->
  5. <!-- &lt;!&ndash; <div v-show="!onlyRead && zoneCode === 'other'">&ndash;&gt;-->
  6. <!-- <el-button @click="addZoneBtn">添加分区</el-button>-->
  7. <!-- <el-select v-model="zoneValue" placeholder="请选择">-->
  8. <!-- <el-option-->
  9. <!-- v-for="item in addZone"-->
  10. <!-- :key="item.value"-->
  11. <!-- :label="item.label"-->
  12. <!-- :value="item.value">-->
  13. <!-- </el-option>-->
  14. <!-- </el-select>-->
  15. <!-- &nbsp;&nbsp; | &nbsp;&nbsp;-->
  16. <!-- </div>-->
  17. <el-select v-model="onlyRead" @change="getData(false)"
  18. style="width:100px;margin-right:20px;vertical-align:bottom;">
  19. <el-option v-for="item in options" :key="item.value" :label="item.label" :value="item.value"></el-option>
  20. </el-select>
  21. <el-select v-model="showType" @change="initHot" style="width:100px;margin-right:10px;vertical-align:bottom;">
  22. <el-option v-for="item in showTypes" :key="item.value" :label="item.label" :value="item.value"></el-option>
  23. </el-select>
  24. <el-button v-show="!onlyRead" @click="addSp">添加</el-button>
  25. <el-button @click="reset">刷新</el-button>
  26. <el-button v-show="!onlyRead" @click="undo">撤销</el-button>
  27. <el-input v-model="zoneItemID" placeholder="请输入业务空间id" @keyup.enter.native="getData"
  28. style="display:inline-block;width:500px;margin-left:20px;">
  29. <i slot="suffix" class="el-input__icon el-icon-search" @click="getData"></i>
  30. </el-input>
  31. </el-row>
  32. <div v-show="main &&main.length" :id="id"></div>
  33. <div class="center" v-show="!main || !main.length" style="height: 400px;padding-top:140px;box-sizing:border-box;">
  34. <i class="icon-wushuju iconfont"></i>
  35. 暂无数据
  36. </div>
  37. <!-- <add-business :buildMess="buildMess" :dialog="dialog"></add-business> -->
  38. <el-pagination class="right" v-show="main && main.length" @size-change="handleSizeChange"
  39. @current-change="handleCurrentChange"
  40. :current-page="page.pageNumber" :page-sizes="page.pageSizes" :page-size="page.pageSize"
  41. layout="total, sizes, prev, pager, next, jumper"
  42. :total="page.total">
  43. </el-pagination>
  44. <!-- <div class="right" v-show="main && main.length">
  45. <my-pagination :page="page" @change="pageChange"></my-pagination>
  46. </div> -->
  47. <!-- 二维码弹窗 -->
  48. <qrcode :dialog="dialog" :qrcodeUrl="qrcodeUrl" :addBody="true" ref="qrcode"></qrcode>
  49. <!-- 上传图片-->
  50. <upload-img-dialog :read="onlyRead" @changeFile="imgChange" :keysArr="imgsArr" :dialog="myDialog"/>
  51. <dialogZone ref="zone"/>
  52. </div>
  53. </template>
  54. <script>
  55. // 引用handsontable插件
  56. import "@/assets/js/chosen.jquery.min";
  57. import tools from "@/utils/scan/tools";
  58. import "@/assets/js/handsontable-chosen-editor";
  59. import lStorage from '@/utils/localStorage'
  60. import myPagination from "@/components/common/myPagination";
  61. import addBusiness from "@/components/business_space/dialogs/addDialog/businessDialog"
  62. import showTools from "@/utils/handsontable/notShow"
  63. import handsonUtils from "@/utils/hasontableUtils"
  64. import Handsontable from "handsontable-pro"
  65. import buildFloor from '@/utils/handsontable/buildFloorData'
  66. import 'handsontable-pro/dist/handsontable.full.css'
  67. import zhCN from 'handsontable-pro/languages/zh-CN';
  68. import uploadImgDialog from "@/components/business_space/dialogs/list/uploadImgDialog"
  69. import qrcode from "@/components/ledger/lib/qrcode";
  70. import {
  71. queryZone,
  72. updateZone,
  73. deleteZone,
  74. createZone,
  75. BeatchQueryParam,
  76. updateRelateInSpAndBuild
  77. } from "@/api/scan/request";
  78. import {mapGetters, mapActions} from "vuex";
  79. import dialogZone from "../../ledger/addDialog/dialogZone";
  80. export default {
  81. props: {
  82. id: {},
  83. zoneCode: {}
  84. },
  85. components: {
  86. qrcode, //二维码页面
  87. myPagination,
  88. addBusiness,
  89. uploadImgDialog,
  90. dialogZone
  91. },
  92. computed: {
  93. ...mapGetters("layout", ["projectId", "secret", "userId"]),
  94. showTypes() {
  95. return this.onlyRead ?
  96. [{value: "Visible", label: '只看采集信息'}, {value: "all", label: '全部'}] :
  97. [{value: "Visible", label: '只看采集信息'}, {value: "all", label: '全部'}]
  98. }
  99. },
  100. data() {
  101. return {
  102. dialog: {
  103. qrcode: false, //二维码弹窗
  104. addDevice: false
  105. },
  106. qrcodeUrl: "",//二维码图片地址
  107. headers: null,
  108. main: [],
  109. hot: null,
  110. isLoading: true,
  111. options: [{
  112. value: true,
  113. label: '只读模式'
  114. }, {
  115. value: false,
  116. label: '编辑模式'
  117. }],
  118. onlyRead: true,
  119. showType: "",
  120. page: {
  121. pageSize: 50,
  122. pageSizes: [10, 20, 50, 100],
  123. pageNumber: 1,
  124. total: 0
  125. },
  126. param: {
  127. ProjId: this.projectId, //项目id
  128. UserId: this.userId, //用户id
  129. secret: this.secret
  130. },
  131. buildMess: null,
  132. filtersArr: [], //表格数据被过滤后的下标
  133. copyMain: [], //深拷贝数组
  134. buildFloorData: [], //楼层数据
  135. zoneItemID: '',
  136. myDialog: {
  137. uploadImgs: false, //上传图片弹窗
  138. },
  139. imgsArr: [], //空间图片
  140. addZone: [{
  141. value: '选项1',
  142. label: '黄金糕'
  143. }, {
  144. value: '选项2',
  145. label: '双皮奶'
  146. }, {
  147. value: '选项3',
  148. label: '蚵仔煎'
  149. }, {
  150. value: '选项4',
  151. label: '龙须面'
  152. }, {
  153. value: '选项5',
  154. label: '北京烤鸭'
  155. }],
  156. zoneValue: '',
  157. };
  158. },
  159. created() {
  160. this.setData()
  161. buildFloor.getData(this.buildFloorData)
  162. },
  163. mounted() {
  164. },
  165. methods: {
  166. setData() {
  167. this.param.ProjId = this.projectId
  168. this.param.UserId = this.userId
  169. this.param.secret = this.secret
  170. },
  171. //获取表格数据
  172. getHeader(headers, buildFloorSelectd) {
  173. this.headers = headers
  174. this.buildFloorSelectd = buildFloorSelectd
  175. this.page.pageNumber = 1
  176. this.getData()
  177. },
  178. getData() {
  179. this.isLoading = true
  180. let params = {
  181. zone: this.zoneCode,
  182. data: {
  183. Filters: ``,
  184. Orders: "createTime desc, RoomID asc",
  185. PageNumber: this.page.pageNumber,
  186. PageSize: this.page.pageSize
  187. }
  188. }
  189. if (this.buildFloorSelectd[0] == "noKnow") {
  190. params.data.Filters += `buildingId isNull`
  191. } else if (this.buildFloorSelectd[0] && this.buildFloorSelectd[0] != "all") {
  192. params.data.Filters += `buildingId='${this.buildFloorSelectd[0]}'`
  193. }
  194. if (this.buildFloorSelectd.length > 1) {
  195. if (this.buildFloorSelectd[1] == "noKnow") {
  196. params.data.Filters += `;floorId isNull`
  197. } else if (this.buildFloorSelectd[1] && this.buildFloorSelectd[1] != "all") {
  198. params.data.Filters += `;floorId='${this.buildFloorSelectd[1]}'`
  199. }
  200. }
  201. if (this.zoneItemID) {
  202. params.data.Filters += `;RoomID='${this.zoneItemID}'`
  203. }
  204. if (!params.data.Filters) {
  205. delete params.data.Filters
  206. }
  207. // if (this.buildFloorSelectd.length && this.buildFloorSelectd[0] && this.buildFloorSelectd[1]) {
  208. // params.data.Filters = `BuildingId='${this.buildFloorSelectd[0]}';FloorId='${this.buildFloorSelectd[1]}'`
  209. // }
  210. // else if (buildFloorSelectd.length && buildFloorSelectd[0] && !buildFloorSelectd[1]) {
  211. // params.data.Filters = `BuildingId='${buildFloorSelectd[0]}'`
  212. // } else {
  213. // params.data.Filters = `BuildingId='';FloorId=''`
  214. // }
  215. queryZone(params, res => {
  216. this.page.total = res.Total
  217. this.main = res.Content.map((item) => {
  218. if (item.hasOwnProperty("BuildingId") && item.hasOwnProperty("FloorId")) {
  219. item.flowBuild = item.BuildingId + "-" + item.FloorId
  220. } else if (item.hasOwnProperty("BuildingId") && !item.hasOwnProperty("FloorId")) {
  221. item.flowBuild = item.BuildingId
  222. }
  223. return item
  224. });
  225. if (this.main && this.main.length && this.main[0].RoomID) {
  226. this.copyMain = tools.deepCopy(this.main);
  227. if (this.onlyRead) {
  228. this.getBatch(this.main)
  229. }
  230. }
  231. this.isLoading = false
  232. this.getMain()
  233. })
  234. },
  235. //获取表格主体内容
  236. getMain() {
  237. if (!!this.hot) {
  238. this.hot.destroy();
  239. this.hot = null;
  240. }
  241. this.$nextTick(() => {
  242. this.initHot();
  243. });
  244. },
  245. //初始化handsontable组件
  246. initHot() {
  247. var container = document.getElementById(this.id);
  248. let winHeight = document.documentElement.clientHeight;
  249. this.hot = new Handsontable(container, {
  250. data: this.main,
  251. colHeaders: this.delHeader(this.headers), //表头文案
  252. columns: this.getType(this.headers), //数据显示格式
  253. filters: true,
  254. fixedColumnsLeft: 4,
  255. maxRows: this.main.length,
  256. height: winHeight - 100 - 50 - 176,
  257. columnSorting: true, //添加排序
  258. sortIndicator: true, //添加排序
  259. renderAllRows: true,
  260. autoColumnSize: true,
  261. observeChanges: false,
  262. language: "zh-CN",
  263. manualColumnResize: true,
  264. manualColumnMove: true,
  265. dropdownMenu: [
  266. "filter_by_condition",
  267. "filter_by_value",
  268. "filter_action_bar"
  269. ],
  270. contextMenu: this.onlyRead ? false : {
  271. items: {
  272. remove_row: {
  273. name: "删除该业务空间"
  274. }
  275. }
  276. },
  277. // 事件
  278. afterChange: this.tdChange, //修改后
  279. afterFilter: this.trimmedRows, //排序前
  280. afterRemoveRow: this.romoveFm, //右键删除
  281. afterOnCellMouseDown: this.eventClick //鼠标点击
  282. });
  283. let pro = document.getElementById("hot-display-license-info");
  284. if (!!pro) {
  285. pro.parentNode.removeChild(pro);
  286. }
  287. },
  288. //表格中的查看详情
  289. eventClick(el, rowArr) {
  290. let filter = this.filtersArr;
  291. //被筛选过后的数组
  292. let trimmedArr = this.trimmedRows();
  293. //是否启用了排序
  294. let isSort = this.hot.getPlugin("columnSorting").isSorted();
  295. // debugger
  296. if (trimmedArr.length && isSort) {
  297. let sortArr = this.myHotArr.getPlugin("columnSorting").rowsMapper
  298. .__arrayMap;
  299. let infos = this.main[trimmedArr[sortArr[rowArr.row]]];
  300. this.getInfors(infos, rowArr);
  301. } else if (isSort) {
  302. //排序后的数组
  303. let sortArr = this.hot.getPlugin("columnSorting").rowsMapper.__arrayMap;
  304. let infos = this.main[sortArr[rowArr.row]];
  305. this.getInfors(infos, rowArr);
  306. } else if (trimmedArr.length) {
  307. let infos = this.main[trimmedArr[rowArr.row]];
  308. this.getInfors(infos, rowArr);
  309. } else {
  310. let infos = this.main[rowArr.row];
  311. this.getInfors(infos, rowArr);
  312. }
  313. },
  314. getInfors(infos, row) {
  315. let val = this.hot.colToProp(row.col);
  316. this.row = row.row;
  317. lStorage.set('screen_data', {path: this.$route.path, data: {RoomID: infos.RoomID, zone: this.zoneCode}})
  318. if (val == "point") {
  319. let query = {
  320. RoomID: infos.RoomID,
  321. zone: this.zoneCode,
  322. isMyTab: 2,
  323. buildFloorSelectd: this.buildFloorSelectd
  324. }
  325. this.$router.push({
  326. path: "/ledger/spaceDetail",
  327. query: query
  328. })
  329. } else if (val == "RoomQRCode") {
  330. this.qrcodeUrl = this.main[row.row].RoomQRCode
  331. if (!!this.qrcodeUrl) {
  332. this.dialog.qrcode = true;
  333. } else {
  334. this.$message("此设备没有设备二维码")
  335. }
  336. } else if (val == "Pic") {
  337. let Picdata = tools.dataForKey(this.main[row.row], val);
  338. this.imgsArr = Picdata ? Picdata : [];
  339. if (!this.onlyRead || this.imgsArr.length) {
  340. this.myDialog.uploadImgs = true;
  341. }
  342. } else {
  343. return false;
  344. }
  345. },
  346. //表格发生更改
  347. tdChange(changeData, source) {
  348. if (!this.onlyRead) {
  349. if (changeData) {
  350. let trimmedArr = this.trimmedRows();
  351. let param = handsonUtils.getParam(changeData, source, this.hot, trimmedArr);
  352. let data = []
  353. for (let i = 0; i < param.length; i++) {
  354. if (param[i].RoomID) {
  355. data.push(param[i])
  356. } else {
  357. this.handleCreateZone(param[i])
  358. }
  359. }
  360. //如果data中包含/且data长度为1,将其转换成.
  361. if (changeData.length == 1 && changeData[0][1].indexOf("/") > 0) {
  362. changeData[0][1] = changeData[0][1].split("/").join(".")
  363. }
  364. // 存在data进行修改请求
  365. if (data && data.length) {
  366. this.updateBusiness(data, changeData)
  367. }
  368. }
  369. }
  370. },
  371. //右键删除
  372. romoveFm() {
  373. let params = tools.differenceArr(this.main, this.copyMain)
  374. if (params.length < 1 || this.main > this.copyMain) {
  375. return
  376. }
  377. let param = {
  378. data: [],
  379. zone: this.zoneCode
  380. }
  381. params.map(item => {
  382. if (item.RoomID)
  383. param.data.push({RoomID: item.RoomID})
  384. })
  385. this.$confirm("此操作将删除业务空间,是否继续?", "提示", {
  386. confirmButtonText: '确定',
  387. cancelButtonText: '取消',
  388. type: 'warning'
  389. }).then(() => {
  390. deleteZone(param, res => {
  391. this.$message.success("删除成功!")
  392. this.getData()
  393. })
  394. }).catch(() => {
  395. this.getData()
  396. this.$message("取消删除")
  397. })
  398. },
  399. //创建业务空间
  400. handleCreateZone(param) {
  401. let keys = Object.keys(param)
  402. keys.map((key) => { //将值为空字符串的属性删除
  403. if (param[key] == "") {
  404. delete param[key]
  405. }
  406. })
  407. if (!param.RoomLocalName) {
  408. this.$message("新增业务空间本地名称不能为空!")
  409. return
  410. }
  411. if (!Object.keys(param).length) {
  412. this.$message("新添加业务空间内容不能为空!")
  413. return
  414. }
  415. if (param.flowBuild) {
  416. param.BuildingId = param.flowBuild.split('-')[0]
  417. param.FloorId = param.flowBuild.split('-')[1] || null
  418. } else {
  419. if (this.buildFloorSelectd) {
  420. if (this.buildFloorSelectd[0] != 'all' && this.buildFloorSelectd[0] != 'noKnow') {
  421. param.BuildingId = this.buildFloorSelectd[0]
  422. }
  423. if (this.buildFloorSelectd[1] && this.buildFloorSelectd[1] != 'all' && this.buildFloorSelectd[1] != 'noKnow') {
  424. param.FloorId = this.buildFloorSelectd[1]
  425. }
  426. }
  427. }
  428. let params = {
  429. zone: this.zoneCode,
  430. data: {
  431. Content: [param]
  432. }
  433. }
  434. createZone(params, res => {
  435. this.$message.success("添加成功!")
  436. this.getData()
  437. })
  438. },
  439. // 修改
  440. updateBusiness(data, change) {
  441. let param = {
  442. data: {
  443. Content: [],
  444. Projection: []
  445. },
  446. zone: this.zoneCode
  447. };
  448. let keyList = [];
  449. //生成要修改字段列表
  450. change.map((item) => {
  451. let key = item[1].split(".")[0]
  452. if (key == "flowBuild" && keyList.indexOf(key) == -1) {
  453. keyList.push("BuildingId", "FloorId")
  454. param.data.Projection.push("BuildingId", "FloorId")
  455. }
  456. if (item[1] && keyList.indexOf(key) == -1) {
  457. keyList.push(key)
  458. }
  459. if (item[1] && item[3] == "" && param.data.Projection.indexOf(key) == -1) {
  460. param.data.Projection.push(key)
  461. }
  462. })
  463. //生成对应修改数据
  464. data.map((item, index) => {
  465. keyList.map(value => {
  466. if (value == "BuildingId") {
  467. let itemData = tools.dataForKey(item, "flowBuild")
  468. if (itemData == "") {
  469. tools.setDataForKey(item, "BuildingId", null)
  470. tools.setDataForKey(item, "FloorId", null)
  471. } else {
  472. let BuildingId = itemData.split("-")[0]
  473. let FloorId = itemData.split("-")[1]
  474. if (BuildingId && FloorId) {
  475. tools.setDataForKey(item, "BuildingId", BuildingId)
  476. tools.setDataForKey(item, "FloorId", FloorId)
  477. } else if (BuildingId && !FloorId) {
  478. tools.setDataForKey(item, "BuildingId", BuildingId)
  479. tools.setDataForKey(item, "FloorId", null)
  480. }
  481. }
  482. } else {
  483. let itemData = tools.dataForKey(item, value)
  484. tools.setDataForKey(item, value, itemData == "" ? null : itemData)
  485. }
  486. })
  487. param.data.Content.push(item);
  488. })
  489. if (param.data.Projection.indexOf('BuildingId') > -1) {
  490. let pa = param.data.Content.map(t => {
  491. return {
  492. type: this.zoneCode,
  493. spaceId: t.RoomID,
  494. id: t.FloorId || t.BuildingId || null,
  495. }
  496. })
  497. updateRelateInSpAndBuild(pa, res => {
  498. this.$message.success('修改成功')
  499. })
  500. } else {
  501. updateZone(param, (res) => {
  502. })
  503. }
  504. },
  505. //获取被筛选掉的行号
  506. trimmedRows() {
  507. // var plugin = hot.getPlugin('trimRows').trimmedRows;//获取被筛选掉的行号
  508. var plugin = this.hot.getPlugin("trimRows").trimmedRows;
  509. let dataLength = this.main.length;
  510. let dataArr = new Array();
  511. for (let i = 0; i < dataLength; i++) {
  512. dataArr.push(i);
  513. }
  514. if (plugin.length <= 0) {
  515. dataArr = undefined;
  516. } else {
  517. dataArr = this.array_diff(dataArr, plugin);
  518. }
  519. this.filtersArr = dataArr;
  520. return dataArr || [];
  521. // var DataArray = new Array();
  522. // for (var i = 0; i < plugin.length; i++) {
  523. // // 通过行号获取数据
  524. // DataArray.push(this.hot.getSourceDataAtRow(plugin[i]));
  525. // }
  526. },
  527. //去除数组中相同的元素
  528. array_diff(a, b) {
  529. for (var i = 0; i < b.length; i++) {
  530. for (var j = 0; j < a.length; j++) {
  531. if (a[j] == b[i]) {
  532. a.splice(j, 1);
  533. j = j - 1;
  534. }
  535. }
  536. }
  537. return a;
  538. },
  539. //获取动态参数
  540. getBatch(data) {
  541. let param = {
  542. secret: this.secret,
  543. ProjId: this.projectId,
  544. data: {
  545. criterias: []
  546. }
  547. };
  548. this.headers.map(head => {
  549. if (
  550. head.InputMode == "L" ||
  551. head.InputMode == "L1" ||
  552. head.InputMode == "L2" ||
  553. head.InputMode == "M"
  554. ) {
  555. data.map(item => {
  556. let cur = tools.dataForKey(item, head.Path);
  557. if (cur) {
  558. param.data.criterias.push({
  559. id: item.RoomID,
  560. code: head.InfoPointCode
  561. });
  562. }
  563. });
  564. }
  565. });
  566. if (param.data.criterias.length) {
  567. BeatchQueryParam(param, res => {
  568. if (!this.onlyRead) {
  569. return false
  570. }
  571. this.main = data.map(item => {
  572. res.Content.map(child => {
  573. if (item.RoomID == child.id) {
  574. if (child.data || child.data == 0) {
  575. this.headers.map(head => {
  576. if (head.InfoPointCode == child.code) {
  577. tools.setDataForKey(item, head.Path, child.data);
  578. }
  579. });
  580. } else {
  581. this.headers.map(head => {
  582. if (head.InfoPointCode == child.code) {
  583. tools.setDataForKey(
  584. item,
  585. head.Path,
  586. // child.error ? "表号功能号格式错误" : "表号功能号不存在"
  587. child.error ? child.value ? "表号功能号格式错误" : "表号功能号不存在" : "暂未采集到实时数据"
  588. );
  589. }
  590. });
  591. }
  592. }
  593. });
  594. return item;
  595. });
  596. this.hot.loadData(this.main);
  597. });
  598. }
  599. },
  600. /**
  601. * 表头文案处理函数
  602. * @param list header数组数据
  603. *
  604. * @return 处理好的文案
  605. */
  606. delHeader(list) {
  607. let arr = tools.copyArr(list)
  608. let data = showTools.headerTextFilter(arr, "space", this.onlyRead, this.showType)
  609. data.unshift("是否关联平面图", "与空间相关联的设备");
  610. if (this.showType == "all") {
  611. data.splice(4, 0, "所属建筑楼层")
  612. }
  613. return data;
  614. },
  615. /**
  616. * 表头数据处理函数
  617. * @param arr header数组数据
  618. *
  619. * @return 处理好的数据格式
  620. */
  621. getType(list) {
  622. let arr = tools.copyArr(list)
  623. let data = showTools.headerTypeFilter(arr, "space", this.onlyRead, this.showType)
  624. data.unshift({
  625. data: "Outline",
  626. renderer: this.myRenderer,
  627. readOnly: true
  628. }, {
  629. data: "point",
  630. renderer: this.facilityRender,
  631. readOnly: true
  632. });
  633. if (this.showType == "all") {
  634. data.splice(4, 0, {
  635. data: "flowBuild",
  636. renderer: tools.customDropdownRenderer,
  637. editor: "chosen",
  638. chosenOptions: {
  639. data: this.buildFloorData
  640. },
  641. readOnly: this.onlyRead
  642. })
  643. }
  644. return data;
  645. },
  646. myRenderer(instance, td, row, col, prop, value, cellProperties) {
  647. if (value && value.length && value[0]) {
  648. td.innerHTML = "已关联"
  649. } else {
  650. td.innerHTML = "未关联"
  651. }
  652. return td;
  653. },
  654. facilityRender(instance, td, row, col, prop, value, cellProperties) {
  655. td.style.color = "#409EFF"
  656. td.style.cursor = "pointer"
  657. td.innerHTML = "点击查看"
  658. return td;
  659. },
  660. /** 页面中的按钮事件--------------------------- */
  661. addSp() {
  662. if (this.main && this.main.length && this.main[0].RoomID) {
  663. this.hot.destroy()
  664. this.hot = null
  665. this.main.unshift({})
  666. this.getMain()
  667. } else {
  668. if (this.main && this.main.length) {
  669. this.$message("请添加完成后继续添加")
  670. } else {
  671. this.main.unshift({})
  672. this.getMain()
  673. }
  674. }
  675. },
  676. //刷新
  677. reset() {
  678. this.getData()
  679. },
  680. //撤回操作
  681. undo() {
  682. this.hot.undo()
  683. },
  684. /** 分页事件------------------------ */
  685. //切换每页显示多少条数据
  686. handleSizeChange(val) {
  687. this.page.pageSize = val
  688. this.page.pageNumber = 1
  689. this.getData()
  690. },
  691. //切换页数
  692. handleCurrentChange(val) {
  693. this.page.pageNumber = val
  694. this.getData()
  695. },
  696. //上传图片弹窗触发事件
  697. imgChange(keys) {
  698. this.setDataToMain(keys, 'Pic', this.row);
  699. },
  700. //判断是否有值,有值赋值
  701. setDataToMain(data, key, row) {
  702. if (!!data && data != '--') {
  703. if (!!this.main[row]) {
  704. tools.setDataForKey(this.main[row], key, data);
  705. this.tdChange([[row, key, null, data]], "edit");
  706. } else {
  707. this.main[row] = {};
  708. tools.setDataForKey(this.main[row], key, data);
  709. }
  710. } else {
  711. tools.setDataForKey(this.main[row], key, "");
  712. }
  713. this.hot.render()
  714. },
  715. addZoneBtn() {
  716. this.$refs.zone.dialogFormVisible = true
  717. }
  718. },
  719. watch: {
  720. projectId() {
  721. this.buildFloorData = []
  722. buildFloor.getData(this.buildFloorData)
  723. this.setData()
  724. this.main = null
  725. },
  726. showTypes: {
  727. handler(newName, oldName) {
  728. if (newName && newName[0] && newName[0].value) {
  729. this.showType = newName[0].value
  730. } else {
  731. this.showType = ""
  732. }
  733. },
  734. immediate: true,
  735. deep: true
  736. }
  737. }
  738. };
  739. </script>
  740. <style lang="less" scoped>
  741. #handsontable {
  742. .left {
  743. padding-top: 0;
  744. padding-bottom: 10px;
  745. }
  746. .no-data {
  747. height: 150px;
  748. line-height: 150px;
  749. text-align: center;
  750. color: gray;
  751. }
  752. }
  753. </style>