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

348 lines
6.7 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]" :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. /deep/ .product-card__view {
  194. // margin: 0 13rpx;
  195. padding: 27rpx 25rpx;
  196. // width: calc(100vw - 13rpx*2);
  197. width: 100%;
  198. box-sizing: border-box;
  199. // transform: translateY(-50%);
  200. .img {
  201. width: 184rpx;
  202. height: 184rpx;
  203. }
  204. .title {
  205. margin-bottom: 14rpx;
  206. }
  207. .price {
  208. margin-top: 15rpx;
  209. }
  210. .sales {
  211. margin-top: 15rpx;
  212. }
  213. }
  214. }
  215. .card {
  216. padding: 22rpx 42rpx 34rpx 41rpx;
  217. color: #000000;
  218. font-size: 28rpx;
  219. .icon {
  220. width: 46rpx;
  221. height: auto;
  222. margin-right: 18rpx;
  223. }
  224. .label {
  225. flex: 1;
  226. }
  227. .desc {
  228. color: #999999;
  229. }
  230. }
  231. .payment {
  232. margin-top: 23rpx;
  233. &-item {
  234. width: 100%;
  235. & + & {
  236. margin-top: 38rpx;
  237. }
  238. }
  239. }
  240. .coupon {
  241. margin-top: 15rpx;
  242. .icon-arrow {
  243. width: 29rpx;
  244. height: auto;
  245. }
  246. }
  247. // 下单
  248. .bar {
  249. position: fixed;
  250. bottom: 0;
  251. left: 0;
  252. width: 100vw;
  253. height: $bar-height;
  254. padding-bottom: env(safe-area-inset-bottom);
  255. background-color: $uni-fg-color;
  256. .count {
  257. flex: 1;
  258. color: #000000;
  259. font-size: 28rpx;
  260. margin-left: 48rpx;
  261. justify-content: flex-start;
  262. .price {
  263. color: #FF2A2A;
  264. font-size: 30rpx;
  265. &-unit {
  266. font-size: 18rpx;
  267. }
  268. }
  269. }
  270. .btn {
  271. border: none;
  272. line-height: 1;
  273. background-color: transparent;
  274. padding: 0;
  275. width: auto;
  276. height: auto;
  277. margin: 0;
  278. &-pay {
  279. margin-right: 41rpx;
  280. padding: 24rpx 137rpx;
  281. color: $uni-text-color-inverse;
  282. font-size: 28rpx;
  283. border-radius: 44rpx;
  284. background-image: linear-gradient(to right, #84A73F, #D8FF8F);
  285. }
  286. }
  287. }
  288. </style>