BuyVip.vue 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231
  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>
  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. <client-only>
  41. <vue-qr :size="176" :text="qrcode"></vue-qr>
  42. </client-only>
  43. <p class="text-[#666] text-18px leading-20px">扫一扫 即可支付</p>
  44. </div>
  45. </div>
  46. </div>
  47. <div v-show="orderStatus === '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. orderStatus: 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. this.orderStatus = res?.result?.statusName
  121. if(this.orderStatus === 'success') {
  122. this.count = 0
  123. setTimeout(() => {
  124. this.$emit('close')
  125. // 更新个人信息
  126. this.getUserInfo()
  127. }, 1000);
  128. }else {
  129. this.count--
  130. }
  131. })
  132. }
  133. }, 2000);
  134. if(this.count === 0) {
  135. this.$once('hook:beforeDestroy',()=> {
  136. clearInterval(interval)
  137. interval = null
  138. })
  139. }
  140. },
  141. getUserInfo() {
  142. this.$axios.get('members/getMemberInfo').then((res)=> {
  143. if(res.code === 200) {
  144. this.$store.commit('setUser',res.result.memberInfo)
  145. this.$router.push('/members/me/expenses')
  146. }
  147. })
  148. },
  149. handlePlayNow() {
  150. const params = {
  151. client: 'web',
  152. payment: 0,
  153. targetType: 'SetPricing',
  154. targetId: this.choosedVip.id
  155. }
  156. this.$axios.post('subscription/create',params).then((res) => {
  157. if(res.code === 200) {
  158. location.href = res.result.order.pagePayUrl
  159. this.$store.commit('OPEN_LOGIN',false)
  160. }
  161. })
  162. }
  163. }
  164. }
  165. </script>
  166. <style lang="scss">
  167. .vip-wechat-qrcode {
  168. img {
  169. display: block;
  170. }
  171. }
  172. .note {
  173. width: 69px;
  174. height: 26px;
  175. background: url(http://cn-file.17pdf.com/website/member_v2/members_tag_price.png) no-repeat;
  176. background-size: 100% 100%;
  177. color: #fff;
  178. position: absolute;
  179. top: -11px;
  180. left: -7px;
  181. font-size: 14px;
  182. text-indent: 4px;
  183. text-align: left;
  184. }
  185. .pay-method{
  186. width: 116px;
  187. height: 50px;
  188. border: 1px solid #b3b3b3;
  189. border-radius: 2px;
  190. margin: 0 20px 0 0;
  191. text-align: center;
  192. cursor: pointer;
  193. display: inline-block;
  194. }
  195. .play-now{
  196. width: 376px;
  197. height: 58px;
  198. margin-left: 35px;
  199. background: #ff4f4f;
  200. font-size: 24px;
  201. border-radius: 2px;
  202. color: #fff;
  203. font-weight: 400;
  204. }
  205. .pay-tittle{
  206. height: 80px;
  207. line-height: 80px;
  208. color: rgb(51,51,51);
  209. font-size: 20px;
  210. text-align: center;
  211. }
  212. .pay-content{
  213. text-align: center;
  214. img{
  215. margin: 50px auto 30px;
  216. }
  217. span{
  218. color: rgb(195,195,195);
  219. margin-bottom: 125px;
  220. font-size: 14px;
  221. display: block;
  222. margin-top: 100px;
  223. }
  224. }
  225. </style>