MaterialAdd.vue 8.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313
  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="90%"
  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: 'usePerson'
  108. },
  109. {
  110. label: '使用岗位',
  111. prop: 'postName'
  112. },
  113. {
  114. label: '负责人',
  115. prop: 'chargePerson'
  116. },
  117. {
  118. label: '有效开始时间',
  119. prop: 'startTime'
  120. },
  121. {
  122. label: '有效结束时间',
  123. prop: 'endTime'
  124. },
  125. {
  126. label: '型号',
  127. prop: 'modelType',
  128. slot: 'modelType'
  129. },
  130. {
  131. label: '规格',
  132. prop: 'specification',
  133. slot: 'specification'
  134. },
  135. {
  136. label: '设备位置',
  137. prop: 'pathName',
  138. slot: 'pathName'
  139. }
  140. ],
  141. // 表格选中数据
  142. selection: [],
  143. processData: []
  144. };
  145. },
  146. components: {
  147. ProductSearch
  148. },
  149. methods: {
  150. /* 表格数据源 */
  151. async datasource({ page, limit, where }) {
  152. const res = await getAssetList({
  153. ...where,
  154. pageNum: page,
  155. size: limit,
  156. categoryLevelId: this.categoryLevelId,
  157. rootCategoryLevelId: this.rootId
  158. });
  159. console.log('res---------', res);
  160. this.categoryId = res.list[0]?.categoryId;
  161. return res;
  162. },
  163. open(ruleIdList, ruleIdListIndex, isAlone, data) {
  164. console.log(ruleIdList);
  165. console.log(ruleIdListIndex);
  166. let list = [];
  167. if (isAlone) {
  168. list = data;
  169. } else {
  170. list = ruleIdList
  171. .map((item) => {
  172. return item.equipmentList;
  173. })
  174. .flat();
  175. this.ruleIdListIndex = ruleIdListIndex;
  176. }
  177. console.log(list);
  178. if (list.length > 0) {
  179. this.processData = list.map((item) => item.id);
  180. } else {
  181. this.processData = [];
  182. }
  183. this.visible = true;
  184. this.getTreeData();
  185. },
  186. async getTreeData() {
  187. try {
  188. this.treeLoading = true;
  189. const res = await getTreeByGroup({ type: 4 });
  190. console.log('res---treeList----------', res);
  191. this.treeLoading = false;
  192. if (res?.code === '0') {
  193. this.treeList = res.data;
  194. return this.treeList;
  195. }
  196. } catch (error) {
  197. console.log(error);
  198. }
  199. this.treeLoading = false;
  200. },
  201. handleNodeClick(data) {
  202. this.rootId = data.rootCategoryLevelId;
  203. this.categoryLevelId = data.id;
  204. this.$refs.table.reload({ pageNum: 1, where: {} });
  205. },
  206. /* 刷新表格 */
  207. reload(where) {
  208. if (this.rootId && this.categoryLevelId) {
  209. this.$refs.table.reload({ page: 1, where: where });
  210. } else {
  211. this.$message.error('请选择设备');
  212. }
  213. },
  214. handleClose() {
  215. this.visible = false;
  216. this.$refs.table.setSelectedRows([]);
  217. this.selection = [];
  218. },
  219. selected() {
  220. if (!this.selection.length) {
  221. this.$message.error('请至少选择一条数据');
  222. return;
  223. }
  224. const selectList = this.$refs.treeRef.getCheckedNodes();
  225. console.log('selectList-----------', selectList);
  226. this.$emit(
  227. 'chooseEquipment',
  228. this.selection,
  229. this.ruleIdListIndex,
  230. this.categoryId
  231. );
  232. this.handleClose();
  233. }
  234. }
  235. };
  236. </script>
  237. <style lang="scss" scoped>
  238. .productModal_dialog {
  239. overflow: hidden;
  240. ::v-deep .el-dialog {
  241. margin: 50px auto !important;
  242. height: 90%;
  243. overflow: hidden;
  244. .el-dialog__body {
  245. position: absolute;
  246. left: 0;
  247. top: 54px;
  248. bottom: 0;
  249. right: 0;
  250. padding: 0;
  251. z-index: 1;
  252. overflow: hidden;
  253. overflow-y: auto;
  254. // 下边设置字体,我的需求是黑底白字
  255. color: #ffffff;
  256. line-height: 30px;
  257. padding: 0 15px;
  258. display: flex;
  259. flex-direction: column;
  260. > div {
  261. flex: 1;
  262. .el-card__body {
  263. height: 100%;
  264. display: flex;
  265. flex-direction: column;
  266. box-sizing: border-box;
  267. > div {
  268. flex: 1;
  269. .ele-split-panel-body {
  270. display: flex;
  271. flex-direction: column;
  272. > div {
  273. height: 100%;
  274. display: flex;
  275. flex-direction: column;
  276. .el-table {
  277. flex: 1 0 auto;
  278. height: 0;
  279. overflow: auto;
  280. }
  281. }
  282. }
  283. }
  284. }
  285. }
  286. .rx-sc {
  287. flex: 0 0 50px;
  288. display: flex;
  289. align-items: center;
  290. justify-content: center;
  291. }
  292. }
  293. }
  294. }
  295. ::v-deep {
  296. .el-checkbox__input.is-disabled .el-checkbox__inner {
  297. background-color: #c1c1c1 !important;
  298. }
  299. }
  300. .ml60 {
  301. margin-left: 60px;
  302. }
  303. </style>