index.ux 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189
  1. <template>
  2. <div class="pay-wrap">
  3. <tabs class="wrap-relative">
  4. <tab-content>
  5. <div class="wrap-relative">
  6. <div class="top-user__wrap">
  7. <div class="user-balance">
  8. <text>您的余额:</text>
  9. <text class="balance">{{balance}}</text>
  10. <text>书币</text>
  11. </div>
  12. <div class="chapter-cost" if="fee">
  13. <text>当前章节需要消耗</text>
  14. <text class="cost">{{fee}}</text>
  15. <text>书币</text>
  16. </div>
  17. </div>
  18. <div class="charge-wrap">
  19. <div class="title">
  20. <text class="border"></text>
  21. <text>支付方式</text>
  22. </div>
  23. <div class="pay-type">
  24. <block for="item in payType">
  25. <div class="pay-type__item {{curPayType === item.value ? 'pay-type__item--cur' : ''}}" @click="changePayType(item)">
  26. <image src="{{item.icon}}"></image>
  27. <text>{{item.name}}</text>
  28. </div>
  29. </block>
  30. </div>
  31. <div class="recharge-list">
  32. <block for="charge in rechargeList">
  33. <stack class="stack-wrap" @click="changeCharge($idx)">
  34. <div class="recharge-item {{curSelect === $idx ? 'recharge-item__select' : ''}}">
  35. <text class="price {{curSelect === $idx ? 'price__select' : ''}}">{{charge.price}}</text>
  36. <text class="send {{curSelect === $idx ? 'send__select' : ''}}">{{charge.text}}</text>
  37. <div class="discount {{curSelect === $idx ? 'discount__select' : ''}}" if="charge.save_text">
  38. <block if="!charge.is_year_order">
  39. <text>省</text>
  40. </block>
  41. <block else>
  42. <image src="../../assets/imgs/year_pay.png"></image>
  43. </block>
  44. <text class="discount-num {{curSelect === $idx ? 'discount-num__select' : ''}}">{{charge.save_text}}</text>
  45. </div>
  46. </div>
  47. <image if="charge.today_special" class="recharge-recommend" src="../../assets/imgs/jinri.png"></image>
  48. </stack>
  49. </block>
  50. </div>
  51. </div>
  52. </div>
  53. </tab-content>
  54. </tabs>
  55. <div class="wrap-fixed">
  56. <image src="../../assets/imgs/shadow.png" class="shadow"></image>
  57. <div class="total-wrap">
  58. <div class="total-cost">
  59. <text>合计:{{total}}</text>
  60. <text class="notice">选择充值金额(1元=100书币)</text>
  61. </div>
  62. <text class="go-to-pay" @click="toPay">立即充值</text>
  63. </div>
  64. </div>
  65. </div>
  66. </template>
  67. <script>
  68. import router from '@system.router';
  69. import prompt from '@system.prompt';
  70. import { getChargeList, getUserInfo, checkWxOrder } from "../../api";
  71. import { configWxPay, configAliPay } from "../../helper";
  72. export default {
  73. protected: {
  74. bid: "",
  75. code: "",
  76. fee: ""
  77. },
  78. private: {
  79. curPayType: 1,
  80. curSelect: 0,
  81. balance: 0,
  82. send_order_id: 0,
  83. total: "50元",
  84. isInPay: false,
  85. payType: [
  86. {
  87. name: "支付宝",
  88. icon: "http://newycsd.oss-cn-hangzhou.aliyuncs.com/images/base/logo/zhifubao.jpg",
  89. value: 1
  90. },
  91. {
  92. name: "微信",
  93. icon: "http://newycsd.oss-cn-hangzhou.aliyuncs.com/images/base/logo/weixin.jpg",
  94. value: 2
  95. }
  96. ],
  97. rechargeList: []
  98. },
  99. changePayType(type) {
  100. this.curPayType = type.value;
  101. },
  102. changeCharge(key) {
  103. this.curSelect = key;
  104. this.total = this.rechargeList[key].price;
  105. },
  106. async getUserInfo() {
  107. let userinfo = await getUserInfo();
  108. this.balance = userinfo.balance;
  109. this.send_order_id = userinfo.send_order_id;
  110. },
  111. async initChargeList() {
  112. this.rechargeList = await getChargeList();
  113. this.rechargeList.forEach((p, k) => {
  114. if (p.today_special) {
  115. this.curSelect = k;
  116. }
  117. })
  118. },
  119. async toPay() {
  120. let cur_pay_type = this.curPayType;
  121. let product_id = this.rechargeList[this.curSelect].product_id;
  122. console.log(cur_pay_type);
  123. this.isInPay = true;
  124. if (cur_pay_type === 1) {
  125. let ret = await configAliPay({ product_id: product_id, bid: this.bid, send_order_id: this.send_order_id });
  126. this.showToastByCode(ret.code);
  127. if (ret.code === "9000") {
  128. router.back();
  129. }
  130. }
  131. else {
  132. let wx_ret = await configWxPay({ product_id: product_id, bid: this.bid, send_order_id: this.send_order_id });
  133. console.log("isInPay", this.isInPay);
  134. this.isInPay = false;
  135. console.log("wx_ret", wx_ret);
  136. console.log("isInPay", this.isInPay);
  137. // 查询订单
  138. this.checkOrderIfNotApp(wx_ret);
  139. }
  140. },
  141. checkOrderIfNotApp(order_info) {
  142. console.log(order_info);
  143. let { data, order } = order_info;
  144. // if (data.final_url) {
  145. // // h5支付回调
  146. // console.log("check h5 order");
  147. // let times = 0;
  148. // this.timer = setInterval(async () => {
  149. // if (times === 10) clearInterval(this.timer), this.showToastByCode("6004");
  150. // else {
  151. // times++;
  152. // let fb = await checkWxOrder(order);
  153. // if (fb) clearInterval(this.timer), this.showToastByCode("9000");
  154. // }
  155. // }, 1000)
  156. // } else if (data.prepayid) {
  157. // // app支付回调
  158. // this.showToastByCode("9000");
  159. // }
  160. },
  161. showToastByCode(code) {
  162. let msg = "支付成功!";
  163. switch (code) {
  164. case "9000": msg = "支付成功!"; break;
  165. case "8000": msg = "订单已提交,请等待结果"; break;
  166. case "4000": msg = "订单支付失败!"; break;
  167. case "5000": msg = "订单重复!"; break;
  168. case "6001": msg = "您已取消支付"; break;
  169. case "6002": msg = "网络错误!"; break;
  170. case "6004": msg = "请联系客服查询订单"; break;
  171. default: msg = "请联系客服" + code;
  172. }
  173. prompt.showToast({ message: msg });
  174. },
  175. onInit() {
  176. this.initChargeList();
  177. this.getUserInfo();
  178. },
  179. onHide() {
  180. this.$app.$def.createShortcut(true);
  181. }
  182. }
  183. </script>
  184. <style lang="less">
  185. @import "../../assets/less/pay.less";
  186. </style>