shoppingCart.vue 28 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971
  1. <template>
  2. <view v-if="checkStatus == '通过'">
  3. <view style="background-color: #fff;padding: 20rpx;border-radius: 20rpx;">
  4. <view style="display: flex;justify-content: space-between;">
  5. <view>
  6. <view style="display: flex;width: 580rpx;" v-if="!editDel" @click="clickAddress">
  7. <u-icon name="map"></u-icon>
  8. <u--text :text="addres.belongtoarea + addres.detailedAddress" size="28rpx" lines="1"></u--text>
  9. </view>
  10. </view>
  11. <!-- <view style="display: flex;">
  12. <view style="margin-right: 40rpx;">|</view>
  13. <view @click="editDel = !editDel">{{editDel?'取消':'编辑'}}</view>
  14. </view> -->
  15. </view>
  16. </view>
  17. <u-checkbox-group v-model="companyValue" placement="column" @change="companyChange" :size='28'>
  18. <view class="collection" v-for="(item,index) in dataList" :key="index">
  19. <view style="margin-left: 40rpx;">
  20. <u-checkbox activeColor="#FD4B09" shape="circle" :customStyle="{marginBottom: '8px'}"
  21. :label="item.name" :name="item.name" labelSize="36rpx"></u-checkbox>
  22. </view>
  23. <view style="margin-left: 20rpx;display: flex;align-items: center;" v-for="(ite,ind) in item.list"
  24. :key="ind">
  25. <view>
  26. <image v-for="(li,inde) in ite.filesList" :key="inde" v-if="li.version === '0'" :src="li.url"
  27. style="width: 200rpx;height: 200rpx;border-radius: 20rpx;">
  28. </image>
  29. </view>
  30. <view class="goods">
  31. <view style="display: flex;">
  32. <u--text :text="ite.goodsName" size="24rpx" lines="2"></u--text>
  33. <u-icon name="trash" size="52rpx" @click="deleteGoods(ite.id)"></u-icon>
  34. </view>
  35. <view class="price">
  36. <view>¥{{ite.price}}</view>
  37. <view v-if="!editDel">
  38. <u-number-box v-model="ite.goodsNum" :min="1" buttonSize="40rpx"
  39. @change="(val)=>{statistics(val,index,ind)}"></u-number-box>
  40. </view>
  41. </view>
  42. </view>
  43. <!-- <view v-if="editDel">
  44. </view> -->
  45. </view>
  46. </view>
  47. </u-checkbox-group>
  48. <view style="height: 120rpx;"></view>
  49. <view class="submitBar">
  50. <view class="bar_view">
  51. <view style="display: flex;align-items: center;">
  52. <view style="margin-left: 40rpx;">
  53. <u-checkbox-group v-model="radiovalue" placement="column" @change="radioGroupChange" :size='28'>
  54. <u-checkbox label="全选" name="全选" activeColor="#FD4B09" shape="circle"
  55. :labelSize='18'></u-checkbox>
  56. </u-checkbox-group>
  57. </view>
  58. <view v-if="!editDel" style="margin-left: 20rpx;">
  59. <view>总计:¥<text>{{totalPrice}}</text></view>
  60. <view style="font-size: 22rpx;color: #FD4B09;">运费:¥{{totalFreight}}</view>
  61. </view>
  62. </view>
  63. <view style="height: 120rpx;display: flex;color: #fff;">
  64. <view v-if="!editDel" class="lvbutton" @click="submit('W01')">他人代付</view>
  65. <view v-if="!editDel" class="redbutton" @click="submit()">立即支付</view>
  66. <view v-else class="redbutton" @click="deleteShopping">删除</view>
  67. <!-- <u-button shape="circle" size="small" text="立即支付" v-if="!editDel"
  68. :disabled="this.selectedProduct.length == 0"
  69. color="linear-gradient(0deg, #FD5003 0%, #FBA680 100%)" @click="submit"></u-button>
  70. <u-button shape="circle" size="small" text="删除" v-else :disabled="this.selectedProduct.length == 0"
  71. color="linear-gradient(0deg, #FD5003 0%, #FBA680 100%)" @click="deleteShopping"></u-button> -->
  72. </view>
  73. </view>
  74. </view>
  75. <u-empty style="position: absolute;top: 45%;left: 50%;transform:translate(-50%,-50%)"
  76. v-if="dataList.length == 0" mode="car" icon="http://cdn.uviewui.com/uview/empty/car.png" />
  77. <u-popup :show="qrcodeshow" mode="center" :closeable="true" @close="qrcodeclose">
  78. <view style="padding: 20rpx;">
  79. <view style="font-size: 26rpx;">截屏二维码支付</view>
  80. <view>
  81. <uqrcode ref="uqrcode" canvas-id="qrcode" size="600" sizeUnit="rpx" :value="qrcodeurl"
  82. :options="{ margin: 5 }"></uqrcode>
  83. <!-- options 配置项 https://uqrcode.cn/doc/document/native.html#%E5%AE%9E%E4%BE%8B%E6%96%B9%E6%B3%95 -->
  84. </view>
  85. <view>
  86. <!-- {{qrcodeData.contacts}} -->
  87. <view style="font-size: 34rpx;font-weight: 500;">{{qrcodeData.salesCompanyName}}</view>
  88. <view style="color: #9a9a9a;font-size: 26rpx;">
  89. <text>金额:</text>
  90. <text style="color: #FD4B09;font-size: 30rpx;">¥{{qrcodeData.salesAmount}}</text>
  91. </view>
  92. <view style="color: #9a9a9a;font-size: 26rpx;">二维码有效期: {{qrcodeData.businesDate}}</view>
  93. </view>
  94. </view>
  95. </u-popup>
  96. <!-- 提取去登录 -->
  97. <u-modal :show="adminShow" :showCancelButton="true" content='当前还未登录请先登录!!' @confirm="adminConfirm"
  98. @cancel="adminCancel"></u-modal>
  99. <u-modal :show="inventoryShow" title="库存不足" @confirm="inventoryShow=false;inventoryContent='';companyValue=[]">
  100. <view class="slot-content">
  101. <rich-text :nodes="inventoryContent"></rich-text>
  102. </view>
  103. </u-modal>
  104. </view>
  105. </template>
  106. <script>
  107. import {
  108. shoppingCartList,
  109. generateOrder,
  110. generateOrderLimit,
  111. shoppingCartUpdate,
  112. getCorpsAddr,
  113. paramserviceDetail,
  114. getParamservice,
  115. isProcurement,
  116. generateOrderShare
  117. } from '@/api/tabBar/shoppingCart.js'
  118. import {
  119. registerRuntimeCompiler
  120. } from "vue"
  121. import {
  122. details
  123. } from '@/api/views/personalInformation/index.js'
  124. import {
  125. appDetail
  126. } from '@/api/views/salesSlip/index.js'
  127. import {
  128. activityList
  129. } from '@/api/tabBar/activity.js'
  130. export default {
  131. data() {
  132. return {
  133. qrcodeshow: false, // 二维码弹窗
  134. qrcodeData: [], // 二维码数据
  135. qrcodeurl: '', // 二维码参数
  136. editDel: false,
  137. radiovalue: [],
  138. companyValue: [],
  139. dataList: [],
  140. companyValueLength: 0,
  141. selectedProduct: [],
  142. totalPrice: 0.00,
  143. totalFreight: 0.00,
  144. addres: {},
  145. checkStatus: null,
  146. adminShow: false,
  147. inventoryShow: false,
  148. inventoryContent: '',
  149. freight: 5,
  150. }
  151. },
  152. watch: {
  153. companyValue() {
  154. if (this.companyValue.length != 0 || this.companyValueLength != 0) {
  155. if (this.companyValue.length == this.companyValueLength) {
  156. this.radiovalue = ["全选"]
  157. } else {
  158. this.radiovalue = []
  159. }
  160. }
  161. this.statistics()
  162. }
  163. },
  164. onShow() {
  165. activityList({
  166. current: 1,
  167. size: 10,
  168. status: 1
  169. }).then(res => {
  170. uni.setTabBarBadge({
  171. index: 2, // tabIndex,tabBar的哪一项,从0开始
  172. text: res.data.total.toString() // 显示的文本,超过 99 显示成 “…”
  173. })
  174. })
  175. if (uni.getStorageSync('userInfo').tenant_id == '000000') {
  176. this.adminShow = true
  177. return
  178. }
  179. // 获取审核状态
  180. details().then(res => {
  181. this.checkStatus = res.data.checkStatus
  182. uni.setStorageSync('checkStatus', res.data.checkStatus);
  183. console.log(1111111)
  184. if (this.checkStatus != '通过') {
  185. uni.showToast({
  186. title: "当前用户未授权,请联系客服",
  187. icon: "none",
  188. mask: true
  189. });
  190. // uni.switchTab({
  191. // url:'/pages/tabBar/home'
  192. // })
  193. // return
  194. }
  195. })
  196. this.editDel = false
  197. this.companyValue = []
  198. shoppingCartList({
  199. whetherIntegral: '0'
  200. }).then(res => {
  201. this.dataList = res.data
  202. this.companyValueLength = this.dataList.length
  203. this.inventoryfun(res.data)
  204. let num = 0
  205. res.data.forEach(e => {
  206. console.log(e.list)
  207. num = num + e.list.length
  208. })
  209. uni.setTabBarBadge({
  210. index: 3, // tabIndex,tabBar的哪一项,从0开始
  211. text: num.toString() // 显示的文本,超过 99 显示成 “…”
  212. })
  213. })
  214. getCorpsAddr().then(res => {
  215. this.addres = res.data
  216. })
  217. // 支付成功之后的回调
  218. let options = wx.getEnterOptionsSync();
  219. if (options.scene == '1038' && options.referrerInfo.appId == 'wxef277996acc166c3') {
  220. // 代表从收银台小程序返回
  221. let extraData = options.referrerInfo.extraData;
  222. if (!extraData) {
  223. // "当前通过物理按键返回,未接收到返参,建议自行查询交易结果";
  224. console.log('当前通过物理按键返回,未接收到返参,建议自行查询交易结果');
  225. } else {
  226. if (extraData.code == 'success') {
  227. // "支付成功";
  228. } else if (extraData.code == 'cancel') {
  229. // "支付已取消";
  230. console.log(extraData, '支付已取消');
  231. } else {
  232. console.log(extraData, '失败');
  233. // "支付失败:" + extraData.errmsg;
  234. }
  235. }
  236. }
  237. isProcurement({
  238. "param": "freight"
  239. }).then(res => {
  240. // res.data.data === '1'
  241. this.freight = res.data
  242. })
  243. },
  244. methods: {
  245. // 库存弹窗
  246. inventoryfun(arr) {
  247. let sum = ''
  248. arr.map((item, index) => {
  249. item.list.map(ite => {
  250. if (Number(ite.goodsNum) > Number(ite.inventory)) {
  251. sum += `${ite.goodsName} 的库存数量为${ite.inventory}<br>`
  252. }
  253. return ite
  254. })
  255. return item
  256. })
  257. if (sum != '') {
  258. this.inventoryContent = sum + '请修正数量后重新结算'
  259. this.inventoryShow = true
  260. return true
  261. }
  262. return false
  263. },
  264. // admin确认
  265. adminConfirm() {
  266. uni.clearStorageSync();
  267. uni.redirectTo({
  268. url: '/pages/login/login'
  269. })
  270. },
  271. // admin取消
  272. adminCancel() {
  273. uni.switchTab({
  274. url: '/pages/tabBar/home'
  275. })
  276. },
  277. // 弹窗关闭
  278. qrcodeclose() {
  279. this.qrcodeshow = false
  280. uni.showLoading({
  281. title: '加载中',
  282. mask: true
  283. });
  284. // 详情调用
  285. shoppingCartList({
  286. whetherIntegral: '0'
  287. }).then(res => {
  288. this.dataList = res.data
  289. this.companyValueLength = this.dataList.length
  290. uni.hideLoading();
  291. }).catch(err => {
  292. uni.hideLoading();
  293. })
  294. },
  295. clickAddress() {
  296. this.$u.route('/pages/views/personalInformation/addressManagement');
  297. },
  298. getList() {
  299. shoppingCartList({
  300. whetherIntegral: '0'
  301. }).then(res => {
  302. this.dataList = res.data
  303. this.companyValueLength = this.dataList.length
  304. let num = 0
  305. res.data.forEach(e => {
  306. num = num + e.list.length
  307. })
  308. uni.setTabBarBadge({
  309. index: 3, // tabIndex,tabBar的哪一项,从0开始
  310. text: num.toString() // 显示的文本,超过 99 显示成 “…”
  311. })
  312. uni.hideLoading();
  313. }).catch(err => {
  314. uni.hideLoading();
  315. })
  316. },
  317. deleteGoods(val) {
  318. let _this = this
  319. uni.showModal({
  320. title: '提示',
  321. content: '是否删除?',
  322. success: function(res) {
  323. if (res.confirm) {
  324. uni.showLoading({
  325. title: '加载中',
  326. mask: true
  327. });
  328. shoppingCartUpdate({
  329. ids: val
  330. }).then(res => {
  331. uni.showToast({
  332. title: "删除成功",
  333. icon: 'none'
  334. });
  335. uni.showLoading({
  336. title: '加载中',
  337. mask: true
  338. });
  339. _this.getList()
  340. // this.editDel = false
  341. _this.companyValue = []
  342. uni.hideLoading();
  343. }).catch(err => {
  344. uni.hideLoading();
  345. })
  346. } else if (res.cancel) {
  347. console.log('用户点击取消');
  348. }
  349. }
  350. });
  351. },
  352. deleteShopping() {
  353. if (this.selectedProduct.length == 0) {
  354. uni.showToast({
  355. title: "请先选择要支付的商品",
  356. icon: 'none'
  357. });
  358. return
  359. }
  360. let data = []
  361. for (let item of this.companyValue) {
  362. for (let ite of this.dataList) {
  363. if (item == ite.name) {
  364. for (let it of ite.list) {
  365. data.push(it.id)
  366. }
  367. }
  368. }
  369. }
  370. uni.showLoading({
  371. title: '加载中',
  372. mask: true
  373. });
  374. shoppingCartUpdate({
  375. ids: data.join(',')
  376. }).then(res => {
  377. uni.showToast({
  378. title: "删除成功",
  379. icon: 'none'
  380. });
  381. uni.hideLoading({
  382. noConflict: true
  383. });
  384. uni.showLoading({
  385. title: '加载中',
  386. mask: true
  387. });
  388. this.editDel = false
  389. this.companyValue = []
  390. shoppingCartList({
  391. whetherIntegral: '0'
  392. }).then(res => {
  393. this.dataList = res.data
  394. this.companyValueLength = this.dataList.length
  395. uni.hideLoading();
  396. }).catch(err => {
  397. uni.hideLoading();
  398. })
  399. }).catch(err => {
  400. uni.hideLoading();
  401. })
  402. },
  403. // 立即支付
  404. submit() {
  405. if (this.selectedProduct.length == 0) {
  406. uni.showToast({
  407. title: "请先选择要支付的商品",
  408. icon: 'none'
  409. });
  410. return
  411. }
  412. if (this.inventoryfun(this.dataList)) {
  413. return
  414. }
  415. isProcurement({
  416. "param": "whether.open.share"
  417. }).then(res => {
  418. if (res.data == 1) {
  419. //共享支付流程
  420. this.sharedPayment()
  421. } else {
  422. //正常支付流程
  423. this.normalPayment()
  424. }
  425. })
  426. },
  427. //原来支付流程
  428. async normalPayment() {
  429. if (this.companyValue.length > 0) {
  430. let data = []
  431. for (let item of this.companyValue) {
  432. for (let ite of this.dataList) {
  433. if (item == ite.name) {
  434. data.push({
  435. name: item,
  436. list: ite.list
  437. })
  438. }
  439. }
  440. }
  441. uni.showLoading({
  442. title: '加载中',
  443. mask: true
  444. });
  445. // 判断是否用额度支付
  446. const personRef = await details()
  447. const totalPrice = Number(this.totalPrice) + Number(this.totalFreight)
  448. // 是否开通额度
  449. getParamservice(1, 10, {
  450. paramKey: 'WeChat.shipping.notification'
  451. }).then(res => {
  452. console.log(res)
  453. if (res.data.records.length > 0) {
  454. let payType = res.data.records[0].paramValue == 1 ? 'W11' : 'W06'
  455. if (personRef.data.ifLimitAmount == 1) {
  456. // 额度是否够用
  457. if (Number(personRef.data.limitAmount >= totalPrice)) {
  458. // 额度
  459. // this.payType='W06'
  460. generateOrderLimit({
  461. payType: res.data.records[0].paramValue == 1 ? 'W11' : 'W06',
  462. address: this.addres.belongtoarea + this.addres
  463. .detailedAddress,
  464. list: data,
  465. }).then(res => {
  466. uni.hideLoading();
  467. uni.showToast({
  468. title: '支付成功',
  469. mask: true,
  470. duration: 2000
  471. });
  472. setTimeout(function() {
  473. uni.hideLoading({
  474. noConflict: true
  475. });
  476. }, 1000);
  477. // 详情调用
  478. shoppingCartList({
  479. whetherIntegral: '0'
  480. }).then(res => {
  481. this.dataList = res.data
  482. this.companyValueLength = this.dataList.length
  483. }).catch(err => {})
  484. })
  485. return
  486. }
  487. }
  488. // 正常支付
  489. generateOrder({
  490. payType: res.data.records[0].paramValue == 1 ? 'W11' : 'W06',
  491. address: this.addres.belongtoarea + this.addres.detailedAddress,
  492. list: data,
  493. }).then(res => {
  494. let generateOrderData = res.data
  495. paramserviceDetail({
  496. paramKey: 'cashier.payment'
  497. }).then(res => {
  498. let paramservice = res.data
  499. // paramservice.paramValue=0
  500. // 判断是调支付台的接口还是微信支付的接口
  501. if (paramservice && paramservice.paramValue == '1') {
  502. console.log(222211111111);
  503. // uni.hideLoading();
  504. // uni.requestPayment({
  505. // provider: "wxpay",
  506. // appId: generateOrderData.appId,
  507. // timeStamp: generateOrderData.timeStamp,
  508. // nonceStr: generateOrderData.nonceStr,
  509. // package: generateOrderData.package,
  510. // signType: generateOrderData.signType,
  511. // paySign: generateOrderData.paySign,
  512. // success(res) {
  513. // uni.showToast({
  514. // title: '支付成功',
  515. // mask: true,
  516. // duration: 2000
  517. // });
  518. // setTimeout(function() {
  519. // uni.hideLoading();
  520. // // this_.refresh(res.data.data.id)
  521. // }, 1000);
  522. // },
  523. // fail(e) {
  524. // console.log(e,11111111);
  525. // uni.showToast({
  526. // title: "支付失败",
  527. // icon: 'none',
  528. // mask: true
  529. // });
  530. // setTimeout(function() {
  531. // uni.hideLoading();
  532. // // this_.refresh(res.data.id)
  533. // }, 1000);
  534. // }
  535. // })
  536. let obj = {
  537. appId: 'wxef277996acc166c3',
  538. extraData: {
  539. cusid: generateOrderData.cusid,
  540. appid: generateOrderData.appid,
  541. orgid: generateOrderData.orgid,
  542. version: generateOrderData.version,
  543. trxamt: generateOrderData.trxamt,
  544. reqsn: generateOrderData.reqsn,
  545. notify_url: generateOrderData.notify_url,
  546. body: generateOrderData.body,
  547. remark: generateOrderData.remark,
  548. validtime: generateOrderData.validtime,
  549. limit_pay: generateOrderData.limit_pay,
  550. randomstr: generateOrderData.randomstr,
  551. paytype: generateOrderData.paytype,
  552. signtype: generateOrderData.signtype,
  553. sign: generateOrderData.sign,
  554. },
  555. }
  556. console.log(obj);
  557. if (!generateOrderData.reqsn) {
  558. uni.showToast({
  559. title: '当前订单号为空,请联系供应商!!!',
  560. icon: 'none',
  561. mask: true,
  562. duration: 2000
  563. });
  564. // 详情调用
  565. shoppingCartList({
  566. whetherIntegral: '0'
  567. }).then(res => {
  568. this.dataList = res.data
  569. this.companyValueLength = this.dataList
  570. .length
  571. }).catch(err => {})
  572. return
  573. }
  574. wx.openEmbeddedMiniProgram({
  575. appId: 'wxef277996acc166c3',
  576. extraData: {
  577. cusid: generateOrderData.cusid,
  578. appid: generateOrderData.appid,
  579. orgid: generateOrderData.orgid,
  580. version: generateOrderData.version,
  581. trxamt: generateOrderData.trxamt,
  582. reqsn: generateOrderData.reqsn,
  583. notify_url: generateOrderData
  584. .notify_url,
  585. body: generateOrderData.body,
  586. remark: generateOrderData.remark,
  587. validtime: generateOrderData.validtime,
  588. // limit_pay: generateOrderData.limit_pay,
  589. limit_pay: "",
  590. randomstr: generateOrderData.randomstr,
  591. paytype: generateOrderData.paytype,
  592. signtype: generateOrderData.signtype,
  593. sign: generateOrderData.sign,
  594. },
  595. success: (a) => {
  596. uni.hideLoading();
  597. },
  598. fail: (err) => {
  599. uni.hideLoading();
  600. }
  601. })
  602. } else {
  603. console.log(2222222222222222);
  604. if (payType && (payType == 'W01' || payType == 'U01' ||
  605. payType == 'A01' || payType == 'S01'
  606. )) {
  607. console.log(generateOrderData, 321);
  608. // 订单详情接口
  609. this.qrcodeurl = generateOrderData.url
  610. appDetail({
  611. id: generateOrderData.id
  612. }).then(res => {
  613. uni.hideLoading();
  614. this.qrcodeshow = true
  615. this.qrcodeData = res.data
  616. console.log(res.data);
  617. })
  618. } else {
  619. uni.requestPayment({
  620. provider: "wxpay",
  621. appId: generateOrderData.appId,
  622. timeStamp: generateOrderData.timeStamp,
  623. nonceStr: generateOrderData.nonceStr,
  624. package: generateOrderData.package,
  625. signType: generateOrderData.signType,
  626. paySign: generateOrderData.paySign,
  627. success(res) {
  628. uni.showToast({
  629. title: '支付成功',
  630. mask: true,
  631. duration: 2000
  632. });
  633. setTimeout(function() {
  634. uni.hideLoading({
  635. noConflict: true
  636. });
  637. // this_.refresh(res.data.data.id)
  638. }, 1000);
  639. },
  640. fail(e) {
  641. console.log(22222222);
  642. uni.showToast({
  643. title: "支付失败",
  644. icon: 'none',
  645. mask: true
  646. });
  647. setTimeout(function() {
  648. uni.hideLoading({
  649. noConflict: true
  650. });
  651. // this_.refresh(res.data.id)
  652. }, 1000);
  653. }
  654. })
  655. }
  656. }
  657. })
  658. }).catch(err => {
  659. uni.hideLoading();
  660. })
  661. }
  662. })
  663. }
  664. },
  665. sharedPayment() {
  666. if (this.companyValue.length > 0) {
  667. let data = []
  668. for (let item of this.companyValue) {
  669. for (let ite of this.dataList) {
  670. if (item == ite.name) {
  671. data = data.concat(ite.list)
  672. }
  673. }
  674. }
  675. let obj = {
  676. address: this.addres.belongtoarea + this.addres.detailedAddress,
  677. shoppingCartList: data,
  678. }
  679. uni.showLoading({
  680. title: '加载中',
  681. mask: true
  682. });
  683. generateOrderShare(obj).then(res => {
  684. // res.data.type=0
  685. let generateOrderData = res.data
  686. //小程序支付
  687. if (res.data.type == '0') {
  688. uni.requestPayment({
  689. provider: "wxpay",
  690. appId: generateOrderData.appId,
  691. timeStamp: generateOrderData.timeStamp,
  692. nonceStr: generateOrderData.nonceStr,
  693. package: generateOrderData.package,
  694. signType: generateOrderData.signType,
  695. paySign: generateOrderData.paySign,
  696. success(res) {
  697. uni.showToast({
  698. title: '支付成功',
  699. mask: true,
  700. duration: 2000
  701. });
  702. setTimeout(function() {
  703. uni.hideLoading({
  704. noConflict: true
  705. });
  706. // this_.refresh(res.data.data.id)
  707. }, 1000);
  708. },
  709. fail(e) {
  710. console.log(22222222);
  711. uni.showToast({
  712. title: "支付失败",
  713. icon: 'none',
  714. mask: true
  715. });
  716. setTimeout(function() {
  717. uni.hideLoading({
  718. noConflict: true
  719. });
  720. // this_.refresh(res.data.id)
  721. }, 1000);
  722. }
  723. })
  724. }
  725. //收银台支付 'w06'
  726. if (res.data.type == '1') {
  727. wx.openEmbeddedMiniProgram({
  728. appId: 'wxef277996acc166c3',
  729. extraData: {
  730. cusid: generateOrderData.cusid,
  731. appid: generateOrderData.appid,
  732. orgid: generateOrderData.orgid,
  733. version: generateOrderData.version,
  734. trxamt: generateOrderData.trxamt,
  735. reqsn: generateOrderData.reqsn,
  736. notify_url: generateOrderData.notify_url,
  737. body: generateOrderData.body,
  738. remark: generateOrderData.remark,
  739. validtime: generateOrderData.validtime,
  740. // limit_pay: generateOrderData.limit_pay,
  741. limit_pay: "",
  742. randomstr: generateOrderData.randomstr,
  743. paytype: generateOrderData.paytype,
  744. signtype: generateOrderData.signtype,
  745. sign: generateOrderData.sign,
  746. },
  747. success: (a) => {
  748. uni.hideLoading();
  749. },
  750. fail: (err) => {
  751. uni.hideLoading();
  752. }
  753. })
  754. }
  755. //额度支付
  756. if (res.data.type == '2') {
  757. details().then(res => {
  758. const personRef = res
  759. const totalPrice = Number(this.totalPrice) + Number(this.totalFreight)
  760. // 是否开通额度
  761. isProcurement({
  762. "param": "WeChat.shipping.notification"
  763. }).then(res => {
  764. if (personRef.data.ifLimitAmount == 1) {
  765. // 额度是否够用
  766. if (Number(personRef.data.limitAmount >= totalPrice)) {
  767. // 额度
  768. // this.payType='W06'
  769. generateOrderLimit({
  770. payType: res.data == 1 ? 'W11' : 'W06',
  771. address: this.addres.belongtoarea +
  772. this.addres
  773. .detailedAddress,
  774. list: data,
  775. }).then(res => {
  776. uni.hideLoading();
  777. uni.showToast({
  778. title: '支付成功',
  779. mask: true,
  780. duration: 2000
  781. });
  782. setTimeout(function() {
  783. uni.hideLoading({
  784. noConflict: true
  785. });
  786. }, 1000);
  787. // 详情调用
  788. shoppingCartList({
  789. whetherIntegral: '0'
  790. }).then(res => {
  791. this.dataList = res.data
  792. this.companyValueLength =
  793. this.dataList.length
  794. }).catch(err => {})
  795. })
  796. }
  797. }
  798. })
  799. })
  800. }
  801. })
  802. }
  803. },
  804. radioGroupChange(e) {
  805. this.radiovalue = e
  806. if (e.length == 0) {
  807. this.companyValue = []
  808. } else {
  809. for (let li of this.dataList) {
  810. if (!this.companyValue.includes(li.name)) {
  811. this.companyValue.push(li.name)
  812. }
  813. }
  814. }
  815. this.inventoryfun(this.dataList)
  816. this.statistics()
  817. },
  818. radioGroupChange(e) {
  819. this.radiovalue = e
  820. if (e.length == 0) {
  821. this.companyValue = []
  822. } else {
  823. for (let li of this.dataList) {
  824. if (!this.companyValue.includes(li.name)) {
  825. this.companyValue.push(li.name)
  826. }
  827. }
  828. }
  829. this.inventoryfun(this.dataList)
  830. this.statistics()
  831. },
  832. statistics(val, index, ind) {
  833. console.log(val, index, ind)
  834. if (val) {
  835. this.dataList[index].list[ind].goodsNum = val.value
  836. }
  837. let data = []
  838. // for (let item of this.companyValue) {
  839. // for (let ite of this.dataList) {
  840. // if (item == ite.name) {
  841. // for (let it of ite.list) {
  842. // data.push(it)
  843. // }
  844. // }
  845. // }
  846. // }、
  847. for (let item of this.companyValue) {
  848. for (let ite of this.dataList) {
  849. if (item == ite.name) {
  850. data.push({
  851. name: item,
  852. list: ite.list
  853. })
  854. }
  855. }
  856. }
  857. this.totalPrice = 0
  858. this.totalFreight = 0
  859. let num = 0
  860. for (let item of data) {
  861. let num1 = 0
  862. for (let items of item.list) {
  863. this.totalPrice += Number(items.price) * Number(items.goodsNum)
  864. num += Number(items.goodsNum)
  865. num1 += Number(items.goodsNum)
  866. }
  867. if (num1 == 1) {
  868. this.totalFreight += this.freight ? Number(this.freight) : 5
  869. }
  870. }
  871. /* if(num>1){
  872. this.totalFreight = 0
  873. } */
  874. this.totalFreight = this.totalFreight.toFixed(2)
  875. this.totalPrice = this.totalPrice.toFixed(2)
  876. this.selectedProduct = data
  877. },
  878. companyChange(n) {
  879. this.companyValue = n
  880. this.inventoryfun(this.dataList)
  881. }
  882. }
  883. }
  884. </script>
  885. <style lang="scss" scoped>
  886. .collection {
  887. background-color: #fff;
  888. padding: 20rpx 40rpx 20rpx 20rpx;
  889. border-radius: 20rpx;
  890. margin-top: 20rpx;
  891. }
  892. .goods {
  893. width: 100%;
  894. margin-left: 20rpx;
  895. height: 200rpx;
  896. display: grid;
  897. align-content: space-between;
  898. .price {
  899. display: flex;
  900. justify-content: space-between !important;
  901. margin-top: 20rpx;
  902. align-items: center;
  903. view:nth-child(1) {
  904. color: #FD4B09;
  905. font-size: 40rpx;
  906. }
  907. }
  908. }
  909. .submitBar {
  910. position: fixed;
  911. bottom: 0;
  912. background-color: #fff;
  913. width: 100%;
  914. z-index: 10;
  915. .bar_view {
  916. display: flex;
  917. justify-content: space-between;
  918. align-items: center;
  919. // padding: 10rpx;
  920. }
  921. }
  922. .redbutton {
  923. background-color: #FD4B09;
  924. height: 120rpx;
  925. line-height: 120rpx;
  926. width: 160rpx;
  927. text-align: center;
  928. }
  929. .lvbutton {
  930. background-color: #4c9e44;
  931. height: 120rpx;
  932. line-height: 120rpx;
  933. width: 160rpx;
  934. text-align: center;
  935. }
  936. </style>