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

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