product-list.vue 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713
  1. <template>
  2. <ele-modal
  3. title="选择物品"
  4. :visible.sync="visible"
  5. v-if="visible"
  6. :before-close="handleClose"
  7. top="5vh"
  8. append-to-body
  9. width="70%"
  10. :maxable="true"
  11. >
  12. <el-card shadow="never">
  13. <searchProduct v-if="dataSources == '1'" @search="reload"></searchProduct>
  14. <el-form
  15. :model="searchForm"
  16. label-width="100px"
  17. @submit.native.prevent
  18. v-else
  19. >
  20. <el-row>
  21. <el-row>
  22. <!-- <el-col :span="6">
  23. <el-form-item label="仓库名称:">
  24. <el-select v-model="searchForm.warehouseId" style="width: 100%">
  25. <el-option
  26. v-for="item in warehouseList"
  27. :key="item.id"
  28. :value="item.id"
  29. :label="item.name"
  30. ></el-option>
  31. </el-select>
  32. </el-form-item>
  33. </el-col> -->
  34. <el-col :span="6">
  35. <el-form-item label="牌号">
  36. <el-input
  37. type="text"
  38. placeholder="搜索牌号"
  39. v-model="searchForm.brandNum"
  40. ></el-input>
  41. </el-form-item>
  42. </el-col>
  43. <el-col :span="6" style="height: 43px">
  44. <el-form-item label="列表维度:" prop="dimension">
  45. <template>
  46. <el-select
  47. style="width: 100%"
  48. @change="changeDimensionHandler"
  49. v-model="dimension"
  50. placeholder="请选择"
  51. >
  52. <el-option label="物料维度" value="4"></el-option>
  53. <el-option label="包装维度" value="3"></el-option>
  54. <el-option label="批次维度" value="2"></el-option>
  55. <el-option label="物品维度" value="1"></el-option>
  56. </el-select>
  57. </template>
  58. </el-form-item>
  59. </el-col>
  60. <el-col :span="6">
  61. <el-form-item label="物品编码:">
  62. <el-input
  63. style="width: 100%"
  64. type="text"
  65. placeholder="搜索物品编码"
  66. v-model="searchForm.categoryCode"
  67. ></el-input>
  68. </el-form-item>
  69. </el-col>
  70. <el-col :span="6">
  71. <el-form-item label="物品名称:">
  72. <el-input
  73. style="width: 100%"
  74. type="text"
  75. placeholder="搜索物品名称"
  76. v-model="searchForm.categoryName"
  77. ></el-input>
  78. </el-form-item>
  79. </el-col>
  80. <el-col style="text-align: right; margin-bottom: 10px">
  81. <el-button type="primary" @click="doSearch">搜索</el-button>
  82. <el-button icon="el-icon-refresh-left" @click="reset"
  83. >重置</el-button
  84. >
  85. </el-col>
  86. </el-row>
  87. <!-- <el-row>
  88. <el-col :span="6">
  89. <el-form-item label="批次号:">
  90. <el-input type="text" placeholder="搜索批次号" v-model="searchForm.batchNo"></el-input>
  91. </el-form-item>
  92. </el-col>
  93. <el-col :span="6">
  94. <el-form-item label="刻码">
  95. <el-input type="text" placeholder="搜索物品刻码" v-model="searchForm.engrave"></el-input>
  96. </el-form-item>
  97. </el-col>
  98. <el-col :span="6">
  99. <el-form-item label="发货码">
  100. <el-input type="text" placeholder="搜索发货码" v-model="searchForm.barcodes"></el-input>
  101. </el-form-item>
  102. </el-col>
  103. <el-col :span="6">
  104. <el-form-item label="牌号">
  105. <el-input type="text" placeholder="搜索牌号" v-model="searchForm.brandNum"></el-input>
  106. </el-form-item>
  107. </el-col>
  108. </el-row> -->
  109. </el-row>
  110. </el-form>
  111. <ele-split-layout
  112. width="244px"
  113. allow-collapse
  114. :right-style="{ overflow: 'hidden' }"
  115. >
  116. <div class="ele-border-lighter split-layout-right-content">
  117. <productTree
  118. @handleNodeClick="handleNodeClick"
  119. :isFirstRefreshTable="isFirstRefreshTable"
  120. ref="treeList"
  121. :ids="ids"
  122. :typeIds="typeIds"
  123. :itemType="itemType"
  124. />
  125. </div>
  126. <!-- 表格 -->
  127. <template v-slot:content>
  128. <ele-pro-table
  129. ref="table"
  130. :columns="columns"
  131. :datasource="datasource"
  132. @row-dblclick="handleDoubleClick"
  133. row-key="id"
  134. height="calc(100vh - 480px)"
  135. class="dict-table"
  136. @cell-click="cellClick"
  137. :selection.sync="selection"
  138. @done="tableDone"
  139. :row-class-name="tableRowClassName"
  140. :initLoad="!isFirstRefreshTable"
  141. @columns-change="handleColumnChange"
  142. :rowClickChecked="true"
  143. :cache-key="'product-list-cache-key'"
  144. >
  145. <!-- 表头工具栏 -->
  146. <template v-slot:action="{ row }">
  147. <!-- <el-radio class="radio" v-model="radio" :label="row.code"></el-radio> -->
  148. <el-radio class="radio" v-model="radio" :label="row.id">
  149. <i></i>
  150. </el-radio>
  151. </template>
  152. <template v-slot:cz="{ row }">
  153. <el-button type="text" @click="handleDoubleClick(row)"
  154. >选择PBom</el-button
  155. >
  156. </template>
  157. </ele-pro-table>
  158. </template>
  159. </ele-split-layout>
  160. </el-card>
  161. <div slot="footer">
  162. <el-button type="primary" size="small" @click="selected">选择</el-button>
  163. <el-button size="small" @click="handleClose">关闭</el-button>
  164. </div>
  165. <c-bom-list
  166. v-if="cBomListDialogFlag"
  167. :cBomListDialogFlag.sync="cBomListDialogFlag"
  168. :current-row="current"
  169. ref="cBomRef"
  170. @changeParent="getSelectionCbom"
  171. ></c-bom-list>
  172. </ele-modal>
  173. </template>
  174. <script>
  175. import {
  176. getOutindetailtwoList,
  177. getBatchList,
  178. getMaterialList,
  179. getPackingList
  180. } from '@/api/wms';
  181. import {
  182. getProductList,
  183. queryLastContractProductList
  184. } from '@/api/saleManage/quotation';
  185. import searchProduct from './searchProduct.vue';
  186. import productTree from '@/components/productTree';
  187. import {
  188. getInventoryTotalAPI,
  189. getCategoryPackageDisposition
  190. } from '@/api/wms';
  191. import cBomList from './cBom-list.vue';
  192. import { getByCode } from '@/api/system/dictionary-data';
  193. import { contactQueryByCategoryIdsAPI } from '@/api/saleManage/contact';
  194. import { lbjtList } from '@/enum/dict.js';
  195. import tabMixins from '@/mixins/tableColumnsMixin';
  196. import { levelList } from '@/enum/dict.js';
  197. export default {
  198. mixins: [tabMixins],
  199. components: {
  200. productTree,
  201. searchProduct,
  202. cBomList
  203. },
  204. props: {
  205. /*是否需要获取仓库产品数量*/
  206. isGetInventoryTotal: {
  207. type: Boolean,
  208. default: false
  209. },
  210. /*已选择的产品*/
  211. data: {
  212. type: Array,
  213. default: () => []
  214. },
  215. /*是否需要cBom*/
  216. isShowCBom: {
  217. type: Boolean,
  218. default: false
  219. },
  220. /*是否需要供应商*/
  221. isSupplier: {
  222. type: Boolean,
  223. default: false
  224. },
  225. //获取上一次销售记录 1销售合同 2采购合同
  226. isSalesRecord: {
  227. default: ''
  228. },
  229. typeIds: {
  230. type: Array,
  231. default: () => []
  232. },
  233. isFirstRefreshTable: {
  234. type: Boolean,
  235. default: false
  236. },
  237. ids: {
  238. type: Array,
  239. default: () => []
  240. },
  241. itemType: {
  242. type: String,
  243. default: '1'
  244. }
  245. },
  246. data() {
  247. return {
  248. visible: false,
  249. currentIndex: null,
  250. radio: null,
  251. cBomListDialogFlag: null,
  252. dictList: {},
  253. selection: [],
  254. isColorId: [],
  255. dataSources: '1', // 0:仓库;1:主数据
  256. dimension: '1',
  257. searchForm: {
  258. categoryCode: '',
  259. categoryName: '',
  260. batchNo: '',
  261. brandNum: '',
  262. engrave: '',
  263. barcodes: '',
  264. categoryLevelId: '',
  265. warehouseId: '',
  266. pageNum: 1,
  267. size: 10
  268. },
  269. datasourceList: [],
  270. columnsVersion: 1
  271. };
  272. },
  273. watch: {},
  274. computed: {
  275. columns() {
  276. let columnsVersion = this.columnsVersion;
  277. let data = null;
  278. if (this.currentIndex != -1) {
  279. data = {
  280. action: 'action',
  281. slot: 'action',
  282. align: 'center',
  283. label: '选择',
  284. reserveSelection: true
  285. };
  286. }
  287. if (this.currentIndex == -1) {
  288. data = {
  289. label: '选择',
  290. width: 45,
  291. type: 'selection',
  292. columnKey: 'selection',
  293. align: 'center',
  294. reserveSelection: true
  295. };
  296. }
  297. return [
  298. data,
  299. {
  300. columnKey: 'index',
  301. type: 'index',
  302. width: 50,
  303. align: 'center',
  304. showOverflowTooltip: true,
  305. label: '序号'
  306. },
  307. {
  308. prop: 'code',
  309. label: '编码',
  310. align: 'center',
  311. showOverflowTooltip: true,
  312. minWidth: 110
  313. },
  314. {
  315. prop: 'name',
  316. label: '名称',
  317. align: 'center',
  318. showOverflowTooltip: true,
  319. minWidth: 110
  320. },
  321. {
  322. prop: 'imgCode',
  323. align: 'center',
  324. label: '图号/件号',
  325. showOverflowTooltip: true,
  326. minWidth: 110
  327. },
  328. {
  329. prop: 'componentAttribute',
  330. align: 'center',
  331. label: '属性类型',
  332. showOverflowTooltip: true,
  333. formatter: (row, column) => {
  334. if (row.componentAttribute) {
  335. return row.componentAttribute
  336. .map((item) => {
  337. return lbjtList[item];
  338. })
  339. .toString();
  340. }
  341. },
  342. minWidth: 110
  343. },
  344. {
  345. prop: 'level',
  346. align: 'center',
  347. label: '级别',
  348. showOverflowTooltip: true,
  349. minWidth: 110
  350. },
  351. {
  352. prop: 'extField.packingSpecification',
  353. align: 'center',
  354. label: '包装规格',
  355. showOverflowTooltip: true,
  356. minWidth: 110
  357. },
  358. {
  359. prop: 'brandNum',
  360. align: 'center',
  361. label: '牌号',
  362. showOverflowTooltip: true
  363. },
  364. {
  365. prop: 'modelType',
  366. label: '型号',
  367. align: 'center',
  368. showOverflowTooltip: true
  369. },
  370. {
  371. prop: 'specification',
  372. label: '规格',
  373. align: 'center',
  374. showOverflowTooltip: true
  375. },
  376. {
  377. prop: 'measureUnit',
  378. label: '计量单位',
  379. showOverflowTooltip: true,
  380. align: 'center',
  381. minWidth: 90
  382. },
  383. {
  384. prop: 'weightUnit',
  385. label: '重量单位',
  386. showOverflowTooltip: true,
  387. align: 'center',
  388. minWidth: 90
  389. },
  390. {
  391. prop: 'roughWeight',
  392. label: '毛重',
  393. showOverflowTooltip: true,
  394. align: 'center',
  395. minWidth: 90
  396. },
  397. {
  398. prop: 'netWeight',
  399. label: '净重',
  400. showOverflowTooltip: true,
  401. align: 'center',
  402. minWidth: 90
  403. },
  404. {
  405. prop: 'packingUnit',
  406. align: 'center',
  407. label: '包装单位',
  408. showOverflowTooltip: true
  409. },
  410. {
  411. prop: 'categoryLevelPath',
  412. label: '分类',
  413. align: 'center',
  414. showOverflowTooltip: true
  415. },
  416. {
  417. slot: 'cz',
  418. align: 'center',
  419. minWidth: 90,
  420. fixed: 'right',
  421. label: '操作',
  422. show: this.isShowCBom
  423. }
  424. ];
  425. }
  426. },
  427. methods: {
  428. getDictV(code, val) {
  429. if (!this.dictList[code]) return '';
  430. return this.dictList[code].find((item) => item.value == val)?.label;
  431. },
  432. async getDictList(code) {
  433. let { data: res } = await getByCode(code);
  434. this.dictList[code] = res.map((item) => {
  435. let values = Object.keys(item);
  436. return {
  437. value: values[0],
  438. label: item[values[0]]
  439. };
  440. });
  441. },
  442. open(item, currentIndex, value) {
  443. this.dataSources = value || '1';
  444. this.currentIndex = currentIndex;
  445. this.visible = true;
  446. this.getDictList('productionType');
  447. },
  448. /* 表格数据源 */
  449. datasource({ page, limit, where, order }) {
  450. if (this.dataSources == '0') {
  451. this.searchForm.pageNum = page;
  452. return this.changeDimension(this.dimension);
  453. }
  454. return getProductList({
  455. pageNum: page,
  456. size: limit,
  457. ...where
  458. });
  459. },
  460. async tableDone() {
  461. if (this.isSalesRecord == 1 || this.isSalesRecord == 2) {
  462. this.isColorId = await queryLastContractProductList(
  463. this.isSalesRecord
  464. );
  465. }
  466. },
  467. //上次销售记录 改变背景色
  468. tableRowClassName({ row }) {
  469. if (this.isColorId?.includes(row?.id)) {
  470. return 'success-row';
  471. }
  472. return '';
  473. },
  474. /* 刷新表格 */
  475. reload(where) {
  476. where.categoryLevelId = this.curNodeData?.id;
  477. this.searchForm.categoryLevelId = this.curNodeData?.id;
  478. this.$refs.table.reload({ pageNum: 1, where: where });
  479. },
  480. handleNodeClick(data, node) {
  481. this.curNodeData = data;
  482. this.$nextTick(() => {
  483. this.reload({ categoryLevelId: data.id });
  484. });
  485. },
  486. // 单击获取id
  487. cellClick(row) {
  488. if (this.currentIndex == -1) return;
  489. this.current = row;
  490. this.radio = row.id;
  491. },
  492. handleDoubleClick(row) {
  493. if (!this.isShowCBom) return;
  494. this.cBomListDialogFlag = true;
  495. this.current = row;
  496. this.$nextTick(() => {
  497. this.$refs.cBomRef.open(row);
  498. });
  499. },
  500. async getSelectionCbom(rows = []) {
  501. console.log(rows);
  502. let list = rows;
  503. //获取供应商
  504. if (this.isSupplier) {
  505. let supplierList = await this.getSupplierObj(list, 'categoryId');
  506. list.forEach((item) => {
  507. item['supplierList'] = supplierList[item.categoryId];
  508. // item['entrustedEnterpriseIdList'] = supplierList[item.categoryId];
  509. if (supplierList[item.categoryId]?.length) {
  510. // item['entrustedEnterpriseId'] = supplierList[item.id][0].id;
  511. item['supplierCode'] = supplierList[item.categoryId][0].code;
  512. item['supplierId'] = supplierList[item.categoryId][0].id;
  513. item['supplierName'] = supplierList[item.categoryId][0].name;
  514. }
  515. });
  516. }
  517. this.$emit('getSelectionCbom', list);
  518. this.handleClose();
  519. },
  520. handleClose() {
  521. this.visible = false;
  522. this.current = null;
  523. this.selection = [];
  524. this.$refs.table.clearSelection();
  525. this.radio = '';
  526. },
  527. async getSupplierObj(productList, queryName) {
  528. try {
  529. let categoryIds = productList
  530. .filter((item) => item[queryName])
  531. .map((item) => item[queryName]);
  532. if (categoryIds.length > 0) {
  533. return await contactQueryByCategoryIdsAPI({
  534. categoryIds
  535. });
  536. } else {
  537. return Promise.resolve({});
  538. }
  539. } catch (e) {
  540. return Promise.resolve({});
  541. }
  542. },
  543. async selected() {
  544. if (!this.current && !this.selection.length) {
  545. return this.$message.warning('请至少选择一条数据');
  546. }
  547. if (this.currentIndex != -1) {
  548. if (
  549. this.data
  550. .map((item) => item.productCode)
  551. .includes(this.current.code)
  552. ) {
  553. return this.$message.error('选择的物品已经存在列表了');
  554. }
  555. } else {
  556. if (
  557. this.selection.some((item) =>
  558. this.data.some((i) => i.productCode == item.code)
  559. )
  560. ) {
  561. return this.$message.error('选择的物品已经存在列表了');
  562. }
  563. }
  564. let list = this.currentIndex == -1 ? this.selection : [this.current];
  565. let codeList = list.map((item) => item.code);
  566. let idList = list.map((item) => item.id);
  567. //获取仓库库存
  568. if (this.isGetInventoryTotal) {
  569. let inventoryTotalList = await getInventoryTotalAPI(codeList);
  570. list.forEach((item) => {
  571. let find =
  572. inventoryTotalList.find((key) => key.code == item.code) || {};
  573. item.availableCountBase = find.availableCountBase;
  574. });
  575. }
  576. //获取供应商
  577. if (this.isSupplier) {
  578. let supplierList = await this.getSupplierObj(list, 'id');
  579. list.forEach((item) => {
  580. item['supplierList'] = supplierList[item.id];
  581. item['entrustedEnterpriseIdList'] = supplierList[item.id];
  582. if (supplierList[item.id]?.length) {
  583. item['entrustedEnterpriseId'] = supplierList[item.id][0].id;
  584. item['supplierCode'] = supplierList[item.id][0].code;
  585. item['supplierId'] = supplierList[item.id][0].id;
  586. item['supplierName'] = supplierList[item.id][0].name;
  587. }
  588. });
  589. }
  590. // 获取包装规格
  591. let packingSpecification = await getCategoryPackageDisposition({
  592. categoryIds: idList
  593. });
  594. list.forEach((item) => {
  595. item['packageDispositionList'] = packingSpecification
  596. .filter((ite) => item.id == ite.categoryId && ite.conversionUnit)
  597. .sort((a, b) => a.sort - b.sort);
  598. if (item.level) {
  599. item['goodsLevel'] = levelList.find(
  600. (val) => val.label == item.level
  601. )?.value;
  602. }
  603. });
  604. this.$emit('changeParent', list, this.currentIndex);
  605. this.handleClose();
  606. },
  607. // 仓库查询
  608. doSearch() {
  609. // this.searchForm.pageNum = 1;
  610. this.reload({ pageNum: 1, where: this.searchForm });
  611. },
  612. // 仓库查询重置
  613. reset() {
  614. this.searchForm = {
  615. categoryCode: '',
  616. categoryName: '',
  617. batchNo: '',
  618. brandNum: '',
  619. engrave: '',
  620. barcodes: '',
  621. categoryLevelId: this.categoryLevelId,
  622. pageNum: 1,
  623. warehouseId: '',
  624. size: 10
  625. };
  626. this.doSearch();
  627. },
  628. // 切换维度
  629. changeDimensionHandler(e) {
  630. // this.searchForm.pageNum = 1;
  631. // this.selectionList = [];
  632. // this.$refs.multipleTable.clearSelection();
  633. this.reload({ pageNum: 1, where: this.searchForm });
  634. },
  635. // 仓库数据
  636. async changeDimension(e) {
  637. this.dimension = e;
  638. let data = [];
  639. if (this.dimension == 1) {
  640. // 物品维度
  641. data = await getOutindetailtwoList(this.searchForm);
  642. } else if (this.dimension == 2) {
  643. // 批次维度
  644. data = await getBatchList(this.searchForm);
  645. } else if (this.dimension == 4) {
  646. // 物料维度
  647. data = await getMaterialList(this.searchForm);
  648. } else {
  649. // 包装维度
  650. data = await getPackingList(this.searchForm);
  651. }
  652. data.list.map((el) => {
  653. el.modelType = el.categoryModel;
  654. el.name = el.categoryName;
  655. el.code = el.categoryCode;
  656. });
  657. return data;
  658. }
  659. }
  660. };
  661. </script>
  662. <style lang="scss" scoped>
  663. :deep(.success-row) {
  664. background: #f0f9eb;
  665. }
  666. .tree_col {
  667. border: 1px solid #eee;
  668. padding: 10px 0;
  669. box-sizing: border-box;
  670. height: 500px;
  671. overflow: auto;
  672. }
  673. .table_col {
  674. padding-left: 10px;
  675. ::v-deep .el-table th.el-table__cell {
  676. background: #f2f2f2;
  677. }
  678. }
  679. .pagination {
  680. text-align: right;
  681. padding: 10px 0;
  682. }
  683. .btns {
  684. text-align: center;
  685. padding: 10px 0;
  686. }
  687. .topsearch {
  688. margin-bottom: 15px;
  689. }
  690. </style>