BuyVip.vue 7.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270
  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">支付方式:</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" @click="goToQuestion">支付遇到问题?</div>
  31. </div>
  32. <button v-if="paymethod === 'alipay'" class="play-now" @click="handlePlayNow">立即支付</button>
  33. <div v-else 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 = 'alipay'
  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. }
  121. })
  122. },
  123. choosePayMethod(type) {
  124. clearInterval(this.interval)
  125. this.interval = null
  126. this.paymethod = type
  127. const params = {
  128. client: 'web',
  129. payment: this.paymethod === 'wechat' ? 1 : 0,
  130. targetType: 'SetPricing',
  131. targetId: this.choosedVip.id
  132. }
  133. this.$axios.post('subscription/create',params).then((res) => {
  134. if(res.code === 200) {
  135. if(this.paymethod === 'wechat') {
  136. this.qrcode = res.result.order.qrcodeUrl
  137. this.getWechatPayStatus(res.result.order.id)
  138. }
  139. }
  140. })
  141. },
  142. getWechatPayStatus(id) {
  143. this.interval = setInterval(() => {
  144. if(this.count > 0) {
  145. this.$axios.get(`order/getWxOrder?orderId=${id}`).then((res)=>{
  146. this.orderStatus = res?.result?.statusName
  147. if(this.orderStatus === 'success') {
  148. this.count = 0
  149. // 支付成功关定时器
  150. clearInterval(this.interval)
  151. setTimeout(() => {
  152. this.$emit('close')
  153. // 更新个人信息
  154. this.getUserInfo()
  155. }, 1000);
  156. }else {
  157. this.count--
  158. }
  159. // 关闭就关定时器
  160. if(!this.globalLoginVisiable){
  161. clearInterval(this.interval)
  162. }
  163. })
  164. }
  165. }, 2000);
  166. if(this.count === 0) {
  167. this.$once('hook:beforeDestroy',()=> {
  168. clearInterval(this.interval)
  169. this.interval = null
  170. })
  171. }
  172. },
  173. getUserInfo() {
  174. this.$axios.get('members/getMemberInfo').then((res)=> {
  175. if(res.code === 200) {
  176. this.$store.commit('setUser',res.result.memberInfo)
  177. this.$router.push('/members/me/vip')
  178. }
  179. })
  180. },
  181. handlePlayNow() {
  182. const params = {
  183. client: 'web',
  184. payment: 0,
  185. targetType: 'SetPricing',
  186. targetId: this.choosedVip.id
  187. }
  188. this.$axios.post('subscription/create',params).then((res) => {
  189. if(res.code === 200) {
  190. location.href = res.result.order.pagePayUrl
  191. setTimeout(() => {
  192. this.$emit('close')
  193. }, 600);
  194. }
  195. })
  196. },
  197. //跳转至question页面
  198. goToQuestion(){
  199. this.$emit('close')
  200. this.$router.push({path: '/question#payment'})
  201. }
  202. }
  203. }
  204. </script>
  205. <style lang="scss">
  206. .vip-wechat-qrcode {
  207. img {
  208. display: block;
  209. }
  210. }
  211. .note {
  212. width: 69px;
  213. height: 26px;
  214. background: url(http://cn-file.17pdf.com/website/member_v2/members_tag_price.png) no-repeat;
  215. background-size: 100% 100%;
  216. color: #fff;
  217. position: absolute;
  218. top: -11px;
  219. left: -7px;
  220. font-size: 14px;
  221. text-indent: 4px;
  222. text-align: left;
  223. }
  224. .pay-method{
  225. width: 116px;
  226. height: 50px;
  227. border: 1px solid #b3b3b3;
  228. border-radius: 2px;
  229. margin: 0 20px 0 0;
  230. text-align: center;
  231. cursor: pointer;
  232. display: inline-block;
  233. }
  234. .play-now{
  235. width: 376px;
  236. height: 58px;
  237. margin-left: 35px;
  238. background: #ff4f4f;
  239. font-size: 24px;
  240. border-radius: 2px;
  241. color: #fff;
  242. font-weight: 400;
  243. }
  244. .pay-tittle{
  245. height: 80px;
  246. line-height: 80px;
  247. color: rgb(51,51,51);
  248. font-size: 20px;
  249. text-align: center;
  250. }
  251. .pay-content{
  252. text-align: center;
  253. img{
  254. margin: 50px auto 30px;
  255. }
  256. span{
  257. color: rgb(195,195,195);
  258. margin-bottom: 125px;
  259. font-size: 14px;
  260. display: block;
  261. margin-top: 100px;
  262. }
  263. }
  264. </style>