pay.vue 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134
  1. <template>
  2. <view class="body">
  3. <view style="margin: 0px 20px;">
  4. <view class="ft18">请选择充值金额 <label class="ft14" style="float: right;">账户余额<label class="ft14 kb-txt">{{
  5. user_info.total_coin }}</label>K币</label></view>
  6. <text class="ft14" style="font-weight: bold;padding-top: 10px;display: block;">1元=100K币</text>
  7. </view>
  8. <view class="pay-box">
  9. <block v-for="(item, key) in list" :key="key">
  10. <view v-if="item.type == 'COIN'" @click="selectPayItem(item)" :class="item.id == select.id ? 'pay-select' : ''"
  11. class="box pay-box-items">
  12. <view style="height: 20px;align-self: flex-end;"><text class="ft12 top-lab" v-if="item.tip_text">{{
  13. item.tip_text }}</text></view>
  14. <text class="ft18 pay-box-items-txt" style="color: #FF9800;">{{ item.price }}元</text>
  15. <view class="ft14 pay-box-items-txt" style="flex-direction: row;">
  16. {{ item.price_text }} <text class="ft14" style="color: #FF9800;">+{{ item.given }}K币</text> </view>
  17. <view class="ft14 pay-box-items-txt" style="flex-direction: row;display: flex;justify-content: space-between;"
  18. :class="item.id == select.id ? 'select-text' : 'given-txt'">
  19. {{ item.given_amount }} <text v-if="item.id == select.id" class="ft14"
  20. style="margin-right: 20px;">&#10003;️</text></view>
  21. </view>
  22. <view v-else @click="selectPayItem(item)" :class="item.id == select.id ? 'pay-select' : ''"
  23. class="box pay-box-items">
  24. <view style="height: 20px;align-self: flex-end;"><text class="ft12 top-lab" v-if="item.tip_text">{{
  25. item.tip_text }}</text></view>
  26. <view class="vip-center">
  27. <view class="">
  28. <text class="ft18 pay-box-items-txt" style="color: #FF9800;">{{ item.price }}元</text>
  29. <view class="ft14 pay-box-items-txt">{{ item.price_text }}</text></view>
  30. </view>
  31. <image class="vip-level-icon" src="/static/icon/vip.png"></image>
  32. </view>
  33. <view class="ft14 pay-box-items-txt" style="flex-direction: row;display: flex;justify-content: space-between;"
  34. :class="item.id == select.id ? 'select-text' : 'given-txt'">
  35. <text class="ft14">{{ item.given_amount }}</text> <text v-if="item.id == select.id" class="ft14"
  36. style="margin-right: 20px;">&#10003;️</text>
  37. </view>
  38. </view>
  39. </block>
  40. </view>
  41. <view @click="toPay" class="ft16 btn-cz mt16 ">
  42. 确认充值{{ select.price || 0 }}
  43. </view>
  44. <view class="ft14" style="margin: 10px 0; padding: 0 20px;">付费须知</view>
  45. <view class="ft14" style="padding: 0 20px;margin-bottom: 50px;display: flex;flex-direction: column;">
  46. <text class="ft12">1、虚拟商品,一经购买不得退换</text>
  47. <text class="ft12">2、充值后K币可能有延迟,1小时未到账请在“我的”页面联系客服</text>
  48. <text class="ft12">3、未满18岁的未成年需要在监护人陪同下购买并观看短剧剧</text>
  49. <text class="ft12">4、购买成功后,“K币”仅在本小程序中使用</text>
  50. <text class="ft12">5、购买成功后可在”我的”页面订单中心进行查看</text>
  51. </view>
  52. </view>
  53. </template>
  54. <script>
  55. import { getUserInfo } from "@/common/apis/my.js";
  56. import {
  57. getOptions,
  58. getPayInfo,
  59. } from "@/common/apis/recharge.js"
  60. export default {
  61. data() {
  62. return {
  63. user_info: {},
  64. list: [],
  65. select: {},
  66. pay_success: false
  67. }
  68. },
  69. async onShow() {
  70. let res = await getUserInfo();
  71. this.user_info = res.data
  72. this.get_options();
  73. },
  74. methods: {
  75. async get_options() {
  76. let res = await getOptions();
  77. this.list = res.data;
  78. this.list.forEach((item, index) => {
  79. if (item.is_default == 1) {
  80. this.select = item;
  81. }
  82. })
  83. }, selectPayItem(item) {
  84. this.select = item;
  85. }, async toPay() {
  86. if (this.select.lenght < 1) {
  87. uni.showToast({ title: '请选择要充值的项', icon: "none" });
  88. return false;
  89. }
  90. let params = {
  91. pay_proudct_id: this.select.id,
  92. video_id: this.video_info && this.video_info.video_id ? this.video_info.video_id : 0,
  93. video_series_sequence: this.video_info && this.video_info.video_series_sequence ? this.video_info.video_series_sequence : 0,
  94. is_first_pay: this.select.is_first_pay,
  95. };
  96. let result = false;
  97. let res = await getPayInfo(params);
  98. if (res.data) {
  99. // #ifdef MP-WEIXIN
  100. this.wxMinPay(res.data);
  101. // #endif
  102. }
  103. }, wxMinPay(param) {
  104. wx.requestPayment({
  105. timeStamp: param.timeStamp,
  106. nonceStr: param.nonceStr,
  107. package: param.package,
  108. signType: param.signType,
  109. paySign: param.paySign,
  110. success(res) {
  111. this.pay_success = true;
  112. uni.showToast({ title: '支付成功', icon: "none" });
  113. // console.log('success:' + JSON.stringify(res));
  114. },
  115. fail(e) {
  116. if (e.errMsg == "requestPayment:fail cancel") {
  117. uni.showToast({ title: '取消支付', icon: "none" });
  118. } else {
  119. uni.showToast({ title: '支付失败', icon: "none" });
  120. }
  121. }
  122. })
  123. }
  124. }
  125. }
  126. </script>
  127. <style>
  128. @import url("style/pay.css");
  129. </style>