inventoryTable.vue 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709
  1. <template>
  2. <el-form ref="form" :model="form" :rules="rules">
  3. <ele-pro-table
  4. ref="table"
  5. :needPage="false"
  6. :columns="columns"
  7. :toolkit="[]"
  8. max-height="500px"
  9. :datasource="form.datasource"
  10. cache-key="systemRoleTable17"
  11. class="time-form"
  12. :selection.sync="selection"
  13. >
  14. <!-- <template v-slot:productName="{ row, $index }">-->
  15. <!-- <el-form-item-->
  16. <!-- style="margin-bottom: 20px"-->
  17. <!-- :prop="'datasource.' + $index + '.productName'"-->
  18. <!-- :rules="{-->
  19. <!-- required: true,-->
  20. <!-- message: '请输入',-->
  21. <!-- trigger: 'change'-->
  22. <!-- }"-->
  23. <!-- >-->
  24. <!-- <el-input-->
  25. <!-- v-model="row.productName"-->
  26. <!-- placeholder="请输入"-->
  27. <!-- disabled-->
  28. <!-- ></el-input>-->
  29. <!-- </el-form-item>-->
  30. <!-- </template>-->
  31. <!-- <template v-slot:productCode="scope">-->
  32. <!-- <el-form-item-->
  33. <!-- style="margin-bottom: 20px"-->
  34. <!-- :prop="'datasource.' + scope.$index + '.productCode'"-->
  35. <!-- >-->
  36. <!-- <el-input v-model="scope.row.productCode" disabled></el-input>-->
  37. <!-- </el-form-item>-->
  38. <!-- </template>-->
  39. <!-- <template v-slot:productCategoryName="scope">-->
  40. <!-- <el-form-item-->
  41. <!-- style="margin-bottom: 20px"-->
  42. <!-- :prop="'datasource.' + scope.$index + '.productCategoryName'"-->
  43. <!-- >-->
  44. <!-- <el-input v-model="scope.row.productCategoryName" disabled></el-input>-->
  45. <!-- </el-form-item>-->
  46. <!-- </template>-->
  47. <!-- <template v-slot:totalCount="scope">-->
  48. <!-- <el-form-item-->
  49. <!-- style="margin-bottom: 20px"-->
  50. <!-- :prop="'datasource.' + scope.$index + '.totalCount'"-->
  51. <!-- :rules="{-->
  52. <!-- required: true,-->
  53. <!-- pattern: numberReg,-->
  54. <!-- message: '请输入数字',-->
  55. <!-- trigger: 'blur'-->
  56. <!-- }"-->
  57. <!-- >-->
  58. <!-- <el-input-->
  59. <!-- v-model="scope.row.totalCount"-->
  60. <!-- disabled-->
  61. <!-- placeholder="请输入"-->
  62. <!-- ></el-input>-->
  63. <!-- </el-form-item>-->
  64. <!-- </template>-->
  65. <!-- <template v-slot:productBrand="scope">-->
  66. <!-- <el-form-item-->
  67. <!-- style="margin-bottom: 20px"-->
  68. <!-- :prop="'datasource.' + scope.$index + '.productBrand'"-->
  69. <!-- >-->
  70. <!-- <el-input v-model="scope.row.productBrand" disabled></el-input>-->
  71. <!-- </el-form-item>-->
  72. <!-- </template>-->
  73. <!-- <template v-slot:modelType="scope">-->
  74. <!-- <el-form-item-->
  75. <!-- style="margin-bottom: 20px"-->
  76. <!-- :prop="'datasource.' + scope.$index + '.modelType'"-->
  77. <!-- >-->
  78. <!-- <el-input v-model="scope.row.modelType" disabled></el-input>-->
  79. <!-- </el-form-item>-->
  80. <!-- </template>-->
  81. <!-- <template v-slot:specification="scope">-->
  82. <!-- <el-form-item-->
  83. <!-- style="margin-bottom: 20px"-->
  84. <!-- :prop="'datasource.' + scope.$index + '.specification'"-->
  85. <!-- >-->
  86. <!-- <el-input v-model="scope.row.specification" disabled></el-input>-->
  87. <!-- </el-form-item>-->
  88. <!-- </template>-->
  89. <!-- <template v-slot:measuringUnit="scope">-->
  90. <!-- <el-form-item-->
  91. <!-- style="margin-bottom: 20px"-->
  92. <!-- :prop="'datasource.' + scope.$index + '.measuringUnit'"-->
  93. <!-- >-->
  94. <!-- <el-input-->
  95. <!-- v-model="scope.row.measuringUnit"-->
  96. <!-- placeholder="请输入"-->
  97. <!-- disabled-->
  98. <!-- ></el-input>-->
  99. <!-- </el-form-item>-->
  100. <!-- </template>-->
  101. <!-- <template v-slot:remark="scope">-->
  102. <!-- <el-form-item-->
  103. <!-- style="margin-bottom: 20px"-->
  104. <!-- :prop="'datasource.' + scope.$index + '.remark'"-->
  105. <!-- >-->
  106. <!-- <el-input-->
  107. <!-- v-model="scope.row.remark"-->
  108. <!-- disabled-->
  109. <!-- type="textarea"-->
  110. <!-- placeholder="请输入"-->
  111. <!-- ></el-input>-->
  112. <!-- </el-form-item>-->
  113. <!-- </template>-->
  114. <!-- <template v-slot:technicalParams="scope">-->
  115. <!-- <el-form-item-->
  116. <!-- style="margin-bottom: 20px"-->
  117. <!-- :prop="'datasource.' + scope.$index + '.technicalParams'"-->
  118. <!-- :rules="{-->
  119. <!-- required: false,-->
  120. <!-- message: '请输入',-->
  121. <!-- trigger: 'change'-->
  122. <!-- }"-->
  123. <!-- >-->
  124. <!-- <el-input-->
  125. <!-- type="textarea"-->
  126. <!-- v-model="scope.row.technicalParams"-->
  127. <!-- placeholder="请输入"-->
  128. <!-- ></el-input>-->
  129. <!-- </el-form-item>-->
  130. <!-- </template>-->
  131. <template v-slot:files="scope">
  132. <el-form-item prop="files">
  133. <el-link
  134. v-for="link in scope.row.files"
  135. :key="link.id"
  136. type="primary"
  137. :underline="false"
  138. @click="downloadFile(link)"
  139. >
  140. {{ link.name }}
  141. </el-link>
  142. </el-form-item>
  143. </template>
  144. <!-- <template v-slot:expectReceiveDate="scope">-->
  145. <!-- <el-form-item-->
  146. <!-- style="margin-bottom: 20px"-->
  147. <!-- :prop="'datasource.' + scope.$index + '.expectReceiveDate'"-->
  148. <!-- :rules="{-->
  149. <!-- required: true,-->
  150. <!-- message: '请选择日期',-->
  151. <!-- trigger: 'blur'-->
  152. <!-- }"-->
  153. <!-- >-->
  154. <!-- <el-date-picker-->
  155. <!-- style="width: 100%"-->
  156. <!-- clearable-->
  157. <!-- v-model="scope.row.expectReceiveDate"-->
  158. <!-- type="date"-->
  159. <!-- value-format="yyyy-MM-dd"-->
  160. <!-- placeholder="请选择日期"-->
  161. <!-- disabled-->
  162. <!-- >-->
  163. <!-- </el-date-picker>-->
  164. <!-- </el-form-item>-->
  165. <!-- </template>-->
  166. <template v-slot:supplierIds="scope">
  167. <el-form-item prop="supplierIds">
  168. <el-select
  169. v-model="scope.row['supplierIds']"
  170. clearable
  171. filterable
  172. multiple
  173. collapse-tags
  174. >
  175. <el-option
  176. v-for="i in scope.row.supplierList"
  177. :key="i.id"
  178. :value="i.id"
  179. :label="i.name"
  180. ></el-option>
  181. </el-select>
  182. </el-form-item>
  183. </template>
  184. <!-- <template v-slot:productNameHeader="{ column, $index }">
  185. <span data-="">{{ column.label }}</span>
  186. <fileUpload
  187. v-model="files"
  188. module="main"
  189. :showLib="false"
  190. :limit="1"
  191. />
  192. </template> -->
  193. <!-- 操作列 -->
  194. <!-- <template v-for="item in supplierList"> -->
  195. <!-- {{ slot }} -->
  196. <!-- <template v-slot:[item.slot]="scope" v-for="item in supplierList">
  197. <el-form-item
  198. style="margin-bottom: 20px"
  199. :prop="'datasource.' + scope.$index + '.' + item.prop"
  200. :rules="{
  201. required: true,
  202. message: '请输入',
  203. trigger: 'blur'
  204. }"
  205. >
  206. <el-input
  207. type="input"
  208. v-model="scope.row[item.prop]"
  209. placeholder="请输入"
  210. ></el-input>
  211. </el-form-item>
  212. </template> -->
  213. <!-- <template v-slot:[item.headerSlot]="scope" v-for="item in supplierList">
  214. <el-form-item style="margin-bottom: 20px">
  215. <span>{{ item.label }}</span>
  216. <fileMain v-model="item.files"></fileMain>
  217. </el-form-item>
  218. </template> -->
  219. <!-- </template> -->
  220. <template v-slot:add="scope">
  221. <el-form-item style="margin-bottom: 20px">
  222. <el-button type="primary" @click="openSupplier(scope.row)"
  223. >新增报价单</el-button
  224. >
  225. </el-form-item>
  226. </template>
  227. <template v-slot:action="scope">
  228. <el-popconfirm
  229. class="ele-action"
  230. title="确定要删除吗?"
  231. @confirm="remove(scope.$index, scope.row.productCode)"
  232. >
  233. <template v-slot:reference>
  234. <el-link type="danger" :underline="false" icon="el-icon-delete">
  235. 删除
  236. </el-link>
  237. </template>
  238. </el-popconfirm>
  239. </template>
  240. </ele-pro-table>
  241. <!-- <head-list ref="headRef" @changeParent="changeAnswer"></head-list> -->
  242. </el-form>
  243. </template>
  244. <script>
  245. import { numberReg } from 'ele-admin';
  246. import dictMixins from '@/mixins/dictMixins';
  247. import fileUpload from '@/components/upload/fileUpload';
  248. import { getFile } from '@/api/system/file';
  249. import { getByCode } from '@/api/system/dictionary-data';
  250. import { getInventoryTotalAPI } from '@/api/bpm/components/wms';
  251. import fileMain from '@/components/addDoc/index.vue';
  252. // import headList from '@/views/saleManage/businessOpportunity/components/headList.vue';
  253. export default {
  254. mixins: [dictMixins],
  255. components: {
  256. fileMain,
  257. fileUpload
  258. // headList
  259. },
  260. props: {
  261. acceptUnpack: {
  262. default: ''
  263. }
  264. },
  265. data() {
  266. const defaultForm = {
  267. key: null,
  268. endTime: '',
  269. isFirst: 0,
  270. name: ''
  271. };
  272. return {
  273. numberReg,
  274. defaultForm,
  275. supplierList: [],
  276. selection: [],
  277. // resultList:'',
  278. form: {
  279. datasource: []
  280. },
  281. dictList: {},
  282. files: [],
  283. rules: {}
  284. };
  285. },
  286. computed: {
  287. canHandl() {
  288. return this.form.datasource.length;
  289. },
  290. columns() {
  291. return [
  292. {
  293. width: 50,
  294. label: '序号',
  295. type: 'index',
  296. columnKey: 'index',
  297. align: 'center',
  298. fixed: 'left'
  299. },
  300. {
  301. width: 45,
  302. type: 'selection',
  303. columnKey: 'selection',
  304. align: 'center',
  305. fixed: 'left'
  306. },
  307. {
  308. minWidth: 180,
  309. slot: 'add',
  310. label: '新增报价',
  311. showOverflowTooltip: true,
  312. fixed: 'left',
  313. align: 'center'
  314. },
  315. {
  316. minWidth: 100,
  317. label: '状态',
  318. fixed: 'left',
  319. filters: [
  320. { value: 0, text: '未核价' },
  321. { value: 1, text: '部分核价' },
  322. { value: 2, text: '全部核价完成' }
  323. ],
  324. filterMethod: this.isInquiryFn,
  325. formatter: (row, column) => {
  326. return row.isInquiry == 1
  327. ? '部分核价'
  328. : row.isInquiry == 2
  329. ? '全部核价完成'
  330. : '未核价';
  331. },
  332. align: 'center'
  333. },
  334. {
  335. minWidth: 100,
  336. prop: 'productCategoryName',
  337. label: '分类',
  338. slot: 'productCategoryName',
  339. showOverflowTooltip: true,
  340. align: 'center'
  341. },
  342. {
  343. minWidth: 100,
  344. prop: 'productCode',
  345. label: '编码',
  346. slot: 'productCode',
  347. showOverflowTooltip: true,
  348. align: 'center'
  349. },
  350. {
  351. minWidth: 140,
  352. prop: 'productName',
  353. label: '名称',
  354. slot: 'productName',
  355. headerSlot: 'productNameHeader',
  356. showOverflowTooltip: true,
  357. align: 'center'
  358. },
  359. {
  360. minWidth: 200,
  361. prop: 'supplierIds',
  362. label: '供应商选择',
  363. slot: 'supplierIds',
  364. align: 'center',
  365. filters: this.supplierList,
  366. filterMethod: this.filterMethod
  367. },
  368. {
  369. minWidth: 100,
  370. prop: 'productBrand',
  371. label: '牌号',
  372. slot: 'productBrand',
  373. showOverflowTooltip: true,
  374. align: 'center'
  375. },
  376. {
  377. minWidth: 80,
  378. prop: 'totalCount',
  379. label: '数量',
  380. slot: 'totalCount',
  381. align: 'center'
  382. },
  383. {
  384. minWidth: 80,
  385. prop: 'availableCountBase',
  386. label: '库存数量',
  387. slot: 'availableCountBase',
  388. align: 'center'
  389. },
  390. {
  391. width: 120,
  392. prop: 'totalWeight',
  393. label: '重量',
  394. slot: 'totalWeight',
  395. align: 'center'
  396. },
  397. {
  398. minWidth: 80,
  399. prop: 'measuringUnit',
  400. label: '单位',
  401. slot: 'measuringUnit',
  402. showOverflowTooltip: true,
  403. align: 'center'
  404. },
  405. {
  406. minWidth: 130,
  407. prop: 'modelType',
  408. label: '型号',
  409. slot: 'modelType',
  410. showOverflowTooltip: true,
  411. align: 'center'
  412. },
  413. {
  414. minWidth: 120,
  415. prop: 'specification',
  416. label: '规格',
  417. slot: 'specification',
  418. showOverflowTooltip: true,
  419. align: 'center'
  420. },
  421. {
  422. minWidth: 120,
  423. prop: 'imgCode',
  424. align: 'center',
  425. label: '图号/件号',
  426. showOverflowTooltip: true
  427. },
  428. {
  429. minWidth: 120,
  430. prop: 'produceType',
  431. align: 'center',
  432. label: '生产类型',
  433. showOverflowTooltip: true,
  434. formatter: (row, column) => {
  435. return row.produceType && row.produceType.length
  436. ? row.produceType
  437. .map((item) => this.getDictV('productionType', item))
  438. .join(',')
  439. : '';
  440. }
  441. },
  442. {
  443. minWidth: 120,
  444. prop: 'approvalNumber',
  445. align: 'center',
  446. label: '批准文号',
  447. showOverflowTooltip: true
  448. },
  449. {
  450. minWidth: 120,
  451. prop: 'packingSpecification',
  452. align: 'center',
  453. label: '包装规格',
  454. showOverflowTooltip: true
  455. },
  456. // {
  457. // width: 130,
  458. // prop: 'brand',
  459. // label: '品牌',
  460. // slot: 'brand'
  461. // },
  462. {
  463. minWidth: 170,
  464. prop: 'expectReceiveDate',
  465. label: '到货日期',
  466. slot: 'expectReceiveDate',
  467. align: 'center'
  468. },
  469. {
  470. minWidth: 140,
  471. prop: 'files',
  472. label: '附件',
  473. slot: 'files',
  474. align: 'center'
  475. },
  476. {
  477. minWidth: 220,
  478. prop: 'remark',
  479. label: '备注',
  480. slot: 'remark',
  481. align: 'center'
  482. }
  483. // {
  484. // columnKey: 'action',
  485. // label: '操作',
  486. // width: 120,
  487. // align: 'center',
  488. // resizable: false,
  489. // slot: 'action',
  490. // fixed: 'right',
  491. // showOverflowTooltip: true
  492. // }
  493. ];
  494. }
  495. },
  496. created() {
  497. this.getDictList('productionType');
  498. },
  499. methods: {
  500. getDictV(code, val) {
  501. if (!this.dictList[code]) return '';
  502. return this.dictList[code].find((item) => item.value == val)?.label;
  503. },
  504. async getDictList(code) {
  505. let { data: res } = await getByCode(code);
  506. this.dictList[code] = res.map((item) => {
  507. let values = Object.keys(item);
  508. return {
  509. value: values[0],
  510. label: item[values[0]]
  511. };
  512. });
  513. },
  514. downloadFile(file) {
  515. getFile({ objectName: file.storePath }, file.name);
  516. },
  517. // 返回列表数据
  518. getTableValue() {
  519. let comitDatasource = this.form.datasource;
  520. if (comitDatasource.length === 0) return [];
  521. comitDatasource.forEach((v) => {
  522. v.totalPrice = (v.totalCount * v.singlePrice)?.toFixed(2) || 0;
  523. v.files = v.files || null;
  524. });
  525. return comitDatasource;
  526. },
  527. setIsInquiry(list) {
  528. // return;
  529. this.form.datasource.forEach((productItem, index) => {
  530. //产品清单
  531. let isInquiry = 0,
  532. totalCountS = [];
  533. list.forEach((item) => {
  534. //供应商列表
  535. item.resultList.forEach((val) => {
  536. //供应商产品
  537. if (val.productCode == productItem.productCode) {
  538. totalCountS.push(
  539. Number(val.totalCount || 0) +
  540. Number(productItem.doneTotalCount || 0)
  541. );
  542. }
  543. });
  544. });
  545. if (totalCountS.length > 0) {
  546. this.$set(
  547. this.form.datasource[index],
  548. 'isInquiry',
  549. Math.max(...totalCountS) >= productItem.totalCount ? 2 : 1
  550. );
  551. } else {
  552. this.$set(this.form.datasource[index], 'isInquiry', 0);
  553. }
  554. console.log(totalCountS, 'codeS');
  555. });
  556. },
  557. filterMethod(value, row, column) {
  558. let ids = row.supplierIds
  559. if (ids.length > 0 && ids.includes(value)) {
  560. return row;
  561. }
  562. },
  563. isInquiryFn(value, row, column) {
  564. if (value == row.isInquiry) {
  565. return row;
  566. }
  567. },
  568. //修改回显
  569. async putTableValue(data) {
  570. if (data && data?.length) {
  571. let supplierList = [],
  572. supplierIds = [];
  573. this.form.datasource = data;
  574. let codeList = this.form.datasource.map((item) => item.productCode);
  575. //获取仓库库存
  576. let inventoryTotalList = await getInventoryTotalAPI(codeList);
  577. this.form.datasource.forEach((item, index) => {
  578. let find =
  579. inventoryTotalList.find((key) => key.code == item.productCode) ||
  580. {};
  581. // item.availableCountBase = find.availableCountBase;
  582. this.$set(
  583. this.form.datasource[index],
  584. 'availableCountBase',
  585. find.availableCountBase
  586. );
  587. supplierList.push(...item.supplierList);
  588. });
  589. supplierIds = Array.from(
  590. new Set(supplierList.map((item) => item.id))
  591. );
  592. this.supplierList = supplierIds.map((id) => {
  593. let data = supplierList.find((item) => item.id == id);
  594. return {
  595. text: data.name,
  596. value: data.id
  597. };
  598. });
  599. this.$refs.table.reload();
  600. }
  601. },
  602. handleSupplierSelect(row) {
  603. this.$emit('supplierSelect', row);
  604. },
  605. //选择产品
  606. handParent() {
  607. this.$refs.productListRef.open();
  608. },
  609. //选择产品回调
  610. changeParent(obj, idx) {
  611. obj['productBrand'] = obj.brandNum;
  612. obj['productCode'] = obj.code;
  613. obj['productName'] = obj.name;
  614. obj['productCategoryName'] = obj.categoryLevelPath;
  615. obj['productCategoryId'] = obj.categoryLevelId;
  616. this.form.datasource.push(obj);
  617. },
  618. remove(i, productCode) {
  619. if (!this.acceptUnpack) {
  620. this.$message.warning('本采购计划不能拆单');
  621. return;
  622. }
  623. this.form.datasource.splice(i, 1);
  624. this.$emit('delList', productCode);
  625. },
  626. // 清空表格
  627. restTable() {
  628. this.form.datasource = [];
  629. },
  630. openSupplier(row) {
  631. this.$emit('supplierSelect', row);
  632. },
  633. // 添加
  634. handlAdd() {
  635. let item = JSON.parse(JSON.stringify(this.defaultForm));
  636. item.key = this.form.datasource.length + 1;
  637. this.form.datasource.push(item);
  638. },
  639. validateForm(callback) {
  640. //开始表单校验
  641. this.$refs.form.validate((valid) => {
  642. callback(valid);
  643. });
  644. }
  645. }
  646. };
  647. </script>
  648. <style lang="scss" scoped>
  649. .headbox {
  650. display: flex;
  651. justify-content: space-between;
  652. align-items: center;
  653. .amount {
  654. font-size: 14px;
  655. font-weight: bold;
  656. }
  657. }
  658. .time-form .el-form-item {
  659. margin-bottom: 0 !important;
  660. }
  661. ::v-deep .period {
  662. display: flex;
  663. .borderleftnone {
  664. .el-input--medium .el-input__inner {
  665. border-top-right-radius: 0;
  666. border-bottom-right-radius: 0;
  667. }
  668. }
  669. .borderrightnone {
  670. .el-input--medium .el-input__inner {
  671. border-top-left-radius: 0;
  672. border-bottom-left-radius: 0;
  673. }
  674. }
  675. }
  676. ::v-deep .time-form tbody > tr:hover > td {
  677. background-color: transparent !important;
  678. }
  679. ::v-deep .time-form .el-table tr {
  680. background-color: #ffffff;
  681. }
  682. </style>