pay.vue 5.1 KB

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