index.vue 8.3 KB

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