index.vue 8.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309
  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. // IOS 不允许购买
  130. if (!this.$util.checkOS()) return
  131. const item = this.combos[this.rechargeActive]
  132. this.$loading('请稍后...')
  133. this.$api.user.recharge.create({ id: item.id }).then(res => {
  134. console.log('-->data', res)
  135. // #ifdef MP-TOUTIAO
  136. tt.pay({
  137. service: 5,
  138. orderInfo: {
  139. order_id: res.data.order_id,
  140. order_token: res.data.order_token
  141. },
  142. success: payRes => {
  143. if (payRes.code === 0) {
  144. this.$loading('支付结果查询中...')
  145. this.query()
  146. } else {
  147. this.$u.toast('支付失败')
  148. }
  149. },
  150. fail: err => {
  151. console.log('-->data', err)
  152. // 调起收银台失败处理逻辑
  153. }
  154. })
  155. // #endif
  156. // #ifdef MP-KUAISHOU
  157. ks.pay({
  158. serviceId: '1',
  159. orderInfo: {
  160. order_no: res.data.order_id,
  161. order_info_token: res.data.order_token
  162. },
  163. success: payRes => {
  164. this.$loading('支付结果查询中...')
  165. this.query()
  166. },
  167. fail: err => {
  168. console.log('-->data', err)
  169. // 调起收银台失败处理逻辑
  170. }
  171. })
  172. // #endif
  173. this.$hideLoading()
  174. }).catch(() => {
  175. this.$hideLoading()
  176. })
  177. },
  178. query() {
  179. if (this.interval) return
  180. this.interval = setInterval(() => {
  181. this.$api.pay.query(this.payId).then(res => {
  182. this.$hideLoading()
  183. this.$u.toast('支付成功')
  184. clearInterval(this.interval)
  185. // 获取用户信息
  186. this.$api.user.info().then(res => {
  187. this.$store.dispatch('user/info', res.data)
  188. })
  189. }).catch(err => {
  190. this.$hideLoading()
  191. })
  192. }, 1000)
  193. }
  194. }
  195. }
  196. </script>
  197. <style lang="scss" scoped>
  198. .recharge {
  199. font-size: 28rpx;
  200. .container{
  201. width: 700rpx;
  202. border: 2rpx solid;
  203. padding: 30rpx;
  204. &.bottom{
  205. width: 750rpx;
  206. border: unset;
  207. }
  208. .static-text{
  209. font-size: 36rpx;
  210. font-weight: 600;
  211. margin-bottom: 40rpx;
  212. .overage{
  213. font-size: 28rpx;
  214. color: $info-color;
  215. }
  216. }
  217. .overage{
  218. color: $info-color;
  219. text{
  220. color: #FB3651 ;
  221. }
  222. }
  223. // 播放充值
  224. .play-container{
  225. .episode{
  226. margin: 40rpx 0 ;
  227. background: linear-gradient(270deg, #6EEBE8, #FF74B9);
  228. border-radius: 20rpx;
  229. height: 180rpx;
  230. padding: 20rpx;
  231. .detail{
  232. .name{
  233. color: $default-color;
  234. font-weight: 600;
  235. }
  236. .sale-box{
  237. margin-top: 40rpx;
  238. .sale-price{
  239. color: $primary-color;
  240. font-size: 28rpx;
  241. }
  242. .origin-price{
  243. color: $default-color;
  244. font-size: 24rpx;
  245. margin-left: 20rpx;
  246. text-decoration: line-through;
  247. opacity: .6;
  248. margin-top: 6rpx;
  249. }
  250. }
  251. }
  252. .buy-num{
  253. color: $default-color;
  254. min-width: 80px;
  255. text-align: center;
  256. }
  257. }
  258. }
  259. // 充值套餐
  260. .recharge-group{
  261. margin-top: 30rpx;
  262. .recharge-item{
  263. border: 4rpx solid $primary-color;
  264. width: calc(#{600rpx} / 2);
  265. margin-right: 20rpx;
  266. margin-bottom: 20rpx;
  267. border-radius: 20rpx;
  268. padding: 40rpx 20rpx;
  269. transition: .3s;
  270. &:nth-child(2n){
  271. margin-right: 0;
  272. }
  273. &.active{
  274. background: #1b1e32;
  275. border: 4rpx solid #1b1e32;
  276. .price{
  277. color: $default-color;
  278. }
  279. }
  280. .price{
  281. margin-bottom: 40rpx;
  282. font-size: 38rpx;
  283. }
  284. .gold{
  285. color: $primary-color;
  286. margin-bottom: 10rpx;
  287. }
  288. .gift{
  289. color: $info-color;
  290. }
  291. }
  292. }
  293. .btn{
  294. background: linear-gradient(270deg, #6EEBE8 0%, #FF74B9 100%);
  295. width: 90%;
  296. margin: 40rpx auto;
  297. padding: 20rpx 0;
  298. text-align: center;
  299. border-radius: 40rpx;
  300. color: $default-color;
  301. letter-spacing: .1rem;
  302. }
  303. }
  304. }
  305. </style>