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

322 lines
6.4 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
  1. <template>
  2. <view class="page">
  3. <!-- 导航栏 -->
  4. <navbar title="商品支付" leftClick @leftClick="$utils.navigateBack" color="#fff" />
  5. <view class="content">
  6. <!-- 商品详情 -->
  7. <productCard :data="payOrderProduct[0]" size="medium" :readonly="true"></productCard>
  8. <view class="card payment">
  9. <uv-radio-group v-model="payMethod">
  10. <view class="flex payment-item">
  11. <image class="icon" src="../static/createOrder/icon-wx.png" mode="widthFix"></image>
  12. <text class="label">微信支付</text>
  13. <uv-radio :name="0" activeColor="#84A73F" size="39rpx" icon-size="39rpx"/>
  14. </view>
  15. <view class="flex payment-item">
  16. <image class="icon" src="../static/createOrder/icon-account.png" mode="widthFix"></image>
  17. <text class="label">账户余额<text class="desc">{{ `(余额:¥${riceInfo.balance || 0}` }}</text></text>
  18. <uv-radio :name="1" activeColor="#84A73F" size="39rpx" icon-size="39rpx"/>
  19. </view>
  20. </uv-radio-group>
  21. </view>
  22. <!-- 优惠券 -->
  23. <view @click="openCoupon" class="card flex coupon">
  24. <image class="icon" src="@/pages_order/static/createOrder/icon-coupon.png" mode="widthFix"></image>
  25. <!-- todo: check is selected coupon -->
  26. <view class="label">优惠券<text v-if="selectedCoupon[0]" class="desc">{{ `满减券:${'满400减40'}` }}</text></view>
  27. <view v-if="selectedCoupon[0]">
  28. <uv-checkbox-group v-model="selectedCoupon" shape="circle" >
  29. <uv-checkbox :name="1" size="39rpx" icon-size="39rpx" activeColor="#84A73F"></uv-checkbox>
  30. </uv-checkbox-group>
  31. </view>
  32. <template v-else>
  33. <image class="icon-arrow" src="../static/createOrder/icon-arrow.png" mode="widthFix"></image>
  34. </template>
  35. </view>
  36. </view>
  37. <!-- 下单 -->
  38. <view class="flex bar">
  39. <view class="flex count">
  40. <text>合计</text>
  41. <view class="price">
  42. <text class="price-unit">¥</text>
  43. <!-- todo: check -->
  44. <text>{{ totalPrice }}</text>
  45. </view>
  46. </view>
  47. <view class="btn btn-pay" @click="submit">
  48. 立即支付
  49. </view>
  50. </view>
  51. <!-- 优惠券选择-->
  52. <uv-popup ref="couponPopup" :round="30">
  53. <couponList ref="couponList" height="60vh" @select="selectCoupon" />
  54. </uv-popup>
  55. <configPopup ref="popup"></configPopup>
  56. </view>
  57. </template>
  58. <script>
  59. import productCard from '@/components/product/productCard.vue'
  60. import couponList from '@/components/couponList/couponList.vue'
  61. import {
  62. mapState
  63. } from 'vuex'
  64. export default {
  65. components: {
  66. productCard,
  67. couponList
  68. },
  69. data() {
  70. return {
  71. selectedCoupon: [1],
  72. num: 1,
  73. coupon: {},
  74. payMethod : 0,
  75. }
  76. },
  77. computed: {
  78. totalPrice() {
  79. let price = 0
  80. this.payOrderProduct.forEach(n => {
  81. price += n.price * n.num
  82. })
  83. if (this.coupon.id) {
  84. price -= this.coupon.money
  85. }
  86. return Number(price).toFixed(2)
  87. },
  88. ...mapState(['userInfo', 'payOrderProduct']),
  89. },
  90. onLoad(args) {
  91. this.$store.commit('getUserInfo')
  92. },
  93. onShow() {
  94. this.getCouponList()
  95. },
  96. methods: {
  97. //获取优惠券列表
  98. getCouponList() {
  99. this.$refs.couponList.getCouponList()
  100. },
  101. // 打开优惠券选择
  102. openCoupon() {
  103. this.$refs.couponPopup.open('bottom')
  104. },
  105. // 选择优惠券
  106. selectCoupon(e) {
  107. // todo
  108. //判断优惠券限制
  109. let {
  110. useMoney
  111. } = e
  112. let productTotalPrice = 0
  113. this.payOrderProduct.forEach(item => {
  114. productTotalPrice += item.price
  115. })
  116. if (productTotalPrice < useMoney) {
  117. return uni.showToast({
  118. title: `此优惠券需要满${useMoney}使用`,
  119. icon: "none"
  120. })
  121. }
  122. this.coupon = e
  123. this.$refs.couponPopup.close()
  124. this.selectedCoupon = [1]
  125. },
  126. submit() {
  127. let data = {}
  128. let api = ''
  129. data = {
  130. addressId,
  131. num: this.payOrderProduct[0].num,
  132. shopId: this.payOrderProduct[0].id,
  133. payType : this.payMethod,
  134. memberNum : 1,
  135. }
  136. api = 'createOrder'
  137. if(this.coupon.id){
  138. data.couponId = this.coupon.id
  139. }
  140. if(this.isGive == 2){
  141. data.memberNum = this.multiNum
  142. }
  143. this.$api(api, data, res => {
  144. if (res.code == 200) {
  145. if(this.payMethod == 1){
  146. // uni.showToast({
  147. // title: '下单成功',
  148. // icon: 'none'
  149. // })
  150. this.paySuccess(res)
  151. return
  152. }
  153. uni.requestPaymentWxPay(res).then(e => {
  154. uni.showToast({
  155. title: '下单成功',
  156. icon: 'none'
  157. })
  158. this.paySuccess(res)
  159. }).catch(n => {
  160. setTimeout(uni.redirectTo, 700, {
  161. url: '/pages/index/order'
  162. })
  163. })
  164. }
  165. })
  166. },
  167. paySuccess(res){
  168. setTimeout(uni.redirectTo, 700, {
  169. url: '/pages/index/order'
  170. })
  171. },
  172. }
  173. }
  174. </script>
  175. <style scoped lang="scss">
  176. $bar-height: 132rpx;
  177. .page {
  178. overflow: auto;
  179. padding-bottom: calc(#{$bar-height} + env(safe-area-inset-bottom));
  180. background-color: #F5F5F5;
  181. /deep/ .nav-bar__view {
  182. padding-bottom: 190rpx;
  183. background-image: linear-gradient(#84A73F, #D8FF8F);
  184. }
  185. .content {
  186. position: absolute;
  187. z-index: 999;
  188. transform: translateY(-118rpx);
  189. width: 100vw;
  190. padding: 0 13rpx;
  191. box-sizing: border-box;
  192. }
  193. }
  194. .card {
  195. padding: 22rpx 42rpx 34rpx 41rpx;
  196. color: #000000;
  197. font-size: 28rpx;
  198. .icon {
  199. width: 46rpx;
  200. height: auto;
  201. margin-right: 18rpx;
  202. }
  203. .label {
  204. flex: 1;
  205. }
  206. .desc {
  207. color: #999999;
  208. }
  209. }
  210. .payment {
  211. margin-top: 23rpx;
  212. &-item {
  213. width: 100%;
  214. & + & {
  215. margin-top: 38rpx;
  216. }
  217. }
  218. }
  219. .coupon {
  220. margin-top: 15rpx;
  221. .icon-arrow {
  222. width: 29rpx;
  223. height: auto;
  224. }
  225. }
  226. // 下单
  227. .bar {
  228. position: fixed;
  229. bottom: 0;
  230. left: 0;
  231. width: 100vw;
  232. height: $bar-height;
  233. padding-bottom: env(safe-area-inset-bottom);
  234. background-color: $uni-fg-color;
  235. .count {
  236. flex: 1;
  237. color: #000000;
  238. font-size: 28rpx;
  239. margin-left: 48rpx;
  240. justify-content: flex-start;
  241. .price {
  242. color: #FF2A2A;
  243. font-size: 30rpx;
  244. &-unit {
  245. font-size: 18rpx;
  246. }
  247. }
  248. }
  249. .btn {
  250. border: none;
  251. line-height: 1;
  252. background-color: transparent;
  253. padding: 0;
  254. width: auto;
  255. height: auto;
  256. margin: 0;
  257. &-pay {
  258. margin-right: 41rpx;
  259. padding: 24rpx 137rpx;
  260. color: $uni-text-color-inverse;
  261. font-size: 28rpx;
  262. border-radius: 44rpx;
  263. background-image: linear-gradient(to right, #84A73F, #D8FF8F);
  264. }
  265. }
  266. }
  267. </style>