BuyVip.vue 7.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271
  1. <!--
  2. * @Description:
  3. * @Author: 欧阳承珺
  4. * @LastEditors: 欧阳承珺
  5. * @Date: 2022-10-31 20:41:42
  6. * @LastEditTime: 2022-11-15 19:24:18
  7. -->
  8. <template>
  9. <div>
  10. <div v-show="orderStatus !== 'success'">
  11. <p class="text-22px text-[#666] text-center font-500">升级成为会员</p>
  12. <div class="py-27px px-35px">
  13. <p class="text-16px text-[#4d4d4d] mb-30px">开通时长:</p>
  14. <div class="flex justify-between">
  15. <div v-for="(item,idx) in list" :key="idx" class="w-116px h-130px relative cursor-pointer" :style="{'border': choosedVip.period === item.period ? '2px solid #FF4F4F' : '1px solid #b3b3b3'}" @click="chooseVip(item)">
  16. <span v-if="idx === 2" class="note">仅{{Math.round(10 * item.price/getMonth(item)) / 10}}/月</span>
  17. <div class="w-full h-79px text-16px font-[#878787] leading-79px text-center font-400"><span class="text-26px font-500">{{item.price}}</span>元</div>
  18. <div style="border-top: 1px solid #b8b8b8;" class="w-90px mx-auto h-49px text-16px text-black leading-49px text-center font-400">{{getMonth(item)}}个月</div>
  19. </div>
  20. </div>
  21. </div>
  22. <div class="py-27px px-35px">
  23. <p class="text-16px text-[#4d4d4d] mb-14px align-middle">支付方式:</p>
  24. <div class="pay-method" :style="{'border': paymethod === 'wechat' ? '2px solid #FF4F4F' : '1px solid #b3b3b3'}" @click="choosePayMethod('wechat')">
  25. <img src="http://cn-file.17pdf.com/website/member_v2/members_ic_pay_weixin.png">
  26. </div>
  27. <div class="pay-method" :style="{'border': paymethod === 'alipay' ? '2px solid #FF4F4F' : '1px solid #b3b3b3'}" @click="choosePayMethod('alipay')">
  28. <img src="http://cn-file.17pdf.com/website/member_v2/members_ic_pay_zhifubao.png">
  29. </div>
  30. <div class="inline-block ml-0px text-[14px] underline cursor-pointer buyQuestion relative top-[-20px]" @click="goToQuestion"><a href="/question#payment" target="_blank">支付遇到问题?</a> </div>
  31. </div>
  32. <button v-if="paymethod === 'alipay'" class="play-now" @click="handlePlayNow">立即支付</button>
  33. <div v-if="paymethod === 'wechat'" class="text-center">
  34. <div v-if="count <= 0">
  35. <div>
  36. <p class="text-18px mb-15px">二维码过期,请刷新</p>
  37. <client-only><el-button @click="handleFreshWechetCode">刷新</el-button></client-only>
  38. </div>
  39. </div>
  40. <div v-else>
  41. <client-only>
  42. <vue-qr :size="176" :text="qrcode"></vue-qr>
  43. </client-only>
  44. <p class="text-[#666] text-18px leading-20px">扫一扫 即可支付</p>
  45. </div>
  46. </div>
  47. </div>
  48. <div v-show="orderStatus === 'success'">
  49. <div class="pay-tittle">
  50. <p>支付成功</p>
  51. </div>
  52. <div class="pay-content">
  53. <img src="http://cn-file.17pdf.com/website/pricings/check.png" />
  54. <span>嘿嘿嘿...尽情享受您的特权吧</span>
  55. </div>
  56. </div>
  57. </div>
  58. </template>
  59. <script>
  60. import { mapState } from 'vuex'
  61. export default {
  62. data() {
  63. return {
  64. list: [],
  65. choosedVip: {},
  66. paymethod: '',
  67. qrcode: '',
  68. count: 150,
  69. orderStatus: false,
  70. interval: ''
  71. }
  72. },
  73. created() {
  74. // this.resetInterfaceStatus()
  75. this.getVipList()
  76. },
  77. computed: {
  78. ...mapState([
  79. "globalLoginVisiable",
  80. ]),
  81. },
  82. watch:{
  83. globalLoginVisiable(newVal){
  84. if(!newVal){
  85. if(this.paymethod === 'wechat'){
  86. this.list=[]
  87. this.choosedVip = {},
  88. this.paymethod = '',
  89. this.qrcode = '',
  90. this.orderStatus = false,
  91. this.count = 150
  92. this.getVipList()
  93. }
  94. }
  95. }
  96. },
  97. methods: {
  98. resetInterfaceStatus() {
  99. // this.getVipList()
  100. },
  101. handleFreshWechetCode() {
  102. this.count = 150
  103. this.choosePayMethod('wechat')
  104. },
  105. chooseVip(item) {
  106. this.choosedVip = item
  107. this.count = 150
  108. this.choosePayMethod(this.paymethod)
  109. },
  110. getMonth({period}) {
  111. return period.split('.')[0]
  112. },
  113. getVipList() {
  114. // 默认选择支付宝支付,调用相关信息
  115. this.paymethod = 'wechat'
  116. this.$axios.get('setPricing/list').then((res)=> {
  117. if(res.code === 200) {
  118. this.list = res.result.filter(item => item.mode !== 0) // 免费模式的不展示
  119. this.choosedVip = this.list[this.list.length - 1]
  120. this.choosePayMethod('wechat')
  121. }
  122. })
  123. },
  124. choosePayMethod(type) {
  125. clearInterval(this.interval)
  126. this.interval = null
  127. this.paymethod = type
  128. const params = {
  129. client: 'web',
  130. payment: this.paymethod === 'wechat' ? 1 : 0,
  131. targetType: 'SetPricing',
  132. targetId: this.choosedVip.id
  133. }
  134. if(this.paymethod === 'wechat'){
  135. this.$axios.post('subscription/create',params).then((res) => {
  136. if(res.code === 200) {
  137. this.qrcode = res.result.order.qrcodeUrl
  138. this.getWechatPayStatus(res.result.order.id)
  139. }
  140. })
  141. }
  142. },
  143. getWechatPayStatus(id) {
  144. this.interval = setInterval(() => {
  145. if(this.count > 0) {
  146. this.$axios.get(`order/getWxOrder?orderId=${id}`).then((res)=>{
  147. this.orderStatus = res?.result?.statusName
  148. if(this.orderStatus === 'success') {
  149. this.count = 0
  150. // 支付成功关定时器
  151. clearInterval(this.interval)
  152. setTimeout(() => {
  153. this.$emit('close')
  154. // 更新个人信息
  155. this.getUserInfo()
  156. }, 1000);
  157. }else {
  158. this.count--
  159. }
  160. // 关闭就关定时器
  161. if(!this.globalLoginVisiable){
  162. clearInterval(this.interval)
  163. }
  164. })
  165. }
  166. }, 2000);
  167. if(this.count === 0) {
  168. this.$once('hook:beforeDestroy',()=> {
  169. clearInterval(this.interval)
  170. this.interval = null
  171. })
  172. }
  173. },
  174. getUserInfo() {
  175. this.$axios.get('members/getMemberInfo').then((res)=> {
  176. if(res.code === 200) {
  177. this.$store.commit('setUser',res.result.memberInfo)
  178. this.$router.push('/members/me/vip')
  179. }
  180. })
  181. },
  182. handlePlayNow() {
  183. const params = {
  184. client: 'web',
  185. payment: 0,
  186. targetType: 'SetPricing',
  187. targetId: this.choosedVip.id
  188. }
  189. this.$axios.post('subscription/create',params).then((res) => {
  190. if(res.code === 200) {
  191. location.href = res.result.order.pagePayUrl
  192. setTimeout(() => {
  193. this.$emit('close')
  194. }, 600);
  195. }
  196. })
  197. },
  198. //跳转至question页面
  199. goToQuestion(){
  200. // this.$emit('close')
  201. // this.$router.resolve({path: '/question#payment'})
  202. }
  203. }
  204. }
  205. </script>
  206. <style lang="scss">
  207. .vip-wechat-qrcode {
  208. img {
  209. display: block;
  210. }
  211. }
  212. .note {
  213. width: 69px;
  214. height: 26px;
  215. background: url(http://cn-file.17pdf.com/website/member_v2/members_tag_price.png) no-repeat;
  216. background-size: 100% 100%;
  217. color: #fff;
  218. position: absolute;
  219. top: -11px;
  220. left: -7px;
  221. font-size: 14px;
  222. text-indent: 4px;
  223. text-align: left;
  224. }
  225. .pay-method{
  226. width: 116px;
  227. height: 50px;
  228. border: 1px solid #b3b3b3;
  229. border-radius: 2px;
  230. margin: 0 20px 0 0;
  231. text-align: center;
  232. cursor: pointer;
  233. display: inline-block;
  234. }
  235. .play-now{
  236. width: 376px;
  237. height: 58px;
  238. margin-left: 35px;
  239. background: #ff4f4f;
  240. font-size: 24px;
  241. border-radius: 2px;
  242. color: #fff;
  243. font-weight: 400;
  244. }
  245. .pay-tittle{
  246. height: 80px;
  247. line-height: 80px;
  248. color: rgb(51,51,51);
  249. font-size: 20px;
  250. text-align: center;
  251. }
  252. .pay-content{
  253. text-align: center;
  254. img{
  255. margin: 50px auto 30px;
  256. }
  257. span{
  258. color: rgb(195,195,195);
  259. margin-bottom: 125px;
  260. font-size: 14px;
  261. display: block;
  262. margin-top: 100px;
  263. }
  264. }
  265. </style>