produceList.vue 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880
  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. <view class="slot-box" slot="productName">
  6. <u-row>
  7. <u-col span="10">
  8. <u--input placeholder="请输入" border="surround" disabled v-model="item.productName"></u--input>
  9. </u-col>
  10. <u-col span="2">
  11. <u-button type="primary" size="mini" @click="selectProduct(item, index)" text="选择"></u-button>
  12. </u-col>
  13. </u-row>
  14. </view>
  15. <view slot="purchaseCount">
  16. <view v-if="isDrawer">
  17. {{ item.purchaseCount + ' ' + (item.purchaseUnit || '') }}
  18. </view>
  19. <view v-else>
  20. <u-row>
  21. <u-col span="6">
  22. <u--input placeholder="请输入" type="number" border="surround" v-model="item.purchaseCount" @input="changeCount(item, index)"></u--input>
  23. </u-col>
  24. <u-col span="6">
  25. <uni-data-picker v-model="item.purchaseUnitId" placeholder="请选择" :localdata="item.packageDispositionList" @change="changeCount(item, index)"></uni-data-picker>
  26. </u-col>
  27. </u-row>
  28. </view>
  29. </view>
  30. <view slot="goodsLevel">
  31. <view v-if="isDrawer">
  32. {{ item.goodsLevel }}
  33. </view>
  34. <view v-else>
  35. <uni-data-picker v-model="item.goodsLevel" placeholder="请选择" :localdata="levelList"></uni-data-picker>
  36. </view>
  37. </view>
  38. <view slot="arrivalWay">
  39. <view v-if="isDrawer">{{ item.arrivalWay }}</view>
  40. <view v-else>
  41. <uni-data-picker v-model="item.arrivalWay" placeholder="请选择" :localdata="arrivalWayList"></uni-data-picker>
  42. </view>
  43. </view>
  44. <view slot="expectReceiveDate">
  45. <view v-if="isDrawer">{{ item.expectReceiveDate }}</view>
  46. <view v-else>
  47. <view v-if="item.arrivalWay == 2">
  48. <span @click="settingDate(item, index)" style="color: #409eff;">设置分批时间</span>
  49. </view>
  50. <view v-else>
  51. <uni-datetime-picker type="date" v-model="item.expectReceiveDate"></uni-datetime-picker>
  52. </view>
  53. </view>
  54. </view>
  55. <view slot="taskName">
  56. <view v-if="isDrawer">{{ item.taskName }}</view>
  57. <view v-else>
  58. <u-row>
  59. <u-col span="10">
  60. <u--input placeholder="" disabled border="surround" v-model="item.taskName"></u--input>
  61. </u-col>
  62. <u-col span="2">
  63. <u-button type="primary" size="mini" @click="selectTaskName(item, index)" text="选择"></u-button>
  64. </u-col>
  65. </u-row>
  66. </view>
  67. </view>
  68. <view slot="supplierName">
  69. <view v-if="isDrawer">{{ item.supplierName }}</view>
  70. <view v-else>
  71. <uni-data-picker v-model="item.supplierId" placeholder="请选择" :localdata="item.supplierList"></uni-data-picker>
  72. </view>
  73. </view>
  74. <view slot="provenance">
  75. <view v-if="isDrawer">{{ getProvenance(item.provenance) }}</view>
  76. <view v-else>
  77. <!-- <uni-data-picker v-model="item.provenance" placeholder="请选择" :localdata="purchase_origin"></uni-data-picker> -->
  78. <u--input placeholder="请输入" border="surround" v-model="item.provenanceName" @click.native="changeMultiple(item, index, 'provenance', purchase_origin)"></u--input>
  79. </view>
  80. </view>
  81. <view slot="brand">
  82. <view v-if="isDrawer">{{ item.brand }}</view>
  83. <view v-else>
  84. <u--input placeholder="请输入" border="surround" disabled v-model="item.productName"></u--input>
  85. </view>
  86. </view>
  87. <view slot="modelKey">
  88. <view v-if="isDrawer">{{ item.modelKey }}</view>
  89. <view v-else>
  90. <u--input placeholder="请输入" border="surround" v-model="item.modelKey" @click.native="changeMultiple(item, index, 'modelKey', product_model_key)"></u--input>
  91. <!-- <uni-data-select
  92. :localdata="product_model_key"
  93. v-model="item.modelKey"
  94. @change="change"
  95. ></uni-data-select> -->
  96. <!-- <zxz-uni-data-select
  97. :localdata="product_model_key"
  98. v-model="item.modelKey"
  99. dataValue="value"
  100. format="{text}"
  101. dataKey="text"
  102. :clear="false"
  103. multiple
  104. ></zxz-uni-data-select> -->
  105. </view>
  106. </view>
  107. <view slot="colorKey">
  108. <view v-if="isDrawer">{{ item.colorKey }}</view>
  109. <view v-else>
  110. <u--input placeholder="请输入" border="surround" v-model="item.colorKey" @click.native="changeMultiple(item, index, 'colorKey', product_color_key)"></u--input>
  111. <!-- <uni-data-select
  112. multiple
  113. :localdata="product_color_key"
  114. v-model="item.colorKey"
  115. ></uni-data-select> -->
  116. <!-- <zxz-uni-data-select
  117. :localdata="product_color_key"
  118. v-model="item.colorKey"
  119. dataValue="value"
  120. format="{text}"
  121. dataKey="text"
  122. :clear="false"
  123. multiple
  124. ></zxz-uni-data-select> -->
  125. </view>
  126. </view>
  127. <view slot="remark">
  128. <view v-if="isDrawer">{{ item.remark }}</view>
  129. <view v-else>
  130. <u--input placeholder="请输入" border="surround" v-model="item.remark"></u--input>
  131. </view>
  132. </view>
  133. <fileMain slot="technicalDrawings" :type="isDrawer ? 'view' : ''" v-model="item.technicalDrawings"></fileMain>
  134. <fileMain slot="files" :type="isDrawer ? 'view' : ''" v-model="item.files"></fileMain>
  135. </myCard>
  136. </view>
  137. <view style="height: 84rpx;" v-if="!isDrawer"></view>
  138. <!-- <view class="footerButton" v-if="!isDrawer">
  139. <u-button type="primary" @click="save" text="保存"></u-button>
  140. </view> -->
  141. <view class="add" @click="add" v-if="!isDrawer">
  142. <u-icon name="plus" color="#fff"></u-icon>
  143. </view>
  144. <u-action-sheet :actions="addList" :show="show" :closeOnClickOverlay="true" :closeOnClickAction="true"
  145. @close="show=false" @select='select'> </u-action-sheet>
  146. <timePopup ref="timePopupRef" @confirm="handleTimeConfirm"></timePopup>
  147. <multipleSelect ref="multipleSelectRef" :range="multipleSelectRange" @confirm="handleMultipleConfirm"></multipleSelect>
  148. </view>
  149. </template>
  150. <!-- 名称,数量,到货方式,到货日期 -->
  151. <script>
  152. import {
  153. getByCode
  154. } from '@/api/pda/common.js'
  155. import myCard from './myCard.vue'
  156. import { mapActions, mapGetters } from 'vuex'
  157. import { levelList, lbjtList } from '@/enum/dict'
  158. import fileMain from "@/pages/doc/index.vue"
  159. import { changeCount } from '@/utils/setProduct.js';
  160. import timePopup from './timePopup.vue'
  161. import baTreePicker from '@/components/ba-tree-picker/ba-tree-picker.vue'
  162. import multipleSelect from './multipleSelect.vue'
  163. export default {
  164. data() {
  165. return {
  166. tableList: [],
  167. multipleSelectRange: [],
  168. addList: [
  169. { name: '选择物品清单', },
  170. { name: '新增临时产品', }
  171. ],
  172. arrivalWayList: [
  173. { text: '一次性到货', value: 1 },
  174. { text: '分批到货', value: 2 }
  175. ],
  176. show: false,
  177. purchaseUnitShow: false,
  178. current: {},
  179. currentIndex: -1,
  180. date_unit: [],
  181. product_color_key: [],
  182. product_model_key: [],
  183. purchase_origin: [],
  184. allPrice: '',
  185. btnList: [{
  186. name: '删除',
  187. apiName: 'del',
  188. btnType: 'error ',
  189. type: '2',
  190. pageUrl: '',
  191. judge: [{
  192. authorities: '',
  193. }, {
  194. // key: 'status',
  195. // value: [0, 3],
  196. fn: (row) => {
  197. return !this.isDrawer
  198. },
  199. }],
  200. }],
  201. defaultForm: {
  202. key: null,
  203. endTime: '',
  204. isFirst: 0,
  205. name: '',
  206. startTime: '',
  207. workHour: '',
  208. guaranteePeriodUnitCode: '',
  209. technicalDrawings: [],
  210. arrivalWay: 1,
  211. modelKey: '',
  212. colorKey: ''
  213. },
  214. levelList
  215. }
  216. },
  217. props: {
  218. isDrawer: {
  219. default: false
  220. },
  221. pricingWay: {
  222. default: 1
  223. },
  224. isTemporary: {
  225. //临时
  226. type: Boolean,
  227. default: false
  228. },
  229. contractId: '',
  230. },
  231. components: {
  232. myCard,
  233. fileMain,
  234. timePopup,
  235. baTreePicker,
  236. multipleSelect
  237. },
  238. computed: {
  239. ...mapGetters(['dict', 'getDict', 'getDictValue']),
  240. columns() {
  241. return [
  242. [{
  243. label: '名称:',
  244. prop: 'productName',
  245. slot: 'productName',
  246. type: 'title',
  247. className: 'perce100',
  248. }],
  249. [{
  250. label: '编码:',
  251. prop: 'productCode'
  252. }, {
  253. label: '分类:',
  254. prop: 'productCategoryName',
  255. }],
  256. [{
  257. label: '数量:',
  258. prop: 'purchaseCount',
  259. slot: 'purchaseCount',
  260. className: 'perce100',
  261. // formatter: (item) => {
  262. // if (item.purchaseCount) {
  263. // return item.purchaseCount + ' ' + (item.purchaseUnit || '');
  264. // }
  265. // }
  266. }],
  267. [
  268. {
  269. label: '计量数量:',
  270. prop: 'totalCount',
  271. formatter: (item) => {
  272. if (item.totalCount) {
  273. return item.totalCount + ' ' + (item.measuringUnit || '');
  274. }
  275. }
  276. },
  277. {
  278. label: '包装规格:',
  279. prop: 'packingSpecification',
  280. }
  281. ],
  282. [{
  283. label: '物品级别:',
  284. prop: 'goodsLevel',
  285. slot: 'goodsLevel',
  286. // formatter: (item) => {
  287. // return levelList.find((i) => i.value == item.goodsLevel)
  288. // ?.label;
  289. // },
  290. },
  291. {
  292. label: '库存数量:',
  293. prop: 'availableCountBase',
  294. }],
  295. [{
  296. label: '已采数量:',
  297. prop: 'doneTotalCount',
  298. formatter: (item) => {
  299. if (item.doneTotalCount) {
  300. return item.doneTotalCount + ' ' + (item.measuringUnit || '');
  301. }
  302. }
  303. }, {
  304. label: '待采数量:',
  305. prop: 'waitTotalCount',
  306. formatter: (item) => {
  307. if (item.waitTotalCount) {
  308. return item.waitTotalCount + ' ' + (item.measuringUnit || '');
  309. }
  310. }
  311. }],
  312. [{
  313. label: '工序:',
  314. prop: 'taskName',
  315. slot: 'taskName',
  316. className: 'perce100',
  317. }],
  318. [{
  319. label: '批次号:',
  320. prop: 'batchNo',
  321. }],
  322. [{
  323. label: '供应商:',
  324. prop: 'supplierName',
  325. slot: 'supplierName'
  326. }, {
  327. label: '产地:',
  328. prop: 'provenance',
  329. slot: 'provenance',
  330. // formatter: (item) => {
  331. // // return item.provenance
  332. // return item.provenance && item.provenance.length
  333. // ? item.provenance
  334. // .map((item) => this.getDictValue('产地', item))
  335. // .join(',')
  336. // : '';
  337. // }
  338. }],
  339. [{
  340. label: '型号:',
  341. prop: 'modelType',
  342. className: 'perce100',
  343. }],
  344. [{
  345. label: '规格:',
  346. prop: 'specification',
  347. }, {
  348. label: '品牌:',
  349. prop: 'brand',
  350. slot: 'brand'
  351. }],
  352. [{
  353. label: '机型:',
  354. prop: 'modelKey',
  355. slot: 'modelKey'
  356. }, {
  357. label: '颜色:',
  358. prop: 'colorKey',
  359. slot: 'colorKey'
  360. }],
  361. [{
  362. label: '到货方式:',
  363. prop: 'arrivalWay',
  364. slot: 'arrivalWay',
  365. // formatter: (item) => {
  366. // return item.arrivalWay == 1 ? '一次性到货' : '分批到货';
  367. // },
  368. }],
  369. [{
  370. label: '到货日期:',
  371. prop: 'expectReceiveDate',
  372. slot: 'expectReceiveDate',
  373. }, {
  374. label: '属性类型:',
  375. prop: 'produceType',
  376. formatter: (item) => {
  377. if (item.produceType) {
  378. return item.produceType
  379. .map((i) => {
  380. return lbjtList[i];
  381. })
  382. .toString();
  383. }
  384. }
  385. }],
  386. [{
  387. label: '图纸附件:',
  388. prop: 'technicalDrawings',
  389. slot: 'technicalDrawings',
  390. }, {
  391. label: '附件:',
  392. prop: 'files',
  393. slot: 'files',
  394. }],
  395. [{
  396. label: '备注:',
  397. prop: 'remark',
  398. slot: 'remark',
  399. className: 'perce100',
  400. }],
  401. [{
  402. label: '操作:',
  403. prop: 'action',
  404. type: 'action',
  405. className: 'perce100',
  406. }],
  407. ]
  408. },
  409. },
  410. created() {
  411. this.getByCode()
  412. // this.requestDict('产地')
  413. uni.$off('setProduceList')
  414. uni.$on('setProduceList', (data) => {
  415. console.log('setProduceList~~', data)
  416. data.forEach(item => {
  417. item['productId'] = item.id
  418. item['categoryName'] = item.name
  419. item['productCategoryId'] = item.categoryLevelId
  420. item['productBrand'] = item.brandNum
  421. item['productCategoryName'] = item.categoryLevelPath
  422. item['productCode'] = item.code
  423. item['productName'] = item.name
  424. item['approvalNumber'] = item.extField.approvalNumber
  425. item['packingSpecification'] = item.extField.packingSpecification
  426. item['packageDispositionList'] = item.packageDispositionList.map(i => {
  427. return {
  428. ...i,
  429. text: i.conversionUnit,
  430. value: i.id
  431. }
  432. })
  433. if (item.packageDispositionList?.length) {
  434. item['purchaseUnitId'] = item.packageDispositionList[0].id
  435. item['purchaseUnit'] = item.packageDispositionList[0].conversionUnit
  436. }
  437. })
  438. console.log(this.currentIndex, this.current)
  439. if(this.currentIndex > -1) {
  440. console.log(111)
  441. // 使用this.$set更新数组项
  442. if (data && data.length > 0) {
  443. this.$set(this.tableList, this.currentIndex, data[0]);
  444. }
  445. this.currentIndex = -1;
  446. this.current = {};
  447. } else {
  448. console.log(222)
  449. this.tableList.push(...data)
  450. }
  451. })
  452. uni.$off('setTaskName')
  453. uni.$on('setTaskName', (data) => {
  454. console.log('setTaskName~~', data)
  455. console.log(this.currentIndex, this.current)
  456. if(this.currentIndex > -1) {
  457. console.log(111)
  458. // 使用this.$set更新数组项
  459. if (data && data.length > 0) {
  460. this.$set(this.tableList[this.currentIndex], 'taskId', data[0].id);
  461. this.$set(this.tableList[this.currentIndex], 'taskName', data[0].name);
  462. this.$set(
  463. this.tableList[this.currentIndex],
  464. 'routingId',
  465. data[0].produceRoutingId
  466. );
  467. }
  468. this.currentIndex = -1;
  469. this.current = {};
  470. }
  471. })
  472. uni.$off('setPBomList')
  473. uni.$on('setPBomList', (data, idx = -1) => {
  474. console.log('setPBomList~~', data)
  475. data.forEach((item, index) => {
  476. let i = idx == -1 ? index : idx;
  477. let row = JSON.parse(JSON.stringify(this.defaultForm));
  478. row.key = this.tableList.length + 1;
  479. let parasm = idx == -1 ? row : this.tableList[i];
  480. this.$set(parasm, 'productId', item.id);
  481. // this.$set(parasm, 'id', item.id);
  482. this.$set(parasm, 'categoryName', item.name);
  483. this.$set(parasm, 'productCategoryId', item.categoryLevelId);
  484. this.$set(parasm, 'productBrand', item.brandNum);
  485. this.$set(
  486. parasm,
  487. 'productCategoryName',
  488. item.category.categoryLevelPath
  489. );
  490. this.$set(parasm, 'totalCount', item.dosage);
  491. this.$set(parasm, 'productCode', item.code);
  492. this.$set(parasm, 'productName', item.name);
  493. this.$set(parasm, 'availableCountBase', item.availableCountBase);
  494. this.$set(parasm, 'modelType', item.modelType);
  495. this.$set(parasm, 'weightUnit', item.unit);
  496. this.$set(parasm, 'measuringUnit', item.unit);
  497. this.$set(parasm, 'specification', item.specification);
  498. this.$set(parasm, 'remark', '');
  499. this.$set(parasm, 'imgCode', item.imgCode);
  500. this.$set(parasm, 'produceType', item.componentAttribute);
  501. this.$set(parasm, 'approvalNumber', item.extField?.approvalNumber);
  502. this.$set(parasm, 'goodsLevel', item.goodsLevel);
  503. this.$set(parasm, 'supplierList', item.supplierList);
  504. this.$set(parasm, 'supplierCode', item.supplierCode);
  505. this.$set(parasm, 'supplierId', item.supplierId);
  506. this.$set(parasm, 'supplierName', item.supplierName);
  507. // if (item.modelKey) {
  508. // this.$set(parasm, 'modelKey', item.modelKey.split(','));
  509. // }
  510. // if (item.colorKey) {
  511. // this.$set(parasm, 'colorKey', item.colorKey.split(','));
  512. // }
  513. this.$set(
  514. parasm,
  515. 'packageDispositionList',
  516. item.packageDispositionList?.map(i => {
  517. return {
  518. ...i,
  519. text: i.conversionUnit,
  520. value: i.id
  521. }
  522. }) || []
  523. );
  524. if (item.packageDispositionList?.length) {
  525. this.$set(
  526. parasm,
  527. 'purchaseUnitId',
  528. item.packageDispositionList[0].id
  529. );
  530. this.$set(
  531. parasm,
  532. 'purchaseUnit',
  533. item.packageDispositionList[0].conversionUnit
  534. );
  535. }
  536. this.$set(
  537. parasm,
  538. 'packingSpecification',
  539. item.extField?.packingSpecification
  540. );
  541. this.$set(parasm, 'provenance', item.purchaseOrigins || '');
  542. this.$set(parasm, 'provenanceName', this.getProvenance(item.provenance));
  543. if (idx == -1) {
  544. this.tableList.push(row);
  545. }
  546. });
  547. })
  548. },
  549. onUnload() {
  550. uni.$off('setProduceList')
  551. uni.$off('setTaskName')
  552. uni.$off('setPBomList')
  553. },
  554. watch: {
  555. contractId(val) {
  556. if (val) {
  557. this.btnList = []
  558. }
  559. }
  560. },
  561. methods: {
  562. ...mapActions('dict', ['requestDict']),
  563. openPicker() {
  564. this.$refs.treePicker._show()
  565. },
  566. getProvenance(item) {
  567. console.log('getProvenance~~~~~', item)
  568. // try {
  569. // 检查item和provenance是否存在
  570. if (!item) {
  571. return '';
  572. }
  573. let arr = item;
  574. if(!Array.isArray(arr)) {
  575. console.log('arr is not array, convert to array')
  576. arr = arr.split(',');
  577. }
  578. return arr && arr.length ? arr.map((i) => {
  579. return this.purchase_origin.find(p => p.value == i)?.text
  580. }).join(',') : '';
  581. },
  582. changeMultiple(item, index, key, range) {
  583. console.log(item, index)
  584. this.current = item;
  585. this.currentIndex = index;
  586. this.multipleSelectRange = range
  587. this.$refs.multipleSelectRef.open(item, index, key)
  588. },
  589. handleMultipleConfirm(data, key) {
  590. this.$set(this.tableList[this.currentIndex], key, data)
  591. if(key == 'provenance'){
  592. this.$set(this.tableList[this.currentIndex], 'provenanceName', this.getProvenance(data))
  593. }
  594. },
  595. change(e){
  596. console.log('e:',e);
  597. },
  598. settingDate(item, index) {
  599. console.log(item, index)
  600. this.current = item;
  601. this.currentIndex = index;
  602. this.$refs.timePopupRef.open(item, index)
  603. },
  604. handleTimeConfirm(data) {
  605. this.$set(this.tableList[this.currentIndex], 'arrivalBatch', data)
  606. },
  607. add() {
  608. this.currentIndex = -1;
  609. this.current = {};
  610. this.c
  611. if (this.isTemporary) {
  612. this.show = true
  613. } else {
  614. uni.navigateTo({
  615. url: '/pages/purchasingManage/components/selectProduce?isAll=' + 1
  616. })
  617. }
  618. },
  619. select({
  620. name
  621. }) {
  622. if (name == '选择物品清单') {
  623. uni.navigateTo({
  624. url: '/pages/purchasingManage/components/selectProduce?isAll=' + 1
  625. })
  626. } else {
  627. this.handlAdd()
  628. }
  629. },
  630. selectProduct(item, index) {
  631. this.current = item;
  632. this.currentIndex = index;
  633. uni.navigateTo({
  634. url: '/pages/purchasingManage/components/selectProduce?isAll=' + 2
  635. })
  636. },
  637. selectTaskName(item, index) {
  638. console.log(item, index)
  639. this.current = item;
  640. this.currentIndex = index;
  641. uni.navigateTo({
  642. url: '/pages/purchasingManage/components/selectTaskName?isAll=' + 2
  643. })
  644. },
  645. // 添加
  646. handlAdd() {
  647. let item = JSON.parse(JSON.stringify(this.defaultForm));
  648. item.key = this.tableList.length + 1;
  649. this.tableList.push(item);
  650. },
  651. init(list) {
  652. if (list) {
  653. this.tableList = JSON.parse(JSON.stringify(list))
  654. // this.getTotalPrice(list)
  655. }
  656. },
  657. getValue() {
  658. return this.tableList
  659. },
  660. del(index) {
  661. this.tableList.splice(index, 1);
  662. },
  663. getByCode() {
  664. const codeS = ['product_model_key', 'product_color_key', 'purchase_origin']
  665. codeS.forEach(async (code) => {
  666. const codeValue = await getByCode(code);
  667. this[code] = codeValue.map(item => {
  668. const key = Object.keys(item)[0]
  669. return {
  670. value: key,
  671. text: item[key]
  672. }
  673. })
  674. console.log(code, this[code])
  675. })
  676. console.log('1111~~~~~~~~~', this.purchase_origin)
  677. },
  678. save() {
  679. uni.$emit('setBusinessOpportunity')
  680. },
  681. //改变数量
  682. changeCount(row, index) {
  683. // this.singleWeightChange(row, index);
  684. // this.getTotalPrice();
  685. this.$set(
  686. this.tableList,
  687. index,
  688. changeCount(row, {
  689. countKey: 'purchaseCount',
  690. unitKey: 'purchaseUnit',
  691. unitIdKey: 'purchaseUnitId'
  692. })
  693. );
  694. this.$forceUpdate();
  695. },
  696. //计算总金额
  697. getTotalPrice(row) {
  698. if (this.tableList.length) {
  699. let sum = 0;
  700. sum = this.getNumTotalPrice();
  701. let allsum = sum.toFixed(2);
  702. this.allPrice = allsum;
  703. if (!row) {
  704. uni.$emit('allsum', allsum)
  705. }
  706. return allsum;
  707. } else {
  708. this.allPrice = 0.0;
  709. if (!row) {
  710. uni.$emit('allsum', allsum)
  711. }
  712. return 0.0;
  713. }
  714. //回显总金额
  715. },
  716. //计算总金额
  717. getNumTotalPrice(sum = 0) {
  718. this.tableList.forEach((r, index) => {
  719. this.$set(
  720. r,
  721. 'discountSinglePrice',
  722. r.singlePrice ? Number(r.singlePrice) : ''
  723. );
  724. if (r.singlePrice && r.totalCount) {
  725. r.totalPrice = this.getAllPrice(r);
  726. r.discountTotalPrice = this.getDiscountTotalPrice(r);
  727. this.$set(this.tableList[index], 'totalPrice', Number(r.totalPrice));
  728. this.$set(
  729. this.tableList[index],
  730. 'discountTotalPrice',
  731. Number(r.discountTotalPrice)
  732. );
  733. sum += Number(r.totalPrice);
  734. } else {
  735. this.$set(r, 'totalPrice', '');
  736. this.$set(r, 'discountTotalPrice', '');
  737. }
  738. });
  739. return isNaN(sum) ? 0 : sum;
  740. },
  741. //计算单重
  742. singleWeightChange(row, index) {
  743. if (row.weightUnit == row.measuringUnit) {
  744. this.$set(this.tableList[index], 'totalWeight', row.totalCount);
  745. } else if (row.totalCount && row.singleWeight) {
  746. this.$set(this.tableList[index], 'totalWeight', (row.singleWeight * row.totalCount).toFixed(2) || 0);
  747. } else {
  748. this.$set(this.tableList[index], 'totalWeight', 0);
  749. }
  750. },
  751. //获取合计
  752. getAllPrice(row) {
  753. let num = Number(row.singlePrice) * Number(row.totalCount);
  754. return isNaN(num) ? '' : num.toFixed(2);
  755. },
  756. //设置优惠后总金额修改产品单价
  757. discountInputByOrder(val) {
  758. //获取优惠金额和总计的差价
  759. this.tableList.forEach((item) => {
  760. if (val === 0) {
  761. item.discountTotalPrice = 0;
  762. item.discountSinglePrice = 0;
  763. return;
  764. }
  765. if (!val) {
  766. item.discountTotalPrice = item.totalPrice;
  767. item.discountSinglePrice = item.singlePrice;
  768. return;
  769. }
  770. //获取折让单价
  771. item.discountSinglePrice = this.getDiscountSinglePrice(item, val);
  772. item.discountTotalPrice = this.getDiscountTotalPrice(item, val);
  773. });
  774. this.$forceUpdate()
  775. },
  776. //获取折让单价
  777. getDiscountSinglePrice(row, val) {
  778. let num =
  779. (Number(val) / Number(this.allPrice)) *
  780. Number(row.singlePrice);
  781. return isNaN(num) ? '' : num;
  782. },
  783. //获取折让合计
  784. getDiscountTotalPrice(row, val) {
  785. let num = Number(row.discountSinglePrice) * Number(row.totalCount);
  786. return isNaN(num) ? '' : num.toFixed(2);
  787. },
  788. //设置客户代号
  789. setCustomerMark(val) {
  790. this.tableList.forEach((item, index) => {
  791. this.$set(this.tableList[index], 'customerMark', val)
  792. })
  793. },
  794. }
  795. }
  796. </script>
  797. <style lang="scss" scoped>
  798. .add {
  799. width: 96rpx;
  800. height: 96rpx;
  801. border-radius: 48rpx;
  802. background: #3c9cff;
  803. position: fixed;
  804. bottom: 100rpx;
  805. right: 24rpx;
  806. display: flex;
  807. align-items: center;
  808. justify-content: center;
  809. z-index: 99;
  810. }
  811. .slot-box {
  812. display: flex;
  813. }
  814. .footerButton {
  815. width: 100%;
  816. height: 84rpx;
  817. display: flex;
  818. position: fixed;
  819. bottom: 0;
  820. z-index: 10;
  821. /deep/.u-button {
  822. height: 100%;
  823. }
  824. >view {
  825. flex: 1;
  826. }
  827. }
  828. /deep/.u-swipe-action-item__right__button__wrapper {
  829. background-color: #f56c6c !important;
  830. }
  831. </style>