index.vue 8.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307
  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 class="origin-price cross-center">原价{{ list.origin_price }}金币</view>
  23. </view>
  24. </view>
  25. <view class="buy-num">{{ 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. <view class="recharge-group dir-left-wrap">
  41. <view
  42. v-for="(combo,index) in combos"
  43. :key="index"
  44. class="recharge-item dir-top-wrap main-center cross-center"
  45. :class="{active: rechargeActive === index}"
  46. @click="rechargeActive = index"
  47. >
  48. <text class="price">{{ combo.price }}元</text>
  49. <text class="gold">{{ combo.gold }}+{{ combo.gift }}金币</text>
  50. <text class="gift">多送{{ combo.gift }}金币</text>
  51. </view>
  52. </view>
  53. <view class="btn" @click="handleRecharge">充值</view>
  54. </view>
  55. </u-popup>
  56. </view>
  57. </template>
  58. <script>
  59. import { mapState } from 'vuex'
  60. export default {
  61. name: 'Recharge',
  62. props: {
  63. show: {
  64. type: Boolean,
  65. default: false
  66. },
  67. mode: {
  68. type: String,
  69. default: 'center'
  70. },
  71. type: {
  72. type: String,
  73. default: 'normal'
  74. },
  75. episode: {
  76. type: Object,
  77. default() {
  78. return {}
  79. }
  80. },
  81. list: {
  82. type: Object,
  83. default() {
  84. return {}
  85. }
  86. }
  87. },
  88. data() {
  89. return {
  90. modal: {
  91. show: false
  92. },
  93. combos: [],
  94. rechargeActive: 0,
  95. buyNum: 0
  96. }
  97. },
  98. computed: {
  99. ...mapState({
  100. userInfo: seate => seate.user.info
  101. })
  102. },
  103. watch: {
  104. show(val) {
  105. this.modal.show = val
  106. }
  107. },
  108. created() {
  109. this.getCombo()
  110. this.getBuyNum()
  111. },
  112. methods: {
  113. getCombo() {
  114. this.$api.setting.rechargeCombo().then(res => {
  115. this.combos = res.data
  116. })
  117. },
  118. close() {
  119. this.$emit('update:show', false)
  120. },
  121. getBuyNum() {
  122. if (this.type === 'play') {
  123. this.$api.episode.listBuyNum(this.list.id).then(res => {
  124. this.buyNum = res.data
  125. })
  126. }
  127. },
  128. handleRecharge() {
  129. const item = this.combos[this.rechargeActive]
  130. this.$loading('请稍后...')
  131. this.$api.user.recharge.create({ id: item.id }).then(res => {
  132. console.log('-->data', res)
  133. // #ifdef MP-TOUTIAO
  134. tt.pay({
  135. service: 5,
  136. orderInfo: {
  137. order_id: res.data.order_id,
  138. order_token: res.data.order_token
  139. },
  140. success: payRes => {
  141. if (payRes.code === 0) {
  142. this.$loading('支付结果查询中...')
  143. this.query()
  144. } else {
  145. this.$u.toast('支付失败')
  146. }
  147. },
  148. fail: err => {
  149. console.log('-->data', err)
  150. // 调起收银台失败处理逻辑
  151. }
  152. })
  153. // #endif
  154. // #ifdef MP-KUAISHOU
  155. ks.pay({
  156. serviceId: '1',
  157. orderInfo: {
  158. order_no: res.data.order_id,
  159. order_info_token: res.data.order_token
  160. },
  161. success: payRes => {
  162. this.$loading('支付结果查询中...')
  163. this.query()
  164. },
  165. fail: err => {
  166. console.log('-->data', err)
  167. // 调起收银台失败处理逻辑
  168. }
  169. })
  170. // #endif
  171. this.$hideLoading()
  172. }).catch(() => {
  173. this.$hideLoading()
  174. })
  175. },
  176. query() {
  177. if (this.interval) return
  178. this.interval = setInterval(() => {
  179. this.$api.pay.query(this.payId).then(res => {
  180. this.$hideLoading()
  181. this.$u.toast('支付成功')
  182. clearInterval(this.interval)
  183. // 获取用户信息
  184. this.$api.user.info().then(res => {
  185. this.$store.dispatch('user/info', res.data)
  186. })
  187. }).catch(err => {
  188. this.$hideLoading()
  189. })
  190. }, 1000)
  191. }
  192. }
  193. }
  194. </script>
  195. <style lang="scss" scoped>
  196. .recharge {
  197. font-size: 28rpx;
  198. .container{
  199. width: 700rpx;
  200. border: 2rpx solid;
  201. padding: 30rpx;
  202. &.bottom{
  203. width: 750rpx;
  204. border: unset;
  205. }
  206. .static-text{
  207. font-size: 36rpx;
  208. font-weight: 600;
  209. margin-bottom: 40rpx;
  210. .overage{
  211. font-size: 28rpx;
  212. color: $info-color;
  213. }
  214. }
  215. .overage{
  216. color: $info-color;
  217. text{
  218. color: #FB3651 ;
  219. }
  220. }
  221. // 播放充值
  222. .play-container{
  223. .episode{
  224. margin: 40rpx 0 ;
  225. background: linear-gradient(270deg, #6EEBE8, #FF74B9);
  226. border-radius: 20rpx;
  227. height: 180rpx;
  228. padding: 20rpx;
  229. .detail{
  230. .name{
  231. color: $default-color;
  232. font-weight: 600;
  233. }
  234. .sale-box{
  235. margin-top: 40rpx;
  236. .sale-price{
  237. color: $primary-color;
  238. font-size: 28rpx;
  239. }
  240. .origin-price{
  241. color: $default-color;
  242. font-size: 24rpx;
  243. margin-left: 20rpx;
  244. text-decoration: line-through;
  245. opacity: .6;
  246. margin-top: 6rpx;
  247. }
  248. }
  249. }
  250. .buy-num{
  251. color: $default-color;
  252. min-width: 80px;
  253. text-align: center;
  254. }
  255. }
  256. }
  257. // 充值套餐
  258. .recharge-group{
  259. margin-top: 30rpx;
  260. .recharge-item{
  261. border: 4rpx solid $primary-color;
  262. width: calc(#{600rpx} / 2);
  263. margin-right: 20rpx;
  264. margin-bottom: 20rpx;
  265. border-radius: 10rpx;
  266. padding: 40rpx 20rpx;
  267. transition: .3s;
  268. &:nth-child(2n){
  269. margin-right: 0;
  270. }
  271. &.active{
  272. background: #1b1e32;
  273. border: 4rpx solid #1b1e32;
  274. .price{
  275. color: $default-color;
  276. }
  277. }
  278. .price{
  279. margin-bottom: 40rpx;
  280. font-size: 38rpx;
  281. }
  282. .gold{
  283. color: $primary-color;
  284. margin-bottom: 10rpx;
  285. }
  286. .gift{
  287. color: $info-color;
  288. }
  289. }
  290. }
  291. .btn{
  292. background: linear-gradient(270deg, #6EEBE8 0%, #FF74B9 100%);
  293. width: 90%;
  294. margin: 40rpx auto;
  295. padding: 20rpx 0;
  296. text-align: center;
  297. border-radius: 40rpx;
  298. color: $default-color;
  299. letter-spacing: .1rem;
  300. }
  301. }
  302. }
  303. </style>