orderPay.vue 19 KB

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