bindSubstanceList.vue 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271
  1. <template>
  2. <ele-modal
  3. :title="title"
  4. :visible.sync="visible"
  5. :before-close="handleClose"
  6. :close-on-click-modal="false"
  7. :close-on-press-escape="false"
  8. append-to-body
  9. width="70%"
  10. :maxable="true"
  11. >
  12. <el-card shadow="never">
  13. <ele-split-layout
  14. width="266px"
  15. allow-collapse
  16. :right-style="{ overflow: 'hidden' }"
  17. >
  18. <div>
  19. <div class="ele-border-lighter sys-organization-list">
  20. <el-tree
  21. :data="treeList"
  22. :props="{
  23. children: 'children',
  24. value: 'id',
  25. label: 'name'
  26. }"
  27. node-key="id"
  28. ref="tree"
  29. :highlight-current="true"
  30. :expand-on-click-node="false"
  31. @node-click="handleNodeClick"
  32. v-bind="$attrs"
  33. :default-expand-all="true"
  34. >
  35. </el-tree>
  36. </div>
  37. </div>
  38. <template v-slot:content>
  39. <ele-pro-table
  40. max-height="500px"
  41. ref="table"
  42. :columns="columns"
  43. :datasource="physicalList"
  44. @selection-change="handleSelectionChange"
  45. row-key="id"
  46. :initLoad="false"
  47. :needPage="false"
  48. >
  49. </ele-pro-table>
  50. </template>
  51. </ele-split-layout>
  52. </el-card>
  53. <div class="rx-sc">
  54. <el-button type="primary" size="small" @click="selected">选择</el-button>
  55. <el-button size="small" @click="handleClose">关闭</el-button>
  56. </div>
  57. </ele-modal>
  58. </template>
  59. <script>
  60. import {
  61. queryBindSubstanceList,
  62. getPhysicalModel,
  63. getDetailInfo
  64. } from '@/api/material/list';
  65. import { getAssetInfo } from '@/api/ledgerAssets/index.js';
  66. export default {
  67. components: {},
  68. props: {
  69. // 是否多选
  70. multiple: {
  71. type: Boolean,
  72. default: false
  73. }
  74. },
  75. computed: {
  76. seekList() {
  77. return [
  78. {
  79. label: '名称',
  80. value: 'name',
  81. type: 'input',
  82. placeholder: '请输入'
  83. }
  84. ];
  85. },
  86. // 表格列配置
  87. columns() {
  88. const list = [
  89. {
  90. columnKey: 'selection',
  91. type: 'selection',
  92. width: 45,
  93. align: 'center',
  94. reserveSelection: true,
  95. fixed: 'left'
  96. },
  97. {
  98. columnKey: 'index',
  99. type: 'index',
  100. label: '序号',
  101. width: 55,
  102. align: 'center',
  103. showOverflowTooltip: true,
  104. fixed: 'left'
  105. },
  106. {
  107. prop: 'name',
  108. label: '名称',
  109. showOverflowTooltip: true
  110. },
  111. {
  112. prop: 'identifier',
  113. label: '点位',
  114. showOverflowTooltip: true,
  115. minWidth: 180
  116. },
  117. {
  118. prop: 'dataType.specs.max',
  119. label: '最大值',
  120. showOverflowTooltip: true,
  121. minWidth: 180
  122. },
  123. {
  124. prop: 'dataType.specs.min',
  125. label: '最小值',
  126. showOverflowTooltip: true,
  127. minWidth: 180
  128. },
  129. {
  130. prop: 'dataType.specs.unitName',
  131. label: '单位',
  132. showOverflowTooltip: true,
  133. minWidth: 180
  134. }
  135. ];
  136. return list;
  137. }
  138. },
  139. data() {
  140. return {
  141. visible: false,
  142. title: '选择',
  143. type: null,
  144. // 表格选中数据
  145. selection: [],
  146. physicalList: [],
  147. cachingData: {},
  148. treeList: [],
  149. current: null
  150. };
  151. },
  152. watch: {},
  153. methods: {
  154. /* 表格数据源 */
  155. async queryBindSubstanceList(id) {
  156. let data = await queryBindSubstanceList({
  157. id,
  158. pageNum: 1,
  159. size: 1000
  160. });
  161. this.treeList[0].children = data.list;
  162. },
  163. getPhysicalModel(id) {
  164. getPhysicalModel(id).then((res) => {
  165. this.physicalList = [];
  166. if (res.code == 0) {
  167. this.physicalList = res.data.properties;
  168. if (this.cachingData[id]) {
  169. this.$refs.table.setSelectedRows(this.cachingData[id].list);
  170. }
  171. }
  172. });
  173. },
  174. handleNodeClick(data) {
  175. // if (data.id == this.treeList[0].id) {
  176. // this.physicalList = [];
  177. // return;
  178. // }
  179. this.current = data;
  180. this.$refs.table.clearSelection();
  181. this.getPhysicalModel(data.id);
  182. },
  183. async open(id) {
  184. const data = await getAssetInfo(id);
  185. console.log(data);
  186. this.visible = true;
  187. if (id) {
  188. this.treeList.push({
  189. ...data,
  190. children: []
  191. });
  192. this.$nextTick(() => {
  193. this.queryBindSubstanceList(id);
  194. });
  195. }
  196. },
  197. handleSelectionChange(data) {
  198. this.cachingData[this.current.id] = {
  199. substanceCode: this.current.code,
  200. substanceId: this.current.id,
  201. substanceName: this.current.name,
  202. iotId: this.current.iotId,
  203. list: data
  204. };
  205. },
  206. handleClose() {
  207. this.physicalList = [];
  208. this.cachingData = [];
  209. this.treeList = [];
  210. this.visible = false;
  211. },
  212. selected() {
  213. let cachingData = [];
  214. let list = [];
  215. for (let key in this.cachingData) {
  216. cachingData.push(this.cachingData[key]);
  217. }
  218. if (!cachingData.length) {
  219. this.$message.warning('请选择设备点位!');
  220. return;
  221. }
  222. cachingData.forEach((item) => {
  223. item.list.forEach((listItem) => {
  224. list.push({
  225. substanceCode: item.substanceCode,
  226. substanceId: item.substanceId,
  227. substanceName: item.substanceName,
  228. iotId: item.iotId,
  229. paramCode: listItem.identifier,
  230. paramValue: listItem.name,
  231. maxValue: listItem.dataType?.specs.max,
  232. minValue: listItem.dataType?.specs.min,
  233. unitName: listItem.dataType?.specs.unitName
  234. });
  235. });
  236. });
  237. this.$emit('bindSubstanceSuccess', list);
  238. this.handleClose();
  239. }
  240. }
  241. };
  242. </script>
  243. <style lang="scss" scoped>
  244. .rx-sc {
  245. display: flex;
  246. align-items: center;
  247. justify-content: center;
  248. }
  249. .ml60 {
  250. margin-left: 60px;
  251. }
  252. :deep(.radio) {
  253. .el-radio__label {
  254. padding: 0;
  255. }
  256. }
  257. </style>