index.ux 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213
  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 class="notice-wrap">
  53. <text class="title">提示:</text>
  54. <text class="notice-item">1.书币属虚拟商品,一经购买不得退换</text>
  55. <text class="notice-item">2.充值后书币到账可能有延迟,1小时内未到账请到个人中心联系客服</text>
  56. <text class="notice-item">3.工作时间:周一 周四 周五 9:00-21:00,周二 周三 周六 周日 9:00-18:00</text>
  57. </div>
  58. </div>
  59. </tab-content>
  60. </tabs>
  61. <div class="wrap-fixed">
  62. <image src="../../assets/imgs/shadow.png" class="shadow"></image>
  63. <div class="total-wrap">
  64. <div class="total-cost">
  65. <text>合计:{{total}}</text>
  66. <text class="notice">选择充值金额(1元=100书币)</text>
  67. </div>
  68. <text class="go-to-pay" @click="toPay">立即充值</text>
  69. </div>
  70. </div>
  71. <div class="loading-wrap" if="showLoading">
  72. <div class="loading-content">
  73. <progress type="circular"></progress>
  74. <text class="loading-text">{{loadingText}}</text>
  75. </div>
  76. </div>
  77. </div>
  78. </template>
  79. <script>
  80. import router from '@system.router';
  81. import prompt from '@system.prompt';
  82. import { getChargeList, getUserInfo, checkWxOrder } from "../../api";
  83. import { configWxPay, configAliPay } from "../../helper";
  84. export default {
  85. protected: {
  86. bid: "",
  87. code: "",
  88. fee: ""
  89. },
  90. private: {
  91. curPayType: 1,
  92. curSelect: 0,
  93. balance: 0,
  94. send_order_id: 0,
  95. total: "0元",
  96. loadingText: "订单查询中...",
  97. isInPay: false,
  98. showLoading: false,
  99. payType: [
  100. {
  101. name: "支付宝",
  102. icon: "http://newycsd.oss-cn-hangzhou.aliyuncs.com/images/base/logo/zhifubao.jpg",
  103. value: 1
  104. },
  105. {
  106. name: "微信",
  107. icon: "http://newycsd.oss-cn-hangzhou.aliyuncs.com/images/base/logo/weixin.jpg",
  108. value: 2
  109. }
  110. ],
  111. rechargeList: []
  112. },
  113. changePayType(type) {
  114. this.curPayType = type.value;
  115. },
  116. changeCharge(key) {
  117. this.curSelect = key;
  118. this.total = this.rechargeList[key].price;
  119. },
  120. async getUserInfo() {
  121. let userinfo = await getUserInfo();
  122. this.balance = userinfo.balance;
  123. this.send_order_id = userinfo.send_order_id;
  124. },
  125. async initChargeList() {
  126. this.rechargeList = await getChargeList();
  127. this.rechargeList.forEach((p, k) => {
  128. if (p.today_special) {
  129. this.curSelect = k;
  130. }
  131. })
  132. },
  133. async toPay() {
  134. let cur_pay_type = this.curPayType;
  135. let product_id = this.rechargeList[this.curSelect].product_id;
  136. let ret = null;
  137. if (cur_pay_type === 1) {
  138. ret = await configAliPay({ product_id: product_id, bid: this.bid, send_order_id: this.send_order_id });
  139. }
  140. else {
  141. ret = await configWxPay({ product_id: product_id, bid: this.bid, send_order_id: this.send_order_id });
  142. }
  143. // 成功支付后的回调操作
  144. if (ret.code === "9000") this.showWaitingWrap(ret);
  145. else this.showToastByCode(ret.code);
  146. },
  147. checkOrder(order_info) {
  148. this.showLoading = true;
  149. let { data, order } = order_info;
  150. let times = 10;
  151. this.loadingText = `订单查询中...${times}s`;
  152. this.timer = setInterval(async () => {
  153. if (times === 0) clearInterval(this.timer), this.showToastByCode("6004");
  154. else {
  155. times--;
  156. this.loadingText = `订单查询中...${times}s`;
  157. let fb = await checkWxOrder(order);
  158. if (fb && typeof fb === "object") clearInterval(this.timer), this.showToastByCode("9000");
  159. }
  160. }, 1000);
  161. },
  162. showWaitingWrap(order) {
  163. prompt.showDialog({
  164. title: "支付结果",
  165. message: "请确认支付结果",
  166. buttons: [
  167. {
  168. text: "完成",
  169. color: "#EF5952"
  170. },
  171. {
  172. text: "支付遇到问题",
  173. color: "#999"
  174. }
  175. ],
  176. success: (data) => {
  177. data.index === 0 && this.checkOrder(order);
  178. },
  179. cancel: () => {
  180. console.log("cancel");
  181. }
  182. });
  183. },
  184. showToastByCode(code) {
  185. this.showLoading = false;
  186. let msg = "支付成功!";
  187. switch (code) {
  188. case "9000": msg = "支付成功!"; break;
  189. case "8000": msg = "订单已提交,请等待结果"; break;
  190. case "4000": msg = "订单支付失败!"; break;
  191. case "5000": msg = "订单重复!"; break;
  192. case "6001": msg = "您已取消支付"; break;
  193. case "6002": msg = "网络错误!"; break;
  194. case "6004": msg = "请联系客服查询订单"; break;
  195. default: msg = "请联系客服" + code;
  196. }
  197. prompt.showToast({ message: msg });
  198. },
  199. onInit() {
  200. this.initChargeList();
  201. this.getUserInfo();
  202. },
  203. onHide() {
  204. this.$app.$def.createShortcut(true);
  205. }
  206. }
  207. </script>
  208. <style lang="less">
  209. @import "../../assets/less/pay.less";
  210. </style>