MaterialAdd.vue 7.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288
  1. <template>
  2. <el-dialog
  3. :title="title"
  4. :visible.sync="visible"
  5. :before-close="handleClose"
  6. class="productModal_dialog"
  7. :close-on-click-modal="false"
  8. :close-on-press-escape="false"
  9. append-to-body
  10. width="70%"
  11. >
  12. <el-card shadow="never">
  13. <ele-split-layout
  14. width="244px"
  15. allow-collapse
  16. :right-style="{ overflow: 'hidden' }"
  17. >
  18. <div class="ele-border-lighter split-layout-right-content">
  19. <el-tree
  20. :data="treeList"
  21. :props="defaultProps"
  22. ref="treeRef"
  23. :expand-on-click-node="false"
  24. :default-expanded-keys="categoryId ? [categoryId] : []"
  25. :highlight-current="true"
  26. node-key="id"
  27. @node-click="handleNodeClick"
  28. ></el-tree>
  29. </div>
  30. <!-- 数据表格 -->
  31. <template v-slot:content>
  32. <ProductSearch @search="reload" ref="searchRef" />
  33. <ele-pro-table
  34. height="400"
  35. ref="table"
  36. :columns="columns"
  37. :datasource="datasource"
  38. :selection.sync="selection"
  39. row-key="id"
  40. :initLoad="false"
  41. >
  42. <template v-slot:modelType="{ row }">
  43. <span>{{ row.category.modelType }}</span>
  44. </template>
  45. <template v-slot:specification="{ row }">
  46. <span>{{ row.category.specification }}</span>
  47. </template>
  48. <template v-slot:pathName="{ row }">
  49. <span>{{ row.position[0].pathName }}</span>
  50. </template>
  51. </ele-pro-table>
  52. </template>
  53. </ele-split-layout>
  54. </el-card>
  55. <div class="rx-sc">
  56. <el-button type="primary" size="small" @click="selected">选择</el-button>
  57. <el-button size="small" @click="handleClose">关闭</el-button>
  58. </div>
  59. </el-dialog>
  60. </template>
  61. <script>
  62. import ProductSearch from './product-search.vue';
  63. import { getAssetList } from '@/api/ruleManagement/plan';
  64. import { getTreeByPid, getTreeByGroup } from '@/api/classifyManage';
  65. export default {
  66. data() {
  67. return {
  68. ruleIdListIndex: 0,
  69. visible: false,
  70. title: '选择设备',
  71. categoryLevelId: null,
  72. categoryId: 1,
  73. treeList: [],
  74. treeLoading: false,
  75. defaultProps: {
  76. children: 'children',
  77. label: 'name'
  78. },
  79. type: null,
  80. // 表格列配置
  81. columns: [
  82. {
  83. columnKey: 'selection',
  84. type: 'selection',
  85. width: 45,
  86. align: 'center',
  87. selectable: (row, index) => {
  88. return !this.processData.some((id) => id == row.id);
  89. },
  90. reserveSelection: true,
  91. fixed: 'left'
  92. },
  93. {
  94. label: '设备名称',
  95. prop: 'name'
  96. },
  97. {
  98. label: '编号',
  99. prop: 'codeNumber'
  100. },
  101. {
  102. label: '固资编码',
  103. prop: 'fixCode'
  104. },
  105. {
  106. label: '型号',
  107. prop: 'modelType',
  108. slot: 'modelType'
  109. },
  110. {
  111. label: '规格',
  112. prop: 'specification',
  113. slot: 'specification'
  114. },
  115. {
  116. label: '设备位置',
  117. prop: 'pathName',
  118. slot: 'pathName'
  119. }
  120. ],
  121. // 表格选中数据
  122. selection: [],
  123. processData: []
  124. };
  125. },
  126. components: {
  127. ProductSearch
  128. },
  129. methods: {
  130. /* 表格数据源 */
  131. async datasource({ page, limit, where }) {
  132. const res = await getAssetList({
  133. ...where,
  134. pageNum: page,
  135. size: limit,
  136. categoryLevelId: this.categoryLevelId,
  137. rootCategoryLevelId: this.rootId
  138. });
  139. console.log('res---------', res);
  140. this.categoryId = res.list[0]?.categoryId;
  141. return res;
  142. },
  143. open(ruleIdList, ruleIdListIndex) {
  144. console.log(ruleIdList);
  145. console.log(ruleIdListIndex);
  146. let list = ruleIdList
  147. .map((item) => {
  148. return item.equipmentList;
  149. })
  150. .flat();
  151. console.log(list);
  152. if (list.length > 0) {
  153. this.processData = list.map((item) => item.id);
  154. } else {
  155. this.processData = [];
  156. }
  157. this.ruleIdListIndex = ruleIdListIndex;
  158. this.visible = true;
  159. this.getTreeData();
  160. },
  161. async getTreeData() {
  162. try {
  163. this.treeLoading = true;
  164. const res = await getTreeByGroup({ type: 4 });
  165. console.log('res---treeList----------', res);
  166. this.treeLoading = false;
  167. if (res?.code === '0') {
  168. this.treeList = res.data;
  169. return this.treeList;
  170. }
  171. } catch (error) {
  172. console.log(error);
  173. }
  174. this.treeLoading = false;
  175. },
  176. handleNodeClick(data) {
  177. this.rootId = data.rootCategoryLevelId;
  178. this.categoryLevelId = data.id;
  179. this.$refs.table.reload({ pageNum: 1, where: {} });
  180. },
  181. /* 刷新表格 */
  182. reload(where) {
  183. if (this.rootId && this.categoryLevelId) {
  184. this.$refs.table.reload({ page: 1, where: where });
  185. } else {
  186. this.$message.error('请选择设备');
  187. }
  188. },
  189. handleClose() {
  190. this.visible = false;
  191. this.$refs.table.setSelectedRows([]);
  192. this.selection = [];
  193. },
  194. selected() {
  195. if (!this.selection.length) {
  196. this.$message.error('请至少选择一条数据');
  197. return;
  198. }
  199. const selectList = this.$refs.treeRef.getCheckedNodes();
  200. console.log('selectList-----------', selectList);
  201. this.$emit(
  202. 'chooseEquipment',
  203. this.selection,
  204. this.ruleIdListIndex,
  205. this.categoryId
  206. );
  207. this.handleClose();
  208. }
  209. }
  210. };
  211. </script>
  212. <style lang="scss" scoped>
  213. .productModal_dialog {
  214. overflow: hidden;
  215. ::v-deep .el-dialog {
  216. margin: 50px auto !important;
  217. height: 90%;
  218. overflow: hidden;
  219. .el-dialog__body {
  220. position: absolute;
  221. left: 0;
  222. top: 54px;
  223. bottom: 0;
  224. right: 0;
  225. padding: 0;
  226. z-index: 1;
  227. overflow: hidden;
  228. overflow-y: auto;
  229. // 下边设置字体,我的需求是黑底白字
  230. color: #ffffff;
  231. line-height: 30px;
  232. padding: 0 15px;
  233. display: flex;
  234. flex-direction: column;
  235. > div {
  236. flex: 1;
  237. .el-card__body {
  238. height: 100%;
  239. display: flex;
  240. flex-direction: column;
  241. box-sizing: border-box;
  242. > div {
  243. flex: 1;
  244. .ele-split-panel-body {
  245. display: flex;
  246. flex-direction: column;
  247. > div {
  248. height: 100%;
  249. display: flex;
  250. flex-direction: column;
  251. .el-table {
  252. flex: 1 0 auto;
  253. height: 0;
  254. overflow: auto;
  255. }
  256. }
  257. }
  258. }
  259. }
  260. }
  261. .rx-sc {
  262. flex: 0 0 50px;
  263. display: flex;
  264. align-items: center;
  265. justify-content: center;
  266. }
  267. }
  268. }
  269. }
  270. ::v-deep {
  271. .el-checkbox__input.is-disabled .el-checkbox__inner {
  272. background-color: #c1c1c1 !important;
  273. }
  274. }
  275. .ml60 {
  276. margin-left: 60px;
  277. }
  278. </style>