index.ux 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473
  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="chapter-cost" if="fee">
  8. <text>当前需要消耗:</text>
  9. <text class="cost">{{ fee }}</text>
  10. <text>书币</text>
  11. </div>
  12. <div class="user-balance">
  13. <text>您的余额:</text>
  14. <text class="balance">{{ balance }}</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"
  76. >1.充值后书币到账可能有延迟,1小时内未到账请到个人中心联系客服</text
  77. >
  78. <text class="notice-item"
  79. >2.未满18周岁的未成年人应在法定监护人同意后进行充值。</text
  80. >
  81. <text class="notice-item"
  82. >3.充值书币,鉴于网络服务性质特殊属于不宜退货商品,不适用无理由退换规定。</text
  83. >
  84. </div>
  85. </div>
  86. </tab-content>
  87. </tabs>
  88. <div class="wrap-fixed">
  89. <image src="../../assets/imgs/shadow.png" class="shadow"></image>
  90. <div class="total-wrap">
  91. <text class="go-to-pay" @click="toPay">立即充值</text>
  92. </div>
  93. </div>
  94. <div class="loading-wrap" if="showLoading">
  95. <div class="loading-content">
  96. <progress type="circular"></progress>
  97. <text class="loading-text">{{ loadingText }}</text>
  98. </div>
  99. </div>
  100. </div>
  101. </template>
  102. <script>
  103. import router from '@system.router'
  104. import prompt from '@system.prompt'
  105. import storage from '@system.storage'
  106. import it from '../../helper/interface.js'
  107. import {
  108. getChargeList,
  109. getUserInfo,
  110. checkWxOrder,
  111. advertOrders,
  112. bannerData,
  113. hasPendingTask
  114. } from '../../api'
  115. import { configWxPay, configAliPay } from '../../helper'
  116. import { getAppConfig } from '../../api/utils.js'
  117. let getConfig
  118. export default {
  119. public: {
  120. push_id: '',
  121. isPendingTask: true
  122. },
  123. protected: {
  124. bid: '',
  125. code: '',
  126. fee: ''
  127. },
  128. private: {
  129. pay_back: 0,
  130. curPayType: 2,
  131. curSelect: 0,
  132. balance: 0,
  133. send_order_id: 0,
  134. total: '0元',
  135. loadingText: '订单查询中...',
  136. isInPay: false,
  137. showLoading: false,
  138. checked: false,
  139. loginPhone: '',
  140. need_check_order: false,
  141. haslogin: '',
  142. isVip: '',
  143. pay_order_id: '',
  144. trade_no: '',
  145. pay_success: false,
  146. last: null,
  147. payType: [
  148. {
  149. name: '支付宝',
  150. icon:
  151. 'http://newycsd.oss-cn-hangzhou.aliyuncs.com/images/base/logo/zhifubao.jpg',
  152. value: 1
  153. },
  154. {
  155. name: '微信',
  156. icon:
  157. 'http://newycsd.oss-cn-hangzhou.aliyuncs.com/images/base/logo/weixin.jpg',
  158. value: 2
  159. }
  160. ],
  161. rechargeList: []
  162. },
  163. //函数节流
  164. throttle(fun, delay) {
  165. let last = this.last
  166. const now = +new Date()
  167. if (now - last > delay) {
  168. fun()
  169. this.last = now
  170. } else {
  171. }
  172. },
  173. changePayType(type) {
  174. this.curPayType = type.value
  175. },
  176. changeCharge(key) {
  177. this.curSelect = key
  178. this.total = this.rechargeList[key].price
  179. },
  180. async getUserInfo() {
  181. let userinfo = await getUserInfo()
  182. this.balance = userinfo.balance
  183. this.send_order_id = userinfo.send_order_id
  184. this.checked = userinfo.is_check
  185. this.loginPhone = (await storage.get({ key: 'loginPhone' })).data
  186. this.haslogin = (await storage.get({ key: 'hasLogin' })).data
  187. this.isVip = userinfo.is_vip
  188. if (userinfo.pay_mode_default == 'weixin') {
  189. this.curPayType = 2
  190. } else {
  191. this.curPayType = 1
  192. }
  193. },
  194. async initChargeList() {
  195. this.rechargeList = await getChargeList()
  196. this.rechargeList.forEach((p, k) => {
  197. if (p.today_special) {
  198. this.curSelect = k
  199. this.total = this.rechargeList[k].price
  200. }
  201. })
  202. },
  203. async onInit() {
  204. if (this.push_id) {
  205. await storage.set({ key: 'push_id', value: this.push_id })
  206. }
  207. getConfig = getAppConfig(this)
  208. let { pay_back_alert_show } = await getConfig('task_center')
  209. this.pay_back = pay_back_alert_show
  210. this.initChargeList()
  211. },
  212. oldtoPay() {
  213. if (!(this.send_order_id || (this.haslogin && this.loginPhone))) {
  214. prompt.showDialog({
  215. title: '友情提示',
  216. message: '您还未绑定手机号,请绑定手机号后在进行相关操作',
  217. buttons: [
  218. {
  219. text: '前往绑定',
  220. color: '#33dd44'
  221. }
  222. ],
  223. success: function(data) {
  224. router.push({
  225. uri: '/views/Phone'
  226. })
  227. },
  228. cancel: function() {
  229. }
  230. })
  231. } else {
  232. this.throttle(() => {
  233. this.payFunc()
  234. }, 1000)
  235. }
  236. },
  237. async toPay() {
  238. let manufacturer = (await it.devManufacturerName()).toLowerCase()
  239. if (
  240. !(this.send_order_id || (this.haslogin && this.loginPhone)) &&
  241. (manufacturer == 'xiaomi' || manufacturer == 'vivo')
  242. ) {
  243. prompt.showDialog({
  244. title: '友情提示',
  245. message: '您还未绑定手机号,请绑定手机号后在进行相关操作',
  246. buttons: [
  247. {
  248. text: '前往绑定',
  249. color: '#33dd44'
  250. }
  251. ],
  252. success: function(data) {
  253. router.push({
  254. uri: '/views/Phone'
  255. })
  256. },
  257. cancel: function() {
  258. }
  259. })
  260. } else {
  261. this.throttle(() => {
  262. this.payFunc()
  263. }, 1000)
  264. }
  265. },
  266. async payFunc() {
  267. let cur_pay_type = this.curPayType
  268. let product_id = this.rechargeList[this.curSelect].product_id
  269. let ret = null
  270. this.need_check_order = false
  271. this.pay_order_id = ''
  272. this.trade_no = ''
  273. if (cur_pay_type === 1) {
  274. ret = await configAliPay({
  275. product_id: product_id,
  276. bid: this.bid,
  277. send_order_id: this.send_order_id
  278. })
  279. this.trade_no = ret.order
  280. this.showToastByCode(ret.code)
  281. } else {
  282. ret = await configWxPay({
  283. product_id: product_id,
  284. bid: this.bid,
  285. send_order_id: this.send_order_id
  286. })
  287. this.trade_no = ret.order
  288. this.pay_order_id = ret.order
  289. this.need_check_order = true
  290. }
  291. return false
  292. // 成功支付后的回调操作
  293. if (ret.code === '9000') this.showWaitingWrap(ret)
  294. else this.showToastByCode(ret.code)
  295. },
  296. checkOrder(order_info) {
  297. this.showLoading = true
  298. let { data, order } = order_info
  299. let times = 10
  300. this.loadingText = `订单查询中...${times}s`
  301. this.timer = setInterval(async () => {
  302. if (times === 0) clearInterval(this.timer), this.showToastByCode('6004')
  303. else {
  304. times--
  305. this.loadingText = `订单查询中...${times}s`
  306. let fb = await checkWxOrder(order)
  307. if (fb && typeof fb === 'object')
  308. clearInterval(this.timer), this.showToastByCode('9000')
  309. }
  310. }, 1000)
  311. },
  312. showWaitingWrap(order) {
  313. prompt.showDialog({
  314. title: '支付结果',
  315. message: '请确认支付结果',
  316. buttons: [
  317. {
  318. text: '已支付',
  319. color: '#EF5952'
  320. },
  321. {
  322. text: '重新选择金额',
  323. color: '#999'
  324. }
  325. ],
  326. success: data => {
  327. if (data.index === 0) this.checkOrder(order)
  328. },
  329. cancel: () => {
  330. }
  331. })
  332. return false
  333. },
  334. showToastByCode(code) {
  335. this.showLoading = false
  336. this.pay_success = false
  337. let msg = '支付成功!'
  338. switch (code) {
  339. case '9000':
  340. this.pay_success = true
  341. try {
  342. advertOrders(this.trade_no)
  343. } catch (e) {
  344. }
  345. ;(msg = '支付成功!'), router.back()
  346. break
  347. case '8000':
  348. msg = '订单已提交,请等待结果'
  349. break
  350. case '4000':
  351. msg = '订单支付失败!'
  352. break
  353. case '5000':
  354. msg = '订单重复!'
  355. break
  356. case '6001':
  357. msg = '您已取消支付'
  358. break
  359. case '6002':
  360. msg = '网络错误!'
  361. break
  362. case '6004':
  363. msg = '请联系客服查询订单'
  364. break
  365. default:
  366. msg = '请联系客服' + code
  367. }
  368. prompt.showToast({ message: msg })
  369. },
  370. async onShow() {
  371. try {
  372. let { has_pend_task } = await hasPendingTask({ type: 'recharge' })
  373. this.isPendingTask = has_pend_task
  374. } catch (err) {
  375. }
  376. this.getUserInfo()
  377. if (this.need_check_order && this.pay_order_id) {
  378. this.checkOrderNew(this.pay_order_id)
  379. }
  380. },
  381. async checkOrderNew(order) {
  382. let fb = await checkWxOrder(order)
  383. if (fb && typeof fb === 'object') {
  384. this.showToastByCode('9000')
  385. } else {
  386. this.showToastByCode('6001')
  387. }
  388. },
  389. onHide() {
  390. },
  391. onBackPress() {
  392. if (this.pay_back && !this.pay_success) {
  393. this.getActivity()
  394. return true
  395. } else {
  396. this.getLastpage()
  397. }
  398. return true
  399. },
  400. async getActivity() {
  401. let back = await bannerData(5)
  402. if (JSON.stringify(back) === '{}') {
  403. let taht = this
  404. if (this.isPendingTask) {
  405. prompt.showDialog({
  406. title: '温馨提示',
  407. message: '每日完成任务,可以免费获取书币~',
  408. buttons: [
  409. {
  410. text: '去做任务',
  411. color: '#EF5952'
  412. },
  413. {
  414. text: '我知道了',
  415. color: '#999'
  416. }
  417. ],
  418. success: function(data) {
  419. if (data.index === 1) {
  420. taht.getLastpage()
  421. } else {
  422. router.push({
  423. uri: '/views/Task'
  424. })
  425. }
  426. },
  427. cancel: function() {
  428. }
  429. })
  430. } else {
  431. this.getLastpage()
  432. }
  433. } else {
  434. router.push({
  435. uri: back.redirect_url,
  436. params: back.param
  437. })
  438. }
  439. },
  440. getLastpage() {
  441. let backPage = {}
  442. try {
  443. let page = router.getState()
  444. let allPage = router.getPages()
  445. for (var k = allPage.length - 1; k >= 0; k--) {
  446. if (allPage[k].name != page.name && allPage[k].name != 'views/Phone') {
  447. backPage = allPage[k]
  448. break
  449. }
  450. }
  451. } catch (e) {
  452. backPage = {}
  453. }
  454. if (JSON.stringify(backPage) === '{}') {
  455. router.replace({ uri: '/views/Index' })
  456. } else {
  457. router.back(backPage)
  458. }
  459. return true
  460. }
  461. }
  462. </script>
  463. <style lang="less">
  464. @import '../../assets/less/pay.less';
  465. </style>