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

355 lines
6.9 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
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. selectedCoupon: [],
  73. num: 1,
  74. coupon: {},
  75. payMethod : 0,
  76. }
  77. },
  78. computed: {
  79. totalPrice() {
  80. let price = 0
  81. this.payOrderProduct.forEach(n => {
  82. price += n.price * (n.num || 1)
  83. })
  84. if (this.coupon.id) {
  85. price -= (this.coupon.money || 0)
  86. }
  87. return Number(price).toFixed(2)
  88. },
  89. ...mapState(['userInfo', 'payOrderProduct']),
  90. },
  91. onLoad(args) {
  92. this.$store.commit('getUserInfo')
  93. },
  94. onShow() {
  95. this.getCouponList()
  96. },
  97. methods: {
  98. //获取优惠券列表
  99. getCouponList() {
  100. this.$refs.couponList.getCouponList()
  101. },
  102. // 打开优惠券选择
  103. openCoupon() {
  104. this.$refs.couponPopup.open('bottom')
  105. },
  106. // 选择优惠券
  107. selectCoupon(e) {
  108. this.coupon = e
  109. this.$refs.couponPopup.close()
  110. this.selectedCoupon = [1]
  111. },
  112. async fetchCreateOrder() {
  113. // todo: check
  114. let params = {
  115. 'massageItem.id': this.payOrderProduct[0].id,
  116. amount: this.totalPrice,
  117. // num: this.payOrderProduct[0].num,
  118. // id: this.payOrderProduct[0].id,
  119. // payType : this.payMethod,
  120. // memberNum : 1,
  121. }
  122. // todo: check
  123. // if (this.coupon.id) {
  124. // data.couponId = this.coupon.id
  125. // }
  126. const res = await this.$fetch('createOrder', params, false)
  127. return res
  128. },
  129. async fetchPayOrder() {
  130. // todo
  131. let params = {
  132. }
  133. await this.$fetch('payOrder', params)
  134. },
  135. async submit() {
  136. // todo
  137. try {
  138. const res = await this.fetchCreateOrder()
  139. if (this.payMethod == 1) { // 账户余额
  140. } else { // 微信支付
  141. await uni.requestPaymentWxPay(res)
  142. }
  143. } catch (err) {
  144. }
  145. return
  146. let data = {
  147. 'massageItem.id': this.payOrderProduct[0].id,
  148. // todo: check
  149. amount: this.totalPrice,
  150. // num: this.payOrderProduct[0].num,
  151. // id: this.payOrderProduct[0].id,
  152. // payType : this.payMethod,
  153. // memberNum : 1,
  154. }
  155. // todo: check
  156. // if (this.coupon.id) {
  157. // data.couponId = this.coupon.id
  158. // }
  159. this.$api('createOrder', data, res => {
  160. if (res.code == 200) {
  161. if(this.payMethod == 1){
  162. uni.showToast({
  163. title: '下单成功',
  164. icon: 'none'
  165. })
  166. this.paySuccess(res)
  167. return
  168. }
  169. uni.requestPaymentWxPay(res).then(e => {
  170. uni.showToast({
  171. title: '下单成功',
  172. icon: 'none'
  173. })
  174. this.paySuccess(res)
  175. }).catch(n => {
  176. setTimeout(uni.redirectTo, 700, {
  177. url: '/pages/index/order'
  178. })
  179. })
  180. }
  181. })
  182. },
  183. paySuccess(res){
  184. setTimeout(uni.redirectTo, 700, {
  185. url: '/pages/index/order'
  186. })
  187. },
  188. }
  189. }
  190. </script>
  191. <style scoped lang="scss">
  192. $bar-height: 132rpx;
  193. .page {
  194. overflow: auto;
  195. padding-bottom: calc(#{$bar-height} + env(safe-area-inset-bottom));
  196. background-color: #F5F5F5;
  197. .bg {
  198. width: 100vw;
  199. height: 331rpx;
  200. background-image: linear-gradient(#84A73F, #D8FF8F);
  201. }
  202. .content {
  203. position: absolute;
  204. left: 0;
  205. top: 0;
  206. width: 100vw;
  207. padding: 0 13rpx;
  208. box-sizing: border-box;
  209. }
  210. }
  211. .card {
  212. padding: 22rpx 42rpx 34rpx 41rpx;
  213. color: #000000;
  214. font-size: 28rpx;
  215. .icon {
  216. width: 46rpx;
  217. height: auto;
  218. margin-right: 18rpx;
  219. }
  220. .label {
  221. flex: 1;
  222. }
  223. .desc {
  224. color: #999999;
  225. }
  226. }
  227. .payment {
  228. margin-top: 23rpx;
  229. &-item {
  230. width: 100%;
  231. & + & {
  232. margin-top: 38rpx;
  233. }
  234. }
  235. }
  236. .coupon {
  237. margin-top: 15rpx;
  238. .icon-arrow {
  239. width: 29rpx;
  240. height: auto;
  241. }
  242. }
  243. // 下单
  244. .bar {
  245. position: fixed;
  246. bottom: 0;
  247. left: 0;
  248. width: 100vw;
  249. height: $bar-height;
  250. padding-bottom: env(safe-area-inset-bottom);
  251. background-color: $uni-fg-color;
  252. .count {
  253. flex: 1;
  254. color: #000000;
  255. font-size: 28rpx;
  256. margin-left: 48rpx;
  257. justify-content: flex-start;
  258. .price {
  259. color: #FF2A2A;
  260. font-size: 30rpx;
  261. &-unit {
  262. font-size: 18rpx;
  263. }
  264. }
  265. }
  266. .btn {
  267. border: none;
  268. line-height: 1;
  269. background-color: transparent;
  270. padding: 0;
  271. width: auto;
  272. height: auto;
  273. margin: 0;
  274. &-pay {
  275. margin-right: 41rpx;
  276. padding: 24rpx 137rpx;
  277. color: $uni-text-color-inverse;
  278. font-size: 28rpx;
  279. border-radius: 44rpx;
  280. background-image: linear-gradient(to right, #84A73F, #D8FF8F);
  281. }
  282. }
  283. }
  284. </style>