addDevice.vue 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496
  1. <template>
  2. <div>
  3. <div class="hanson-bar">
  4. <span>当前选择的设备类型:{{deviceType.facility}}</span>
  5. <el-button size="small" @click="undo" icon="iconfont icon-undo">撤销</el-button>
  6. <el-button size="small" @click="reset" icon="iconfont icon-shuaxin">刷新</el-button>
  7. </div>
  8. <qrcode :dialog="dialog" :addBody="true" ref="qrcode"></qrcode>
  9. <firm :dialog="dialog"></firm>
  10. <supply-dialog :dialog="dialog"></supply-dialog>
  11. <supplier-dialog :dialog="dialog"></supplier-dialog>
  12. <guarantee-dialog :dialog="dialog"></guarantee-dialog>
  13. <upload-files-dialog :dialog="dialog"></upload-files-dialog>
  14. <div v-show="main && main.length" id="myHandson" ref="myHandson"></div>
  15. </div>
  16. </template>
  17. <script>
  18. import { getSpaceHeader } from "@/api/scan/request";
  19. import tools from "@/utils/scan/tools";
  20. import qrcode from "@/components/ledger/lib/qrcode";
  21. import firm from "@/components/dialogs/list/firm";
  22. import supplyDialog from "@/components/dialogs/list/supplyDialog";
  23. import supplierDialog from "@/components/dialogs/list/supplierDialog";
  24. import guaranteeDialog from "@/components/dialogs/list/guaranteeDialog";
  25. import uploadFilesDialog from "@/components/dialogs/list/filesDialog";
  26. export default {
  27. props: {
  28. deviceType: {
  29. type: Object
  30. }
  31. },
  32. components: {
  33. qrcode, //二维码页面
  34. firm, //
  35. supplyDialog,
  36. supplierDialog,
  37. guaranteeDialog,
  38. uploadFilesDialog,
  39. },
  40. data() {
  41. let table = function (num) {
  42. let main = []
  43. for (let i = 0; i < num; i++) {
  44. main.push({})
  45. }
  46. return main
  47. }
  48. return {
  49. main: table(20),
  50. mess: {},
  51. headers: null,
  52. page: {
  53. size: 10,
  54. sizes: [10, 30, 50, 100, 150, 200],
  55. total: 400,
  56. currentPage: 1
  57. },
  58. dialog: {
  59. qrcode: false, //二维码弹窗
  60. firm: false, //厂商弹窗
  61. supply: false, //选择供应合同
  62. supplier: false, //供应商选择
  63. guarantee: false //选择保单
  64. }
  65. };
  66. },
  67. created() {
  68. },
  69. mounted() { },
  70. methods: {
  71. //获取header的mess
  72. getHeader(mess) {
  73. this.mess = mess;
  74. console.log(this.mess);
  75. },
  76. //获取主体内容
  77. getMain(floorMess) {
  78. console.log(floorMess);
  79. },
  80. //获取表头
  81. getData() {
  82. getSpaceHeader({
  83. code: this.deviceType.code,
  84. ProjId: this.$route.query.projId
  85. }).then(res => {
  86. this.headers = res.data.Content;
  87. if (!!this.hot) {
  88. this.hot.destroy();
  89. this.hot = null;
  90. }
  91. this.initHot();
  92. });
  93. },
  94. //撤回
  95. undo() {
  96. this.hot.undo();
  97. },
  98. //刷新
  99. reset() {
  100. this.getData();
  101. },
  102. //添加设备
  103. addDevice() {
  104. console.log("addDevice")
  105. },
  106. /**
  107. * 表头文案处理函数
  108. * @param arr header数组数据
  109. *
  110. * @return 处理好的文案
  111. */
  112. delHeader(arr) {
  113. let data = arr.map(item => {
  114. if (
  115. item.InputMode == "A1" ||
  116. item.InputMode == "A2" ||
  117. item.InputMode == "B1" ||
  118. item.InputMode == "C5" ||
  119. item.InputMode == "D1" ||
  120. item.InputMode == "D2" ||
  121. item.InputMode == "X" ||
  122. item.InputMode == "L" ||
  123. item.InputMode == "L1" ||
  124. item.InputMode == "L2" ||
  125. item.InputMode == "F1" ||
  126. item.InputMode == "F2"
  127. ) {
  128. if (item.unit == "") {
  129. return item.InfoPointName;
  130. } else {
  131. return item.InfoPointName + "(" + item.unit + ")";
  132. }
  133. } else {
  134. return undefined;
  135. }
  136. });
  137. data = data.filter(item => item);
  138. data.unshift("同时创建资产", "所属建筑楼层", "所属系统实例");
  139. return data;
  140. },
  141. /**
  142. * 表头数据处理函数
  143. * @param arr header数组数据
  144. *
  145. * @return 处理好的数据格式
  146. */
  147. getType(arr) {
  148. let data = arr.map(item => {
  149. //二维码
  150. if (item.infoPointCode == "EquipQRCode") {
  151. return {
  152. data: "infos." + item.infoPointCode,
  153. renderer: tools.lookDetails,
  154. readOnly: true
  155. }
  156. }
  157. //厂商选择
  158. if (item.infoPointCode == "Brand" || item.infoPointCode == "Specification") {
  159. return {
  160. data: "infos." + item.infoPointCode,
  161. renderer: tools.lookDetails,
  162. readOnly: true
  163. }
  164. }
  165. if (item.infoPointCode == "SupplierContractID") {
  166. return {
  167. data: "infos." + item.infoPointCode,
  168. renderer: tools.lookDetails,
  169. readOnly: true
  170. }
  171. }
  172. if (item.infoPointCode == "InsuranceNum") {
  173. //选择保单
  174. return {
  175. data: "infos." + item.infoPointCode,
  176. renderer: tools.lookDetails,
  177. readOnly: true
  178. }
  179. }
  180. if (item.infoPointCode == "InsuranceFile" || item.infoPointCode == "Archive") {
  181. return {
  182. data: "infos." + item.infoPointCode,
  183. renderer: tools.lookDetails,
  184. readOnly: true
  185. }
  186. }
  187. if (
  188. item.infoPointCode == "InstallLocation" ||
  189. item.infoPointCode == "InstallPic" ||
  190. item.infoPointCode == "InstallDrawing" ||
  191. item.infoPointCode == "Nameplate" ||
  192. item.infoPointCode == "Pic" ||
  193. item.infoPointCode == "Drawing"
  194. ) {
  195. return {
  196. data: "infos." + item.infoPointCode,
  197. renderer: tools.lookDetails,
  198. readOnly: true
  199. }
  200. }
  201. if (
  202. item.infoPointCode == "Maintainer" ||
  203. item.infoPointCode == "Supplier" ||
  204. item.infoPointCode == "Insurer" ||
  205. item.infoPointCode == "InsurerContactor"
  206. ) {
  207. return {
  208. data: "infos." + item.infoPointCode,
  209. renderer: tools.lookDetails,
  210. readOnly: true
  211. }
  212. }
  213. if (item.InputMode == "D1") {
  214. return {
  215. data: "infos." + item.infoPointCode,
  216. renderer: tools.customDropdownRenderer,
  217. editor: "chosen",
  218. chosenOptions: {
  219. // multiple: true,//多选
  220. data: item.DataSource.Content || ""
  221. }
  222. };
  223. } else if (item.InputMode == "A1" || item.InputMode == "A2") {
  224. return {
  225. data: "infos." + item.infoPointCode,
  226. type: "numeric",
  227. numericFormat: {
  228. pattern: "0,0.00"
  229. // culture: 'de-DE' // use this for EUR (German),
  230. // more cultures available on http://numbrojs.com/languages.html
  231. }
  232. };
  233. } else if (item.InputMode == "C5") {
  234. return {
  235. data: "infos." + item.infoPointCode,
  236. type: "date",
  237. dateFormat: "YYYY-MM-DD",
  238. correctFormat: true
  239. };
  240. } else if (
  241. item.InputMode == "B1" ||
  242. item.InputMode == "L" ||
  243. item.InputMode == "L1" ||
  244. item.InputMode == "L2"
  245. ) {
  246. return {
  247. data: "infos." + item.infoPointCode
  248. };
  249. } else if (
  250. item.InputMode == "X" ||
  251. item.InputMode == "F2"
  252. // item.InputMode == "L1" ||
  253. // item.InputMode == "L2"
  254. ) {
  255. return {
  256. data: "infos." + item.infoPointCode,
  257. readOnly: true
  258. };
  259. } else if (item.InputMode == "D2") {
  260. return {
  261. data: "infos." + item.infoPointCode,
  262. renderer: tools.customDropdownRenderer,
  263. editor: "chosen",
  264. chosenOptions: {
  265. multiple: true, //多选
  266. data: item.DataSource.Content || ""
  267. }
  268. };
  269. } else {
  270. return undefined;
  271. }
  272. });
  273. data.unshift(
  274. {
  275. type: "checkbox",
  276. checkedTemplate: 1,
  277. uncheckedTemplate: 0,
  278. data: "Checked",
  279. label: {
  280. position: "after",
  281. }
  282. },
  283. {
  284. data: "flowBuild",
  285. renderer: tools.customDropdownRenderer,
  286. editor: "chosen",
  287. chosenOptions: {
  288. // multiple: true,//多选
  289. // data: item.DataSource.Content || ""
  290. }
  291. },
  292. {
  293. data: "system",
  294. renderer: tools.customDropdownRenderer,
  295. editor: "chosen",
  296. chosenOptions: {
  297. // multiple: true,//多选
  298. // data: item.DataSource.Content || ""
  299. }
  300. }
  301. );
  302. data = data.filter(item => item);
  303. return data;
  304. },
  305. //初始化插件
  306. initHot() {
  307. var container = document.getElementById("myHandson");
  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. height: winHeight - 100 - 50 - 60,
  315. columnSorting: true, //添加排序
  316. sortIndicator: true, //添加排序
  317. renderAllRows: true,
  318. autoColumnSize: true,
  319. language: "zh-CN",
  320. manualColumnResize: true,
  321. manualColumnMove: true,
  322. dropdownMenu: [
  323. "filter_by_condition",
  324. "filter_by_value",
  325. "filter_action_bar"
  326. ],
  327. contextMenu: {
  328. items: {
  329. remove_row: {
  330. name: "删除该业务空间"
  331. }
  332. }
  333. },
  334. // 事件
  335. afterChange: this.tdChange, //修改后
  336. afterFilter: this.trimmedRows, //排序前
  337. beforeRemoveRow: this.romoveFm, //右键删除
  338. afterOnCellMouseDown: this.eventClick //鼠标点击
  339. });
  340. let pro = document.getElementById("hot-display-license-info");
  341. if (!!pro) {
  342. pro.parentNode.removeChild(pro);
  343. }
  344. this.isLoading = false;
  345. },
  346. //表格中的点击
  347. eventClick(el, rowArr) {
  348. let filter = this.filtersArr;
  349. //被筛选过后的数组
  350. let trimmedArr = this.trimmedRows();
  351. //是否启用了排序
  352. let isSort = this.hot.getPlugin("columnSorting").isSorted();
  353. if (trimmedArr.length && isSort) {
  354. let sortArr = this.myHotArr.getPlugin("columnSorting").rowsMapper
  355. .__arrayMap;
  356. let infos = this.main[trimmedArr[sortArr[rowArr.row]]];
  357. this.getInfors(infos, rowArr);
  358. } else if (isSort) {
  359. //排序后的数组
  360. let sortArr = this.hot.getPlugin("columnSorting").rowsMapper.__arrayMap;
  361. let infos = this.main[sortArr[rowArr.row]];
  362. this.getInfors(infos, rowArr);
  363. } else if (trimmedArr.length) {
  364. let infos = this.main[trimmedArr[rowArr.row]];
  365. this.getInfors(infos, rowArr);
  366. } else {
  367. let infos = this.main[rowArr.row];
  368. this.getInfors(infos, rowArr);
  369. }
  370. },
  371. getInfors(infos, row) {
  372. //点击的是表头
  373. if (row.row < 0) {
  374. return;
  375. }
  376. //其他的开始判断
  377. let val = this.hot.colToProp(row.col);
  378. if (val == "infos.EquipQRCode") {
  379. this.dialog.qrcode = true;
  380. this.$refs.qrcode.getCanvas(1111);
  381. }
  382. if (val == "infos.Brand" || val == "infos.Specification") {
  383. this.dialog.firm = true;
  384. }
  385. if (val == "infos.SupplierContractID") {
  386. this.dialog.supply = true;
  387. }
  388. if (val == "infos.InsuranceNum") {
  389. //选择保单
  390. this.dialog.guarantee = true;
  391. }
  392. if (val == "infos.InsuranceFile" || val == "infos.Archive") {
  393. alert("上传文件");
  394. }
  395. if (
  396. val == "infos.InstallLocation" ||
  397. val == "infos.InstallPic" ||
  398. val == "infos.InstallDrawing" ||
  399. val == "infos.Nameplate" ||
  400. val == "infos.Pic" ||
  401. val == "infos.Drawing"
  402. ) {
  403. alert("上传图片");
  404. }
  405. if (
  406. val == "infos.Maintainer" ||
  407. val == "infos.Supplier" ||
  408. val == "infos.Insurer" ||
  409. val == "infos.InsurerContactor"
  410. ) {
  411. this.dialog.supplier = true;
  412. }
  413. console.log(val);
  414. },
  415. //获取被筛选掉的行号
  416. trimmedRows() {
  417. // var plugin = hot.getPlugin('trimRows').trimmedRows;//获取被筛选掉的行号
  418. var plugin = this.hot.getPlugin("trimRows").trimmedRows;
  419. let dataLength = this.main.length;
  420. let dataArr = new Array();
  421. for (let i = 0; i < dataLength; i++) {
  422. dataArr.push(i);
  423. }
  424. if (plugin.length <= 0) {
  425. dataArr = undefined;
  426. } else {
  427. dataArr = this.array_diff(dataArr, plugin);
  428. }
  429. return dataArr || [];
  430. // var DataArray = new Array();
  431. // for (var i = 0; i < plugin.length; i++) {
  432. // // 通过行号获取数据
  433. // DataArray.push(this.hot.getSourceDataAtRow(plugin[i]));
  434. // }
  435. },
  436. //判断是否为空行
  437. isEmptyRow(instance, row) {
  438. var rowData = instance.countRows();
  439. for (var i = 0, ilen = rowData.length; i < ilen; i++) {
  440. if (rowData[i] !== null) {
  441. return false;
  442. }
  443. }
  444. return true;
  445. }
  446. },
  447. watch: {
  448. deviceType: {
  449. handler(newName, oldName) {
  450. this.getData()
  451. },
  452. immediate: true
  453. }
  454. }
  455. };
  456. </script>
  457. <style lang="less">
  458. .hanson-bar {
  459. height: 40px;
  460. padding: 5px;
  461. font-size: 16px;
  462. overflow: hidden;
  463. .iconfont {
  464. font-size: 12px;
  465. }
  466. .el-button {
  467. margin-right: 10px;
  468. }
  469. }
  470. </style>