index.vue 9.4 KB

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