selectStockLedgerDialog.vue 13 KB

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