BuyVip.vue 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211
  1. <!--
  2. * @Description:
  3. * @Author: 欧阳承珺
  4. * @LastEditors: 欧阳承珺
  5. * @Date: 2022-10-31 20:41:42
  6. * @LastEditTime: 2022-11-02 19:06:53
  7. -->
  8. <template>
  9. <div>
  10. <div v-show="!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>
  31. <button v-if="paymethod === 'alipay'" class="play-now" @click="handlePlayNow">立即支付</button>
  32. <div v-else class="text-center">
  33. <div v-if="count <= 0">
  34. <div>
  35. <p class="text-18px mb-15px">二维码过期,请刷新</p>
  36. <el-button @click="handleFreshWechetCode">刷新</el-button>
  37. </div>
  38. </div>
  39. <div v-else>
  40. <no-ssr>
  41. <vue-qr :size="176" :text="qrcode"></vue-qr>
  42. </no-ssr>
  43. <p class="text-[#666] text-18px leading-20px">扫一扫 即可支付</p>
  44. </div>
  45. </div>
  46. </div>
  47. <div v-show="success">
  48. <div class="pay-tittle">
  49. <p>支付成功</p>
  50. </div>
  51. <div class="pay-content">
  52. <img src="http://cn-file.17pdf.com/website/pricings/check.png" />
  53. <span>嘿嘿嘿...尽情享受您的特权吧</span>
  54. </div>
  55. </div>
  56. </div>
  57. </template>
  58. <script>
  59. export default {
  60. data() {
  61. return {
  62. list: [],
  63. choosedVip: {},
  64. paymethod: '',
  65. qrcode: '',
  66. count: 60,
  67. success: false
  68. }
  69. },
  70. created() {
  71. // this.resetInterfaceStatus()
  72. this.getVipList()
  73. },
  74. methods: {
  75. resetInterfaceStatus() {
  76. // this.getVipList()
  77. },
  78. handleFreshWechetCode() {
  79. this.count = 60
  80. this.choosePayMethod('wechat')
  81. },
  82. chooseVip(item) {
  83. this.choosedVip = item
  84. this.choosePayMethod(this.paymethod)
  85. },
  86. getMonth({period}) {
  87. return period.split('.')[0]
  88. },
  89. getVipList() {
  90. // 默认选择支付宝支付,调用相关信息
  91. this.paymethod = 'alipay'
  92. this.$axios.get('setPricing/list').then((res)=> {
  93. if(res.code === 200) {
  94. this.list = res.result.filter(item => item.mode !== 0) // 免费模式的不展示
  95. this.choosedVip = this.list[this.list.length - 1]
  96. }
  97. })
  98. },
  99. choosePayMethod(type) {
  100. this.paymethod = type
  101. const params = {
  102. client: 'web',
  103. payment: this.paymethod === 'wechat' ? 1 : 0,
  104. targetType: 'SetPricing',
  105. targetId: this.choosedVip.id
  106. }
  107. this.$axios.post('subscription/create',params).then((res) => {
  108. if(res.code === 200) {
  109. if(this.paymethod === 'wechat') {
  110. this.qrcode = res.result.order.qrcodeUrl
  111. this.getWechatPayStatus(res.result.order.id)
  112. }
  113. }
  114. })
  115. },
  116. getWechatPayStatus(id) {
  117. let interval = setInterval(() => {
  118. if(this.count > 0) {
  119. this.$axios.get(`order/getWxOrder?orderId=${id}`).then((res)=>{
  120. if(res?.result?.trade_state === 'SUCCESS') {
  121. this.success = true
  122. this.count = 0
  123. setTimeout(() => {
  124. this.$emit('close')
  125. this.$router.push('/members/me/expenses')
  126. }, 1000);
  127. }else {
  128. this.count--
  129. }
  130. })
  131. }
  132. }, 2000);
  133. if(this.count === 0) {
  134. this.$once('hook:beforeDestroy',()=> {
  135. clearInterval(interval)
  136. interval = null
  137. })
  138. }
  139. },
  140. handlePlayNow() {
  141. }
  142. }
  143. }
  144. </script>
  145. <style lang="scss">
  146. .vip-wechat-qrcode {
  147. img {
  148. display: block;
  149. }
  150. }
  151. .note {
  152. width: 69px;
  153. height: 26px;
  154. background: url(http://cn-file.17pdf.com/website/member_v2/members_tag_price.png) no-repeat;
  155. background-size: 100% 100%;
  156. color: #fff;
  157. position: absolute;
  158. top: -11px;
  159. left: -7px;
  160. font-size: 14px;
  161. text-indent: 4px;
  162. text-align: left;
  163. }
  164. .pay-method{
  165. width: 116px;
  166. height: 50px;
  167. border: 1px solid #b3b3b3;
  168. border-radius: 2px;
  169. margin: 0 20px 0 0;
  170. text-align: center;
  171. cursor: pointer;
  172. display: inline-block;
  173. }
  174. .play-now{
  175. width: 376px;
  176. height: 58px;
  177. margin-left: 35px;
  178. background: #ff4f4f;
  179. font-size: 24px;
  180. border-radius: 2px;
  181. color: #fff;
  182. font-weight: 400;
  183. }
  184. .pay-tittle{
  185. height: 80px;
  186. line-height: 80px;
  187. color: rgb(51,51,51);
  188. font-size: 20px;
  189. text-align: center;
  190. }
  191. .pay-content{
  192. text-align: center;
  193. img{
  194. margin: 50px auto 30px;
  195. }
  196. span{
  197. color: rgb(195,195,195);
  198. margin-bottom: 125px;
  199. font-size: 14px;
  200. display: block;
  201. margin-top: 100px;
  202. }
  203. }
  204. </style>