index.vue 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167
  1. <template class="page">
  2. <view class="tickets">
  3. <view class="l-tickets">
  4. <view>
  5. <span>{{orderInfo.course_name}}</span>
  6. </view>
  7. <view>
  8. <span class="price">¥{{orderInfo.order_price}}</span>
  9. </view>
  10. <view>
  11. <span>请在10分钟内完成支付</span>
  12. </view>
  13. <view>
  14. <span class="pay-button" @click="payMent">立即支付</span>
  15. </view>
  16. </view>
  17. <view class="r-tickets">
  18. {{orderNo}}
  19. </view>
  20. </view>
  21. </template>
  22. <script>
  23. export default {
  24. data() {
  25. return {
  26. orderNo:'',
  27. orderInfo: ''
  28. }
  29. },
  30. onLoad() {
  31. this.getWxAuth()
  32. },
  33. methods: {
  34. getWxAuth() {
  35. if (window.location.href.indexOf('code') > -1) {
  36. let code = window.location.href.split('code=')[1].split('&')[0]
  37. console.log('111111111111111111111111111111',code)
  38. uni.request({
  39. url: '/api/school/wx/auth',
  40. method: 'GET',
  41. data:{
  42. code: code
  43. }
  44. }).then(res => {
  45. if(res.data.ok){
  46. // if (window.location.href.indexOf('state') > -1) {
  47. const orderNo = window.location.href.split('state=')[1].split('&')[0]
  48. const data = JSON.parse(res.data.data)
  49. uni.setStorageSync('openId', data.openid)
  50. uni.setStorageSync('orderNo', orderNo)
  51. this.createOrder(orderNo)
  52. // }
  53. }
  54. })
  55. } else {
  56. console.log(window.location.href);
  57. // if (window.location.href.indexOf('orderNo') > -1) {
  58. let orderNo = window.location.href.split('orderNo=')[1].split('&')[0]
  59. this.orderNo = orderNo
  60. window.location.replace(`https://open.weixin.qq.com/connect/oauth2/authorize?appid=wxa8bead7acbe0a236&redirect_uri=http://192.168.2.184:8083/pages/index/index&response_type=code&scope=snsapi_base&state=${orderNo}#wechat_redirect`)
  61. // }
  62. }
  63. },
  64. /**
  65. * 创建订单
  66. */
  67. createOrder(order_no){
  68. uni.request({
  69. url: '/api/school/student/order/wxqry',
  70. method:"GET",
  71. data: {
  72. order_no
  73. }
  74. }).then(res=>{
  75. console.log(res);
  76. if(res.data.ok){
  77. this.orderInfo = res.data.data
  78. }
  79. })
  80. },
  81. /**
  82. * 立即支付
  83. */
  84. payMent(){
  85. uni.request({
  86. url: `/api/school/student/order/wxpub?open_id=${uni.getStorageSync('openId')}&order_no=${this.orderInfo.order_no}`,
  87. method:"POST",
  88. }).then(res=>{
  89. console.log(res.data);
  90. })
  91. }
  92. }
  93. }
  94. </script>
  95. <style>
  96. .page{
  97. background-color: rgb(34, 41, 65);
  98. }
  99. .tickets {
  100. display: flex;
  101. padding: 40rpx;
  102. width: 100%;
  103. height: 100vh;
  104. box-sizing: border-box;
  105. flex-direction: column;
  106. align-items: center;
  107. filter: drop-shadow(0 5px 10px rgba(0, 0, 0, .3));
  108. background-color: rgb(34, 41, 65);
  109. }
  110. .r-tickets {
  111. flex: 1;
  112. width: 100%;
  113. }
  114. .r-tickets {
  115. flex: 1;
  116. position: relative;
  117. }
  118. .r-tickets::before {
  119. content: '';
  120. height: 1rpx;
  121. width: 96%;
  122. background: linear-gradient(to right, rgb(34, 41, 65) 0%, rgb(34, 41, 65) 50%, transparent 50%) top left / 20rpx 1rpx repeat-x;
  123. position: absolute;
  124. left: 50%;
  125. top: 0;
  126. transform: translateX(-50%);
  127. }
  128. .l-tickets {
  129. width: 100%;
  130. height: 75%;
  131. position: relative;
  132. border-top-left-radius: 8px;
  133. border-top-right-radius: 8px;
  134. background: radial-gradient(circle at left bottom, transparent 16rpx, white 0) left bottom / 50% 100% no-repeat,
  135. radial-gradient(circle at right bottom, transparent 16rpx, white 0) right bottom / 50% 100% no-repeat;
  136. display: flex;
  137. flex-direction: column;
  138. align-items: center;
  139. justify-content: center;
  140. gap: 20px;
  141. }
  142. .r-tickets {
  143. position: relative;
  144. border-bottom-left-radius: 8px;
  145. border-bottom-right-radius: 8px;
  146. background: radial-gradient(circle at left top, transparent 16rpx, white 0) left top / 50% 100% no-repeat,
  147. radial-gradient(circle at right top, transparent 16rpx, white 0) right top / 50% 100% no-repeat;
  148. }
  149. .price{
  150. font-size: 26px;
  151. color: rgb(74, 144, 226);
  152. }
  153. .pay-button{
  154. line-height: 40px;
  155. background-color: rgb(74, 144, 226);
  156. color: #fff;
  157. padding: 10px 20px;
  158. width: 40vw;
  159. display: block;
  160. text-align: center;
  161. }
  162. </style>