index.ux 9.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338
  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
  26. class="pay-type__item {{curPayType === item.value ? 'pay-type__item--cur' : ''}}"
  27. @click="changePayType(item)"
  28. >
  29. <image src="{{item.icon}}"></image>
  30. <text>{{ item.name }}</text>
  31. </div>
  32. </block>
  33. </div>
  34. <div class="recharge-list">
  35. <block for="charge in rechargeList">
  36. <stack class="stack-wrap" @click="changeCharge($idx)">
  37. <div
  38. class="recharge-item {{curSelect === $idx ? 'recharge-item__select' : ''}}"
  39. >
  40. <text
  41. class="price {{curSelect === $idx ? 'price__select' : ''}}"
  42. >{{ charge.price }}</text
  43. >
  44. <text
  45. class="send {{curSelect === $idx ? 'send__select' : ''}}"
  46. >{{ charge.text }}</text
  47. >
  48. <div
  49. class="discount {{curSelect === $idx ? 'discount__select' : ''}}"
  50. if="charge.save_text"
  51. >
  52. <block if="!charge.is_year_order">
  53. <text>省</text>
  54. </block>
  55. <block else>
  56. <image src="../../assets/imgs/year_pay.png"></image>
  57. </block>
  58. <text
  59. class="discount-num {{curSelect === $idx ? 'discount-num__select' : ''}}"
  60. >{{ charge.save_text }}</text
  61. >
  62. </div>
  63. </div>
  64. <image
  65. if="charge.today_special"
  66. class="recharge-recommend"
  67. src="../../assets/imgs/jinri.png"
  68. ></image>
  69. </stack>
  70. </block>
  71. </div>
  72. </div>
  73. <div class="notice-wrap">
  74. <text class="title">提示:</text>
  75. <text class="notice-item">1.书币属虚拟商品,一经购买不得退换</text>
  76. <text class="notice-item"
  77. >2.充值后书币到账可能有延迟,1小时内未到账请到个人中心联系客服</text
  78. >
  79. <text class="notice-item"
  80. >3.工作时间:周一 周四 周五 9:00-21:00,周二 周三 周六 周日
  81. 9:00-18:00</text
  82. >
  83. </div>
  84. </div>
  85. </tab-content>
  86. </tabs>
  87. <div class="wrap-fixed">
  88. <image src="../../assets/imgs/shadow.png" class="shadow"></image>
  89. <div class="total-wrap">
  90. <div class="total-cost">
  91. <text>合计:{{ total }}</text>
  92. <text class="notice">选择充值金额(1元=100书币)</text>
  93. </div>
  94. <text class="go-to-pay" @click="toPay">立即充值</text>
  95. </div>
  96. </div>
  97. <div class="loading-wrap" if="showLoading">
  98. <div class="loading-content">
  99. <progress type="circular"></progress>
  100. <text class="loading-text">{{ loadingText }}</text>
  101. </div>
  102. </div>
  103. </div>
  104. </template>
  105. <script>
  106. import router from '@system.router';
  107. import prompt from '@system.prompt';
  108. import storage from "@system.storage";
  109. import { getChargeList, getUserInfo, checkWxOrder } from "../../api";
  110. import { configWxPay, configAliPay } from "../../helper";
  111. import { getAppConfig } from '../../api/utils.js';
  112. let getConfig;
  113. export default {
  114. public: {
  115. push_id: "",
  116. },
  117. protected: {
  118. bid: "",
  119. code: "",
  120. fee: ""
  121. },
  122. private: {
  123. pay_back: 0,
  124. curPayType: 2,
  125. curSelect: 0,
  126. balance: 0,
  127. send_order_id: 0,
  128. total: "0元",
  129. loadingText: "订单查询中...",
  130. isInPay: false,
  131. showLoading: false,
  132. checked: false,
  133. phone: '',
  134. haslogin: '',
  135. isVip: '',
  136. last: null,
  137. payType: [
  138. {
  139. name: "支付宝",
  140. icon: "http://newycsd.oss-cn-hangzhou.aliyuncs.com/images/base/logo/zhifubao.jpg",
  141. value: 1
  142. },
  143. {
  144. name: "微信",
  145. icon: "http://newycsd.oss-cn-hangzhou.aliyuncs.com/images/base/logo/weixin.jpg",
  146. value: 2
  147. }
  148. ],
  149. rechargeList: []
  150. },
  151. //函数节流
  152. throttle(fun, delay) {
  153. let last = this.last;
  154. const now = + new Date();
  155. if (now - last > delay) {
  156. fun();
  157. this.last = now;
  158. } else {
  159. console.log('间隔太短了')
  160. }
  161. },
  162. changePayType(type) {
  163. this.curPayType = type.value;
  164. },
  165. changeCharge(key) {
  166. this.curSelect = key;
  167. this.total = this.rechargeList[key].price;
  168. },
  169. async getUserInfo() {
  170. let userinfo = await getUserInfo();
  171. this.balance = userinfo.balance;
  172. this.send_order_id = userinfo.send_order_id;
  173. this.checked = userinfo.is_check;
  174. this.phone = (await storage.get({ key: "loginPhone" })).data;
  175. this.haslogin = (await storage.get({ key: "hasLogin" })).data;
  176. this.isVip = userinfo.is_vip;
  177. if (userinfo.pay_mode_default == 'weixin') {
  178. this.curPayType = 2;
  179. } else {
  180. this.curPayType = 1;
  181. }
  182. },
  183. async initChargeList() {
  184. this.rechargeList = await getChargeList();
  185. this.rechargeList.forEach((p, k) => {
  186. if (p.today_special) {
  187. this.curSelect = k;
  188. this.total = this.rechargeList[k].price;
  189. }
  190. })
  191. },
  192. async onInit() {
  193. if (this.push_id) {
  194. await storage.set({ key: "push_id", value: this.push_id });
  195. }
  196. getConfig = getAppConfig(this);
  197. let { pay_back_alert_show } = await getConfig('task_center');
  198. this.pay_back = pay_back_alert_show;
  199. this.initChargeList();
  200. },
  201. toPay() {
  202. if (!(this.send_order_id || (this.haslogin && this.loginPhone))) {
  203. prompt.showDialog({
  204. title: '友情提示',
  205. message: '您还未绑定手机号,请绑定手机号后在进行相关操作',
  206. buttons: [
  207. {
  208. text: '前往绑定',
  209. color: '#33dd44'
  210. }
  211. ],
  212. success: function (data) {
  213. router.push({
  214. uri: '/views/Phone'
  215. })
  216. },
  217. cancel: function () {
  218. console.log('取消绑定')
  219. },
  220. })
  221. } else {
  222. this.throttle(() => { this.payFunc() }, 1000)
  223. }
  224. },
  225. async payFunc() {
  226. let cur_pay_type = this.curPayType;
  227. let product_id = this.rechargeList[this.curSelect].product_id;
  228. let ret = null;
  229. if (cur_pay_type === 1) {
  230. ret = await configAliPay({ product_id: product_id, bid: this.bid, send_order_id: this.send_order_id });
  231. }
  232. else {
  233. ret = await configWxPay({ product_id: product_id, bid: this.bid, send_order_id: this.send_order_id });
  234. }
  235. // 成功支付后的回调操作
  236. if (ret.code === "9000") this.showWaitingWrap(ret);
  237. else this.showToastByCode(ret.code);
  238. },
  239. checkOrder(order_info) {
  240. this.showLoading = true;
  241. let { data, order } = order_info;
  242. let times = 10;
  243. this.loadingText = `订单查询中...${times}s`;
  244. this.timer = setInterval(async () => {
  245. if (times === 0) clearInterval(this.timer), this.showToastByCode("6004");
  246. else {
  247. times--;
  248. this.loadingText = `订单查询中...${times}s`;
  249. let fb = await checkWxOrder(order);
  250. if (fb && typeof fb === "object") clearInterval(this.timer), this.showToastByCode("9000");
  251. }
  252. }, 1000);
  253. },
  254. showWaitingWrap(order) {
  255. prompt.showDialog({
  256. title: "支付结果",
  257. message: "请确认支付结果",
  258. buttons: [
  259. {
  260. text: "已支付",
  261. color: "#EF5952"
  262. },
  263. {
  264. text: "重新选择金额",
  265. color: "#999"
  266. }
  267. ],
  268. success: (data) => {
  269. if (data.index === 0) this.checkOrder(order);
  270. },
  271. cancel: () => {
  272. console.log("cancel");
  273. }
  274. });
  275. },
  276. showToastByCode(code) {
  277. this.showLoading = false;
  278. let msg = "支付成功!";
  279. switch (code) {
  280. case "9000": (msg = "支付成功!", router.back()); break;
  281. case "8000": msg = "订单已提交,请等待结果"; break;
  282. case "4000": msg = "订单支付失败!"; break;
  283. case "5000": msg = "订单重复!"; break;
  284. case "6001": msg = "您已取消支付"; break;
  285. case "6002": msg = "网络错误!"; break;
  286. case "6004": msg = "请联系客服查询订单"; break;
  287. default: msg = "请联系客服" + code;
  288. }
  289. prompt.showToast({ message: msg });
  290. },
  291. onShow() {
  292. this.getUserInfo();
  293. },
  294. onHide() {
  295. //this.$app.$def.createShortcut(true);
  296. },
  297. onBackPress() {
  298. if (!this.isVip && this.pay_back) {
  299. prompt.showDialog({
  300. title: '温馨提示',
  301. message: '每日完成任务,可以免费获取书币~',
  302. buttons: [
  303. {
  304. text: '去做任务',
  305. color: '#EF5952'
  306. },
  307. {
  308. text: '我知道了',
  309. color: '#999'
  310. }
  311. ],
  312. success: function (data) {
  313. if (data.index === 1) {
  314. router.back();
  315. } else {
  316. router.push({
  317. uri: '/views/Task'
  318. })
  319. }
  320. },
  321. cancel: function () {
  322. console.log('取消前往')
  323. },
  324. })
  325. return true;
  326. }
  327. }
  328. }
  329. </script>
  330. <style lang="less">
  331. @import "../../assets/less/pay.less";
  332. </style>