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

310 lines
6.1 KiB

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