index.vue 9.5 KB

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