orderPay.vue 18 KB

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