BuyTicket.vue 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228
  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 === 'wechat' ? '2px solid #4bcb70' : '1px solid #f0f0f0'}" @click="choosePayMethod('wechat')">
  23. <img class="inline-block" src="http://cn-file.17pdf.com/website/pricings/wechat_logo.png"> 微信
  24. </div>
  25. <div class="pay-method" :style="{'border': paymethod === 'alipay' ? '2px solid #3fa9e7' : '1px solid #f0f0f0'}" @click="choosePayMethod('alipay')">
  26. <img class="inline-block" src="http://cn-file.17pdf.com/website/pricings/alipay_logo.png"> 支付宝
  27. </div>
  28. <div class="inline-block ml-90px text-[14px] underline cursor-pointer buyQuestion" @click="goToQuestion"><a href="/question#payment" target="_blank">支付遇到问题?</a></div>
  29. </div>
  30. <button v-if="paymethod === 'alipay'" class="play-now" style="margin-left: 68px" @click="handlePlayNow">立即支付</button>
  31. <div v-if="paymethod === 'wechat'" class="text-center">
  32. <div v-if="count <= 0">
  33. <div>
  34. <p class="text-18px mb-15px">二维码过期,请刷新</p>
  35. <client-only><el-button @click="handleFreshWechetCode">刷新</el-button></client-only>
  36. </div>
  37. </div>
  38. <div v-else>
  39. <client-only>
  40. <vue-qr :size="176" :text="qrcode"></vue-qr>
  41. </client-only>
  42. <p class="text-[#666] text-18px leading-20px">扫一扫 即可支付</p>
  43. </div>
  44. </div>
  45. </div>
  46. <div v-show="orderStatus === 'success'">
  47. <div class="pay-tittle">
  48. <p>支付成功</p>
  49. </div>
  50. <div class="pay-content">
  51. <img src="http://cn-file.17pdf.com/website/pricings/check.png" />
  52. <span>嘿嘿嘿...尽情享受您的特权吧</span>
  53. </div>
  54. </div>
  55. </div>
  56. </template>
  57. <script>
  58. import { mapState } from 'vuex'
  59. export default {
  60. data() {
  61. return {
  62. list: [],
  63. choosedTicket: {},
  64. paymethod: '',
  65. border: {
  66. border0: '2px solid #9688ff',
  67. border1: '2px solid #27d6c5',
  68. border2: '2px solid #e1b973',
  69. border3: '2px solid #ff6a98'
  70. },
  71. qrcode: '',
  72. count: 150,
  73. orderStatus: false,
  74. interval: ''
  75. }
  76. },
  77. created() {
  78. this.getVipList()
  79. },
  80. computed: {
  81. ...mapState([
  82. "globalLoginVisiable",
  83. ]),
  84. },
  85. watch:{
  86. globalLoginVisiable(newVal){
  87. if(!newVal){
  88. if(this.paymethod === 'wechat'){
  89. this.list=[]
  90. this.choosedTicket = {},
  91. this.paymethod = '',
  92. this.qrcode = '',
  93. this.orderStatus = false,
  94. this.count = 150
  95. this.getVipList()
  96. }
  97. }
  98. }
  99. },
  100. methods: {
  101. resetInterfaceStatus() {
  102. },
  103. chooseTicket(item) {
  104. this.choosedTicket = item
  105. this.count = 150
  106. this.choosePayMethod(this.paymethod)
  107. },
  108. handleFreshWechetCode() {
  109. this.count = 150
  110. this.choosePayMethod('wechat')
  111. },
  112. getTickets(item) {
  113. return item.productCode.split('.')[1]
  114. },
  115. getVipList() {
  116. this.$axios.post('pricing/list',{client: 'web',language: 'zh'}).then((res)=> {
  117. if(res.code === 200) {
  118. this.list = res.result.pricingList.filter(item => item.mode !== 1) // 加云的不展示
  119. this.choosedTicket = this.list[this.list.length - 1]
  120. this.paymethod = 'wechat'
  121. this.choosePayMethod('wechat')
  122. }
  123. })
  124. },
  125. choosePayMethod(type) {
  126. clearInterval(this.interval)
  127. this.interval = null
  128. this.paymethod = type
  129. if(type === 'wechat') {
  130. const params = {
  131. client: 'web',
  132. payment: this.paymethod === 'wechat' ? 1 : 0,
  133. targetType: 'Pricing',
  134. targetId: this.choosedTicket.id
  135. }
  136. this.$axios.post('subscription/create',params).then((res) => {
  137. if(res.code === 200) {
  138. this.qrcode = res.result.order.qrcodeUrl
  139. this.getWechatPayStatus(res.result.order.id)
  140. }
  141. })
  142. }
  143. },
  144. getWechatPayStatus(id) {
  145. this.interval = setInterval(() => {
  146. if(this.count > 0) {
  147. this.$axios.get(`order/getWxOrder?orderId=${id}`).then((res)=>{
  148. this.orderStatus = res?.result?.statusName
  149. if(this.orderStatus === 'success') {
  150. this.count = 0
  151. // 支付成功关定时器
  152. clearInterval(this.interval)
  153. setTimeout(() => {
  154. this.$emit('close')
  155. // 更新个人信息
  156. this.getUserInfo()
  157. }, 1000);
  158. }else {
  159. this.count--
  160. }
  161. // 关闭就关定时器
  162. if(!this.globalLoginVisiable){
  163. clearInterval(this.interval)
  164. }
  165. })
  166. }
  167. }, 2000);
  168. if(this.count === 0) {
  169. this.$once('hook:beforeDestroy',()=> {
  170. clearInterval(this.interval)
  171. this.interval = null
  172. })
  173. }
  174. },
  175. handlePlayNow() {
  176. const params = {
  177. client: 'web',
  178. payment: 0,
  179. targetType: 'Pricing',
  180. targetId: this.choosedTicket.id
  181. }
  182. this.$axios.post('subscription/create',params).then((res) => {
  183. if(res.code === 200) {
  184. location.href = res.result.order.pagePayUrl
  185. setTimeout(() => {
  186. this.$emit('close')
  187. }, 600);
  188. // this.$store.commit('OPEN_LOGIN',false)
  189. }
  190. })
  191. },
  192. getUserInfo() {
  193. this.$axios.get('members/getMemberInfo').then((res)=> {
  194. if(res.code === 200) {
  195. this.$store.commit('setUser',res.result.memberInfo)
  196. this.$router.push('/members/me/points')
  197. }
  198. })
  199. },
  200. //跳转至question页面
  201. goToQuestion(){
  202. // this.$emit('close')
  203. // this.$router.push({path: '/question#payment'})
  204. }
  205. }
  206. }
  207. </script>
  208. <style lang="scss">
  209. .ticket0 {
  210. background: linear-gradient(#b98dff, #7384ff);
  211. }
  212. .ticket1 {
  213. background: linear-gradient(#60b8ff, #27d6c5);
  214. }
  215. .ticket2 {
  216. background: linear-gradient(#ff8e4a, #e1b973);
  217. }
  218. .ticket3 {
  219. background: linear-gradient(#ff8279, #ff6a98);
  220. }
  221. .buyQuestion:hover{
  222. color: #FF4F4F;
  223. }
  224. </style>