推拿小程序前端代码仓库
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

324 lines
6.4 KiB

4 months ago
4 months ago
4 months ago
4 months ago
4 months ago
4 months ago
4 months ago
4 months ago
4 months ago
4 months ago
4 months ago
4 months ago
4 months ago
4 months ago
4 months ago
4 months ago
4 months ago
4 months ago
4 months ago
4 months ago
4 months ago
4 months ago
4 months ago
4 months ago
4 months ago
4 months ago
4 months ago
4 months ago
4 months ago
4 months ago
4 months ago
4 months ago
4 months ago
  1. <template>
  2. <view class="page">
  3. <view class="bg"></view>
  4. <view class="content">
  5. <!-- 导航栏 -->
  6. <navbar title="商品支付" leftClick @leftClick="$utils.navigateBack" bgColor="transparent" color="#fff" />
  7. <!-- 商品详情 -->
  8. <productCard :data="payOrderProduct[0]" size="medium" :readonly="true"></productCard>
  9. <view class="card payment">
  10. <uv-radio-group v-model="payMethod">
  11. <view class="flex payment-item">
  12. <image class="icon" src="../static/createOrder/icon-wx.png" mode="widthFix"></image>
  13. <text class="label">微信支付</text>
  14. <uv-radio :name="0" activeColor="#84A73F" size="39rpx" icon-size="39rpx"/>
  15. </view>
  16. <view class="flex payment-item">
  17. <image class="icon" src="../static/createOrder/icon-account.png" mode="widthFix"></image>
  18. <!-- todo: check -->
  19. <text class="label">账户余额<text class="desc">{{ `(余额:¥${userInfo.price || 0}` }}</text></text>
  20. <uv-radio :name="1" activeColor="#84A73F" size="39rpx" icon-size="39rpx"/>
  21. </view>
  22. </uv-radio-group>
  23. </view>
  24. <!-- 优惠券 -->
  25. <view @click="openCoupon" class="card flex coupon">
  26. <image class="icon" src="@/pages_order/static/createOrder/icon-coupon.png" mode="widthFix"></image>
  27. <!-- todo: check is selected coupon -->
  28. <view class="label">优惠券<text v-if="selectedCoupon[0]" class="desc">{{ `满减券:${coupon.discountAmount}` }}</text></view>
  29. <view v-if="selectedCoupon[0]">
  30. <uv-checkbox-group v-model="selectedCoupon" shape="circle" >
  31. <uv-checkbox :name="1" size="39rpx" icon-size="39rpx" activeColor="#84A73F"></uv-checkbox>
  32. </uv-checkbox-group>
  33. </view>
  34. <template v-else>
  35. <image class="icon-arrow" src="../static/createOrder/icon-arrow.png" mode="widthFix"></image>
  36. </template>
  37. </view>
  38. </view>
  39. <!-- 下单 -->
  40. <view class="flex bar">
  41. <view class="flex count">
  42. <text>合计</text>
  43. <view class="price">
  44. <text class="price-unit">¥</text>
  45. <text>{{ totalPrice }}</text>
  46. </view>
  47. </view>
  48. <view class="btn btn-pay" @click="submit">
  49. 立即支付
  50. </view>
  51. </view>
  52. <!-- 优惠券选择-->
  53. <uv-popup ref="couponPopup" :round="30">
  54. <couponList ref="couponList" height="60vh" :status="0" :maxLimit="totalPrice" @select="selectCoupon" />
  55. </uv-popup>
  56. <configPopup ref="popup"></configPopup>
  57. </view>
  58. </template>
  59. <script>
  60. import productCard from '@/components/product/productCard.vue'
  61. import couponList from '@/components/couponList/couponList.vue'
  62. import {
  63. mapState
  64. } from 'vuex'
  65. export default {
  66. components: {
  67. productCard,
  68. couponList
  69. },
  70. data() {
  71. return {
  72. orderId: null,
  73. selectedCoupon: [],
  74. num: 1,
  75. coupon: {},
  76. payMethod : 0,
  77. }
  78. },
  79. computed: {
  80. totalPrice() {
  81. let price = 0
  82. this.payOrderProduct.forEach(n => {
  83. price += n.price * (n.num || 1)
  84. })
  85. if (this.coupon.id) {
  86. price -= (this.coupon.money || 0)
  87. }
  88. return Number(Number(price).toFixed(2))
  89. },
  90. ...mapState(['userInfo', 'payOrderProduct']),
  91. },
  92. onLoad({ id }) {
  93. this.orderId = id
  94. if(uni.getStorageSync('token')) {
  95. this.$store.commit('getUserInfo')
  96. this.$store.commit('getUserCenterInfo')
  97. }
  98. },
  99. onShow() {
  100. },
  101. methods: {
  102. //获取优惠券列表
  103. getCouponList() {
  104. this.$refs.couponList.getCouponList()
  105. },
  106. // 打开优惠券选择
  107. openCoupon() {
  108. this.$refs.couponPopup.open('bottom')
  109. this.$nextTick(() => {
  110. this.getCouponList()
  111. })
  112. },
  113. // 选择优惠券
  114. selectCoupon(e) {
  115. this.coupon = e
  116. this.$refs.couponPopup.close()
  117. this.selectedCoupon = [1]
  118. },
  119. async fetchPayOrder() {
  120. // todo: check
  121. let params = {
  122. payType : this.payMethod,
  123. // id: this.payOrderProduct[0].id,
  124. // num: this.payOrderProduct[0].num,
  125. // memberNum : 1,
  126. }
  127. let api = 'createOrder'
  128. if (this.orderId) { // 支付订单
  129. params.orderId = this.orderId
  130. api = 'payOrder'
  131. } else { // 创建订单
  132. params.itemId = this.payOrderProduct[0].id
  133. params.amount = this.totalPrice
  134. }
  135. const res = await this.$fetch(api, params, false)
  136. return res
  137. },
  138. async submit() {
  139. try {
  140. const res = await this.fetchPayOrder()
  141. if (!res.success) {
  142. return
  143. }
  144. if (this.payMethod == 1) { // 账户余额
  145. } else { // 微信支付
  146. console.log('--发起支付接口回调', res)
  147. // #ifdef MP-WEIXIN
  148. await uni.requestPaymentWxPay(res)
  149. // #endif
  150. // #ifdef H5
  151. console.log('$wxPay');
  152. await this.$wxPay(res)
  153. // #endif
  154. }
  155. uni.showToast({
  156. title: '下单成功',
  157. icon: 'none'
  158. })
  159. setTimeout(uni.redirectTo, 700, {
  160. url: '/pages/index/order'
  161. })
  162. } catch (err) {
  163. }
  164. },
  165. }
  166. }
  167. </script>
  168. <style scoped lang="scss">
  169. $bar-height: 132rpx;
  170. .page {
  171. overflow: auto;
  172. padding-bottom: calc(#{$bar-height} + env(safe-area-inset-bottom));
  173. background-color: #F5F5F5;
  174. .bg {
  175. width: 100vw;
  176. height: 331rpx;
  177. background-image: linear-gradient(#84A73F, #D8FF8F);
  178. }
  179. .content {
  180. position: absolute;
  181. left: 0;
  182. top: 0;
  183. width: 100vw;
  184. padding: 0 13rpx;
  185. box-sizing: border-box;
  186. }
  187. }
  188. .card {
  189. padding: 22rpx 42rpx 34rpx 41rpx;
  190. color: #000000;
  191. font-size: 28rpx;
  192. .icon {
  193. width: 46rpx;
  194. height: auto;
  195. margin-right: 18rpx;
  196. }
  197. .label {
  198. flex: 1;
  199. }
  200. .desc {
  201. color: #999999;
  202. }
  203. }
  204. .payment {
  205. margin-top: 23rpx;
  206. &-item {
  207. width: 100%;
  208. & + & {
  209. margin-top: 38rpx;
  210. }
  211. }
  212. }
  213. .coupon {
  214. margin-top: 15rpx;
  215. .icon-arrow {
  216. width: 29rpx;
  217. height: auto;
  218. }
  219. }
  220. // 下单
  221. .bar {
  222. position: fixed;
  223. bottom: 0;
  224. left: 0;
  225. width: 100vw;
  226. height: $bar-height;
  227. padding-bottom: env(safe-area-inset-bottom);
  228. background-color: $uni-fg-color;
  229. .count {
  230. flex: 1;
  231. color: #000000;
  232. font-size: 28rpx;
  233. margin-left: 48rpx;
  234. justify-content: flex-start;
  235. .price {
  236. color: #FF2A2A;
  237. font-size: 30rpx;
  238. &-unit {
  239. font-size: 18rpx;
  240. }
  241. }
  242. }
  243. .btn {
  244. border: none;
  245. line-height: 1;
  246. background-color: transparent;
  247. padding: 0;
  248. width: auto;
  249. height: auto;
  250. margin: 0;
  251. &-pay {
  252. margin-right: 41rpx;
  253. padding: 24rpx 137rpx;
  254. color: $uni-text-color-inverse;
  255. font-size: 28rpx;
  256. border-radius: 44rpx;
  257. background-image: linear-gradient(to right, #84A73F, #D8FF8F);
  258. }
  259. }
  260. }
  261. </style>