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

313 lines
6.2 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
  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. await uni.requestPaymentWxPay(res)
  146. }
  147. uni.showToast({
  148. title: '下单成功',
  149. icon: 'none'
  150. })
  151. setTimeout(uni.redirectTo, 700, {
  152. url: '/pages/index/order'
  153. })
  154. } catch (err) {
  155. }
  156. },
  157. }
  158. }
  159. </script>
  160. <style scoped lang="scss">
  161. $bar-height: 132rpx;
  162. .page {
  163. overflow: auto;
  164. padding-bottom: calc(#{$bar-height} + env(safe-area-inset-bottom));
  165. background-color: #F5F5F5;
  166. .bg {
  167. width: 100vw;
  168. height: 331rpx;
  169. background-image: linear-gradient(#84A73F, #D8FF8F);
  170. }
  171. .content {
  172. position: absolute;
  173. left: 0;
  174. top: 0;
  175. width: 100vw;
  176. padding: 0 13rpx;
  177. box-sizing: border-box;
  178. }
  179. }
  180. .card {
  181. padding: 22rpx 42rpx 34rpx 41rpx;
  182. color: #000000;
  183. font-size: 28rpx;
  184. .icon {
  185. width: 46rpx;
  186. height: auto;
  187. margin-right: 18rpx;
  188. }
  189. .label {
  190. flex: 1;
  191. }
  192. .desc {
  193. color: #999999;
  194. }
  195. }
  196. .payment {
  197. margin-top: 23rpx;
  198. &-item {
  199. width: 100%;
  200. & + & {
  201. margin-top: 38rpx;
  202. }
  203. }
  204. }
  205. .coupon {
  206. margin-top: 15rpx;
  207. .icon-arrow {
  208. width: 29rpx;
  209. height: auto;
  210. }
  211. }
  212. // 下单
  213. .bar {
  214. position: fixed;
  215. bottom: 0;
  216. left: 0;
  217. width: 100vw;
  218. height: $bar-height;
  219. padding-bottom: env(safe-area-inset-bottom);
  220. background-color: $uni-fg-color;
  221. .count {
  222. flex: 1;
  223. color: #000000;
  224. font-size: 28rpx;
  225. margin-left: 48rpx;
  226. justify-content: flex-start;
  227. .price {
  228. color: #FF2A2A;
  229. font-size: 30rpx;
  230. &-unit {
  231. font-size: 18rpx;
  232. }
  233. }
  234. }
  235. .btn {
  236. border: none;
  237. line-height: 1;
  238. background-color: transparent;
  239. padding: 0;
  240. width: auto;
  241. height: auto;
  242. margin: 0;
  243. &-pay {
  244. margin-right: 41rpx;
  245. padding: 24rpx 137rpx;
  246. color: $uni-text-color-inverse;
  247. font-size: 28rpx;
  248. border-radius: 44rpx;
  249. background-image: linear-gradient(to right, #84A73F, #D8FF8F);
  250. }
  251. }
  252. }
  253. </style>