index.vue 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242
  1. <template>
  2. <view class="member-container">
  3. <view class="header dir-top-wrap cross-center">
  4. <view class="title">会员充值</view>
  5. <text class="tips">会员指定短剧无限观看、xxx 等特权</text>
  6. </view>
  7. <view class="content main-left">
  8. <view
  9. v-for="(item,index) in settings"
  10. :key="index"
  11. class="item dir-top-wrap cross-center main-center"
  12. :class="{active: activeIndex === index}"
  13. @click="handleSelect(index)"
  14. >
  15. <view class="border" />
  16. <view v-if="activeIndex === index" class="selected">已选择</view>
  17. <text class="day">{{ item.valid_day }}天</text>
  18. <text class="price">¥{{ item.price }}</text>
  19. </view>
  20. </view>
  21. <view class="free main-center cross-center" @click="$u.route('/pages/member/free')">
  22. 查看 <text>免费片单</text>
  23. </view>
  24. <!--购买弹窗-->
  25. <u-modal
  26. :show="modal.show"
  27. content="确定购买?"
  28. show-cancel-button
  29. @confirm="handleBuy"
  30. @cancel="modal.show = false"
  31. />
  32. </view>
  33. </template>
  34. <script>
  35. export default {
  36. data() {
  37. return {
  38. settings: [],
  39. activeIndex: 0,
  40. payId: null,
  41. interval: null,
  42. modal: {
  43. show: false
  44. }
  45. }
  46. },
  47. methods: {
  48. getSetting() {
  49. this.$loading()
  50. this.$api.user.vip.setting().then(res => {
  51. this.$hideLoading()
  52. this.settings = res.data
  53. })
  54. },
  55. handleSelect(index) {
  56. this.activeIndex = index
  57. this.modal.show = true
  58. },
  59. handleBuy() {
  60. const item = this.settings[this.activeIndex]
  61. this.$loading('购买中...')
  62. this.$api.user.vip.create({ id: item.id }).then(res => {
  63. this.$hideLoading()
  64. this.payId = res.pay_id
  65. this.modal.show = false
  66. // #ifdef MP-TOUTIAO
  67. tt.pay({
  68. service: 5,
  69. orderInfo: {
  70. order_id: res.data.order_id,
  71. order_token: res.data.order_token
  72. },
  73. success: payRes => {
  74. if (payRes.code === 0) {
  75. this.$loading('支付结果查询中...')
  76. this.query()
  77. } else {
  78. this.$u.toast('支付失败')
  79. }
  80. },
  81. fail: err => {
  82. console.log('-->data', err)
  83. // 调起收银台失败处理逻辑
  84. }
  85. })
  86. // #endif
  87. // #ifdef MP-KUAISHOU
  88. ks.pay({
  89. serviceId: '1',
  90. orderInfo: {
  91. order_no: res.data.order_id,
  92. order_info_token: res.data.order_token
  93. },
  94. success: payRes => {
  95. this.$loading('支付结果查询中...')
  96. this.query()
  97. },
  98. fail: err => {
  99. console.log('-->data', err)
  100. // 调起收银台失败处理逻辑
  101. }
  102. })
  103. // #endif
  104. }).catch(() => {
  105. this.$hideLoading()
  106. })
  107. },
  108. query() {
  109. if (this.interval) return
  110. this.interval = setInterval(() => {
  111. this.$api.pay.query(this.payId).then(res => {
  112. this.$hideLoading()
  113. this.$u.toast('支付成功')
  114. clearInterval(this.interval)
  115. // 获取用户信息
  116. this.$api.user.info().then(res => {
  117. this.$store.dispatch('user/info', res.data)
  118. })
  119. }).catch(err => {
  120. })
  121. }, 1000)
  122. }
  123. },
  124. onLoad() {
  125. this.getSetting()
  126. }
  127. }
  128. </script>
  129. <style lang="scss" scoped>
  130. .member-container{
  131. padding: 20rpx 0;
  132. font-size: 30rpx;
  133. .header{
  134. color: $primary-color;
  135. margin-top: 50rpx;
  136. .title{
  137. position: relative;
  138. font-size: 42rpx;
  139. font-weight: 600;
  140. width: 100%;
  141. text-align: center;
  142. &:before,&:after{
  143. content: "";
  144. background: url("/static/image/member-line-bg.png") no-repeat;
  145. background-size: 100%;
  146. position: absolute;
  147. top: 50%;
  148. left: 60rpx;
  149. width: 200rpx;
  150. height: 20rpx;
  151. }
  152. &:after{
  153. transform: rotate(180deg);
  154. right: 60rpx;
  155. left: unset;
  156. top: 20%;
  157. }
  158. }
  159. .tips{
  160. color: $dark-color;
  161. font-size: 26rpx;
  162. margin-top: 20rpx;
  163. }
  164. }
  165. .content{
  166. padding: 0 20rpx;
  167. margin-top: 80rpx;
  168. .item{
  169. color: $default-color;
  170. margin-left: 20rpx;
  171. flex: 1;
  172. height: 300rpx;
  173. position: relative;
  174. .border{
  175. position: absolute;
  176. top: 0;
  177. left: 0;
  178. right: 0;
  179. bottom: 0;
  180. z-index: 0;
  181. border: 4rpx solid $info-color;
  182. border-radius: 10rpx;
  183. overflow: hidden;
  184. }
  185. &.active .border{
  186. border: unset;
  187. &:after{
  188. content: "";
  189. position: absolute;
  190. top: 0;
  191. left: 0;
  192. right: 0;
  193. bottom: 0;
  194. border: 4rpx solid;
  195. border-image: linear-gradient(222deg, #6EEBE8, #FF74B9) 1;
  196. z-index: 0;
  197. }
  198. }
  199. .selected{
  200. position: absolute;
  201. top: -20rpx;
  202. background: url("/static/image/member-selected-bg.png") no-repeat;
  203. background-size: 100%;
  204. text-align: center;
  205. width: 120rpx;
  206. height: 40rpx;
  207. font-size: 24rpx;
  208. line-height: 40rpx;
  209. left: 20rpx;
  210. z-index: 1;
  211. }
  212. &:first-child{
  213. margin-left: 0;
  214. }
  215. .day{
  216. font-size: 32rpx;
  217. margin-bottom: 80rpx;
  218. }
  219. .price{
  220. font-size: 38rpx;
  221. color: $primary-color;
  222. }
  223. }
  224. }
  225. .free{
  226. background: #1B1E32;
  227. width: 100%;
  228. padding: 20rpx 0;
  229. color: $info-color;
  230. text-align: center;
  231. font-size: 26rpx;
  232. margin-top: 60px;
  233. text{
  234. color: $dark-color;
  235. }
  236. }
  237. }
  238. </style>