produceList.vue 23 KB

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