index.vue 8.0 KB

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