detailedList.vue 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732
  1. <template>
  2. <div class="ele-body">
  3. <BOMSearch @search="reload" :statusOpt="statusOpt" />
  4. <ele-pro-table ref="table" :key="tableKey" :columns="columns" :datasource="datasource" class="dict-table"
  5. tool-class="ele-toolbar-actions">
  6. <template v-slot:toolbar>
  7. <div class="toolbar_box">
  8. <div v-if="attributeData.status != 1">
  9. <el-button type="primary" size="mini" @click="handleAdd">新增</el-button>
  10. <el-button type="primary" size="mini" @click="handleSave">保存</el-button>
  11. </div>
  12. <div class="toolbar_box_right"><span>基本数量</span>
  13. <el-input placeholder="请输入" v-model.number="attributeData.baseCount">
  14. <template #append>
  15. {{
  16. attributeData.category && attributeData.category.measuringUnit
  17. }}</template>
  18. </el-input>
  19. </div>
  20. </div>
  21. </template>
  22. <!-- 用量 -->
  23. <template v-slot:dosage="{ row }">
  24. <el-input v-model="row.dosage" placeholder="请输入" size="mini" style="width: 68px">
  25. </el-input>
  26. </template>
  27. <template v-slot:versions="{ row }"> V{{ row.versions }}.0 </template>
  28. <template v-slot:produceType="{ row }">
  29. <el-select v-model="row.produceType" filterable multiple disabled class="ele-block" size="mini">
  30. <el-option v-for="item in dictList" :key="item.value" :value="item.value" :label="item.label"></el-option>
  31. </el-select>
  32. </template>
  33. <template v-slot:attributeType="{ row }">
  34. <el-select v-model="row.attributeType" filterable disabled class="ele-block" size="mini">
  35. <el-option v-for="item in attributeList" :key="item.value" :value="item.value"
  36. :label="item.label"></el-option>
  37. </el-select>
  38. </template>
  39. <template v-slot:resourceBomVersion="{ row }">
  40. <div v-if="!row.id">
  41. <el-select v-model="row.resourceBomVersion" disabled class="ele-block" size="mini"
  42. @change="resourceBomVersionFn($event, row)">
  43. <el-option v-for="item in row.resourceBomVersionList" :key="item.versions" :value="item.versions"
  44. :label="'V' + item.versions + '.0'"></el-option>
  45. </el-select>
  46. </div>
  47. <div v-else v-if="row.resourceBomVersion">
  48. {{ 'V' + row.resourceBomVersion + '.0' }}
  49. </div>
  50. </template>
  51. <template v-slot:materielDesignation="{ row }">
  52. <el-input v-model="row.materielDesignation" placeholder="请输入物料代号" size="mini" style="width: 120px">
  53. </el-input>
  54. </template>
  55. <template v-slot:supplierId="{ row }">
  56. <el-select v-model="row.supplierId" size="mini" clearable class="ele-block" filterable placeholder="请选择供应商">
  57. <el-option v-for="(item, index) in gysList" :key="item.id + index" :value="item.id"
  58. :label="item.name"></el-option>
  59. </el-select>
  60. </template>
  61. <template v-slot:factories="{ row }">
  62. <div style="display: flex;">
  63. <el-input v-model="row.factories" disabled :value="row.factories" placeholder="请选择生产厂家" size="mini" style="width: 120px">
  64. </el-input>
  65. <!-- -->
  66. <el-button type="primary" @click="factoriesFn(row.code)">选择</el-button>
  67. <!-- <el-select v-model="row.factories" size="mini" clearable class="ele-block" filterable placeholder="请选择生产厂家">
  68. <el-option v-for="(item, index) in sccjList" :key="item.id + index" :value="item.id"
  69. :label="item.name"></el-option>
  70. </el-select> -->
  71. </div>
  72. <!-- <el-input v-model="row.factories" placeholder="请输入生产厂家" size="mini" style="width: 120px">
  73. </el-input> -->
  74. </template>
  75. <!-- 表头工具栏 -->
  76. <template v-slot:action="{ row }">
  77. <el-link v-if="attributeData.status != 1" type="danger" :underline="false" icon="el-icon-delete"
  78. @click="handleDel(row)">
  79. 删除
  80. </el-link>
  81. </template>
  82. </ele-pro-table>
  83. <bomTreeDialog ref="bomTreeDialogRef" @reload="bomClose" />
  84. <standardOutput ref="standardOutputRefs" @selection="chooseStandardList"></standardOutput>
  85. <clientDialog ref="clientSelectionRef" @success="confirmSelection"></clientDialog>
  86. </div>
  87. </template>
  88. <script>
  89. import BOMSearch from './BOM-search.vue';
  90. import {
  91. getBomPageCategoryId,
  92. contactList,
  93. deleteBomTreeList,
  94. updateBatchBOM,
  95. sourceBomVersion
  96. } from '@/api/material/BOM';
  97. import clientDialog from "./clientDialog.vue"
  98. import { getByCode } from '@/api/system/dictionary-data';
  99. import bomTreeDialog from './bomTreeDialog.vue';
  100. import standardOutput from './standardOutput.vue';
  101. export default {
  102. name: 'SystemDictionary',
  103. components: { BOMSearch, bomTreeDialog, standardOutput, clientDialog },
  104. data() {
  105. return {
  106. // 表格列配置
  107. columns: [
  108. {
  109. label: '序号',
  110. columnKey: 'index',
  111. type: 'index',
  112. width: 55,
  113. align: 'center',
  114. showOverflowTooltip: true
  115. },
  116. {
  117. prop: 'code',
  118. label: '编码',
  119. showOverflowTooltip: true,
  120. width: 120
  121. },
  122. {
  123. prop: 'name',
  124. label: '名称',
  125. width: 150
  126. },
  127. {
  128. prop: 'level',
  129. label: '层级'
  130. },
  131. {
  132. prop: 'brandNum',
  133. label: '牌号'
  134. },
  135. {
  136. prop: 'modelType',
  137. label: '型号',
  138. align: 'center',
  139. showOverflowTooltip: true
  140. },
  141. {
  142. prop: 'specification',
  143. label: '规格',
  144. align: 'center',
  145. showOverflowTooltip: true
  146. },
  147. {
  148. prop: 'dosage',
  149. slot: 'dosage',
  150. label: '用量',
  151. width: 100
  152. },
  153. {
  154. prop: 'measuringUnit',
  155. label: '计量单位',
  156. showOverflowTooltip: true
  157. },
  158. {
  159. prop: 'produceType',
  160. slot: 'produceType',
  161. label: '生产类型',
  162. width: 260
  163. },
  164. {
  165. prop: 'attributeType',
  166. slot: 'attributeType',
  167. label: '属性类型',
  168. width: 260
  169. },
  170. {
  171. prop: 'materielDesignation',
  172. slot: 'materielDesignation',
  173. label: '物料代号',
  174. width: 150
  175. },
  176. {
  177. prop: 'supplierId',
  178. slot: 'supplierId',
  179. label: '供应商',
  180. width: 150
  181. },
  182. {
  183. prop: 'factories',
  184. slot: 'factories',
  185. label: '生产厂家',
  186. width: 180
  187. },
  188. {
  189. prop: 'resourceBomVersion',
  190. slot: 'resourceBomVersion',
  191. label: '来源版本',
  192. width: 180
  193. },
  194. {
  195. prop: 'versions',
  196. slot: 'versions',
  197. label: '版本'
  198. },
  199. {
  200. prop: 'status ',
  201. label: '状态',
  202. formatter: (row) => {
  203. return this.statusOpt[+row.status];
  204. }
  205. },
  206. {
  207. prop: 'createName',
  208. label: '创建人',
  209. showOverflowTooltip: true
  210. },
  211. {
  212. prop: 'createTime',
  213. label: '创建日期',
  214. width: 160
  215. },
  216. {
  217. action: 'action',
  218. slot: 'action',
  219. fixed: 'right',
  220. label: '操作',
  221. width: 120
  222. }
  223. ],
  224. statusOpt: {
  225. '': '全部',
  226. 0: '草稿',
  227. 1: '已发布'
  228. },
  229. attributeList: [
  230. {
  231. label: '总装',
  232. value: 1
  233. },
  234. {
  235. label: '部件',
  236. value: 2
  237. },
  238. {
  239. label: '零件',
  240. value: 3
  241. },
  242. {
  243. label: '原材料',
  244. value: 4
  245. }
  246. ],
  247. isList:false,
  248. isId: null,
  249. tableKey:"",
  250. list: [],//表格数据
  251. listTow:[],
  252. newList: [],
  253. gysList: [],
  254. sccjList: [],
  255. newTreeId: null,
  256. responsesList: [],
  257. dictList: []
  258. };
  259. },
  260. created() {
  261. this.getDictList('productionType');
  262. this.getContactList();
  263. },
  264. mounted() { },
  265. props: {
  266. attributeData: {
  267. type: Object,
  268. default: {}
  269. },
  270. treeId: {
  271. type: String,
  272. default: ''
  273. },
  274. isTemp: {
  275. type: Number,
  276. default: 0
  277. }
  278. },
  279. watch: {
  280. treeId: {
  281. handler(val) {
  282. this.newTreeId = val;
  283. },
  284. deep: true,
  285. immediate: true
  286. },
  287. attributeData: {
  288. handler(val) {
  289. this.$nextTick(() => {
  290. this.reload();
  291. });
  292. },
  293. deep: true,
  294. immediate: true
  295. },
  296. data: {
  297. handler(val) {
  298. console.log(val);
  299. this.$nextTick(() => {
  300. this.reload();
  301. });
  302. },
  303. deep: true,
  304. immediate: true
  305. },
  306. },
  307. // computed: {
  308. // processedItems() {
  309. // return this.list.map(item => {
  310. // // 处理逻辑
  311. // console.log(item);
  312. // // return processedItem;
  313. // });
  314. // }
  315. // },
  316. methods: {
  317. factoriesFn(code) {
  318. this.isId = code;
  319. this.$refs.clientSelectionRef.open();
  320. },
  321. // 选择工厂
  322. confirmSelection(obj) {
  323. let list = this.$refs.table.getData();
  324. list.map(v => {
  325. if (v.code == this.isId) {
  326. v.factories = obj.name;
  327. }
  328. });
  329. console.log(list,'list');
  330. // arr.factories = obj.name;
  331. this.$nextTick(() => {
  332. this.list = [...list];
  333. this.listTow = JSON.parse(JSON.stringify(this.list));
  334. console.log(this.listTow,'listTowlistTowlistTowlistTow');
  335. this.$refs.table.setData(this.list)
  336. this.updateFn()
  337. this.tableKey = Date.now();
  338. });
  339. this.$forceUpdate();
  340. },
  341. updateFn(list){
  342. this.isList = true;
  343. this.reload();
  344. setTimeout(() => {
  345. this.isList = false;
  346. }, 1000);
  347. },
  348. /* 表格数据源 */
  349. datasource({ where, page, limit }) {
  350. // let that = this;
  351. // console.log(getBomPageCategoryId({
  352. // ...where,
  353. // pageNum: page,
  354. // size: limit,
  355. // id: this.attributeData.id,
  356. // bomType: this.attributeData.bomType
  357. // }));
  358. // return new Promise((resolve, reject) => {
  359. // getBomPageCategoryId({
  360. // ...where,
  361. // pageNum: page,
  362. // size: limit,
  363. // id: that.attributeData.id,
  364. // bomType: that.attributeData.bomType
  365. // }).then((res) => {
  366. // console.log(res, '111111111111');
  367. // if(res.list && res.list.length ){
  368. // const arrays = []
  369. // res.list.map((item) => {
  370. // arrays.push(item.categoryId);
  371. // });
  372. // that.getResourceBomVersionListFn(arrays).then(v => {
  373. // v.map(element => {
  374. // res.list.map((item2, i) => {
  375. // if (element.categoryId == item2.id) {
  376. // item2.resourceBomVersionList.push(element);
  377. // }
  378. // item2.resourceBomVersion = item2.resourceBomVersionList[0].versions;
  379. // item2.resourceBomId = item2.resourceBomVersionList[0].resourceBomId;
  380. // // item2.id ="";
  381. // })
  382. // })
  383. // this.$nextTick(() => {
  384. // resolve(res);
  385. // })
  386. // })
  387. // }
  388. // })
  389. // .catch((err) => {
  390. // reject(err);
  391. // });
  392. // });
  393. let data = getBomPageCategoryId({
  394. ...where,
  395. pageNum: page,
  396. size: limit,
  397. id: this.attributeData.id,
  398. bomType: this.attributeData.bomType
  399. });
  400. if(this.isList){
  401. data= this.listTow;
  402. }
  403. return data;
  404. },
  405. /* 刷新表格 */
  406. reload(where) {
  407. this.$refs.table.reload({ where });
  408. },
  409. async getDictList(code) {
  410. let { data: res } = await getByCode(code);
  411. this.dictList = res.map((item) => {
  412. let values = Object.keys(item);
  413. return {
  414. value: Number(values[0]),
  415. label: item[values[0]]
  416. };
  417. });
  418. },
  419. getContactList() {
  420. let param = {
  421. pageNum: 1,
  422. type: 2,
  423. size: -1,
  424. status: 1
  425. };
  426. contactList(param).then((res) => {
  427. this.gysList = res.list;
  428. });
  429. },
  430. handleAdd() {
  431. // // 打开树形对话框
  432. // this.$refs.bomTreeDialogRef.open(
  433. // this.attributeData.bomType,
  434. // this.attributeData.versions,
  435. // this.attributeData.categoryId,
  436. // this.newTreeId,
  437. // this.isTemp
  438. // );
  439. let _list = this.$refs.table.getData() ?? [];
  440. this.$refs.standardOutputRefs.open(_list);
  441. },
  442. // 勾选
  443. async chooseStandardList(data) {
  444. const that = this;
  445. const arrays = []
  446. console.log(data, '99999999');
  447. data.map((m) => {
  448. m.parentId = this.newTreeId;
  449. m.createTime = '';
  450. m.bomType = this.attributeData.bomType;
  451. m.level = Number(this.attributeData.level) + 1;
  452. m.versions = this.attributeData.versions;
  453. m.categoryId = m.id;
  454. m.rootCategoryLevelId = m.categoryLevelPathIdParent;
  455. m.resourceBomVersionList = [];
  456. arrays.push(m.id)
  457. // Promise.all(arrays).then(responses => {
  458. // // 默认选择第一个
  459. // console.log(responses,responses[0].length,66666666);
  460. // if(responses[0].length){
  461. // m.resourceBomVersionList=responses[0];
  462. // m.resourceBomVersion = responses[0][0].versions;
  463. // m.resourceBomId = responses[0][0].resourceBomId;
  464. // }else{
  465. // m.resourceBomVersionList=[];
  466. // m.resourceBomVersion = '';
  467. // m.resourceBomId = '';
  468. // }
  469. // this.responsesList = responses;
  470. // })
  471. // m.id = '';
  472. });
  473. console.log(data);
  474. this.getResourceBomVersionListFn(arrays).then(v => {
  475. if (v.length) {
  476. v.map(element => {
  477. data.map((item2, i) => {
  478. if (element.categoryId == item2.id) {
  479. item2.resourceBomVersionList.push(element);
  480. }
  481. item2.resourceBomVersion = item2.resourceBomVersionList[0].versions;
  482. item2.resourceBomId = item2.resourceBomVersionList[0].resourceBomId;
  483. setTimeout(() => {
  484. item2.id = "";
  485. }, 100);
  486. })
  487. })
  488. }
  489. this.$nextTick(() => {
  490. data.map(v => {
  491. v.id = "";
  492. })
  493. this.list = [...data, ...this.$refs.table.getData()];
  494. this.$refs.table.setData(this.list)
  495. })
  496. })
  497. // this.$nextTick(() => {
  498. // this.list = [...data, ...this.$refs.table.getData()];
  499. // console.log(this.list,'9999999999');
  500. // // this.$refs.table.setData(this.list);
  501. // console.log(this.$refs.table._data,'this.$refs.table');
  502. // // this.$refs.table._data.tableData = [];
  503. // //
  504. // // this.$set(this.$refs.table._data,"tableData",this.list);
  505. // // this.bomClose();
  506. // });
  507. },
  508. resourceBomVersionFn(e, row) {
  509. let arr = row.resourceBomVersionList.find(item => item.versions == e);
  510. console.log(arr, 'eeeeeeeeee');
  511. this.$forceUpdate();
  512. row.resourceBomVersion = arr.versions;
  513. row.resourceBomId = arr.resourceBomId;
  514. console.log(row);
  515. },
  516. async getResourceBomVersionListFn(id) {
  517. return new Promise((resolve, reject) => {
  518. sourceBomVersion({
  519. bomType: this.attributeData.bomType,
  520. categoryIds: id
  521. }).then((res) => {
  522. resolve(res.data);
  523. });
  524. });
  525. },
  526. bomClose() {
  527. this.$nextTick(() => {
  528. this.$refs.table.reload({
  529. pageNum: 1
  530. });
  531. });
  532. },
  533. handleDel(row) {
  534. this.$confirm('是否确认删除?', '提示', {
  535. confirmButtonText: '确定',
  536. cancelButtonText: '取消',
  537. type: 'warning'
  538. })
  539. .then(() => {
  540. if (row.id) {
  541. deleteBomTreeList([row.id]).then((msg) => {
  542. this.$message.success('删除' + msg);
  543. this.$refs.table.reload({
  544. pageNum: 1
  545. });
  546. });
  547. } else {
  548. let _list = this.$refs.table.getData() ?? [];
  549. _list = _list.filter((item) => item.id !== row.id);
  550. this.$refs.table.setData(_list);
  551. }
  552. })
  553. .finally(() => { });
  554. },
  555. handleSave() {
  556. let _list = this.$refs.table.getData() ?? [];
  557. if (_list.length == 0) {
  558. return this.$message.info('明细表最少有一条数据');
  559. }
  560. let list = JSON.parse(JSON.stringify(_list));
  561. console.log(list, 'list');
  562. const arr = list.every(v => {
  563. return v.dosage && v.quantity !== ''
  564. })
  565. if (!arr) {
  566. return this.$message.info('用量不能为空')
  567. }
  568. updateBatchBOM(list).then((res) => {
  569. if (res) {
  570. this.$message.success('保存成功');
  571. this.reload();
  572. // this.$refs.table.reload({
  573. // pageNum: 1
  574. // });
  575. }
  576. });
  577. }
  578. }
  579. };
  580. </script>
  581. <style lang="scss" scoped>
  582. .ele-body {
  583. height: 100%;
  584. ::v-deep .el-card {
  585. height: 100%;
  586. .el-card__body {
  587. height: 100%;
  588. display: flex;
  589. flex-direction: column;
  590. .dict-table {
  591. flex: 1;
  592. overflow: hidden;
  593. display: flex;
  594. flex-direction: column;
  595. .el-table {
  596. flex: 1;
  597. overflow-y: auto;
  598. }
  599. }
  600. }
  601. }
  602. }
  603. .toolbar_box {
  604. display: flex;
  605. justify-content: space-between;
  606. align-items: center;
  607. .toolbar_box_right {
  608. display: flex;
  609. align-items: center;
  610. justify-content: center;
  611. margin-right: 10px;
  612. >span {
  613. width: 150px;
  614. }
  615. >div {
  616. margin-left: 10px;
  617. }
  618. }
  619. }
  620. </style>