index.vue 7.4 KB

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