AssetsInWarehouse.vue 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520
  1. <template>
  2. <div class="assets-container" v-show="assetsName">
  3. <div class="tree-wrapper">
  4. <div class="title">
  5. {{ assetsName }}
  6. <el-checkbox
  7. :value="assetsSelectAll"
  8. @click.native.prevent="handleAssetsSelectAll"
  9. :disabled="isBindPlan"
  10. ></el-checkbox>
  11. </div>
  12. <div class="scroll-wrapper">
  13. <el-tree
  14. show-checkbox
  15. :data="treeList"
  16. :props="{
  17. children: 'children',
  18. value: 'code',
  19. label: 'name',
  20. }"
  21. :filter-node-method="filterNode"
  22. v-loading="treeLoading"
  23. node-key="id"
  24. ref="treeRef"
  25. :default-expanded-keys="defaultExpandedKeys"
  26. :highlight-current="true"
  27. @node-click="handleNodeClick"
  28. @check="clickCheck"
  29. >
  30. <span class="custom-tree-node" slot-scope="{ node, data }">
  31. <span>{{ node.label }}</span>
  32. </span>
  33. </el-tree>
  34. </div>
  35. </div>
  36. <div :class="isBindPlan ? 'table-wrapper' : 'table-box'">
  37. <el-table
  38. style="width: 100% !important"
  39. height="400px"
  40. ref="tableRef"
  41. :data="tableData"
  42. @selection-change="handleSelectionChange"
  43. @select="handleCurSelectionChange"
  44. :key="assetsName"
  45. :header-cell-style="{
  46. background: '#F0F3F3',
  47. border: 'none',
  48. }"
  49. :disabled="isBindPlan"
  50. >
  51. <el-table-column
  52. v-for="item in tableInfoData"
  53. :key="item.key"
  54. :prop="item.inKey"
  55. :label="item.label"
  56. :width="item.width"
  57. >
  58. </el-table-column>
  59. <el-table-column
  60. type="selection"
  61. :selectable="selectable"
  62. :width="tableData.length ? '55' : '500'"
  63. >
  64. </el-table-column>
  65. </el-table>
  66. </div>
  67. </div>
  68. </template>
  69. <script>
  70. // import classManagement from "@/api/ledgerAssets/classManagement";
  71. // import { tableContentData } from '../../../components/enum'
  72. import { mapGetters } from "vuex";
  73. // import {
  74. // getInventoryListGroup,
  75. // getgoodspage,
  76. // } from "@/api/stockManagement/stocking";
  77. import { tableContentData } from "./tableContentData.js";
  78. export default {
  79. props: {
  80. assetsName: {
  81. type: String,
  82. default: "",
  83. },
  84. warehouseId: {
  85. type: [Number, String],
  86. default: "",
  87. },
  88. tableValuableList: {
  89. type: Array,
  90. default: () => [],
  91. },
  92. assetsType: {
  93. type: [String, Number],
  94. default: "",
  95. },
  96. assetSubType: {
  97. type: [String, Number],
  98. default: "",
  99. },
  100. planRuleInventoryDetailList: {
  101. type: Array,
  102. default: [],
  103. },
  104. isBindPlan: {
  105. type: Boolean,
  106. default: function () {
  107. return false;
  108. },
  109. },
  110. },
  111. computed: {
  112. ...mapGetters(["addOrUpdate"]),
  113. },
  114. watch: {
  115. // warehouseId() {
  116. // if (this.curNode) {
  117. // this.getTableInfo(
  118. // this.curNode.data.id === this.curNode.data.originId
  119. // ? ""
  120. // : this.curNode.data.id
  121. // );
  122. // }
  123. // },
  124. planRuleInventoryDetailList(val) {
  125. console.log('asd',val)
  126. if (val) {
  127. this.$nextTick(() => {
  128. val.forEach((item) => {
  129. if (!this.tableSelectionList[item.bizTypeId]) {
  130. this.tableSelectionList[item.bizTypeId] = [item];
  131. } else {
  132. this.tableSelectionList[item.bizTypeId].push(item);
  133. }
  134. });
  135. this.handleAssetsChange();
  136. });
  137. }
  138. },
  139. },
  140. data() {
  141. return {
  142. treeList: [],
  143. tableInfoData: [],
  144. tableData: [],
  145. requestApi: "",
  146. treeLoading: false,
  147. tableSelectionList: {},
  148. assetsSelectionList: [],
  149. assetsSelectAll: false,
  150. curNode: null,
  151. defaultExpandedKeys: [],
  152. changeData: [],
  153. isChecked: false,
  154. };
  155. },
  156. mounted() {
  157. this.$nextTick(() => {
  158. this.handleAssetsChange();
  159. });
  160. },
  161. created() {
  162. // console.log('库内')
  163. // if(this.planRuleInventoryDetailList){
  164. // console.log('this.planRuleInventoryDetailList',this.planRuleInventoryDetailList)
  165. // this.tableData = this.planRuleInventoryDetailList
  166. // }
  167. },
  168. methods: {
  169. //表格复选框禁用
  170. selectable(row, rowIndex) {
  171. if (this.isBindPlan) {
  172. return false;
  173. } else {
  174. return true;
  175. }
  176. },
  177. // 重置
  178. resetData() {
  179. this.clearSelection();
  180. this.treeList = [];
  181. },
  182. //清除选中
  183. clearSelection() {
  184. this.assetsSelectAll = false;
  185. this.tableData = [];
  186. this.tableSelectionList = {};
  187. },
  188. //派单过滤
  189. filterNode(value, data, node) {
  190. return (
  191. this.tableValuableList.findIndex(
  192. (item) => item.bizTypeId === data.id
  193. ) !== -1
  194. );
  195. },
  196. getSelectList() {
  197. const classificationList =
  198. (this.$refs.treeRef && this.$refs.treeRef.getCheckedNodes()) || [];
  199. const list = Object.values(this.tableSelectionList) || [];
  200. var arr = [];
  201. list.map((item, index) => {
  202. for (var i = 0; i < item.length; i++) {
  203. arr.push(item[i]);
  204. }
  205. });
  206. const tableSelectionList = arr;
  207. return {
  208. classificationList,
  209. tableSelectionList,
  210. // tableSelectionList: Object.values(this.tableSelectionList)
  211. // .flat()
  212. // .filter(
  213. // // i => !classificationList.find(itm => i.classificationId == itm.id)
  214. // i => !classificationList.find(itm => i.bizTypeId == itm.id)
  215. // )
  216. // .map(item => {
  217. // item.minPackUnit = item.minPackUtil
  218. // return item
  219. // })
  220. };
  221. },
  222. handleAssetsChange() {
  223. setTimeout(() => {
  224. if (this.assetsName) {
  225. let obj = tableContentData.find(
  226. (item) => item.name === this.assetsName
  227. );
  228. this.tableInfoData = (obj && obj.tableData) || [];
  229. this._getTreeList();
  230. // this.clearSelection()
  231. }
  232. }, 0);
  233. },
  234. // 设备、舟皿、周转车、模具
  235. async _getTreeList() {
  236. let res = await classManagement.getClassificationTreeAsyncCall({
  237. id: "0",
  238. type: this.assetsType,
  239. });
  240. if (res?.success) {
  241. this.treeList = res.data[0]?.children || [];
  242. if (this.isBindPlan) {
  243. this.deepEach(this.treeList);
  244. }
  245. if (this.tableValuableList?.length) {
  246. this.$nextTick(() => {
  247. this.$refs.treeRef.filter();
  248. });
  249. }
  250. if (this.addOrUpdate === "edit") {
  251. let keys = [];
  252. this.planRuleInventoryDetailList.map((item) => {
  253. if (item.bizTypeId !== null) {
  254. keys.push(item.bizTypeId);
  255. }
  256. });
  257. keys = [...new Set(keys)];
  258. this.defaultExpandedKeys = keys;
  259. if (keys.length) {
  260. this.$nextTick(() => {
  261. this.$refs.treeRef.setCurrentKey(keys[0]);
  262. this.convertTreeData();
  263. let chooseData = null;
  264. this.changeData.map((item) => {
  265. if (item.id == keys[0]) {
  266. chooseData = item;
  267. }
  268. });
  269. if (chooseData) {
  270. this.getTableInfo(chooseData.id);
  271. }
  272. // this.handleNodeClick(chooseData,node)
  273. });
  274. }
  275. }
  276. }
  277. },
  278. handleNodeClick(data, node) {
  279. console.log(node, "node");
  280. if (!node.isLeaf) return; //限制叶子节点
  281. this.curNode = node;
  282. // this.getTableInfo(data.id === data.originId ? '' : data.id)
  283. this.getTableInfo({
  284. assetType: data.type,
  285. classificationIds: [data.id],
  286. });
  287. },
  288. setclassIds(data, list) {
  289. if (data && data.length !== 0) {
  290. data.forEach((item) => {
  291. if (item.children && item.children.length !== 0) {
  292. this.setclassIds(item.children, list);
  293. }
  294. list.push(item.id);
  295. });
  296. }
  297. return list;
  298. },
  299. async getTableInfo(assetSubType) {
  300. const params = {
  301. page: 1,
  302. size: 9999,
  303. ...assetSubType,
  304. };
  305. if (assetSubType) {
  306. params.assetSubType = assetSubType;
  307. }
  308. const res = await getgoodspage(params);
  309. if (res?.success) {
  310. if (this.tableValuableList && this.tableValuableList.length) {
  311. // 派单过滤
  312. this.tableData = res.data.records
  313. .filter(
  314. (item) =>
  315. this.tableValuableList.findIndex(
  316. (i) => i.assetId == item.id
  317. ) !== -1
  318. )
  319. .map((i, index) => ({
  320. ...i,
  321. index,
  322. classificationId: assetSubType,
  323. }));
  324. } else {
  325. this.tableData = res.data.records.map((i, index) => ({
  326. ...i,
  327. index,
  328. classificationId: assetSubType,
  329. }));
  330. }
  331. const checkedTrees = this.$refs.treeRef.getCheckedKeys();
  332. // if(this.addOrUpdate === 'edit'){
  333. // this.defaultExpandedKeys
  334. // }
  335. this.$nextTick(() => {
  336. //分类选中
  337. this.tableData.map((item) => {
  338. if (checkedTrees.includes(item.classificationId + "")) {
  339. this.$refs.tableRef.toggleRowSelection(item);
  340. }
  341. });
  342. // 表格选中(切换保存状态
  343. for (const key in this.tableSelectionList) {
  344. this.tableSelectionList[key].forEach((item) => {
  345. const row = this.tableData.find((i) => i.id === item.id);
  346. if (row) {
  347. //this.$refs.tableRef.toggleRowSelection(row, true)
  348. }
  349. });
  350. }
  351. });
  352. if (this.addOrUpdate === "edit") {
  353. if (this.planRuleInventoryDetailList) {
  354. this.tableData.map((item) => {
  355. for (
  356. var i = 0;
  357. i < this.planRuleInventoryDetailList.length;
  358. i++
  359. ) {
  360. if (
  361. item.id == this.planRuleInventoryDetailList[i].id
  362. ) {
  363. this.$nextTick(() => {
  364. this.$refs.tableRef.toggleRowSelection(item, true);
  365. });
  366. }
  367. }
  368. });
  369. }
  370. }
  371. }
  372. },
  373. // tree选中状态改变
  374. clickCheck(data, checkinfo) {
  375. const isChecked = checkinfo.checkedKeys.indexOf(data.id) > -1;
  376. if (!isChecked) {
  377. //取消全选
  378. this.assetsSelectAll = false;
  379. }
  380. if (this.curNode && this.curNode.data.id === data.id) {
  381. this.tableData.forEach((row) => {
  382. this.$refs.tableRef.toggleRowSelection(row, isChecked);
  383. });
  384. }
  385. },
  386. // 资产分类全选 通过点击事件更改状态
  387. handleAssetsSelectAll() {
  388. if (this.isBindPlan) return;
  389. this.assetsSelectAll = !this.assetsSelectAll;
  390. if (this.assetsSelectAll) {
  391. const keys = this.treeList.map((item) => item.id);
  392. this.$refs.treeRef.setCheckedKeys(keys);
  393. } else {
  394. this.$refs.treeRef.setCheckedKeys([]);
  395. }
  396. },
  397. handleSelectionChange(val) {
  398. console.log(val);
  399. let bizType = {};
  400. if (this.curNode) {
  401. bizType = {
  402. bizTypeId: this.curNode.data?.id,
  403. bizTypeName: this.curNode.data?.name,
  404. };
  405. this.$set(
  406. this.tableSelectionList,
  407. this.curNode.data.id,
  408. val.map((i) => ({
  409. ...i,
  410. ...bizType,
  411. }))
  412. );
  413. }
  414. if (val.length > 0 && val.length === this.tableData.length) {
  415. //全选
  416. this.$refs.treeRef.setChecked(val[0].classificationId, true);
  417. }
  418. if (val.length === 0 && this.tableData.length > 0) {
  419. //全不选
  420. this.$refs.treeRef.setChecked(
  421. this.tableData[0].classificationId,
  422. false
  423. );
  424. }
  425. },
  426. handleCurSelectionChange(selection, row) {
  427. if (selection.findIndex((item) => item.index === row.index) === -1) {
  428. //取消选中
  429. this.$refs.treeRef.setChecked(row.classificationId, false);
  430. for (const key in this.tableSelectionList) {
  431. const idx = this.tableSelectionList[key].findIndex(
  432. (item) => item.id === row.id
  433. );
  434. if (idx !== -1) {
  435. this.tableSelectionList[key].splice(idx, 1);
  436. }
  437. }
  438. }
  439. },
  440. convertTreeData() {
  441. this.changeData = this.treeList;
  442. for (let i = 0; i < this.changeData.length; i++) {
  443. if (this.changeData[i].children != undefined) {
  444. const temp = this.changeData[i].children;
  445. delete this.changeData[i].children;
  446. this.changeData = this.changeData.concat(temp);
  447. }
  448. }
  449. },
  450. // 子节点处理
  451. deepEach(arr) {
  452. arr.forEach((item) => {
  453. item.disabled = true;
  454. if (item.children) {
  455. this.deepEach(item.children); // 递归
  456. }
  457. });
  458. },
  459. },
  460. };
  461. </script>
  462. <style scoped lang="scss">
  463. ::v-deep .table-wrapper .el-table__header-wrapper .el-checkbox {
  464. display: none;
  465. }
  466. ::v-deep.assets-container {
  467. display: flex;
  468. width: 100%;
  469. .el-tree-node__content > .el-checkbox {
  470. position: absolute;
  471. right: 0;
  472. }
  473. .tree-wrapper {
  474. // width: 350px;
  475. width: 30%;
  476. margin-right: 12px;
  477. border: 1px solid #ccc;
  478. .title {
  479. text-align: center;
  480. font-size: 16px;
  481. font-weight: bold;
  482. background: #f0f3f3;
  483. padding: 4px;
  484. padding-right: 8px;
  485. .el-checkbox {
  486. float: right;
  487. }
  488. }
  489. .scroll-wrapper {
  490. padding-top: 8px;
  491. }
  492. }
  493. .table-wrapper {
  494. width: 70%;
  495. padding: 8px;
  496. border: 1px solid #ccc;
  497. }
  498. .table-box {
  499. width: 70%;
  500. padding: 8px;
  501. border: 1px solid #ccc;
  502. }
  503. }
  504. </style>