MaterialAdd.vue 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276
  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. style="min-height: 400px"
  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. let list = ruleIdList
  145. .map((item) => {
  146. return item.equipmentList;
  147. })
  148. .flat();
  149. this.processData = list.map((item) => item.id);
  150. this.ruleIdListIndex = ruleIdListIndex;
  151. this.visible = true;
  152. this.getTreeData();
  153. },
  154. async getTreeData() {
  155. try {
  156. this.treeLoading = true;
  157. const res = await getTreeByGroup({ type: 4 });
  158. this.treeLoading = false;
  159. if (res?.code === '0') {
  160. this.treeList = res.data;
  161. return this.treeList;
  162. }
  163. } catch (error) {}
  164. this.treeLoading = false;
  165. },
  166. handleNodeClick(data) {
  167. this.rootId = data.rootCategoryLevelId;
  168. this.categoryLevelId = data.id;
  169. this.$refs.table.reload({ pageNum: 1, where: {} });
  170. },
  171. /* 刷新表格 */
  172. reload(where) {
  173. if (this.rootId && this.categoryLevelId) {
  174. this.$refs.table.reload({ page: 1, where: where });
  175. } else {
  176. this.$message.error('请选择设备');
  177. }
  178. },
  179. handleClose() {
  180. this.visible = false;
  181. this.$refs.table.setSelectedRows([]);
  182. this.selection = [];
  183. },
  184. selected() {
  185. if (!this.selection.length) {
  186. this.$message.error('请至少选择一条数据');
  187. return;
  188. }
  189. const selectList = this.$refs.treeRef.getCheckedNodes();
  190. console.log('selectList-----------', selectList);
  191. this.$emit(
  192. 'chooseEquipment',
  193. this.selection,
  194. this.ruleIdListIndex,
  195. this.categoryId
  196. );
  197. this.handleClose();
  198. }
  199. }
  200. };
  201. </script>
  202. <style lang="scss" scoped>
  203. .productModal_dialog {
  204. overflow: hidden;
  205. ::v-deep .el-dialog {
  206. margin: 50px auto !important;
  207. height: 90%;
  208. overflow: hidden;
  209. .el-dialog__body {
  210. position: absolute;
  211. left: 0;
  212. top: 54px;
  213. bottom: 0;
  214. right: 0;
  215. padding: 0;
  216. z-index: 1;
  217. overflow: hidden;
  218. overflow-y: auto;
  219. // 下边设置字体,我的需求是黑底白字
  220. color: #ffffff;
  221. line-height: 30px;
  222. padding: 0 15px;
  223. display: flex;
  224. flex-direction: column;
  225. > div {
  226. flex: 1;
  227. .el-card__body {
  228. height: 100%;
  229. display: flex;
  230. flex-direction: column;
  231. > div {
  232. flex: 1;
  233. .ele-split-panel-body {
  234. > div {
  235. height: 100%;
  236. display: flex;
  237. flex-direction: column;
  238. .el-table {
  239. flex: 1 0 auto;
  240. height: 0;
  241. overflow: auto;
  242. }
  243. }
  244. }
  245. }
  246. }
  247. }
  248. .rx-sc {
  249. flex: 0 0 50px;
  250. display: flex;
  251. align-items: center;
  252. justify-content: center;
  253. }
  254. }
  255. }
  256. }
  257. ::v-deep {
  258. .el-checkbox__input.is-disabled .el-checkbox__inner {
  259. background-color: #c1c1c1 !important;
  260. }
  261. }
  262. .ml60 {
  263. margin-left: 60px;
  264. }
  265. </style>