selectStockLedgerDialog.vue 13 KB

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