MaterialAdd.vue 7.8 KB

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