BuyVip.vue 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256
  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. <client-only><el-button @click="handleFreshWechetCode">刷新</el-button></client-only>
  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. import { mapState } from 'vuex'
  60. export default {
  61. data() {
  62. return {
  63. list: [],
  64. choosedVip: {},
  65. paymethod: '',
  66. qrcode: '',
  67. count: 60,
  68. orderStatus: false
  69. }
  70. },
  71. created() {
  72. // this.resetInterfaceStatus()
  73. this.getVipList()
  74. },
  75. computed: {
  76. ...mapState([
  77. "globalLoginVisiable",
  78. ]),
  79. },
  80. // watch:{
  81. // globalLoginVisiable(newVal){
  82. // if(!newVal){
  83. // this.list=[]
  84. // this.choosedVip = {},
  85. // this.paymethod = '',
  86. // this.qrcode = '',
  87. // this.orderStatus = false,
  88. // this.count = 60
  89. // this.getVipList()
  90. // }
  91. // }
  92. // },
  93. methods: {
  94. resetInterfaceStatus() {
  95. // this.getVipList()
  96. },
  97. handleFreshWechetCode() {
  98. this.count = 60
  99. this.choosePayMethod('wechat')
  100. },
  101. chooseVip(item) {
  102. this.choosedVip = item
  103. this.choosePayMethod(this.paymethod)
  104. },
  105. getMonth({period}) {
  106. return period.split('.')[0]
  107. },
  108. getVipList() {
  109. // 默认选择支付宝支付,调用相关信息
  110. this.paymethod = 'alipay'
  111. this.$axios.get('setPricing/list').then((res)=> {
  112. if(res.code === 200) {
  113. this.list = res.result.filter(item => item.mode !== 0) // 免费模式的不展示
  114. this.choosedVip = this.list[this.list.length - 1]
  115. }
  116. })
  117. },
  118. choosePayMethod(type) {
  119. this.paymethod = type
  120. const params = {
  121. client: 'web',
  122. payment: this.paymethod === 'wechat' ? 1 : 0,
  123. targetType: 'SetPricing',
  124. targetId: this.choosedVip.id
  125. }
  126. this.$axios.post('subscription/create',params).then((res) => {
  127. if(res.code === 200) {
  128. if(this.paymethod === 'wechat') {
  129. this.qrcode = res.result.order.qrcodeUrl
  130. this.getWechatPayStatus(res.result.order.id)
  131. }
  132. }
  133. })
  134. },
  135. getWechatPayStatus(id) {
  136. let interval = setInterval(() => {
  137. if(this.count > 0) {
  138. this.$axios.get(`order/getWxOrder?orderId=${id}`).then((res)=>{
  139. this.orderStatus = res?.result?.statusName
  140. if(this.orderStatus === 'success') {
  141. this.count = 0
  142. // 支付成功关定时器
  143. clearInterval(interval)
  144. setTimeout(() => {
  145. this.$emit('close')
  146. // 更新个人信息
  147. this.getUserInfo()
  148. }, 1000);
  149. }else {
  150. this.count--
  151. }
  152. // 关闭就关定时器
  153. if(!this.globalLoginVisiable){
  154. clearInterval(interval)
  155. }
  156. })
  157. }
  158. }, 2000);
  159. if(this.count === 0) {
  160. this.$once('hook:beforeDestroy',()=> {
  161. clearInterval(interval)
  162. interval = null
  163. })
  164. }
  165. },
  166. getUserInfo() {
  167. this.$axios.get('members/getMemberInfo').then((res)=> {
  168. if(res.code === 200) {
  169. this.$store.commit('setUser',res.result.memberInfo)
  170. this.$router.push('/members/me/expenses')
  171. }
  172. })
  173. },
  174. handlePlayNow() {
  175. const params = {
  176. client: 'web',
  177. payment: 0,
  178. targetType: 'SetPricing',
  179. targetId: this.choosedVip.id
  180. }
  181. this.$axios.post('subscription/create',params).then((res) => {
  182. if(res.code === 200) {
  183. location.href = res.result.order.pagePayUrl
  184. this.$store.commit('OPEN_LOGIN',false)
  185. }
  186. })
  187. }
  188. }
  189. }
  190. </script>
  191. <style lang="scss">
  192. .vip-wechat-qrcode {
  193. img {
  194. display: block;
  195. }
  196. }
  197. .note {
  198. width: 69px;
  199. height: 26px;
  200. background: url(http://cn-file.17pdf.com/website/member_v2/members_tag_price.png) no-repeat;
  201. background-size: 100% 100%;
  202. color: #fff;
  203. position: absolute;
  204. top: -11px;
  205. left: -7px;
  206. font-size: 14px;
  207. text-indent: 4px;
  208. text-align: left;
  209. }
  210. .pay-method{
  211. width: 116px;
  212. height: 50px;
  213. border: 1px solid #b3b3b3;
  214. border-radius: 2px;
  215. margin: 0 20px 0 0;
  216. text-align: center;
  217. cursor: pointer;
  218. display: inline-block;
  219. }
  220. .play-now{
  221. width: 376px;
  222. height: 58px;
  223. margin-left: 35px;
  224. background: #ff4f4f;
  225. font-size: 24px;
  226. border-radius: 2px;
  227. color: #fff;
  228. font-weight: 400;
  229. }
  230. .pay-tittle{
  231. height: 80px;
  232. line-height: 80px;
  233. color: rgb(51,51,51);
  234. font-size: 20px;
  235. text-align: center;
  236. }
  237. .pay-content{
  238. text-align: center;
  239. img{
  240. margin: 50px auto 30px;
  241. }
  242. span{
  243. color: rgb(195,195,195);
  244. margin-bottom: 125px;
  245. font-size: 14px;
  246. display: block;
  247. margin-top: 100px;
  248. }
  249. }
  250. </style>