BuyTicket.vue 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186
  1. <!--
  2. * @Description:
  3. * @Author: 欧阳承珺
  4. * @LastEditors: 欧阳承珺
  5. * @Date: 2022-11-01 14:10:22
  6. * @LastEditTime: 2022-11-16 09:44:53
  7. -->
  8. <template>
  9. <div>
  10. <div v-show="orderStatus !== 'success'">
  11. <p class="text-18px text-[#666] text-center font-400">购买券</p>
  12. <div class="py-27px">
  13. <div class="flex justify-between">
  14. <div v-for="(item,idx) in list" :key="idx" class="w-116px h-130px relative cursor-pointer" @click="chooseTicket(item)">
  15. <div :class="`ticket${idx}`" class="w-full h-79px text-14px text-[#fff] leading-79px text-center font-200"><span class="text-36px mr-6px">{{getTickets(item)}}</span>券</div>
  16. <div :style="{'border': choosedTicket.productCode === item.productCode ? border[`border${idx}`] : '1px solid #f0f0f0'}" class="w-full mx-auto h-49px text-20px text-black leading-49px text-center font-200">¥{{item.price}}</div>
  17. </div>
  18. </div>
  19. </div>
  20. <div class="py-27px">
  21. <p class="text-16px text-[#999] mb-14px">选择支付方式</p>
  22. <div class="pay-method" :style="{'border': paymethod === 'alipay' ? '2px solid #3fa9e7' : '1px solid #f0f0f0'}" @click="choosePayMethod('alipay',0)">
  23. <img class="inline-block" src="http://cn-file.17pdf.com/website/pricings/alipay_logo.png"> 支付宝
  24. </div>
  25. <div class="pay-method" :style="{'border': paymethod === 'wechat' ? '2px solid #4bcb70' : '1px solid #f0f0f0'}" @click="choosePayMethod('wechat',1)">
  26. <img class="inline-block" src="http://cn-file.17pdf.com/website/pricings/wechat_logo.png"> 微信
  27. </div>
  28. </div>
  29. <button v-if="paymethod === 'alipay'" class="play-now" style="margin-left: 68px" @click="handlePlayNow">立即支付</button>
  30. <div v-else class="text-center">
  31. <div v-if="count <= 0">
  32. <div>
  33. <p class="text-18px mb-15px">二维码过期,请刷新</p>
  34. <el-button @click="handleFreshWechetCode">刷新</el-button>
  35. </div>
  36. </div>
  37. <div v-else>
  38. <client-only>
  39. <vue-qr :size="176" :text="qrcode"></vue-qr>
  40. </client-only>
  41. <p class="text-[#666] text-18px leading-20px">扫一扫 即可支付</p>
  42. </div>
  43. </div>
  44. </div>
  45. <div v-show="orderStatus === 'success'">
  46. <div class="pay-tittle">
  47. <p>支付成功</p>
  48. </div>
  49. <div class="pay-content">
  50. <img src="http://cn-file.17pdf.com/website/pricings/check.png" />
  51. <span>嘿嘿嘿...尽情享受您的特权吧</span>
  52. </div>
  53. </div>
  54. </div>
  55. </template>
  56. <script>
  57. export default {
  58. data() {
  59. return {
  60. list: [],
  61. choosedTicket: {},
  62. paymethod: '',
  63. border: {
  64. border0: '2px solid #9688ff',
  65. border1: '2px solid #27d6c5',
  66. border2: '2px solid #e1b973',
  67. border3: '2px solid #ff6a98'
  68. },
  69. qrcode: '',
  70. count: 60,
  71. orderStatus: false,
  72. interval: ''
  73. }
  74. },
  75. created() {
  76. this.getVipList()
  77. },
  78. methods: {
  79. resetInterfaceStatus() {
  80. },
  81. chooseTicket(item) {
  82. this.choosedTicket = item
  83. },
  84. handleFreshWechetCode() {
  85. this.count = 60
  86. this.choosePayMethod('wechat')
  87. },
  88. getTickets(item) {
  89. return item.productCode.split('.')[1]
  90. },
  91. getVipList() {
  92. this.$axios.post('pricing/list',{client: 'web',language: 'zh'}).then((res)=> {
  93. if(res.code === 200) {
  94. this.list = res.result.pricingList.filter(item => item.mode !== 1) // 加云的不展示
  95. this.choosedTicket = this.list[this.list.length - 1]
  96. this.paymethod = 'alipay'
  97. }
  98. })
  99. },
  100. choosePayMethod(type,payment) {
  101. this.interval = null
  102. clearInterval(this.interval)
  103. this.paymethod = type
  104. if(type === 'wechat') {
  105. const params = {
  106. client: 'web',
  107. payment,
  108. targetType: 'Pricing',
  109. targetId: this.choosedTicket.id
  110. }
  111. this.$axios.post('subscription/create',params).then((res) => {
  112. if(res.code === 200) {
  113. this.qrcode = res.result.order.qrcodeUrl
  114. this.getWechatPayStatus(res.result.order.id)
  115. }
  116. })
  117. }
  118. },
  119. getWechatPayStatus(id) {
  120. this.interval = setInterval(() => {
  121. if(this.count > 0) {
  122. this.$axios.get(`order/getWxOrder?orderId=${id}`).then((res)=>{
  123. this.orderStatus = res?.result?.statusName
  124. if(this.orderStatus === 'success') {
  125. this.count = 0
  126. setTimeout(() => {
  127. this.$emit('close')
  128. // 更新个人信息
  129. this.getUserInfo()
  130. }, 1000);
  131. }else {
  132. this.count--
  133. }
  134. })
  135. }
  136. }, 2000);
  137. if(this.count === 0) {
  138. this.$once('hook:beforeDestroy',()=> {
  139. clearInterval(this.interval)
  140. this.interval = null
  141. })
  142. }
  143. },
  144. handlePlayNow() {
  145. const params = {
  146. client: 'web',
  147. payment: 0,
  148. targetType: 'Pricing',
  149. targetId: this.choosedTicket.id
  150. }
  151. this.$axios.post('subscription/create',params).then((res) => {
  152. if(res.code === 200) {
  153. location.href = res.result.order.pagePayUrl
  154. this.$store.commit('OPEN_LOGIN',false)
  155. }
  156. })
  157. },
  158. getUserInfo() {
  159. this.$axios.get('members/getMemberInfo').then((res)=> {
  160. if(res.code === 200) {
  161. this.$store.commit('setUser',res.result.memberInfo)
  162. this.$router.push('/members/me/expenses')
  163. }
  164. })
  165. },
  166. }
  167. }
  168. </script>
  169. <style lang="scss">
  170. .ticket0 {
  171. background: linear-gradient(#b98dff, #7384ff);
  172. }
  173. .ticket1 {
  174. background: linear-gradient(#60b8ff, #27d6c5);
  175. }
  176. .ticket2 {
  177. background: linear-gradient(#ff8e4a, #e1b973);
  178. }
  179. .ticket3 {
  180. background: linear-gradient(#ff8279, #ff6a98);
  181. }
  182. </style>