selectStockLedgerDialog.vue 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501
  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. ></el-input>
  63. </template>
  64. <template v-slot:action="{ row }">
  65. <el-radio class="radio" v-model="radio" :label="row.id"
  66. ><i></i
  67. ></el-radio>
  68. </template>
  69. </ele-pro-table>
  70. </template>
  71. </ele-split-layout>
  72. </el-card>
  73. <div slot="footer">
  74. <el-button type="primary" size="small" @click="selected">选择</el-button>
  75. <el-button size="small" @click="handleClose">关闭</el-button>
  76. </div>
  77. </el-dialog>
  78. </template>
  79. <script>
  80. import {
  81. getOutindetailtwoList,
  82. getTreeByGroup,
  83. getBatchList,
  84. getCategoryPackageDisposition
  85. } from '@/api/wms';
  86. import ItemSearch from './item-search.vue';
  87. import { contactQueryByCategoryIdsAPI } from '@/api/saleManage/contact';
  88. import tabMixins from '@/mixins/tableColumnsMixin';
  89. export default {
  90. mixins: [tabMixins],
  91. components: { ItemSearch },
  92. props: {
  93. /*已选择的产品*/
  94. data: {
  95. type: Array,
  96. default: () => []
  97. },
  98. /*是否需要供应商*/
  99. isSupplier: {
  100. type: Boolean,
  101. default: false
  102. },
  103. /*是否显示销售数量*/
  104. showSaleCount: {
  105. type: Boolean,
  106. default: false
  107. },
  108. cacheKeyUrl: {
  109. type: String,
  110. default: 'eom-sales-selectStockLedgerDialog-202605131603'
  111. }
  112. },
  113. data() {
  114. return {
  115. visible: false,
  116. currentIndex: null,
  117. radio: null,
  118. dictList: {},
  119. curNodeData: {},
  120. selection: [],
  121. treeData: [],
  122. dimension:'2',
  123. defaultProps: {
  124. children: 'children',
  125. label: 'name'
  126. },
  127. treeList: [],
  128. treeLoading: false,
  129. // cacheKeyUrl: '',
  130. columnsVersion: 1
  131. };
  132. },
  133. watch: {},
  134. computed: {
  135. columns() {
  136. const version = this.columnsVersion;
  137. let data = null;
  138. if (this.currentIndex != -1) {
  139. data = {
  140. action: 'action',
  141. slot: 'action',
  142. align: 'center',
  143. label: '选择',
  144. reserveSelection: true
  145. };
  146. }
  147. if (this.currentIndex == -1) {
  148. data = {
  149. label: '选择',
  150. width: 45,
  151. type: 'selection',
  152. columnKey: 'selection',
  153. align: 'center',
  154. reserveSelection: true,
  155. selectable: (row) => {
  156. return row.measureQuantity != 0;
  157. }
  158. };
  159. }
  160. const tempData = [
  161. data,
  162. {
  163. columnKey: 'index',
  164. type: 'index',
  165. width: 50,
  166. align: 'center',
  167. showOverflowTooltip: true,
  168. label: '序号'
  169. },
  170. {
  171. prop: 'categoryCode',
  172. label: '编码',
  173. align: 'center',
  174. showOverflowTooltip: true,
  175. minWidth: 110
  176. },
  177. {
  178. prop: 'categoryName',
  179. label: '名称',
  180. align: 'center',
  181. showOverflowTooltip: true,
  182. minWidth: 110
  183. },
  184. {
  185. prop: 'brandNum',
  186. align: 'center',
  187. label: '牌号',
  188. showOverflowTooltip: true
  189. },
  190. this.dimension=="2"?
  191. {
  192. prop: 'batchNo',
  193. label: '批次号',
  194. align: 'center',
  195. showOverflowTooltip: true
  196. }:{
  197. width:1
  198. },
  199. {
  200. prop: 'categoryModel',
  201. label: '型号',
  202. align: 'center',
  203. showOverflowTooltip: true
  204. },
  205. {
  206. prop: 'specification',
  207. label: '规格',
  208. align: 'center',
  209. showOverflowTooltip: true
  210. },
  211. {
  212. prop: 'colorKey',
  213. label: '颜色',
  214. align: 'center',
  215. showOverflowTooltip: true
  216. },
  217. {
  218. prop: 'modelKey',
  219. label: '机型',
  220. align: 'center',
  221. showOverflowTooltip: true
  222. },
  223. {
  224. prop: 'warehouseName',
  225. label: '仓库',
  226. showOverflowTooltip: true,
  227. align: 'center',
  228. minWidth: 90
  229. },
  230. {
  231. prop: 'inventoryCycle',
  232. label: '存货周期(天)',
  233. align: 'center',
  234. width: 150,
  235. sortable: true,
  236. showOverflowTooltip: true,
  237. hide: this.dimension == 1
  238. },
  239. {
  240. prop: 'saleCount',
  241. slot: 'saleCount',
  242. label: '订单数量',
  243. showOverflowTooltip: true,
  244. align: 'center',
  245. minWidth: 120,
  246. hide: !this.showSaleCount
  247. },
  248. {
  249. prop: 'measureQuantity',
  250. label: '库存',
  251. showOverflowTooltip: true,
  252. align: 'center',
  253. minWidth: 90
  254. },
  255. {
  256. prop: 'lockQuantity',
  257. label: '锁库数量',
  258. showOverflowTooltip: true,
  259. align: 'center',
  260. minWidth: 90
  261. },
  262. {
  263. prop: 'useQuantity',
  264. label: '可用数量',
  265. showOverflowTooltip: true,
  266. align: 'center',
  267. minWidth: 90,
  268. formatter: (row) => {
  269. // 使用toFixed处理浮点数精度问题,保留4位小数
  270. const measureQuantity = parseFloat(row.measureQuantity) || 0;
  271. const lockQuantity = parseFloat(row.lockQuantity) || 0;
  272. const available = measureQuantity - lockQuantity;
  273. // 使用toFixed避免精度丢失,然后去除末尾多余的0
  274. return available.toFixed(4).replace(/\.?0+$/, '');
  275. }
  276. },
  277. {
  278. prop: 'measureUnit',
  279. label: '单位',
  280. showOverflowTooltip: true,
  281. align: 'center',
  282. minWidth: 90
  283. },
  284. {
  285. prop: 'weight',
  286. label: '重量',
  287. showOverflowTooltip: true,
  288. align: 'center',
  289. minWidth: 90
  290. },
  291. {
  292. prop: 'weightUnit',
  293. label: '重量单位',
  294. showOverflowTooltip: true,
  295. align: 'center',
  296. minWidth: 90
  297. },
  298. {
  299. prop: 'packingUnit',
  300. align: 'center',
  301. label: '包装单位',
  302. showOverflowTooltip: true
  303. }
  304. ];
  305. return tempData.filter((item) => !item.hide);
  306. }
  307. },
  308. methods: {
  309. getDictV(code, val) {
  310. if (!this.dictList[code]) return '';
  311. return this.dictList[code].find((item) => item.value == val)?.label;
  312. },
  313. open(item, currentIndex) {
  314. console.log(item, currentIndex);
  315. this.currentIndex = currentIndex;
  316. this.visible = true;
  317. this.getTreeData();
  318. },
  319. async getTreeData() {
  320. try {
  321. this.treeLoading = true;
  322. let res = null;
  323. res = await getTreeByGroup({ type: 2 });
  324. this.treeLoading = false;
  325. if (res?.code === '0') {
  326. this.treeList = res.data;
  327. return this.treeList;
  328. }
  329. } catch (error) {
  330. console.log(error);
  331. }
  332. this.treeLoading = false;
  333. },
  334. /* 表格数据源 */
  335. datasource({ page, limit, where, order }) {
  336. this.dimension = where.dimension||'2';
  337. let api = where.dimension == '1' ? getOutindetailtwoList : getBatchList;
  338. return api({
  339. ...where,
  340. ...order,
  341. pageNum: page,
  342. size: limit
  343. });
  344. },
  345. /* 刷新表格 */
  346. reload(where) {
  347. this.$refs.table.reload({ pageNum: 1, where: where });
  348. },
  349. handleNodeClick(data, node) {
  350. this.curNodeData = data;
  351. if (data.id == this.currentId) {
  352. this.$refs.treeRef.setCurrentKey(null);
  353. this.reload();
  354. } else {
  355. this.reload({ categoryLevelId: data.id });
  356. }
  357. },
  358. async getSupplierObj(productList, queryName) {
  359. try {
  360. let categoryIds = productList
  361. .filter((item) => item.id)
  362. .map((item) => item.id);
  363. if (categoryIds.length > 0) {
  364. return await contactQueryByCategoryIdsAPI({
  365. categoryIds,
  366. isQueryEE: 1
  367. });
  368. } else {
  369. return Promise.resolve({});
  370. }
  371. } catch (e) {
  372. return Promise.resolve({});
  373. }
  374. },
  375. // 单击获取id
  376. cellClick(row) {
  377. if (this.currentIndex == -1) return;
  378. this.current = row;
  379. this.radio = row.id;
  380. },
  381. handleClose() {
  382. this.visible = false;
  383. this.current = null;
  384. this.selection = [];
  385. this.$refs.table.clearSelection();
  386. this.radio = '';
  387. },
  388. async selected() {
  389. if (!this.current && !this.selection.length) {
  390. return this.$message.warning('请至少选择一条数据');
  391. }
  392. if (this.currentIndex != -1) {
  393. if (
  394. this.data
  395. .map((item) => item.productCode)
  396. .includes(this.current.code)
  397. ) {
  398. return this.$message.error('选择的物品已经存在列表了');
  399. }
  400. } else {
  401. if (
  402. this.selection.some((item) =>
  403. this.data.some((i) => i.productCode == item.code)
  404. )
  405. ) {
  406. return this.$message.error('选择的物品已经存在列表了');
  407. }
  408. }
  409. let list = this.currentIndex == -1 ? this.selection : [this.current];
  410. //获取供应商
  411. if (this.isSupplier) {
  412. let supplierList = await this.getSupplierObj(list);
  413. list.forEach((item) => {
  414. item['entrustedEnterpriseIdList'] = supplierList[item.id];
  415. if (supplierList[item.id]?.length === 1) {
  416. item['entrustedEnterpriseId'] = supplierList[item.id][0].id;
  417. }
  418. });
  419. }
  420. let idList = list.map((item) => item.categoryId);
  421. // 获取包装规格
  422. let packingSpecification = await getCategoryPackageDisposition({
  423. categoryIds: idList
  424. });
  425. list.forEach((item, index) => {
  426. item.productName = item.categoryName;
  427. item.productCode = item.categoryCode;
  428. item.productCategoryName = '';
  429. item.productBrand = item.brandNum;
  430. item.provenance = item.provenance || [];
  431. if(this.showSaleCount){
  432. item.saleCount = item.saleCount;
  433. }
  434. item['packageDispositionList'] = packingSpecification
  435. .filter(
  436. (ite) => item.categoryId == ite.categoryId && ite.conversionUnit
  437. )
  438. .sort((a, b) => a.sort - b.sort);
  439. this.$set(list[index], 'totalCount', 1);
  440. // item.totalCount = 1;
  441. item.measuringUnit = item.measureUnit;
  442. //item.weightUnit = item.weightUnit;
  443. // item.warehouseNum = item.measureQuantity;
  444. item.productId = item.categoryId;
  445. item.id = '';
  446. item.batchNo = this.dimension != 1 ? item.batchNo : '';
  447. // item.specification = item.specification;
  448. });
  449. this.$emit('changeParent', list, this.currentIndex);
  450. this.handleClose();
  451. }
  452. }
  453. };
  454. </script>
  455. <style lang="scss" scoped>
  456. .tree_col {
  457. border: 1px solid #eee;
  458. padding: 10px 0;
  459. box-sizing: border-box;
  460. height: 500px;
  461. overflow: auto;
  462. }
  463. .table_col {
  464. padding-left: 10px;
  465. ::v-deep .el-table th.el-table__cell {
  466. background: #f2f2f2;
  467. }
  468. }
  469. .pagination {
  470. text-align: right;
  471. padding: 10px 0;
  472. }
  473. .btns {
  474. text-align: center;
  475. padding: 10px 0;
  476. }
  477. .topsearch {
  478. margin-bottom: 15px;
  479. }
  480. </style>