orderPay.vue 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733
  1. <template>
  2. <view class="container">
  3. <view class="address-info-box" @click="selectAddress()">
  4. <view class="address-icon">
  5. <text class="iconfont icondizhi"></text>
  6. </view>
  7. <view class="address-content">
  8. <text class="address-info">
  9. <text class="address-name">{{addressData.username}}</text>
  10. <text class="address-phone">{{addressData.phone}}</text>
  11. </text>
  12. <view class="address-detail">{{addressData.address}}</view>
  13. </view>
  14. <view class="address-link">
  15. <text class="iconfont iconfangxiang"></text>
  16. </view>
  17. </view>
  18. <view class="goods-info-box">
  19. <view class="shop-info">
  20. <text class="iconfont icondianpu"></text>
  21. <text class="shop-name">{{orderData.supplierName}}</text>
  22. <text class="iconfont iconfangxiang"></text>
  23. </view>
  24. <view class="goods-list">
  25. <view class="goods-row" v-for="(item, index) in orderData.goodsList" :key="index">
  26. <cover-image class="goods-img" :src="item.imgUrl"></cover-image>
  27. <view class="goods-info">
  28. <view class="goods-name">{{item.productName}}</view>
  29. <view class="goods-type">
  30. 类型:{{item.productType == 1 ? '普通商品' : (item.productType == 2 ? '拍卖商品' : (item.productType == 3 ? '自助采摘' : '共享种植'))}}
  31. </view>
  32. <view class="plant-area" v-if="orderType == 3">面积:{{orderData.areaSize}}㎡</view>
  33. <view class="goods-price-number">
  34. <text class="goods-unit">¥</text>
  35. <text class="goods-price">{{orderType == 1 ? item.bizPrice : paySum}}</text>
  36. <text class="goods-number">x{{item.buyNum}}</text>
  37. <text class="plant-text" v-if="orderType == 3">有效期:{{orderData.term}}天</text>
  38. </view>
  39. </view>
  40. </view>
  41. </view>
  42. <view class="order-info">
  43. <u-cell-group :border="false">
  44. <u-cell-item title="商品金额" :arrow="false" :border-bottom="false" title-width="170" :title-style="{textAlign: 'right'}">
  45. <text class="order-text-right">¥{{orderType == 1 ? getAllGoodsInitialPrice() : paySum}}</text>
  46. </u-cell-item>
  47. <u-cell-item title="积分抵扣" :arrow="false" :border-bottom="false" title-width="170" :title-style="{textAlign: 'right'}"
  48. v-if="orderType == 1">
  49. <view>
  50. <text class="order-text-left">-{{getIntegral()+'积分'}}</text>
  51. <text class="order-text-right">-¥{{(getIntegral()/100).toFixed(2)}}</text>
  52. </view>
  53. </u-cell-item>
  54. <u-cell-item title="优惠卷" :border-bottom="false" title-width="170" :title-style="{textAlign: 'right'}" @click="showCoupon()"
  55. v-if="orderType == 1">
  56. <view>
  57. <text class="order-text-left">{{coupon.couponName}}</text>
  58. <text class="order-text-right">-¥{{coupon.discountAmount.toFixed(2)}}</text>
  59. </view>
  60. </u-cell-item>
  61. <u-field label="备注" v-model="notes" placeholder="请输入备注" :border-bottom="false" label-align="right" label-width="170"
  62. :field-style="{marginLeft: '16px'}"></u-field>
  63. </u-cell-group>
  64. </view>
  65. <view class="pay-info">
  66. <text class="pay-text">共{{getAllGoodsNumber()}}件</text>
  67. <text class="pay-text">总计</text>
  68. <text class="pay-price">¥{{orderType == 1 ? getAllGoodsPrice() : paySum}}</text>
  69. </view>
  70. </view>
  71. <view class="handle-box">
  72. <view class="handle-info">
  73. <text class="handle-text" style="margin-right: 12px;">共{{getAllGoodsNumber()}}件</text>
  74. <text class="handle-text">合计:</text>
  75. <text class="handle-price">¥{{orderType == 1 ? getAllGoodsPrice() : paySum}}</text>
  76. </view>
  77. <view class="handle-button" @click="submitOrder()">提交订单</view>
  78. </view>
  79. <uni-popup ref="popup" type="bottom">
  80. <view class="coupon-box">
  81. <view class="coupon-row" v-for="(item, index) in couponList" :key="index" @click="selectCoupon(item)">
  82. <view class="coupon-left">
  83. <view class="coupon-left-price"><text style="font-size: 16px;">¥</text>{{item.discountAmount}}</view>
  84. <view class="coupon-left-text">满减金额</view>
  85. </view>
  86. <view class="coupon-info">
  87. <view class="coupon-text1">{{item.couponName}}</view>
  88. <view class="coupon-text1" style="margin-bottom: 4px;">满{{item.fullAmount}}减{{item.discountAmount}}</view>
  89. <view class="coupon-text2">{{item.couponType == 1 ? '仅限用于' + item.supplierName + '的店铺' : ''}}</view>
  90. <view class="coupon-text2" style="color: #999999;">有效期:{{item.publishStartTime}}~{{item.useEndTime}}</view>
  91. </view>
  92. </view>
  93. </view>
  94. </uni-popup>
  95. <u-top-tips ref="uTips"></u-top-tips>
  96. </view>
  97. </template>
  98. <script>
  99. const NET = require('@/utils/request')
  100. const API = require('@/config/api')
  101. export default {
  102. data() {
  103. return {
  104. flag: 1,
  105. orderType: 1,
  106. addressData: {
  107. memberAddressId: '',
  108. username: '',
  109. phone: '',
  110. province: '',
  111. city: '',
  112. area: '',
  113. address: '',
  114. },
  115. userData: {},
  116. orderData: {
  117. tenantCode: '',
  118. supplierName: '',
  119. areaSize: '',
  120. term: '',
  121. goodsList: []
  122. },
  123. integral: 0,
  124. coupon: {
  125. couponId: '',
  126. couponName: '',
  127. discountAmount: 0,
  128. couponType: '',
  129. },
  130. couponList: [],
  131. notes: '',
  132. paySum: 0,
  133. }
  134. },
  135. onLoad(options) {
  136. this.orderType = options.orderType
  137. this.paySum = options.paySum ? options.paySum : 0
  138. this.flag = options.flag
  139. this.userData = uni.getStorageSync("userData")
  140. this.orderData = uni.getStorageSync("orderData")
  141. if (!uni.getStorageSync("defaultAddress")) {
  142. NET.request(API.getAddressList, {}, 'POST').then(res => {
  143. if (res.data.find(site => site.isDefault == 1)) {
  144. let address = res.data.find(site => site.isDefault == 1)
  145. this.addressData = {
  146. memberAddressId: address.id,
  147. username: address.username,
  148. phone: address.phone,
  149. province: address.province,
  150. city: address.city,
  151. area: address.area,
  152. address: address.address
  153. }
  154. }
  155. }).catch(error => {
  156. this.$refs.uTips.show({
  157. title: '获取默认地址失败',
  158. type: 'warning',
  159. })
  160. })
  161. }
  162. if (this.orderType == 1) {
  163. NET.request(API.getIntegral, {}, 'POST').then(res => {
  164. this.mineIntegral = res.data.usableIntegral
  165. }).catch(error => {
  166. this.$refs.uTips.show({
  167. title: '获取个人积分失败',
  168. type: 'warning',
  169. })
  170. })
  171. NET.request(API.getUsableCouponList, {
  172. tenantCode: this.orderData.tenantCode,
  173. totalPrice: this.getAllGoodsInitialPrice(),
  174. }, 'GET').then(res => {
  175. this.couponList = res.data
  176. }).catch(error => {
  177. this.$refs.uTips.show({
  178. title: '获取优惠券列表失败',
  179. type: 'warning',
  180. })
  181. })
  182. }
  183. },
  184. onShow() {
  185. if (uni.getStorageSync("defaultAddress")) {
  186. this.addressData = uni.getStorageSync("defaultAddress")
  187. }
  188. },
  189. methods: {
  190. // 获取全部商品原价格
  191. getAllGoodsInitialPrice() {
  192. let price = this.orderData.goodsList.reduce((total, site) => {
  193. return total + site.bizPrice * site.buyNum
  194. }, 0)
  195. return price.toFixed(2)
  196. },
  197. // 获取全部价格
  198. getAllGoodsPrice() {
  199. let price = this.orderData.goodsList.reduce((total, site) => {
  200. return total + site.bizPrice * site.buyNum
  201. }, 0)
  202. return (price - this.coupon.discountAmount - (this.getIntegral() / 100)).toFixed(2)
  203. },
  204. // 获取全部商品数量
  205. getAllGoodsNumber() {
  206. let number = this.orderData.goodsList.reduce((total, site) => {
  207. return total + site.buyNum
  208. }, 0)
  209. return number
  210. },
  211. // 选择地址
  212. selectAddress() {
  213. uni.navigateTo({
  214. url: '/pagesMain/addressList?type=2'
  215. });
  216. },
  217. // 获取积分
  218. getIntegral() {
  219. let price = this.orderData.goodsList.reduce((total, site) => {
  220. return total + site.bizPrice * site.buyNum
  221. }, 0) - this.coupon.discountAmount
  222. if (this.integral / 100 > price) {
  223. return price * 100
  224. } else {
  225. return this.integral
  226. }
  227. },
  228. // 显示优惠券弹窗
  229. showCoupon() {
  230. this.$refs.popup.open()
  231. },
  232. // 选择优惠券
  233. selectCoupon(item) {
  234. this.coupon = {
  235. couponId: item.couponId,
  236. couponName: item.couponName,
  237. discountAmount: item.discountAmount,
  238. couponType: item.couponType,
  239. }
  240. this.$refs.popup.close()
  241. },
  242. // 提交订单
  243. submitOrder() {
  244. if (!this.addressData.username) {
  245. this.$refs.uTips.show({
  246. title: '请选择地址',
  247. type: 'warning',
  248. })
  249. } else {
  250. NET.request(API.submitOrder, {
  251. // 会员
  252. mid: this.userData.userId,
  253. nickname: this.userData.userName,
  254. // 地址
  255. ...this.addressData,
  256. // 商铺
  257. supplierName: this.orderData.supplierName,
  258. tenantCode: this.orderData.tenantCode,
  259. // 商品
  260. productIds: this.orderData.goodsList.map(site => {
  261. return site.productId
  262. }).join(','),
  263. productType: this.orderData.goodsList.map(site => {
  264. return site.productType
  265. }).join(','),
  266. products: this.orderData.goodsList.map(site => {
  267. return {
  268. ...site,
  269. supplierName: this.orderData.supplierName,
  270. tenantCode: this.orderData.tenantCode,
  271. bizPrice: this.orderType == 1 ? site.bizPrice : this.paySum,
  272. }
  273. }),
  274. // 优惠券
  275. couponId: this.orderType == 1 ? this.coupon.couponId : '',
  276. couponDiscountAmount: this.orderType == 1 ? this.coupon.discountAmount : '',
  277. couponType: this.orderType == 1 ? this.coupon.couponType : '',
  278. // 积分
  279. integralValue: this.orderType == 1 ? this.getIntegral() : 0,
  280. integralAmount: this.orderType == 1 ? this.getIntegral() / 100 : 0,
  281. // 金额
  282. discountAmount: this.orderType == 1 ? (parseFloat(this.coupon.discountAmount) + (this.getIntegral() / 100)) : 0,
  283. orderSum: this.orderType == 1 ? this.orderData.goodsList.reduce((total, site) => {
  284. return total + site.bizPrice * site.buyNum
  285. }, 0) : this.paySum,
  286. paySum: this.orderType == 1 ? this.getAllGoodsPrice() : this.paySum,
  287. // 支付类型
  288. flag: this.flag,
  289. orderType: this.orderType,
  290. // 备注
  291. notes: this.notes,
  292. }, 'POST').then(res => {
  293. uni.requestPayment({
  294. provider: 'wxpay',
  295. timeStamp: res.data.timeStamp,
  296. nonceStr: res.data.nonceStr,
  297. package: res.data.packageValue,
  298. signType: res.data.signType,
  299. paySign: res.data.paySign,
  300. success: (payRes) => {
  301. console.log('success:' + JSON.stringify(payRes));
  302. uni.reLaunch({
  303. url: '/pagesMain/paySuccess'
  304. });
  305. },
  306. fail: (error) => {
  307. console.log('fail:' + JSON.stringify(error));
  308. this.$refs.uTips.show({
  309. title: '支付失败',
  310. type: 'warning',
  311. })
  312. }
  313. })
  314. }).catch(error => {
  315. this.$refs.uTips.show({
  316. title: '提交订单失败',
  317. type: 'warning',
  318. })
  319. })
  320. }
  321. },
  322. },
  323. }
  324. </script>
  325. <style lang="less" scoped>
  326. page {
  327. width: 100%;
  328. height: 100%;
  329. }
  330. .container {
  331. width: 100%;
  332. height: 100%;
  333. float: left;
  334. background-color: #f7f7f7;
  335. box-sizing: border-box;
  336. padding-bottom: 70px;
  337. overflow-y: auto;
  338. .address-info-box {
  339. width: calc(100% - 32px);
  340. float: left;
  341. box-sizing: border-box;
  342. padding: 16px 18px 16px 16px;
  343. margin: 10px 16px;
  344. background: #FFFFFF;
  345. border-radius: 10px;
  346. .address-icon {
  347. width: 36px;
  348. height: 40px;
  349. float: left;
  350. align-items: center;
  351. display: flex;
  352. .iconfont {
  353. color: #52A63A;
  354. font-size: 36px;
  355. }
  356. }
  357. .address-content {
  358. width: calc(100% - 66px);
  359. height: 40px;
  360. float: left;
  361. margin: 0 8px 0 12px;
  362. .address-info {
  363. height: 20px;
  364. font-family: PingFang SC;
  365. line-height: 20px;
  366. overflow: hidden;
  367. text-overflow: ellipsis;
  368. white-space: nowrap;
  369. .address-name {
  370. font-size: 16px;
  371. color: #333333;
  372. margin-right: 14px;
  373. }
  374. .address-phone {
  375. font-size: 12px;
  376. color: #666666;
  377. }
  378. }
  379. .address-detail {
  380. height: 20px;
  381. font-size: 16px;
  382. font-family: PingFang SC;
  383. color: #333333;
  384. line-height: 20px;
  385. overflow: hidden;
  386. text-overflow: ellipsis;
  387. white-space: nowrap;
  388. }
  389. }
  390. .address-link {
  391. width: 10px;
  392. height: 40px;
  393. float: left;
  394. align-items: center;
  395. display: flex;
  396. .iconfont {
  397. color: #999999;
  398. font-size: 12px;
  399. }
  400. }
  401. }
  402. .goods-info-box {
  403. width: calc(100% - 32px);
  404. float: left;
  405. margin: 0 16px 10px 16px;
  406. background: #FFFFFF;
  407. border-radius: 10px;
  408. .shop-info {
  409. width: 100%;
  410. height: 48px;
  411. float: left;
  412. box-sizing: border-box;
  413. padding: 13px 15px 12px 15px;
  414. border-bottom: 1px solid #EEEEEE;
  415. line-height: 22px;
  416. .icondianpu {
  417. font-size: 22px;
  418. color: #333333;
  419. }
  420. .shop-name {
  421. font-size: 15px;
  422. font-family: PingFang SC;
  423. color: #333333;
  424. margin: 0 8px 0 10px;
  425. }
  426. .iconshangjia {
  427. font-size: 12px;
  428. color: #999999;
  429. }
  430. }
  431. .goods-list {
  432. width: 100%;
  433. float: left;
  434. box-sizing: border-box;
  435. padding: 10px 15px 0 15px;
  436. .goods-row {
  437. width: 100%;
  438. height: 90px;
  439. float: left;
  440. display: flex;
  441. margin-bottom: 10px;
  442. .goods-img {
  443. width: 90px;
  444. height: 90px;
  445. border-radius: 5px;
  446. object-fit: cover;
  447. }
  448. .goods-info {
  449. width: calc(100% - 106px);
  450. height: 90px;
  451. margin-left: 16px;
  452. .goods-name {
  453. width: 100%;
  454. height: 36px;
  455. float: left;
  456. font-size: 14px;
  457. font-family: PingFang SC;
  458. color: #333333;
  459. line-height: 18px;
  460. overflow: hidden;
  461. text-overflow: ellipsis;
  462. display: -webkit-box;
  463. -webkit-line-clamp: 2;
  464. -webkit-box-orient: vertical;
  465. word-wrap: break-word;
  466. }
  467. .goods-type {
  468. height: 20px;
  469. float: left;
  470. background: #F0F0F0;
  471. border-radius: 4px;
  472. padding: 0 8px;
  473. margin: 6px 0;
  474. font-size: 10px;
  475. font-family: PingFang SC;
  476. color: #666666;
  477. line-height: 20px;
  478. }
  479. .plant-area {
  480. height: 20px;
  481. float: right;
  482. margin: 6px 0;
  483. font-size: 12px;
  484. font-family: PingFang SC;
  485. color: #333333;
  486. }
  487. .goods-price-number {
  488. width: 100%;
  489. height: 20px;
  490. float: left;
  491. line-height: 20px;
  492. font-family: PingFang SC;
  493. color: #333333;
  494. .goods-unit {
  495. font-size: 12px;
  496. }
  497. .goods-price {
  498. font-size: 15px;
  499. margin-right: 6px;
  500. }
  501. .goods-number {
  502. font-size: 12px;
  503. }
  504. }
  505. .plant-text {
  506. float: right;
  507. font-size: 12px;
  508. font-family: PingFang SC;
  509. color: #333333;
  510. }
  511. }
  512. }
  513. }
  514. .order-info {
  515. width: 100%;
  516. float: left;
  517. .order-text-left {
  518. font-size: 13px;
  519. font-family: PingFang SC;
  520. color: #666666;
  521. float: left;
  522. margin-left: 16px;
  523. }
  524. .order-text-right {
  525. font-size: 13px;
  526. font-family: PingFang SC;
  527. color: #52A63A;
  528. }
  529. /deep/.u-cell_title {
  530. color: #333333;
  531. }
  532. /deep/.u-label-text {
  533. color: #333333;
  534. }
  535. }
  536. .pay-info {
  537. width: 100%;
  538. height: 46px;
  539. float: left;
  540. box-sizing: border-box;
  541. border-top: 1px solid #EEEEEE;
  542. padding-right: 15px;
  543. line-height: 44px;
  544. font-family: PingFang SC;
  545. font-size: 14px;
  546. text-align: right;
  547. white-space: nowrap;
  548. .pay-text {
  549. color: #333333;
  550. margin-right: 6px;
  551. }
  552. .pay-price {
  553. color: #52A63A;
  554. }
  555. }
  556. }
  557. .handle-box {
  558. width: 100%;
  559. height: 70px;
  560. box-sizing: border-box;
  561. padding: 15px 0 15px 16px;
  562. position: fixed;
  563. bottom: 0;
  564. background: #FFFFFF;
  565. box-shadow: 0px 3px 13px 0px rgba(0, 0, 0, 0.15);
  566. .handle-info {
  567. width: calc(100% - 110px);
  568. height: 40px;
  569. float: left;
  570. line-height: 40px;
  571. font-family: PingFang SC;
  572. text-align: left;
  573. white-space: nowrap;
  574. .handle-text {
  575. font-size: 16px;
  576. color: #666666;
  577. }
  578. .handle-price {
  579. font-size: 15px;
  580. color: #52A63A;
  581. }
  582. }
  583. .handle-button {
  584. width: 100px;
  585. height: 40px;
  586. float: right;
  587. box-sizing: border-box;
  588. padding-left: 10px;
  589. background: #52A63A;
  590. border-radius: 20px 0px 0px 20px;
  591. font-size: 15px;
  592. font-family: PingFang SC;
  593. color: #FFFFFF;
  594. line-height: 40px;
  595. text-align: center;
  596. }
  597. }
  598. .coupon-box {
  599. width: 100vw;
  600. height: 500px;
  601. background-color: #FFFFFF;
  602. border-radius: 15px 15px 0px 0px;
  603. box-sizing: border-box;
  604. padding: 16px 16px 0 16px;
  605. overflow-y: auto;
  606. .coupon-row {
  607. width: 100%;
  608. height: 105px;
  609. float: left;
  610. margin-bottom: 10px;
  611. border-radius: 10px;
  612. background: #FFFFFF;
  613. box-shadow: 0px 0px 10px 0px rgba(103, 103, 103, 0.3);
  614. overflow: hidden;
  615. .coupon-left {
  616. width: 107px;
  617. height: 105px;
  618. box-sizing: border-box;
  619. padding-right: 10px;
  620. float: left;
  621. background-size: 107px 105px;
  622. background-position: center;
  623. background-repeat: no-repeat;
  624. background-image: url(@/static/images/couponHead.png);
  625. .coupon-left-price {
  626. width: 100%;
  627. height: 24px;
  628. float: left;
  629. margin: 28px 0 12px 0;
  630. font-size: 24px;
  631. font-family: PingFang SC;
  632. color: #FFFFFF;
  633. line-height: 24px;
  634. text-align: center;
  635. }
  636. .coupon-left-text {
  637. width: 100%;
  638. height: 20px;
  639. float: left;
  640. color: #FFFFFF;
  641. font-size: 12px;
  642. font-family: PingFang SC;
  643. line-height: 20px;
  644. text-align: center;
  645. }
  646. }
  647. .coupon-info {
  648. width: calc(100% - 115px);
  649. height: 100%;
  650. float: right;
  651. box-sizing: border-box;
  652. padding: 16px 0 12px 0;
  653. .coupon-text1 {
  654. width: 100%;
  655. height: 20px;
  656. float: right;
  657. font-size: 15px;
  658. font-family: PingFang SC;
  659. color: #333333;
  660. line-height: 20px;
  661. white-space: nowrap;
  662. text-overflow: ellipsis;
  663. overflow: hidden;
  664. }
  665. .coupon-text2 {
  666. width: 100%;
  667. height: 18px;
  668. float: right;
  669. font-size: 13px;
  670. font-family: PingFang SC;
  671. color: #EB5F2F;
  672. line-height: 18px;
  673. white-space: nowrap;
  674. text-overflow: ellipsis;
  675. overflow: hidden;
  676. }
  677. }
  678. }
  679. }
  680. }
  681. </style>