index.vue 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290
  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. // IOS 不允许购买
  74. if (!this.$util.checkOS()) return
  75. const item = this.settings[this.activeIndex]
  76. this.$loading('购买中...')
  77. this.$api.user.vip.create({ id: item.id }).then(res => {
  78. this.$hideLoading()
  79. this.payId = res.pay_id
  80. this.modal.show = false
  81. // #ifdef MP-TOUTIAO
  82. tt.pay({
  83. service: 5,
  84. orderInfo: {
  85. order_id: res.data.order_id,
  86. order_token: res.data.order_token
  87. },
  88. success: payRes => {
  89. if (payRes.code === 0) {
  90. this.$loading('支付结果查询中...')
  91. this.query()
  92. } else {
  93. this.$u.toast('支付失败')
  94. }
  95. },
  96. fail: err => {
  97. console.log('-->data', err)
  98. // 调起收银台失败处理逻辑
  99. }
  100. })
  101. // #endif
  102. // #ifdef MP-KUAISHOU
  103. ks.pay({
  104. serviceId: '1',
  105. orderInfo: {
  106. order_no: res.data.order_id,
  107. order_info_token: res.data.order_token
  108. },
  109. success: payRes => {
  110. this.$loading('支付结果查询中...')
  111. this.query()
  112. },
  113. fail: err => {
  114. console.log('-->data', err)
  115. // 调起收银台失败处理逻辑
  116. }
  117. })
  118. // #endif
  119. }).catch(() => {
  120. this.$hideLoading()
  121. })
  122. },
  123. query() {
  124. if (this.interval) return
  125. this.interval = setInterval(() => {
  126. this.$api.pay.query(this.payId).then(res => {
  127. this.$hideLoading()
  128. this.$u.toast('支付成功')
  129. clearInterval(this.interval)
  130. // 获取用户信息
  131. this.$api.user.info().then(res => {
  132. this.$store.dispatch('user/info', res.data)
  133. })
  134. }).catch(err => {
  135. })
  136. }, 1000)
  137. }
  138. },
  139. onLoad() {
  140. this.getSetting()
  141. }
  142. }
  143. </script>
  144. <style lang="scss" scoped>
  145. .member-container{
  146. padding: 20rpx 0;
  147. font-size: 30rpx;
  148. .header{
  149. color: $primary-color;
  150. margin-top: 50rpx;
  151. .title{
  152. position: relative;
  153. font-size: 42rpx;
  154. font-weight: 600;
  155. width: 100%;
  156. text-align: center;
  157. &:before,&:after{
  158. content: "";
  159. background: url("/static/image/member-line-bg.png") no-repeat;
  160. background-size: 100%;
  161. position: absolute;
  162. top: 50%;
  163. left: 60rpx;
  164. width: 200rpx;
  165. height: 20rpx;
  166. }
  167. &:after{
  168. transform: rotate(180deg);
  169. right: 60rpx;
  170. left: unset;
  171. top: 20%;
  172. }
  173. }
  174. .tips{
  175. color: $dark-color;
  176. font-size: 26rpx;
  177. margin-top: 20rpx;
  178. }
  179. }
  180. .content{
  181. padding: 0 20rpx;
  182. margin-top: 80rpx;
  183. .item{
  184. color: $default-color;
  185. margin-left: 20rpx;
  186. flex: 1;
  187. height: 300rpx;
  188. position: relative;
  189. .border{
  190. position: absolute;
  191. top: 0;
  192. left: 0;
  193. right: 0;
  194. bottom: 0;
  195. z-index: 0;
  196. border: 4rpx solid $info-color;
  197. border-radius: 10rpx;
  198. overflow: hidden;
  199. }
  200. &.active .border{
  201. border: unset;
  202. &:after{
  203. content: "";
  204. position: absolute;
  205. top: 0;
  206. left: 0;
  207. right: 0;
  208. bottom: 0;
  209. border: 4rpx solid;
  210. border-image: linear-gradient(222deg, #6EEBE8, #FF74B9) 1;
  211. z-index: 0;
  212. }
  213. }
  214. .selected{
  215. position: absolute;
  216. top: -20rpx;
  217. background: url("/static/image/member-selected-bg.png") no-repeat;
  218. background-size: 100%;
  219. text-align: center;
  220. width: 120rpx;
  221. height: 40rpx;
  222. font-size: 24rpx;
  223. line-height: 40rpx;
  224. left: 20rpx;
  225. z-index: 1;
  226. }
  227. &:first-child{
  228. margin-left: 0;
  229. }
  230. .day{
  231. font-size: 32rpx;
  232. margin-bottom: 80rpx;
  233. }
  234. .price{
  235. font-size: 38rpx;
  236. color: $primary-color;
  237. }
  238. }
  239. }
  240. .free{
  241. background: #1B1E32;
  242. width: 100%;
  243. padding: 20rpx 0;
  244. color: $info-color;
  245. text-align: center;
  246. font-size: 26rpx;
  247. margin-top: 60px;
  248. text{
  249. color: $dark-color;
  250. }
  251. }
  252. .footer{
  253. position: fixed;
  254. bottom: 60rpx;
  255. left: 0;
  256. right: 0;
  257. padding: 0 30rpx;
  258. .price{
  259. text{
  260. color: #fff;
  261. }
  262. .price{
  263. color: $primary-color;
  264. font-size: 48rpx;
  265. margin-left: 10rpx;
  266. font-weight: 500;
  267. line-height: 1;
  268. &:first-letter{
  269. font-size: 30rpx;
  270. font-weight: normal;
  271. }
  272. }
  273. }
  274. .buy-btn{
  275. background: linear-gradient(270deg, #6EEBE8 0%, #FF74B9 100%);
  276. border-radius: 42rpx;
  277. width: 400rpx;
  278. font-weight: 600;
  279. color: #151728;
  280. padding: 18rpx 0;
  281. }
  282. }
  283. }
  284. </style>