index.vue 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437
  1. <template>
  2. <view class="recharge">
  3. <u-popup
  4. :show="show"
  5. :mode="mode"
  6. round="20rpx"
  7. :close-on-click-overlay="false"
  8. @close="close"
  9. >
  10. <view class="container" :class="{bottom: mode === 'bottom'}">
  11. <template v-if="type === 'play'">
  12. <view class="play-container">
  13. <view class="header main-between cross-center">
  14. <text>感谢您的支持,本集解锁后可继续观看</text>
  15. <u-icon name="arrow-down" size="28rpx" @click="close" />
  16. </view>
  17. <view class="episode main-between cross-center">
  18. <view class="detail">
  19. <view class="name">{{ episode.name }} 第{{ list.sort }}集</view>
  20. <view class="sale-box main-left cross-center">
  21. <view class="sale-price cross-center">专享价{{ list.sale_price }}金币</view>
  22. <view v-if="list.origin_price" class="origin-price cross-center">原价{{ list.origin_price }}金币</view>
  23. </view>
  24. </view>
  25. <view class="buy-num">{{ $util.tranNumber(buyNum) }}人购买</view>
  26. </view>
  27. </view>
  28. <view class="static-text main-between cross-center">
  29. <text>充值金币</text>
  30. <view class="overage">账户余额:<text>{{ userInfo.info.integral }}金币</text></view>
  31. </view>
  32. </template>
  33. <template v-else>
  34. <view class="static-text main-between cross-center">
  35. <text>充值金币</text>
  36. <u-icon name="close-circle" size="52rpx" color="#BEBDBB" @click="close" />
  37. </view>
  38. <view class="overage">账户余额:<text>{{ userInfo.info.integral }}金币</text></view>
  39. </template>
  40. <scroll-view
  41. class="recharge-group-view dir-left-wrap"
  42. scroll-y
  43. scroll-with-animation
  44. :enable-flex="true"
  45. >
  46. <view class="recharge-group dir-left-wrap">
  47. <view
  48. v-for="(combo,index) in combos"
  49. :key="index"
  50. class="recharge-item dir-top-wrap main-center cross-center"
  51. :class="{active: rechargeActive === index}"
  52. @click="rechargeActive = index"
  53. >
  54. <template v-if="!combo.vip_combo">
  55. <text class="price">{{ combo.price }}元</text>
  56. <text class="gold">{{ combo.gold }}+{{ combo.gift }}金币</text>
  57. <text class="gift">多送{{ combo.gift }}金币</text>
  58. </template>
  59. <template v-else>
  60. <text class="price">{{ combo.price }}元</text>
  61. <text class="gift">{{ combo.name }}</text>
  62. </template>
  63. </view>
  64. </view>
  65. </scroll-view>
  66. <view class="btn" @click="handleRecharge">充值</view>
  67. </view>
  68. </u-popup>
  69. </view>
  70. </template>
  71. <script>
  72. import { mapState } from 'vuex'
  73. export default {
  74. name: 'Recharge',
  75. props: {
  76. show: {
  77. type: Boolean,
  78. default: false
  79. },
  80. mode: {
  81. type: String,
  82. default: 'center'
  83. },
  84. type: {
  85. type: String,
  86. default: 'normal'
  87. },
  88. episode: {
  89. type: Object,
  90. default() {
  91. return {}
  92. }
  93. },
  94. list: {
  95. type: Object,
  96. default() {
  97. return {}
  98. }
  99. }
  100. },
  101. data() {
  102. return {
  103. modal: {
  104. show: false
  105. },
  106. combos: [],
  107. rechargeActive: 0,
  108. buyNum: 0,
  109. payId: 0
  110. }
  111. },
  112. computed: {
  113. ...mapState({
  114. userInfo: seate => seate.user.info
  115. })
  116. },
  117. watch: {
  118. show(val) {
  119. this.modal.show = val
  120. if (val) {
  121. this.getCombo()
  122. this.getBuyNum()
  123. }
  124. }
  125. },
  126. created() {
  127. // this.getCombo()
  128. // this.getBuyNum()
  129. },
  130. methods: {
  131. getCombo() {
  132. this.$api.setting.rechargeCombo().then(res => {
  133. this.combos = res.data
  134. })
  135. },
  136. close() {
  137. this.$emit('update:show', false)
  138. },
  139. getBuyNum() {
  140. if (this.type === 'play') {
  141. this.$api.episode.listBuyNum(this.list.id).then(res => {
  142. this.buyNum = res.data
  143. })
  144. }
  145. },
  146. handleRecharge() {
  147. // IOS 不允许购买
  148. // #ifdef MP-TOUTIAO
  149. if (!this.$util.checkOS()) return
  150. // #endif
  151. const item = this.combos[this.rechargeActive]
  152. console.log('-->data', item)
  153. let promise = null
  154. // 选择的是会员套餐
  155. if (typeof item.vip_combo !== 'undefined' && item.vip_combo) {
  156. promise = this.$api.user.vip.create({ id: item.id })
  157. } else {
  158. promise = this.$api.user.recharge.create({ id: item.id })
  159. }
  160. this.$loading('请稍后...')
  161. promise.then(res => {
  162. this.payId = res.pay_id
  163. delete res.pay_id
  164. console.log('-->data', res)
  165. // #ifdef MP-TOUTIAO
  166. tt.pay({
  167. service: 5,
  168. orderInfo: {
  169. order_id: res.data.order_id,
  170. order_token: res.data.order_token
  171. },
  172. success: payRes => {
  173. if (payRes.code === 0) {
  174. this.$loading('支付结果查询中...')
  175. this.query()
  176. } else {
  177. this.$u.toast('支付失败')
  178. }
  179. },
  180. fail: err => {
  181. console.log('-->data', err)
  182. clearInterval(this.interval)
  183. // 调起收银台失败处理逻辑
  184. }
  185. })
  186. // #endif
  187. // #ifdef MP-KUAISHOU
  188. ks.pay({
  189. serviceId: '1',
  190. orderInfo: {
  191. order_no: res.data.order_id,
  192. order_info_token: res.data.order_token
  193. },
  194. success: payRes => {
  195. this.$loading('支付结果查询中...')
  196. this.query()
  197. },
  198. fail: err => {
  199. console.log('-->data', err)
  200. clearInterval(this.interval)
  201. // 调起收银台失败处理逻辑
  202. }
  203. })
  204. // #endif
  205. // #ifdef MP-WEIXIN
  206. uni.requestPayment({
  207. ...res.data,
  208. provider: 'wxpay',
  209. success: res => {
  210. console.log('success:' + JSON.stringify(res))
  211. // _this.$u.toast("支付成功")
  212. this.$loading('支付结果查询中...')
  213. this.query()
  214. },
  215. fail: err => {
  216. console.log('fail:' + JSON.stringify(err))
  217. // _this.$u.toast("支付失败")
  218. clearInterval(this.interval)
  219. }
  220. })
  221. // #endif
  222. this.$hideLoading()
  223. }).catch(() => {
  224. this.$hideLoading()
  225. })
  226. },
  227. handleBuyVip() {
  228. // #ifdef MP-TOUTIAO | MP-WEIXIN
  229. if (!this.$util.checkOS()) return
  230. // #endif
  231. const item = this.settings[this.activeIndex]
  232. this.$loading('购买中...')
  233. this.$api.user.vip.create({ id: item.id }).then(res => {
  234. this.$hideLoading()
  235. this.payId = res.pay_id
  236. delete res.pay_id
  237. this.modal.show = false
  238. // #ifdef MP-TOUTIAO
  239. tt.pay({
  240. service: 5,
  241. orderInfo: {
  242. order_id: res.data.order_id,
  243. order_token: res.data.order_token
  244. },
  245. success: payRes => {
  246. if (payRes.code === 0) {
  247. this.$loading('支付结果查询中...')
  248. this.query()
  249. } else {
  250. this.$u.toast('支付失败')
  251. }
  252. },
  253. fail: err => {
  254. console.log('-->data', err)
  255. // 调起收银台失败处理逻辑
  256. }
  257. })
  258. // #endif
  259. // #ifdef MP-KUAISHOU
  260. ks.pay({
  261. serviceId: '1',
  262. orderInfo: {
  263. order_no: res.data.order_id,
  264. order_info_token: res.data.order_token
  265. },
  266. success: payRes => {
  267. this.$loading('支付结果查询中...')
  268. this.query()
  269. },
  270. fail: err => {
  271. console.log('-->data', err)
  272. // 调起收银台失败处理逻辑
  273. }
  274. })
  275. // #endif
  276. // #ifdef MP-WEIXIN
  277. uni.requestPayment({
  278. ...res.data,
  279. provider: 'wxpay',
  280. success: res => {
  281. console.log('success:' + JSON.stringify(res))
  282. // _this.$u.toast("支付成功")
  283. this.$loading('支付结果查询中...')
  284. this.query()
  285. },
  286. fail: err => {
  287. console.log('fail:' + JSON.stringify(err))
  288. // _this.$u.toast("支付失败")
  289. clearInterval(this.interval)
  290. }
  291. })
  292. // #endif
  293. }).catch(() => {
  294. this.$hideLoading()
  295. })
  296. },
  297. query() {
  298. if (this.interval) return
  299. this.interval = setInterval(() => {
  300. this.$api.pay.query(this.payId).then(res => {
  301. this.$hideLoading()
  302. this.$u.toast('支付成功')
  303. clearInterval(this.interval)
  304. // 获取用户信息
  305. this.$api.user.info().then(res => {
  306. this.$store.dispatch('user/info', res.data)
  307. })
  308. }).catch(err => {
  309. this.$hideLoading()
  310. })
  311. }, 1000)
  312. }
  313. }
  314. }
  315. </script>
  316. <style lang="scss" scoped>
  317. .recharge {
  318. font-size: 28rpx;
  319. .container{
  320. width: 700rpx;
  321. border: 2rpx solid;
  322. padding: 30rpx;
  323. &.bottom{
  324. width: 750rpx;
  325. border: unset;
  326. .recharge-group{
  327. .recharge-item{
  328. width: calc(#{670rpx} / 2) !important;
  329. }
  330. }
  331. }
  332. .static-text{
  333. font-size: 36rpx;
  334. font-weight: 600;
  335. margin-bottom: 40rpx;
  336. .overage{
  337. font-size: 28rpx;
  338. color: $info-color;
  339. }
  340. }
  341. .overage{
  342. color: $info-color;
  343. text{
  344. color: #FB3651 ;
  345. }
  346. }
  347. // 播放充值
  348. .play-container{
  349. .episode{
  350. margin: 40rpx 0 ;
  351. background: linear-gradient(270deg, #6EEBE8, #FF74B9);
  352. border-radius: 20rpx;
  353. height: 180rpx;
  354. padding: 20rpx;
  355. .detail{
  356. .name{
  357. color: $default-color;
  358. font-weight: 600;
  359. }
  360. .sale-box{
  361. margin-top: 40rpx;
  362. .sale-price{
  363. color: $primary-color;
  364. font-size: 28rpx;
  365. }
  366. .origin-price{
  367. color: $default-color;
  368. font-size: 24rpx;
  369. margin-left: 20rpx;
  370. text-decoration: line-through;
  371. opacity: .6;
  372. margin-top: 6rpx;
  373. }
  374. }
  375. }
  376. .buy-num{
  377. color: $default-color;
  378. min-width: 80px;
  379. text-align: center;
  380. }
  381. }
  382. }
  383. // 充值套餐
  384. .recharge-group-view{
  385. .recharge-group{
  386. margin-top: 30rpx;
  387. height: 50vh;
  388. display: flex;
  389. .recharge-item{
  390. border: 4rpx solid $primary-color;
  391. width: calc(#{600rpx} / 2);
  392. margin-right: 20rpx;
  393. margin-bottom: 20rpx;
  394. border-radius: 20rpx;
  395. padding: 40rpx 20rpx;
  396. transition: .3s;
  397. &:nth-child(2n){
  398. margin-right: 0;
  399. }
  400. &.active{
  401. background: #1b1e32;
  402. border: 4rpx solid #1b1e32;
  403. .price{
  404. color: $default-color;
  405. }
  406. }
  407. .price{
  408. margin-bottom: 40rpx;
  409. font-size: 38rpx;
  410. }
  411. .gold{
  412. color: $primary-color;
  413. margin-bottom: 10rpx;
  414. }
  415. .gift{
  416. color: $info-color;
  417. }
  418. }
  419. }
  420. }
  421. .btn{
  422. background: linear-gradient(270deg, #6EEBE8 0%, #FF74B9 100%);
  423. width: 90%;
  424. margin: 40rpx auto;
  425. padding: 20rpx 0;
  426. text-align: center;
  427. border-radius: 40rpx;
  428. color: $default-color;
  429. letter-spacing: .1rem;
  430. }
  431. }
  432. }
  433. </style>