推拿小程序前端代码仓库
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.

321 lines
6.3 KiB

9 months ago
9 months ago
9 months ago
9 months ago
9 months ago
9 months ago
9 months ago
9 months ago
9 months ago
9 months ago
9 months ago
9 months ago
9 months ago
9 months ago
9 months ago
9 months ago
9 months ago
9 months ago
9 months ago
9 months ago
9 months ago
9 months ago
9 months ago
9 months ago
9 months ago
9 months ago
9 months ago
9 months ago
9 months ago
9 months ago
9 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.vouchersId_dictText}` }}</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" @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(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. this.getCouponList()
  101. },
  102. methods: {
  103. //获取优惠券列表
  104. getCouponList() {
  105. this.$refs.couponList.getCouponList()
  106. },
  107. // 打开优惠券选择
  108. openCoupon() {
  109. this.$refs.couponPopup.open('bottom')
  110. },
  111. // 选择优惠券
  112. selectCoupon(e) {
  113. this.coupon = e
  114. this.$refs.couponPopup.close()
  115. this.selectedCoupon = [1]
  116. },
  117. async fetchPayOrder() {
  118. // todo: check
  119. let params = {
  120. payType : this.payMethod,
  121. // id: this.payOrderProduct[0].id,
  122. // num: this.payOrderProduct[0].num,
  123. // memberNum : 1,
  124. }
  125. let api = 'createOrder'
  126. if (this.orderId) { // 支付订单
  127. params.orderId = this.orderId
  128. api = 'payOrder'
  129. } else { // 创建订单
  130. params.itemId = this.payOrderProduct[0].id
  131. params.amount = this.totalPrice
  132. }
  133. const res = await this.$fetch(api, params, false)
  134. return res
  135. },
  136. async submit() {
  137. try {
  138. const res = await this.fetchPayOrder()
  139. if (!res.success) {
  140. return
  141. }
  142. if (this.payMethod == 1) { // 账户余额
  143. } else { // 微信支付
  144. console.log('--发起支付接口回调', res)
  145. // #ifdef MP-WEIXIN
  146. await uni.requestPaymentWxPay(res)
  147. // #endif
  148. // #ifdef H5
  149. await this.$wxPay(res)
  150. // #endif
  151. }
  152. uni.showToast({
  153. title: '下单成功',
  154. icon: 'none'
  155. })
  156. setTimeout(uni.redirectTo, 700, {
  157. url: '/pages/index/order'
  158. })
  159. } catch (err) {
  160. }
  161. },
  162. }
  163. }
  164. </script>
  165. <style scoped lang="scss">
  166. $bar-height: 132rpx;
  167. .page {
  168. overflow: auto;
  169. padding-bottom: calc(#{$bar-height} + env(safe-area-inset-bottom));
  170. background-color: #F5F5F5;
  171. .bg {
  172. width: 100vw;
  173. height: 331rpx;
  174. background-image: linear-gradient(#84A73F, #D8FF8F);
  175. }
  176. .content {
  177. position: absolute;
  178. left: 0;
  179. top: 0;
  180. width: 100vw;
  181. padding: 0 13rpx;
  182. box-sizing: border-box;
  183. }
  184. }
  185. .card {
  186. padding: 22rpx 42rpx 34rpx 41rpx;
  187. color: #000000;
  188. font-size: 28rpx;
  189. .icon {
  190. width: 46rpx;
  191. height: auto;
  192. margin-right: 18rpx;
  193. }
  194. .label {
  195. flex: 1;
  196. }
  197. .desc {
  198. color: #999999;
  199. }
  200. }
  201. .payment {
  202. margin-top: 23rpx;
  203. &-item {
  204. width: 100%;
  205. & + & {
  206. margin-top: 38rpx;
  207. }
  208. }
  209. }
  210. .coupon {
  211. margin-top: 15rpx;
  212. .icon-arrow {
  213. width: 29rpx;
  214. height: auto;
  215. }
  216. }
  217. // 下单
  218. .bar {
  219. position: fixed;
  220. bottom: 0;
  221. left: 0;
  222. width: 100vw;
  223. height: $bar-height;
  224. padding-bottom: env(safe-area-inset-bottom);
  225. background-color: $uni-fg-color;
  226. .count {
  227. flex: 1;
  228. color: #000000;
  229. font-size: 28rpx;
  230. margin-left: 48rpx;
  231. justify-content: flex-start;
  232. .price {
  233. color: #FF2A2A;
  234. font-size: 30rpx;
  235. &-unit {
  236. font-size: 18rpx;
  237. }
  238. }
  239. }
  240. .btn {
  241. border: none;
  242. line-height: 1;
  243. background-color: transparent;
  244. padding: 0;
  245. width: auto;
  246. height: auto;
  247. margin: 0;
  248. &-pay {
  249. margin-right: 41rpx;
  250. padding: 24rpx 137rpx;
  251. color: $uni-text-color-inverse;
  252. font-size: 28rpx;
  253. border-radius: 44rpx;
  254. background-image: linear-gradient(to right, #84A73F, #D8FF8F);
  255. }
  256. }
  257. }
  258. </style>