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

352 lines
6.8 KiB

9 months ago
9 months ago
9 months ago
9 months ago
9 months ago
9 months ago
9 months ago
9 months ago
9 months ago
9 months ago
9 months ago
9 months ago
9 months ago
9 months ago
9 months ago
9 months ago
9 months ago
9 months ago
9 months ago
9 months ago
9 months ago
9 months ago
9 months ago
9 months ago
9 months ago
9 months ago
9 months ago
9 months ago
9 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 addressList from '../components/address/addressList.vue'
  61. import couponList from '@/components/couponList/couponList.vue'
  62. import {
  63. mapState
  64. } from 'vuex'
  65. export default {
  66. components: {
  67. productCard,
  68. addressList,
  69. couponList
  70. },
  71. data() {
  72. return {
  73. selectedCoupon: [1],
  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
  84. })
  85. if (this.coupon.id) {
  86. price -= this.coupon.money
  87. }
  88. return Number(price).toFixed(2)
  89. },
  90. ...mapState(['userInfo', 'payOrderProduct']),
  91. },
  92. onLoad(args) {
  93. this.$store.commit('getUserInfo')
  94. },
  95. onShow() {
  96. this.getCouponList()
  97. },
  98. methods: {
  99. //获取优惠券列表
  100. getCouponList() {
  101. this.$refs.couponList.getCouponList()
  102. },
  103. // 打开优惠券选择
  104. openCoupon() {
  105. this.$refs.couponPopup.open('bottom')
  106. },
  107. // 选择优惠券
  108. selectCoupon(e) {
  109. // todo
  110. //判断优惠券限制
  111. let {
  112. useMoney
  113. } = e
  114. let productTotalPrice = 0
  115. this.payOrderProduct.forEach(item => {
  116. productTotalPrice += item.price
  117. })
  118. if (productTotalPrice < useMoney) {
  119. return uni.showToast({
  120. title: `此优惠券需要满${useMoney}使用`,
  121. icon: "none"
  122. })
  123. }
  124. this.coupon = e
  125. this.$refs.couponPopup.close()
  126. this.selectedCoupon = [1]
  127. },
  128. submit() {
  129. let data = {}
  130. let api = ''
  131. data = {
  132. addressId,
  133. num: this.payOrderProduct[0].num,
  134. shopId: this.payOrderProduct[0].id,
  135. payType : this.payMethod,
  136. memberNum : 1,
  137. }
  138. api = 'createOrder'
  139. if(this.coupon.id){
  140. data.couponId = this.coupon.id
  141. }
  142. if(this.isGive == 2){
  143. data.memberNum = this.multiNum
  144. }
  145. this.$api(api, data, res => {
  146. if (res.code == 200) {
  147. if(this.payMethod == 1){
  148. // uni.showToast({
  149. // title: '下单成功',
  150. // icon: 'none'
  151. // })
  152. this.paySuccess(res)
  153. return
  154. }
  155. uni.requestPaymentWxPay(res).then(e => {
  156. uni.showToast({
  157. title: '下单成功',
  158. icon: 'none'
  159. })
  160. this.paySuccess(res)
  161. }).catch(n => {
  162. setTimeout(uni.redirectTo, 700, {
  163. url: '/pages/index/order'
  164. })
  165. })
  166. }
  167. })
  168. },
  169. paySuccess(res){
  170. setTimeout(uni.redirectTo, 700, {
  171. url: '/pages/index/order'
  172. })
  173. },
  174. }
  175. }
  176. </script>
  177. <style scoped lang="scss">
  178. $bar-height: 132rpx;
  179. .page {
  180. overflow: auto;
  181. padding-bottom: calc(#{$bar-height} + env(safe-area-inset-bottom));
  182. background-color: #F5F5F5;
  183. /deep/ .nav-bar__view {
  184. padding-bottom: 190rpx;
  185. background-image: linear-gradient(#84A73F, #D8FF8F);
  186. }
  187. .content {
  188. position: absolute;
  189. z-index: 999;
  190. transform: translateY(-118rpx);
  191. width: 100vw;
  192. padding: 0 13rpx;
  193. box-sizing: border-box;
  194. }
  195. /deep/ .product-card__view {
  196. // margin: 0 13rpx;
  197. padding: 27rpx 25rpx;
  198. // width: calc(100vw - 13rpx*2);
  199. width: 100%;
  200. box-sizing: border-box;
  201. // transform: translateY(-50%);
  202. .img {
  203. width: 184rpx;
  204. height: 184rpx;
  205. }
  206. .title {
  207. margin-bottom: 14rpx;
  208. }
  209. .price {
  210. margin-top: 15rpx;
  211. }
  212. .sales {
  213. margin-top: 15rpx;
  214. }
  215. }
  216. }
  217. .card {
  218. padding: 22rpx 42rpx 34rpx 41rpx;
  219. color: #000000;
  220. font-size: 28rpx;
  221. .icon {
  222. width: 46rpx;
  223. height: auto;
  224. margin-right: 18rpx;
  225. }
  226. .label {
  227. flex: 1;
  228. }
  229. .desc {
  230. color: #999999;
  231. }
  232. }
  233. .payment {
  234. margin-top: 23rpx;
  235. &-item {
  236. width: 100%;
  237. & + & {
  238. margin-top: 38rpx;
  239. }
  240. }
  241. }
  242. .coupon {
  243. margin-top: 15rpx;
  244. .icon-arrow {
  245. width: 29rpx;
  246. height: auto;
  247. }
  248. }
  249. // 下单
  250. .bar {
  251. position: fixed;
  252. bottom: 0;
  253. left: 0;
  254. width: 100vw;
  255. height: $bar-height;
  256. padding-bottom: env(safe-area-inset-bottom);
  257. background-color: $uni-fg-color;
  258. .count {
  259. flex: 1;
  260. color: #000000;
  261. font-size: 28rpx;
  262. margin-left: 48rpx;
  263. justify-content: flex-start;
  264. .price {
  265. color: #FF2A2A;
  266. font-size: 30rpx;
  267. &-unit {
  268. font-size: 18rpx;
  269. }
  270. }
  271. }
  272. .btn {
  273. border: none;
  274. line-height: 1;
  275. background-color: transparent;
  276. padding: 0;
  277. width: auto;
  278. height: auto;
  279. margin: 0;
  280. &-pay {
  281. margin-right: 41rpx;
  282. padding: 24rpx 137rpx;
  283. color: $uni-text-color-inverse;
  284. font-size: 28rpx;
  285. border-radius: 44rpx;
  286. background-image: linear-gradient(to right, #84A73F, #D8FF8F);
  287. }
  288. }
  289. }
  290. </style>