BuyTicket.vue 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230
  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')">
  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')">
  26. <img class="inline-block" src="http://cn-file.17pdf.com/website/pricings/wechat_logo.png"> 微信
  27. </div>
  28. <div class="inline-block ml-90px text-[14px] underline cursor-pointer buyQuestion" @click="goToQuestion">支付遇到问题?</div>
  29. </div>
  30. <button v-if="paymethod === 'alipay'" class="play-now" style="margin-left: 68px" @click="handlePlayNow">立即支付</button>
  31. <div v-else 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 = 'alipay'
  121. }
  122. })
  123. },
  124. choosePayMethod(type) {
  125. clearInterval(this.interval)
  126. this.interval = null
  127. this.paymethod = type
  128. if(type === 'wechat') {
  129. const params = {
  130. client: 'web',
  131. payment: this.paymethod === 'wechat' ? 1 : 0,
  132. targetType: 'Pricing',
  133. targetId: this.choosedTicket.id
  134. }
  135. this.$axios.post('subscription/create',params).then((res) => {
  136. if(res.code === 200) {
  137. // console.log("展示微信二维码")
  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. // console.log("查询微信支付")
  150. if(this.orderStatus === 'success') {
  151. // console.log("微信支付成功")
  152. this.count = 0
  153. // 支付成功关定时器
  154. clearInterval(this.interval)
  155. setTimeout(() => {
  156. this.$emit('close')
  157. // 更新个人信息
  158. this.getUserInfo()
  159. }, 1000);
  160. }else {
  161. this.count--
  162. }
  163. // 关闭就关定时器
  164. if(!this.globalLoginVisiable){
  165. clearInterval(this.interval)
  166. }
  167. })
  168. }
  169. }, 2000);
  170. if(this.count === 0) {
  171. this.$once('hook:beforeDestroy',()=> {
  172. clearInterval(this.interval)
  173. this.interval = null
  174. })
  175. }
  176. },
  177. handlePlayNow() {
  178. const params = {
  179. client: 'web',
  180. payment: 0,
  181. targetType: 'Pricing',
  182. targetId: this.choosedTicket.id
  183. }
  184. this.$axios.post('subscription/create',params).then((res) => {
  185. if(res.code === 200) {
  186. location.href = res.result.order.pagePayUrl
  187. setTimeout(() => {
  188. this.$emit('close')
  189. }, 600);
  190. // this.$store.commit('OPEN_LOGIN',false)
  191. }
  192. })
  193. },
  194. getUserInfo() {
  195. this.$axios.get('members/getMemberInfo').then((res)=> {
  196. if(res.code === 200) {
  197. this.$store.commit('setUser',res.result.memberInfo)
  198. this.$router.push('/members/me/points')
  199. }
  200. })
  201. },
  202. //跳转至question页面
  203. goToQuestion(){
  204. this.$emit('close')
  205. this.$router.push({path: '/question#payment'})
  206. }
  207. }
  208. }
  209. </script>
  210. <style lang="scss">
  211. .ticket0 {
  212. background: linear-gradient(#b98dff, #7384ff);
  213. }
  214. .ticket1 {
  215. background: linear-gradient(#60b8ff, #27d6c5);
  216. }
  217. .ticket2 {
  218. background: linear-gradient(#ff8e4a, #e1b973);
  219. }
  220. .ticket3 {
  221. background: linear-gradient(#ff8279, #ff6a98);
  222. }
  223. .buyQuestion:hover{
  224. color: #FF4F4F;
  225. }
  226. </style>