produceList.vue 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700
  1. <template>
  2. <view class="mainBox">
  3. <view v-for="(item, index) in tableList" :key="index" style="position: relative;">
  4. <myCard :item="item" :btnList="btnList" :index="index+1" :columns="columns" @del="del(index)">
  5. <u--input slot="purchaseCount" @input="changeCount(item,index)" type="number" placeholder="请输入"
  6. border="surround" :disabled="!!contractId" v-model="item.purchaseCount">
  7. </u--input>
  8. <u--input :disabled="!!contractId" slot="singleWeight" @input="singleWeightChange(item,index)"
  9. type="number" placeholder="请输入" border="surround" v-model="item.singleWeight"></u--input>
  10. <u--input :disabled="!!contractId" slot="singlePrice" style="flex:none;width: 50%;"
  11. @input="getTotalPrice()" type="number" placeholder="请输入" border="surround"
  12. v-model="item.singlePrice">
  13. <template slot="suffix">元</template>
  14. </u--input>
  15. <uni-datetime-picker :disabled="!!contractId" type="date" slot="customerExpectDeliveryDeadline"
  16. v-model="item.customerExpectDeliveryDeadline">
  17. </uni-datetime-picker>
  18. <u--input :disabled="!!contractId" slot="guaranteePeriod" placeholder="请输入" border="surround"
  19. v-model="item.guaranteePeriod"></u--input>
  20. <uni-data-picker :readonly="!!contractId" slot="guaranteePeriodUnitCode"
  21. v-model="item.guaranteePeriodUnitCode" placeholder="请选择" :localdata="date_unit">
  22. </uni-data-picker>
  23. <u--input slot="customerMark" placeholder="请输入" border="surround" v-model="item.customerMark">
  24. </u--input>
  25. <u--input slot="productBrand" placeholder="请输入" border="surround" :disabled="item.productCode"
  26. v-model="item.productBrand">
  27. </u--input>
  28. <u--input slot="specification" placeholder="请输入" border="surround" :disabled="item.productCode"
  29. v-model="item.specification">
  30. </u--input>
  31. <u--input slot="goodsLevel" placeholder="请输入" border="surround" :disabled="item.productCode"
  32. v-model="item.goodsLevel">
  33. </u--input>
  34. <u--input slot="modelType" placeholder="请输入" border="surround" :disabled="item.productCode"
  35. v-model="item.modelType">
  36. </u--input>
  37. <u--input slot="productName" placeholder="请输入" border="surround" :disabled="item.productCode"
  38. v-model="item.productName">
  39. </u--input>
  40. <fileMain slot="files" type="view" v-model="item.files"></fileMain>
  41. </myCard>
  42. </view>
  43. <view style="height: 84rpx;" v-if="isDrawer"></view>
  44. <view class="footerButton" v-if="isDrawer">
  45. <u-button type="primary" @click="save" text="保存"></u-button>
  46. </view>
  47. <view class="add" @click="add" v-if="isDrawer">
  48. <u-icon name="plus" color="#fff"></u-icon>
  49. </view>
  50. <u-action-sheet :actions="addList" :show="show" :closeOnClickOverlay="true" :closeOnClickAction="true"
  51. @close="show=false" @select='select'> </u-action-sheet>
  52. </view>
  53. </template>
  54. <script>
  55. import {
  56. getByCode
  57. } from '@/api/pda/common.js'
  58. import myCard from './myCard.vue'
  59. import { mapActions, mapGetters } from 'vuex'
  60. import dictEnum from '@/enum/dict'
  61. import { levelList, lbjtList } from '@/enum/dict'
  62. import fileMain from "@/pages/doc/index.vue"
  63. export default {
  64. data() {
  65. return {
  66. tableList: [],
  67. addList: [{
  68. name: '选择物品清单',
  69. },
  70. {
  71. name: '新增临时产品',
  72. }
  73. ],
  74. show: false,
  75. current: {},
  76. date_unit: [],
  77. allPrice: '',
  78. btnList: [{
  79. name: '删除',
  80. apiName: 'del',
  81. btnType: 'error ',
  82. type: '2',
  83. pageUrl: '',
  84. }],
  85. defaultForm: {
  86. key: null,
  87. endTime: '',
  88. isFirst: 0,
  89. name: '',
  90. startTime: '',
  91. workHour: '',
  92. guaranteePeriodUnitCode: '',
  93. technicalDrawings: [],
  94. arrivalWay: 1
  95. }
  96. }
  97. },
  98. props: {
  99. isDrawer: {
  100. default: false
  101. },
  102. pricingWay: {
  103. default: 1
  104. },
  105. isTemporary: {
  106. //临时
  107. type: Boolean,
  108. default: false
  109. },
  110. contractId: '',
  111. // columns: {
  112. // type: Array,
  113. // default: () => [
  114. // [{
  115. // label: '名称:',
  116. // prop: 'productName',
  117. // slot: 'productName',
  118. // type: 'title',
  119. // className: 'perce100',
  120. // }],
  121. // [{
  122. // label: '编码:',
  123. // prop: 'productCode'
  124. // }, {
  125. // label: '分类:',
  126. // prop: 'productCategoryName',
  127. // }],
  128. // [{
  129. // label: '数量:',
  130. // prop: 'purchaseCount',
  131. // // slot: 'purchaseCount',
  132. // formatter: (item) => {
  133. // if (item.purchaseCount) {
  134. // return item.purchaseCount + ' ' + (item.purchaseUnit || '');
  135. // }
  136. // }
  137. // },
  138. // {
  139. // label: '计量数量:',
  140. // prop: 'totalCount',
  141. // formatter: (item) => {
  142. // if (item.totalCount) {
  143. // return item.totalCount + ' ' + (item.measuringUnit || '');
  144. // }
  145. // }
  146. // }],
  147. // [{
  148. // label: '包装规格:',
  149. // prop: 'packingSpecification',
  150. // }, {
  151. // label: '物品级别:',
  152. // prop: 'goodsLevel',
  153. // formatter: (item) => {
  154. // return levelList.find((i) => i.value == item.goodsLevel)
  155. // ?.label;
  156. // },
  157. // }],
  158. // [{
  159. // label: '库存数量:',
  160. // prop: 'availableCountBase',
  161. // }],
  162. // [{
  163. // label: '已采数量:',
  164. // prop: 'doneTotalCount',
  165. // formatter: (item) => {
  166. // if (item.doneTotalCount) {
  167. // return item.doneTotalCount + ' ' + (item.measuringUnit || '');
  168. // }
  169. // }
  170. // }, {
  171. // label: '待采数量:',
  172. // prop: 'waitTotalCount',
  173. // formatter: (item) => {
  174. // if (item.waitTotalCount) {
  175. // return item.waitTotalCount + ' ' + (item.measuringUnit || '');
  176. // }
  177. // }
  178. // }],
  179. // [{
  180. // label: '工序:',
  181. // prop: 'taskName',
  182. // }, {
  183. // label: '批次号:',
  184. // prop: 'batchNo',
  185. // }],
  186. // [{
  187. // label: '供应商:',
  188. // prop: 'supplierName',
  189. // }, {
  190. // label: '产地:',
  191. // prop: 'provenance',
  192. // formatter: (item) => {
  193. // // return item.provenance
  194. // return item.provenance && item.provenance.length
  195. // ? item.provenance
  196. // .map((item) => this.getDictValue('产地', item))
  197. // .join(',')
  198. // : '';
  199. // }
  200. // }],
  201. // [{
  202. // label: '型号:',
  203. // prop: 'modelType',
  204. // className: 'perce100',
  205. // }],
  206. // [{
  207. // label: '规格:',
  208. // prop: 'specification',
  209. // }, {
  210. // label: '品牌:',
  211. // prop: 'brand',
  212. // }],
  213. // [{
  214. // label: '机型:',
  215. // prop: 'modelKey',
  216. // }, {
  217. // label: '颜色:',
  218. // prop: 'colorKey',
  219. // }],
  220. // [{
  221. // label: '到货方式:',
  222. // prop: 'arrivalWay',
  223. // formatter: (item) => {
  224. // return item.arrivalWay == 1 ? '一次性到货' : '分批到货';
  225. // },
  226. // }],
  227. // [{
  228. // label: '到货日期:',
  229. // prop: 'expectReceiveDate',
  230. // slot: 'expectReceiveDate',
  231. // }, {
  232. // label: '属性类型:',
  233. // prop: 'produceType',
  234. // formatter: (item) => {
  235. // if (item.produceType) {
  236. // return item.produceType
  237. // .map((i) => {
  238. // return lbjtList[i];
  239. // })
  240. // .toString();
  241. // }
  242. // }
  243. // }],
  244. // [{
  245. // label: '图纸附件:',
  246. // prop: 'technicalDrawings',
  247. // slot: 'technicalDrawings',
  248. // }, {
  249. // label: '附件:',
  250. // prop: 'files',
  251. // slot: 'files',
  252. // }],
  253. // [{
  254. // label: '备注:',
  255. // prop: 'remark',
  256. // className: 'perce100',
  257. // }],
  258. // [{
  259. // label: '操作:',
  260. // prop: 'action',
  261. // type: 'action',
  262. // className: 'perce100',
  263. // }],
  264. // ]
  265. // }
  266. },
  267. components: {
  268. myCard
  269. },
  270. computed: {
  271. ...mapGetters(['dict', 'getDict', 'getDictValue']),
  272. columns() {
  273. return [
  274. [{
  275. label: '名称:',
  276. prop: 'productName',
  277. // slot: 'productName',
  278. type: 'title',
  279. className: 'perce100',
  280. }],
  281. [{
  282. label: '编码:',
  283. prop: 'productCode'
  284. }, {
  285. label: '分类:',
  286. prop: 'productCategoryName',
  287. }],
  288. [{
  289. label: '数量:',
  290. prop: 'purchaseCount',
  291. // slot: 'purchaseCount',
  292. formatter: (item) => {
  293. if (item.purchaseCount) {
  294. return item.purchaseCount + ' ' + (item.purchaseUnit || '');
  295. }
  296. }
  297. },
  298. {
  299. label: '计量数量:',
  300. prop: 'totalCount',
  301. formatter: (item) => {
  302. if (item.totalCount) {
  303. return item.totalCount + ' ' + (item.measuringUnit || '');
  304. }
  305. }
  306. }],
  307. [{
  308. label: '包装规格:',
  309. prop: 'packingSpecification',
  310. }, {
  311. label: '物品级别:',
  312. prop: 'goodsLevel',
  313. formatter: (item) => {
  314. return levelList.find((i) => i.value == item.goodsLevel)
  315. ?.label;
  316. },
  317. }],
  318. [{
  319. label: '库存数量:',
  320. prop: 'availableCountBase',
  321. }],
  322. [{
  323. label: '已采数量:',
  324. prop: 'doneTotalCount',
  325. formatter: (item) => {
  326. if (item.doneTotalCount) {
  327. return item.doneTotalCount + ' ' + (item.measuringUnit || '');
  328. }
  329. }
  330. }, {
  331. label: '待采数量:',
  332. prop: 'waitTotalCount',
  333. formatter: (item) => {
  334. if (item.waitTotalCount) {
  335. return item.waitTotalCount + ' ' + (item.measuringUnit || '');
  336. }
  337. }
  338. }],
  339. [{
  340. label: '工序:',
  341. prop: 'taskName',
  342. }, {
  343. label: '批次号:',
  344. prop: 'batchNo',
  345. }],
  346. [{
  347. label: '供应商:',
  348. prop: 'supplierName',
  349. }, {
  350. label: '产地:',
  351. prop: 'provenance',
  352. formatter: (item) => {
  353. // return item.provenance
  354. return item.provenance && item.provenance.length
  355. ? item.provenance
  356. .map((item) => this.getDictValue('产地', item))
  357. .join(',')
  358. : '';
  359. }
  360. }],
  361. [{
  362. label: '型号:',
  363. prop: 'modelType',
  364. className: 'perce100',
  365. }],
  366. [{
  367. label: '规格:',
  368. prop: 'specification',
  369. }, {
  370. label: '品牌:',
  371. prop: 'brand',
  372. }],
  373. [{
  374. label: '机型:',
  375. prop: 'modelKey',
  376. }, {
  377. label: '颜色:',
  378. prop: 'colorKey',
  379. }],
  380. [{
  381. label: '到货方式:',
  382. prop: 'arrivalWay',
  383. formatter: (item) => {
  384. return item.arrivalWay == 1 ? '一次性到货' : '分批到货';
  385. },
  386. }],
  387. [{
  388. label: '到货日期:',
  389. prop: 'expectReceiveDate',
  390. slot: 'expectReceiveDate',
  391. }, {
  392. label: '属性类型:',
  393. prop: 'produceType',
  394. formatter: (item) => {
  395. if (item.produceType) {
  396. return item.produceType
  397. .map((i) => {
  398. return lbjtList[i];
  399. })
  400. .toString();
  401. }
  402. }
  403. }],
  404. [{
  405. label: '图纸附件:',
  406. prop: 'technicalDrawings',
  407. slot: 'technicalDrawings',
  408. }, {
  409. label: '附件:',
  410. prop: 'files',
  411. slot: 'files',
  412. }],
  413. [{
  414. label: '备注:',
  415. prop: 'remark',
  416. className: 'perce100',
  417. }],
  418. [{
  419. label: '操作:',
  420. prop: 'action',
  421. type: 'action',
  422. className: 'perce100',
  423. }],
  424. ]
  425. }
  426. },
  427. created() {
  428. // this.requestDict('产地')
  429. uni.$off('setProduceList')
  430. uni.$on('setProduceList', (data) => {
  431. data.forEach(item => {
  432. item['productId'] = item.id
  433. item['categoryName'] = item.name
  434. item['productCategoryId'] = item.categoryLevelId
  435. item['productBrand'] = item.brandNum
  436. item['productCategoryName'] = item.categoryLevelPath
  437. item['productCode'] = item.code
  438. item['productName'] = item.name
  439. item['approvalNumber'] = item.extField.approvalNumber
  440. item['packingSpecification'] = item.extField.packingSpecification
  441. item['packageDispositionList'] = item.packageDispositionList
  442. if (item.packageDispositionList?.length) {
  443. item['saleUnitId'] = item.packageDispositionList[0].id
  444. item['saleUnit'] = item.packageDispositionList[0].conversionUnit
  445. }
  446. })
  447. this.tableList.push(...data)
  448. })
  449. this.getByCode()
  450. },
  451. watch: {
  452. contractId(val) {
  453. if (val) {
  454. this.btnList = []
  455. }
  456. }
  457. },
  458. methods: {
  459. ...mapActions('dict', ['requestDict']),
  460. add() {
  461. if (this.isTemporary) {
  462. this.show = true
  463. } else {
  464. uni.navigateTo({
  465. url: '/pages/saleManage/components/selectProduce?isAll=' + 1
  466. })
  467. }
  468. },
  469. select({
  470. name
  471. }) {
  472. if (name == '选择物品清单') {
  473. uni.navigateTo({
  474. url: '/pages/saleManage/components/selectProduce?isAll=' + 1
  475. })
  476. } else {
  477. this.handlAdd()
  478. }
  479. },
  480. // 添加
  481. handlAdd() {
  482. let item = JSON.parse(JSON.stringify(this.defaultForm));
  483. item.key = this.tableList.length + 1;
  484. this.tableList.push(item);
  485. },
  486. init(list) {
  487. if (list) {
  488. this.tableList = JSON.parse(JSON.stringify(list))
  489. this.getTotalPrice(list)
  490. }
  491. },
  492. getValue() {
  493. return this.tableList
  494. },
  495. del(index) {
  496. this.tableList.splice(index, 1);
  497. },
  498. getByCode() {
  499. const codeS = ['date_unit']
  500. codeS.forEach(async (code) => {
  501. const codeValue = await getByCode(code);
  502. this[code] = codeValue.map(item => {
  503. const key = Object.keys(item)[0]
  504. return {
  505. value: key,
  506. text: item[key]
  507. }
  508. })
  509. })
  510. },
  511. save() {
  512. uni.$emit('setBusinessOpportunity')
  513. },
  514. //改变数量
  515. changeCount(row, index) {
  516. this.singleWeightChange(row, index);
  517. this.getTotalPrice();
  518. },
  519. //计算总金额
  520. getTotalPrice(row) {
  521. if (this.tableList.length) {
  522. let sum = 0;
  523. sum = this.getNumTotalPrice();
  524. let allsum = sum.toFixed(2);
  525. this.allPrice = allsum;
  526. if (!row) {
  527. uni.$emit('allsum', allsum)
  528. }
  529. return allsum;
  530. } else {
  531. this.allPrice = 0.0;
  532. if (!row) {
  533. uni.$emit('allsum', allsum)
  534. }
  535. return 0.0;
  536. }
  537. //回显总金额
  538. },
  539. //计算总金额
  540. getNumTotalPrice(sum = 0) {
  541. this.tableList.forEach((r, index) => {
  542. this.$set(
  543. r,
  544. 'discountSinglePrice',
  545. r.singlePrice ? Number(r.singlePrice) : ''
  546. );
  547. if (r.singlePrice && r.totalCount) {
  548. r.totalPrice = this.getAllPrice(r);
  549. r.discountTotalPrice = this.getDiscountTotalPrice(r);
  550. this.$set(this.tableList[index], 'totalPrice', Number(r.totalPrice));
  551. this.$set(
  552. this.tableList[index],
  553. 'discountTotalPrice',
  554. Number(r.discountTotalPrice)
  555. );
  556. sum += Number(r.totalPrice);
  557. } else {
  558. this.$set(r, 'totalPrice', '');
  559. this.$set(r, 'discountTotalPrice', '');
  560. }
  561. });
  562. return isNaN(sum) ? 0 : sum;
  563. },
  564. //计算单重
  565. singleWeightChange(row, index) {
  566. if (row.weightUnit == row.measuringUnit) {
  567. this.$set(this.tableList[index], 'totalWeight', row.totalCount);
  568. } else if (row.totalCount && row.singleWeight) {
  569. this.$set(this.tableList[index], 'totalWeight', (row.singleWeight * row.totalCount).toFixed(2) || 0);
  570. } else {
  571. this.$set(this.tableList[index], 'totalWeight', 0);
  572. }
  573. },
  574. //获取合计
  575. getAllPrice(row) {
  576. let num = Number(row.singlePrice) * Number(row.totalCount);
  577. return isNaN(num) ? '' : num.toFixed(2);
  578. },
  579. //设置优惠后总金额修改产品单价
  580. discountInputByOrder(val) {
  581. //获取优惠金额和总计的差价
  582. this.tableList.forEach((item) => {
  583. if (val === 0) {
  584. item.discountTotalPrice = 0;
  585. item.discountSinglePrice = 0;
  586. return;
  587. }
  588. if (!val) {
  589. item.discountTotalPrice = item.totalPrice;
  590. item.discountSinglePrice = item.singlePrice;
  591. return;
  592. }
  593. //获取折让单价
  594. item.discountSinglePrice = this.getDiscountSinglePrice(item, val);
  595. item.discountTotalPrice = this.getDiscountTotalPrice(item, val);
  596. });
  597. this.$forceUpdate()
  598. },
  599. //获取折让单价
  600. getDiscountSinglePrice(row, val) {
  601. let num =
  602. (Number(val) / Number(this.allPrice)) *
  603. Number(row.singlePrice);
  604. return isNaN(num) ? '' : num;
  605. },
  606. //获取折让合计
  607. getDiscountTotalPrice(row, val) {
  608. let num = Number(row.discountSinglePrice) * Number(row.totalCount);
  609. return isNaN(num) ? '' : num.toFixed(2);
  610. },
  611. //设置客户代号
  612. setCustomerMark(val) {
  613. this.tableList.forEach((item, index) => {
  614. this.$set(this.tableList[index], 'customerMark', val)
  615. })
  616. },
  617. }
  618. }
  619. </script>
  620. <style lang="scss" scoped>
  621. .add {
  622. width: 96rpx;
  623. height: 96rpx;
  624. border-radius: 48rpx;
  625. background: #3c9cff;
  626. position: fixed;
  627. bottom: 100rpx;
  628. right: 24rpx;
  629. display: flex;
  630. align-items: center;
  631. justify-content: center;
  632. z-index: 99;
  633. }
  634. .footerButton {
  635. width: 100%;
  636. height: 84rpx;
  637. display: flex;
  638. position: fixed;
  639. bottom: 0;
  640. z-index: 10;
  641. /deep/.u-button {
  642. height: 100%;
  643. }
  644. >view {
  645. flex: 1;
  646. }
  647. }
  648. /deep/.u-swipe-action-item__right__button__wrapper {
  649. background-color: #f56c6c !important;
  650. }
  651. </style>