MaterialAdd.vue 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562
  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
  33. @search="reload"
  34. ref="searchRef"
  35. :factoryName="factoryName"
  36. />
  37. <ele-pro-table
  38. height="400"
  39. ref="table"
  40. :columns="columns"
  41. :datasource="datasource"
  42. :selection.sync="selection"
  43. row-key="id"
  44. :initLoad="false"
  45. cache-key="main-material-add-2511121044"
  46. >
  47. <template v-slot:radio="{ row }">
  48. <el-radio
  49. v-model="currentId"
  50. :label="row.id"
  51. @change="currentInfo = row"
  52. >
  53. <i></i>
  54. </el-radio>
  55. </template>
  56. <template v-slot:modelType="{ row }">
  57. <span>{{ row.category.modelType }}</span>
  58. </template>
  59. <template v-slot:specification="{ row }">
  60. <span>{{ row.category.specification }}</span>
  61. </template>
  62. <template v-slot:pathName="{ row }">
  63. <span>{{
  64. row.position.length > 0 ? row.position[0].pathName : ''
  65. }}</span>
  66. </template>
  67. </ele-pro-table>
  68. </template>
  69. </ele-split-layout>
  70. </el-card>
  71. <div class="rx-sc">
  72. <el-button type="primary" size="small" @click="selected">选择</el-button>
  73. <el-button size="small" @click="handleClose">关闭</el-button>
  74. </div>
  75. </el-dialog>
  76. </template>
  77. <script>
  78. import ProductSearch from './product-search.vue';
  79. import { getAssetList } from '@/api/ruleManagement/plan';
  80. import { getTreeByPid, getTreeByGroup } from '@/api/classifyManage';
  81. import { getMaterialList } from '@/api/material/list';
  82. export default {
  83. components: {
  84. ProductSearch
  85. },
  86. props: {
  87. // 是否支持多选
  88. multiple: {
  89. type: Boolean,
  90. default: true
  91. },
  92. //是否主数据
  93. isMain: {
  94. type: Boolean,
  95. default: false
  96. }
  97. },
  98. data() {
  99. return {
  100. ruleIdListIndex: 0,
  101. visible: false,
  102. title: '选择设备',
  103. categoryLevelId: null,
  104. categoryId: 1,
  105. treeList: [],
  106. treeLoading: false,
  107. defaultProps: {
  108. children: 'children',
  109. label: 'name'
  110. },
  111. type: null,
  112. factoryId: '',
  113. factoryName: '',
  114. // 表格选中数据
  115. selection: [],
  116. processData: [],
  117. checkedKeys: [],
  118. currentId: null,
  119. currentInfo: null
  120. };
  121. },
  122. computed: {
  123. // 表格列配置
  124. columns() {
  125. let list = this.isMain
  126. ? [
  127. {
  128. columnKey: 'index',
  129. type: 'index',
  130. width: 50,
  131. align: 'center',
  132. showOverflowTooltip: true,
  133. label: '序号'
  134. },
  135. {
  136. prop: 'code',
  137. label: '编码',
  138. align: 'center',
  139. showOverflowTooltip: true,
  140. sortable: true,
  141. minWidth: 110
  142. },
  143. {
  144. prop: 'name',
  145. label: '名称',
  146. align: 'center',
  147. showOverflowTooltip: true,
  148. minWidth: 110
  149. },
  150. {
  151. prop: 'categoryLevelPath',
  152. label: '分类',
  153. align: 'center',
  154. showOverflowTooltip: true
  155. },
  156. {
  157. prop: 'brandNum',
  158. align: 'center',
  159. label: '牌号',
  160. showOverflowTooltip: true
  161. },
  162. {
  163. prop: 'modelType',
  164. label: '型号',
  165. align: 'center',
  166. showOverflowTooltip: true
  167. },
  168. {
  169. prop: 'specification',
  170. label: '规格',
  171. align: 'center',
  172. showOverflowTooltip: true
  173. },
  174. {
  175. prop: 'level',
  176. label: '级别',
  177. align: 'center',
  178. showOverflowTooltip: true
  179. },
  180. {
  181. prop: 'bomStatus',
  182. label: 'MBOM状态',
  183. align: 'center',
  184. minWidth: 120,
  185. formatter: (row, column) => {
  186. return row.bomStatus == 1 ? '有' : '无';
  187. },
  188. showOverflowTooltip: true
  189. },
  190. {
  191. prop: 'pBomStatus',
  192. label: 'PBOM状态',
  193. align: 'center',
  194. minWidth: 120,
  195. formatter: (row, column) => {
  196. return row.pbomStatus == 1 ? '有' : '无';
  197. },
  198. showOverflowTooltip: true
  199. },
  200. {
  201. prop: 'aBomStatus',
  202. label: 'ABOM状态',
  203. align: 'center',
  204. minWidth: 120,
  205. formatter: (row, column) => {
  206. return row.abomStatus == 1 ? '有' : '无';
  207. },
  208. showOverflowTooltip: true
  209. },
  210. {
  211. prop: 'isUnpack',
  212. label: '是否允许拆包',
  213. align: 'center',
  214. minWidth: 120,
  215. formatter: (row, column) => {
  216. return row.isUnpack == 1 ? '是' : '否';
  217. },
  218. showOverflowTooltip: true
  219. },
  220. {
  221. prop: 'isComeCheck',
  222. label: '是否采购来料检验',
  223. align: 'center',
  224. minWidth: 120,
  225. formatter: (row, column) => {
  226. return row.isComeCheck == 1 ? '是' : '否';
  227. },
  228. showOverflowTooltip: true
  229. },
  230. {
  231. prop: 'isOutsourcingCheck',
  232. label: '是否委外来料检验',
  233. align: 'center',
  234. minWidth: 120,
  235. formatter: (row, column) => {
  236. return row.isOutsourcingCheck == 1 ? '是' : '否';
  237. },
  238. showOverflowTooltip: true
  239. },
  240. {
  241. prop: 'measuringUnit',
  242. label: '计量单位',
  243. showOverflowTooltip: true,
  244. minWidth: 90
  245. },
  246. {
  247. prop: 'weightUnit',
  248. label: '重量单位',
  249. showOverflowTooltip: true,
  250. minWidth: 90
  251. },
  252. {
  253. prop: 'roughWeight',
  254. label: '毛重',
  255. showOverflowTooltip: true,
  256. minWidth: 90
  257. },
  258. {
  259. prop: 'netWeight',
  260. label: '净重',
  261. showOverflowTooltip: true,
  262. minWidth: 90
  263. },
  264. {
  265. prop: 'packingUnit',
  266. align: 'center',
  267. label: '包装单位',
  268. showOverflowTooltip: true
  269. },
  270. {
  271. prop: 'createTime',
  272. label: '创建时间',
  273. align: 'center',
  274. showOverflowTooltip: true
  275. },
  276. {
  277. prop: 'createUserName',
  278. label: '创建人',
  279. align: 'center',
  280. showOverflowTooltip: true
  281. },
  282. {
  283. prop: 'isEnabled',
  284. align: 'center',
  285. label: '状态',
  286. slot: 'isEnabled',
  287. showOverflowTooltip: true,
  288. fixed: 'right',
  289. formatter: (row, column) => {
  290. return row.isEnabled === 0
  291. ? '停用'
  292. : row.isEnabled === 1
  293. ? '启用'
  294. : '';
  295. }
  296. }
  297. ]
  298. : [
  299. {
  300. label: '设备名称',
  301. prop: 'name'
  302. },
  303. {
  304. label: '编号',
  305. prop: 'codeNumber'
  306. },
  307. {
  308. label: '固资编码',
  309. prop: 'fixCode'
  310. },
  311. {
  312. label: '所属工厂',
  313. prop: 'factoryName'
  314. },
  315. {
  316. label: '使用人',
  317. prop: 'usePerson'
  318. },
  319. {
  320. label: '使用单位',
  321. prop: 'postName'
  322. },
  323. {
  324. label: '负责人',
  325. prop: 'chargePerson'
  326. },
  327. {
  328. label: '有效开始时间',
  329. prop: 'startTime'
  330. },
  331. {
  332. label: '有效结束时间',
  333. prop: 'endTime'
  334. },
  335. {
  336. label: '型号',
  337. prop: 'modelType',
  338. slot: 'modelType'
  339. },
  340. {
  341. label: '规格',
  342. prop: 'specification',
  343. slot: 'specification'
  344. },
  345. {
  346. label: '设备位置',
  347. prop: 'pathName',
  348. slot: 'pathName'
  349. }
  350. ];
  351. if (this.multiple) {
  352. list.unshift({
  353. columnKey: 'selection',
  354. type: 'selection',
  355. width: 45,
  356. align: 'center',
  357. selectable: (row, index) => {
  358. return !this.processData.some((id) => id == row.id);
  359. },
  360. reserveSelection: true,
  361. fixed: 'left'
  362. });
  363. } else {
  364. list.unshift({
  365. slot: 'radio',
  366. width: 50,
  367. align: 'center',
  368. fixed: 'left'
  369. });
  370. }
  371. return list;
  372. }
  373. },
  374. methods: {
  375. /* 表格数据源 */
  376. async datasource({ page, limit, where }) {
  377. let api = this.isMain ? getMaterialList : getAssetList;
  378. const res = await api({
  379. ...where,
  380. pageNum: page,
  381. size: limit,
  382. categoryLevelId: this.categoryLevelId,
  383. rootCategoryLevelId: this.rootId,
  384. factoryId: this.factoryId||''
  385. });
  386. console.log('res---------', res);
  387. this.categoryId = res.list[0]?.categoryId;
  388. return res;
  389. },
  390. open(ruleIdList, ruleIdListIndex, factoryId,factoryName) {
  391. let list = ruleIdList
  392. .map((item) => {
  393. return item.equipmentList;
  394. })
  395. .flat();
  396. if (list.length > 0) {
  397. this.processData = list.map((item) => item.id);
  398. } else {
  399. this.processData = [];
  400. }
  401. this.ruleIdListIndex = ruleIdListIndex;
  402. this.visible = true;
  403. this.factoryId = factoryId;
  404. this.factoryName = factoryName;
  405. this.getTreeData();
  406. },
  407. async getTreeData() {
  408. try {
  409. this.treeLoading = true;
  410. const res = await getTreeByGroup({ type: 4 });
  411. this.treeLoading = false;
  412. if (res?.code === '0') {
  413. this.treeList = res.data;
  414. // 默认选中第一个节点
  415. if (this.treeList.length > 0) {
  416. this.$nextTick(() => {
  417. this.$refs.treeRef.setCurrentKey(this.treeList[0].id);
  418. this.handleNodeClick(this.treeList[0]);
  419. });
  420. }
  421. return this.treeList;
  422. }
  423. } catch (error) {}
  424. this.treeLoading = false;
  425. },
  426. handleNodeClick(data) {
  427. this.rootId = data.rootCategoryLevelId;
  428. this.categoryLevelId = data.id;
  429. this.$refs.table.reload({ pageNum: 1, where: {} });
  430. },
  431. /* 刷新表格 */
  432. reload(where) {
  433. if (this.rootId && this.categoryLevelId) {
  434. this.$refs.table.reload({ page: 1, where: where });
  435. } else {
  436. this.$message.error('请选择设备');
  437. }
  438. },
  439. handleClose() {
  440. this.visible = false;
  441. this.$refs.table.setSelectedRows([]);
  442. this.currentInfo = null;
  443. this.currentId = null;
  444. this.selection = [];
  445. },
  446. selected() {
  447. if (this.multiple) {
  448. if (!this.selection.length) {
  449. this.$message.error('请选择设备');
  450. return;
  451. }
  452. } else {
  453. if (!this.currentInfo) {
  454. this.$message.error('请选择设备');
  455. return;
  456. }
  457. }
  458. const selectList = this.$refs.treeRef.getCheckedNodes();
  459. console.log('selectList-----------', selectList);
  460. this.$emit(
  461. 'chooseEquipment',
  462. this.multiple ? this.selection : this.currentInfo,
  463. this.ruleIdListIndex,
  464. this.categoryId
  465. );
  466. this.handleClose();
  467. }
  468. }
  469. };
  470. </script>
  471. <style lang="scss" scoped>
  472. .productModal_dialog {
  473. overflow: hidden;
  474. ::v-deep .el-dialog {
  475. margin: 50px auto !important;
  476. height: 90%;
  477. overflow: hidden;
  478. .el-dialog__body {
  479. position: absolute;
  480. left: 0;
  481. top: 54px;
  482. bottom: 0;
  483. right: 0;
  484. padding: 0;
  485. z-index: 1;
  486. overflow: hidden;
  487. overflow-y: auto;
  488. // 下边设置字体,我的需求是黑底白字
  489. color: #ffffff;
  490. line-height: 30px;
  491. padding: 0 15px;
  492. display: flex;
  493. flex-direction: column;
  494. > div {
  495. flex: 1;
  496. .el-card__body {
  497. height: 100%;
  498. display: flex;
  499. flex-direction: column;
  500. > div {
  501. flex: 1;
  502. .ele-split-panel-body {
  503. display: flex;
  504. flex-direction: column;
  505. > div {
  506. height: 100%;
  507. display: flex;
  508. flex-direction: column;
  509. .el-table {
  510. flex: 1 0 auto;
  511. height: 0;
  512. overflow: auto;
  513. }
  514. }
  515. }
  516. }
  517. }
  518. }
  519. .rx-sc {
  520. flex: 0 0 50px;
  521. display: flex;
  522. align-items: center;
  523. justify-content: center;
  524. }
  525. }
  526. }
  527. }
  528. ::v-deep {
  529. .el-checkbox__input.is-disabled .el-checkbox__inner {
  530. background-color: #c1c1c1 !important;
  531. }
  532. }
  533. .ml60 {
  534. margin-left: 60px;
  535. }
  536. </style>