MaterialAdd.vue 7.8 KB

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