selectStockLedgerDialog.vue 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560
  1. <template>
  2. <el-dialog
  3. title="库存台账"
  4. :visible.sync="visible"
  5. :before-close="handleClose"
  6. :close-on-click-modal="false"
  7. top="5vh"
  8. :close-on-press-escape="false"
  9. append-to-body
  10. width="70%"
  11. :maxable="true"
  12. :resizable="true"
  13. >
  14. <el-card shadow="never">
  15. <item-search @search="reload" ref="refSeavch"></item-search>
  16. <ele-split-layout
  17. width="244px"
  18. allow-collapse
  19. :right-style="{ overflow: 'hidden' }"
  20. >
  21. <div class="ele-border-lighter split-layout-right-content">
  22. <el-tree
  23. :data="treeList"
  24. :props="defaultProps"
  25. ref="treeRef"
  26. :default-expanded-keys="
  27. curNodeData && curNodeData.id ? [curNodeData.id] : []
  28. "
  29. :highlight-current="true"
  30. node-key="id"
  31. :expand-on-click-node="false"
  32. @node-click="handleNodeClick"
  33. ><span class="custom-tree-node" slot-scope="{ node, data }">
  34. <span
  35. >{{ data.factoryName ? data.factoryName + '-' : ''
  36. }}{{ data.name }}</span
  37. >
  38. </span></el-tree
  39. >
  40. </div>
  41. <!-- 表格 -->
  42. <template v-slot:content>
  43. <ele-pro-table
  44. ref="table"
  45. :columns="columns"
  46. :datasource="datasource"
  47. row-key="id"
  48. height="calc(100vh - 480px)"
  49. class="dict-table"
  50. @cell-click="cellClick"
  51. :selection.sync="selection"
  52. :cache-key="cacheKeyUrl"
  53. @columns-change="handleColumnChange"
  54. >
  55. <template v-slot:saleCount="{ row }">
  56. <el-input
  57. v-model="row.saleCount"
  58. style="width: 100%"
  59. placeholder="请输入"
  60. type="number"
  61. :min="0"
  62. @input="handleSaleCountInput(row)"
  63. ></el-input>
  64. </template>
  65. <template v-slot:action="{ row }">
  66. <el-radio class="radio" v-model="radio" :label="row.id"
  67. ><i></i
  68. ></el-radio>
  69. </template>
  70. </ele-pro-table>
  71. </template>
  72. </ele-split-layout>
  73. </el-card>
  74. <div slot="footer">
  75. <el-button type="primary" size="small" @click="selected">选择</el-button>
  76. <el-button size="small" @click="handleClose">关闭</el-button>
  77. </div>
  78. </el-dialog>
  79. </template>
  80. <script>
  81. import {
  82. getOutindetailtwoList,
  83. getTreeByGroup,
  84. getBatchList,
  85. getCategoryPackageDisposition
  86. } from '@/api/wms';
  87. import ItemSearch from './item-search.vue';
  88. import { contactQueryByCategoryIdsAPI } from '@/api/saleManage/contact';
  89. import tabMixins from '@/mixins/tableColumnsMixin';
  90. export default {
  91. mixins: [tabMixins],
  92. components: { ItemSearch },
  93. props: {
  94. /*已选择的产品*/
  95. data: {
  96. type: Array,
  97. default: () => []
  98. },
  99. /*是否需要供应商*/
  100. isSupplier: {
  101. type: Boolean,
  102. default: false
  103. },
  104. /*是否显示销售数量*/
  105. showSaleCount: {
  106. type: Boolean,
  107. default: false
  108. },
  109. cacheKeyUrl: {
  110. type: String,
  111. default: 'eom-sales-selectStockLedgerDialog-202605131603'
  112. }
  113. },
  114. data() {
  115. return {
  116. visible: false,
  117. currentIndex: null,
  118. radio: null,
  119. dictList: {},
  120. curNodeData: {},
  121. selection: [],
  122. treeData: [],
  123. dimension:'2',
  124. defaultProps: {
  125. children: 'children',
  126. label: 'name'
  127. },
  128. treeList: [],
  129. treeLoading: false,
  130. // cacheKeyUrl: '',
  131. columnsVersion: 1
  132. };
  133. },
  134. watch: {},
  135. computed: {
  136. columns() {
  137. const version = this.columnsVersion;
  138. let data = null;
  139. if (this.currentIndex != -1) {
  140. data = {
  141. action: 'action',
  142. slot: 'action',
  143. align: 'center',
  144. label: '选择',
  145. reserveSelection: true
  146. };
  147. }
  148. if (this.currentIndex == -1) {
  149. data = {
  150. label: '选择',
  151. width: 45,
  152. type: 'selection',
  153. columnKey: 'selection',
  154. align: 'center',
  155. reserveSelection: true,
  156. selectable: (row) => {
  157. return row.measureQuantity != 0;
  158. }
  159. };
  160. }
  161. const tempData = [
  162. data,
  163. {
  164. columnKey: 'index',
  165. type: 'index',
  166. width: 50,
  167. align: 'center',
  168. showOverflowTooltip: true,
  169. label: '序号'
  170. },
  171. {
  172. prop: 'categoryCode',
  173. label: '编码',
  174. align: 'center',
  175. showOverflowTooltip: true,
  176. minWidth: 110
  177. },
  178. {
  179. prop: 'categoryName',
  180. label: '名称',
  181. align: 'center',
  182. showOverflowTooltip: true,
  183. minWidth: 110
  184. },
  185. {
  186. prop: 'brandNum',
  187. align: 'center',
  188. label: '牌号',
  189. showOverflowTooltip: true
  190. },
  191. this.dimension=="2"?
  192. {
  193. prop: 'batchNo',
  194. label: '批次号',
  195. align: 'center',
  196. showOverflowTooltip: true
  197. }:{
  198. width:1
  199. },
  200. this.dimension == "2"
  201. ? {
  202. prop: 'systemBatchNo',
  203. label: '系统内部批次号',
  204. align: 'center',
  205. minWidth: 180,
  206. showOverflowTooltip: true,
  207. formatter: (row) => row.systemBatchNo || '-'
  208. }
  209. : {
  210. width: 1
  211. },
  212. {
  213. prop: 'categoryModel',
  214. label: '型号',
  215. align: 'center',
  216. showOverflowTooltip: true
  217. },
  218. {
  219. prop: 'specification',
  220. label: '规格',
  221. align: 'center',
  222. showOverflowTooltip: true
  223. },
  224. {
  225. prop: 'colorKey',
  226. label: '颜色',
  227. align: 'center',
  228. showOverflowTooltip: true
  229. },
  230. {
  231. prop: 'modelKey',
  232. label: '机型',
  233. align: 'center',
  234. showOverflowTooltip: true
  235. },
  236. {
  237. prop: 'warehouseName',
  238. label: '仓库',
  239. showOverflowTooltip: true,
  240. align: 'center',
  241. minWidth: 90
  242. },
  243. {
  244. prop: 'inventoryCycle',
  245. label: '存货周期(天)',
  246. align: 'center',
  247. width: 150,
  248. sortable: true,
  249. showOverflowTooltip: true,
  250. hide: this.dimension == 1
  251. },
  252. {
  253. prop: 'saleCount',
  254. slot: 'saleCount',
  255. label: '订单数量',
  256. showOverflowTooltip: true,
  257. align: 'center',
  258. minWidth: 120,
  259. hide: !this.showSaleCount
  260. },
  261. {
  262. prop: 'measureQuantity',
  263. label: '库存',
  264. showOverflowTooltip: true,
  265. align: 'center',
  266. minWidth: 90
  267. },
  268. {
  269. prop: 'lockQuantity',
  270. label: '锁库数量',
  271. showOverflowTooltip: true,
  272. align: 'center',
  273. minWidth: 90
  274. },
  275. {
  276. prop: 'useQuantity',
  277. label: '可用数量',
  278. showOverflowTooltip: true,
  279. align: 'center',
  280. minWidth: 90,
  281. formatter: (row) => {
  282. // 使用toFixed处理浮点数精度问题,保留4位小数
  283. const measureQuantity = parseFloat(row.measureQuantity) || 0;
  284. const lockQuantity = parseFloat(row.lockQuantity) || 0;
  285. const available = measureQuantity - lockQuantity;
  286. // 使用toFixed避免精度丢失,然后去除末尾多余的0
  287. return available.toFixed(4).replace(/\.?0+$/, '');
  288. }
  289. },
  290. {
  291. prop: 'measureUnit',
  292. label: '单位',
  293. showOverflowTooltip: true,
  294. align: 'center',
  295. minWidth: 90
  296. },
  297. {
  298. prop: 'weight',
  299. label: '重量',
  300. showOverflowTooltip: true,
  301. align: 'center',
  302. minWidth: 90
  303. },
  304. {
  305. prop: 'weightUnit',
  306. label: '重量单位',
  307. showOverflowTooltip: true,
  308. align: 'center',
  309. minWidth: 90
  310. },
  311. {
  312. prop: 'packingUnit',
  313. align: 'center',
  314. label: '包装单位',
  315. showOverflowTooltip: true
  316. },
  317. {
  318. prop: 'reelSpecification',
  319. label: '盘具',
  320. showOverflowTooltip: true,
  321. align: 'center'
  322. }
  323. ];
  324. return tempData.filter((item) => !item.hide);
  325. }
  326. },
  327. methods: {
  328. getDictV(code, val) {
  329. if (!this.dictList[code]) return '';
  330. return this.dictList[code].find((item) => item.value == val)?.label;
  331. },
  332. open(item, currentIndex) {
  333. console.log(item, currentIndex);
  334. this.currentIndex = currentIndex;
  335. this.visible = true;
  336. this.getTreeData();
  337. },
  338. async getTreeData() {
  339. try {
  340. this.treeLoading = true;
  341. let res = null;
  342. res = await getTreeByGroup({ type: 2 });
  343. this.treeLoading = false;
  344. if (res?.code === '0') {
  345. this.treeList = res.data;
  346. return this.treeList;
  347. }
  348. } catch (error) {
  349. console.log(error);
  350. }
  351. this.treeLoading = false;
  352. },
  353. /* 表格数据源 */
  354. datasource({ page, limit, where, order }) {
  355. this.dimension = where.dimension||'2';
  356. let api = where.dimension == '1' ? getOutindetailtwoList : getBatchList;
  357. return api({
  358. ...where,
  359. ...order,
  360. pageNum: page,
  361. size: limit
  362. });
  363. },
  364. /* 刷新表格 */
  365. reload(where) {
  366. this.$refs.table.reload({ pageNum: 1, where: where });
  367. },
  368. handleNodeClick(data, node) {
  369. this.curNodeData = data;
  370. if (data.id == this.currentId) {
  371. this.$refs.treeRef.setCurrentKey(null);
  372. this.reload();
  373. } else {
  374. this.reload({ categoryLevelId: data.id });
  375. }
  376. },
  377. async getSupplierObj(productList, queryName) {
  378. try {
  379. let categoryIds = productList
  380. .filter((item) => item.id)
  381. .map((item) => item.id);
  382. if (categoryIds.length > 0) {
  383. return await contactQueryByCategoryIdsAPI({
  384. categoryIds,
  385. isQueryEE: 1
  386. });
  387. } else {
  388. return Promise.resolve({});
  389. }
  390. } catch (e) {
  391. return Promise.resolve({});
  392. }
  393. },
  394. // 单击获取id
  395. cellClick(row) {
  396. if (this.currentIndex == -1) return;
  397. this.current = row;
  398. this.radio = row.id;
  399. },
  400. // 限制订单数量不超过可用数量(measureQuantity - lockQuantity)
  401. handleSaleCountInput(row) {
  402. const measureQuantity = parseFloat(row.measureQuantity) || 0;
  403. const lockQuantity = parseFloat(row.lockQuantity) || 0;
  404. const available = measureQuantity - lockQuantity;
  405. const val = parseFloat(row.saleCount);
  406. if (!isNaN(val) && val > available) {
  407. this.$message.warning(
  408. `订单数量不能超过可用数量(${available})`
  409. );
  410. this.$set(row, 'saleCount', available);
  411. }
  412. },
  413. handleClose() {
  414. this.visible = false;
  415. this.current = null;
  416. this.selection = [];
  417. this.$refs.table.clearSelection();
  418. this.radio = '';
  419. },
  420. isSameStockRecord(source, target) {
  421. if (source.batchStockId && target.id) {
  422. return source.batchStockId == target.id;
  423. }
  424. const sourceProductId = source.productId || source.categoryId;
  425. const targetProductId = target.categoryId || target.productId;
  426. const sourceProductCode =
  427. source.productCode || source.categoryCode || source.code;
  428. const targetProductCode =
  429. target.categoryCode || target.productCode || target.code;
  430. const sameProduct =
  431. sourceProductId && targetProductId
  432. ? sourceProductId == targetProductId
  433. : sourceProductCode == targetProductCode;
  434. const sameWarehouse =
  435. !source.warehouseId ||
  436. !target.warehouseId ||
  437. source.warehouseId == target.warehouseId;
  438. return (
  439. sameProduct &&
  440. sameWarehouse &&
  441. source.batchNo == target.batchNo &&
  442. (source.systemBatchNo || '') == (target.systemBatchNo || '')
  443. );
  444. },
  445. async selected() {
  446. if (!this.current && !this.selection.length) {
  447. return this.$message.warning('请至少选择一条数据');
  448. }
  449. if (this.currentIndex != -1) {
  450. if (
  451. this.data.some((item) => this.isSameStockRecord(item, this.current))
  452. ) {
  453. return this.$message.error('选择的库存记录已经存在列表了');
  454. }
  455. } else {
  456. if (
  457. this.selection.some((item) =>
  458. this.data.some((source) => this.isSameStockRecord(source, item))
  459. )
  460. ) {
  461. return this.$message.error('选择的库存记录已经存在列表了');
  462. }
  463. }
  464. let list = this.currentIndex == -1 ? this.selection : [this.current];
  465. //获取供应商
  466. if (this.isSupplier) {
  467. let supplierList = await this.getSupplierObj(list);
  468. list.forEach((item) => {
  469. item['entrustedEnterpriseIdList'] = supplierList[item.id];
  470. if (supplierList[item.id]?.length === 1) {
  471. item['entrustedEnterpriseId'] = supplierList[item.id][0].id;
  472. }
  473. });
  474. }
  475. let idList = list.map((item) => item.categoryId);
  476. // 获取包装规格
  477. let packingSpecification = await getCategoryPackageDisposition({
  478. categoryIds: idList
  479. });
  480. list.forEach((item, index) => {
  481. item.productName = item.categoryName;
  482. item.productCode = item.categoryCode;
  483. item.productCategoryName = '';
  484. item.productBrand = item.brandNum;
  485. item.provenance = item.provenance || [];
  486. if(this.showSaleCount){
  487. item.saleCount = item.saleCount;
  488. }
  489. item['packageDispositionList'] = packingSpecification
  490. .filter(
  491. (ite) => item.categoryId == ite.categoryId && ite.conversionUnit
  492. )
  493. .sort((a, b) => a.sort - b.sort);
  494. this.$set(list[index], 'totalCount', 1);
  495. // item.totalCount = 1;
  496. item.measuringUnit = item.measureUnit;
  497. //item.weightUnit = item.weightUnit;
  498. // item.warehouseNum = item.measureQuantity;
  499. item.productId = item.categoryId;
  500. item.batchStockId = item.id;
  501. item.id = '';
  502. item.batchNo = this.dimension != 1 ? item.batchNo : '';
  503. item.systemBatchNo =
  504. this.dimension != 1 ? item.systemBatchNo || '' : '';
  505. // item.specification = item.specification;
  506. });
  507. this.$emit('changeParent', list, this.currentIndex);
  508. this.handleClose();
  509. }
  510. }
  511. };
  512. </script>
  513. <style lang="scss" scoped>
  514. .tree_col {
  515. border: 1px solid #eee;
  516. padding: 10px 0;
  517. box-sizing: border-box;
  518. height: 500px;
  519. overflow: auto;
  520. }
  521. .table_col {
  522. padding-left: 10px;
  523. ::v-deep .el-table th.el-table__cell {
  524. background: #f2f2f2;
  525. }
  526. }
  527. .pagination {
  528. text-align: right;
  529. padding: 10px 0;
  530. }
  531. .btns {
  532. text-align: center;
  533. padding: 10px 0;
  534. }
  535. .topsearch {
  536. margin-bottom: 15px;
  537. }
  538. </style>