index.ux 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606
  1. <import name="x-page" src="../../components/page/page.ux"></import>
  2. <template>
  3. <div class="consume-record__wrap">
  4. <div class="stack" style="background-color: #ff8b63" if="{{activity}}">
  5. <image
  6. src="https://cdn-novel.iycdm.com/h5/channelActivity/activity-2020-04-17/20200417173207-bg.jpeg"
  7. ></image>
  8. <div class="contain">
  9. <text class="promotion-title" if="{{activity.isForever!='1'}}"
  10. >活动时间:{{ activity.startTime.substring(0, 10) }} 至
  11. {{ activity.endTime.substring(0, 10) }}</text
  12. >
  13. <div
  14. class="charge-item {{currentIdx==$idx?'charge-on':''}}"
  15. for="{{activity.products}}"
  16. @click="chooseItem($item, $idx)"
  17. >
  18. <block if="{{$item.type=='YEAR_ORDER'}}">
  19. <text class="limit {{currentIdx==$idx?'checked':''}}"
  20. >限充{{ $item.limit }}次</text
  21. >
  22. <text class="title"><span>365包年</span></text>
  23. <text class="desc">全站小说免费阅读</text>
  24. </block>
  25. <block elif="{{$item.type=='QUARTER'}}">
  26. <text class="limit {{currentIdx==$idx?'checked':''}}"
  27. >限充{{ $item.limit }}次</text
  28. >
  29. <text class="title"><span>98元包季</span></text>
  30. <text class="desc">全站小说免费阅读</text>
  31. </block>
  32. <block else>
  33. <text class="limit {{currentIdx==$idx?'checked':''}}"
  34. >限充{{ $item.limit }}次</text
  35. >
  36. <text class="title"
  37. >充<span>{{ $item.price }}元</span>得<span
  38. >{{ $item.total }}书币</span
  39. ></text
  40. >
  41. <text class="desc">多得{{ $item.given }}书币</text>
  42. </block>
  43. </div>
  44. <text class="charge-button" @click="wantCharge">
  45. 立即充值
  46. </text>
  47. </div>
  48. <div class="rule">
  49. <text class="rule-bd">活动说明</text>
  50. <text
  51. >1.充值后书币到账可能有延迟,1小时内未到账请到个人中心联系客服</text
  52. >
  53. <text>2.未满18周岁的未成年人应在法定监护人同意后进行充值</text>
  54. <text>3.此充值为书币充值,1元=100书币</text>
  55. <text
  56. >4.充值书币,鉴于网络服务性质特殊属于不宜退货商品,不适用无理由退换规定</text
  57. >
  58. </div>
  59. </div>
  60. <!-- <div class="loading-wrap" if="showLoading">
  61. <div class="loading-content">
  62. <progress type="circular"></progress>
  63. <text class="loading-text">{{loadingText}}</text>
  64. </div>
  65. </div> -->
  66. <div class="mask" if="{{showPay}}" @click="closeMask">
  67. <div class="pop-pay">
  68. <div class="title-pay">
  69. <text class="index"></text><text>支付方式</text>
  70. <image src="../../assets/imgs/close.png" @click="closeMask"></image>
  71. </div>
  72. <div
  73. class="pay-item"
  74. @click="changePayType(0)"
  75. if="{{activity.payChannels.wechat=='1'}}"
  76. >
  77. <div class="item-left">
  78. <image src="../../assets/imgs/wechat.png"></image
  79. ><text>微信支付</text>
  80. </div>
  81. <image
  82. src="../../assets/imgs/pay_checked.png"
  83. class="checked"
  84. if="{{!payType}}"
  85. ></image>
  86. <image
  87. src="../../assets/imgs/rank_grey.png"
  88. class="checked"
  89. if="{{payType}}"
  90. ></image>
  91. </div>
  92. <div
  93. class="pay-item"
  94. @click="changePayType(1)"
  95. if="{{activity.payChannels.ali=='1'}}"
  96. >
  97. <div class="item-left">
  98. <image src="../../assets/imgs/zfb.png"></image
  99. ><text>支付宝支付</text>
  100. </div>
  101. <image
  102. src="../../assets/imgs/rank_grey.png"
  103. class="checked"
  104. if="{{!payType}}"
  105. ></image>
  106. <image
  107. src="../../assets/imgs/pay_checked.png"
  108. class="checked"
  109. if="{{payType}}"
  110. ></image>
  111. </div>
  112. <text class="charge-now" @click="goPay">确认充值</text>
  113. </div>
  114. </div>
  115. </div>
  116. </template>
  117. <script>
  118. import { configWxPay, configAliPay } from '../../helper'
  119. import {
  120. getAcitivity,
  121. getUserInfo,
  122. checkWxOrder,
  123. advertOrders,
  124. hasPendingTask
  125. } from '../../api'
  126. import { getAppConfig, getToken } from '../../api/utils'
  127. import router from '@system.router'
  128. import prompt from '@system.prompt'
  129. import storage from '@system.storage'
  130. export default {
  131. public: {
  132. token: '',
  133. pay_back: 0,
  134. isPendingTask: false
  135. },
  136. private: {
  137. showPay: false,
  138. activity: null,
  139. payType: 0,
  140. currentProduct: null,
  141. currentIdx: 0,
  142. showLoading: false,
  143. pay_order_id: '',
  144. trade_no: '',
  145. haslogin: '',
  146. loginPhone: '',
  147. pay_success: false,
  148. need_check_order: false
  149. },
  150. async onInit() {
  151. // getAppConfig(this);
  152. this.getUserInfo()
  153. setTimeout(() => {
  154. this.getAcitvy()
  155. }, 1000)
  156. getConfig = getAppConfig(this)
  157. let { pay_back_alert_show } = await getConfig('task_center')
  158. this.pay_back = pay_back_alert_show
  159. },
  160. changePayType(type, evt) {
  161. evt.stopPropagation()
  162. this.payType = type
  163. return false
  164. },
  165. closeMask() {
  166. this.showPay = false
  167. },
  168. async getAcitvy() {
  169. let activity = await getAcitivity(this.token)
  170. this.activity = activity
  171. this.currentProduct = this.activity.products[0]
  172. },
  173. wantCharge() {
  174. if (!(this.send_order_id || (this.haslogin && this.loginPhone))) {
  175. prompt.showDialog({
  176. title: '友情提示',
  177. message: '您还未绑定手机号,请绑定手机号后在进行相关操作',
  178. buttons: [
  179. {
  180. text: '前往绑定',
  181. color: '#33dd44'
  182. }
  183. ],
  184. success: function(data) {
  185. router.push({
  186. uri: '/views/Phone'
  187. })
  188. },
  189. cancel: function() {}
  190. })
  191. } else {
  192. this.showPay = true
  193. }
  194. },
  195. async getUserInfo() {
  196. try {
  197. this.loginPhone = (await storage.get({ key: 'loginPhone' })).data
  198. this.haslogin = (await storage.get({ key: 'hasLogin' })).data
  199. let userinfo = await getUserInfo()
  200. if (userinfo) {
  201. this.send_order_id = userinfo.send_order_id
  202. }
  203. } catch (e) {}
  204. },
  205. chooseItem(product, idx) {
  206. this.currentProduct = product
  207. this.currentIdx = idx
  208. },
  209. async goPay(evt) {
  210. evt.stopPropagation()
  211. let cur_pay_type = this.payType
  212. let product_id = this.currentProduct.product_id
  213. let ret = null
  214. this.need_check_order = false
  215. this.pay_order_id = ''
  216. this.trade_no = ''
  217. if (cur_pay_type == 1) {
  218. ret = await configAliPay({
  219. product_id: product_id,
  220. send_order_id: this.send_order_id,
  221. activity_token: this.token
  222. })
  223. this.trade_no = ret.order
  224. this.showToastByCode(ret.code)
  225. } else {
  226. ret = await configWxPay({
  227. product_id: product_id,
  228. send_order_id: this.send_order_id,
  229. activity_token: this.token
  230. })
  231. this.trade_no = ret.order
  232. this.pay_order_id = ret.order
  233. this.need_check_order = true
  234. }
  235. return false
  236. // 成功支付后的回调操作
  237. if (ret.code === '9000') this.showWaitingWrap(ret)
  238. else this.showToastByCode(ret.code)
  239. },
  240. checkOrder(order_info) {
  241. this.showLoading = true
  242. let { data, order } = order_info
  243. let times = 10
  244. /* this.loadingText = `订单查询中...${times}s`;
  245. this.timer = setInterval(async () => {
  246. if (times === 0) clearInterval(this.timer), this.showToastByCode("6004");
  247. else {
  248. times--;
  249. this.loadingText = `订单查询中...${times}s`;
  250. let fb = await checkWxOrder(order);
  251. if (fb && typeof fb === "object") clearInterval(this.timer), this.showToastByCode("9000");
  252. }
  253. }, 1000); */
  254. setTimeout(() => {
  255. if (router.getLength() === 1) {
  256. router.replace({ uri: '/views/Index' })
  257. return true
  258. } else {
  259. router.back()
  260. }
  261. }, 2000)
  262. },
  263. async onShow() {
  264. try {
  265. let { has_pend_task } = await hasPendingTask({ type: 'recharge' })
  266. this.isPendingTask = has_pend_task
  267. await this.getUserInfo()
  268. console.log(this.isPendingTask, 'this.isPendingTask')
  269. } catch (err) {
  270. console.lg(err)
  271. }
  272. if (this.need_check_order && this.pay_order_id) {
  273. this.checkOrderNew(this.pay_order_id)
  274. }
  275. },
  276. async checkOrderNew(order) {
  277. // this.showLoading = true;
  278. let fb = await checkWxOrder(order)
  279. // this.showToastByCode('9000')
  280. if (fb && typeof fb === 'object') {
  281. this.showToastByCode('9000')
  282. } else {
  283. this.showToastByCode('6001')
  284. }
  285. },
  286. showToastByCode(code) {
  287. this.showLoading = false
  288. this.pay_success = false
  289. let msg = '支付成功!'
  290. switch (code) {
  291. case '9000':
  292. this.pay_success = true
  293. try {
  294. advertOrders(this.trade_no)
  295. } catch (e) {}
  296. msg = '支付成功!'
  297. break
  298. case '8000':
  299. msg = '订单已提交,请等待结果'
  300. break
  301. case '4000':
  302. msg = '订单支付失败!'
  303. break
  304. case '5000':
  305. msg = '订单重复!'
  306. break
  307. case '6001':
  308. msg = '您已取消支付'
  309. break
  310. case '6002':
  311. msg = '网络错误!'
  312. break
  313. case '6004':
  314. msg = '请联系客服查询订单'
  315. break
  316. default:
  317. msg = '请联系客服' + code
  318. }
  319. prompt.showToast({ message: msg })
  320. },
  321. showWaitingWrap(order) {
  322. prompt.showDialog({
  323. title: '支付结果',
  324. message: '请确认支付结果',
  325. buttons: [
  326. {
  327. text: '已支付',
  328. color: '#EF5952'
  329. },
  330. {
  331. text: '重新选择金额',
  332. color: '#999'
  333. }
  334. ],
  335. success: data => {
  336. if (data.index === 0) this.checkOrder(order)
  337. },
  338. cancel: () => {}
  339. })
  340. },
  341. onBackPress() {
  342. if (!this.pay_success) {
  343. let taht = this
  344. if (this.isPendingTask) {
  345. prompt.showDialog({
  346. title: '温馨提示',
  347. message: '每日完成任务,可以免费获取书币~',
  348. buttons: [
  349. {
  350. text: '去做任务',
  351. color: '#EF5952'
  352. },
  353. {
  354. text: '我知道了',
  355. color: '#999'
  356. }
  357. ],
  358. success: function(data) {
  359. if (data.index === 1) {
  360. taht.getLastpage()
  361. } else {
  362. router.push({
  363. uri: '/views/Task'
  364. })
  365. }
  366. },
  367. cancel: function() {
  368. console.log('取消前往')
  369. }
  370. })
  371. } else {
  372. this.getLastpage()
  373. }
  374. return true
  375. } else {
  376. this.getLastpage()
  377. }
  378. return true
  379. },
  380. getLastpage() {
  381. let backPage = {}
  382. try {
  383. let page = router.getState()
  384. let allPage = router.getPages()
  385. for (var k = allPage.length - 1; k >= 0; k--) {
  386. if (
  387. allPage[k].name != page.name &&
  388. allPage[k].name != 'views/Phone' &&
  389. allPage[k].name != 'views/Pay'
  390. ) {
  391. backPage = allPage[k]
  392. break
  393. }
  394. }
  395. } catch (e) {
  396. backPage = {}
  397. }
  398. if (JSON.stringify(backPage) === '{}') {
  399. router.replace({ uri: '/views/Index' })
  400. } else {
  401. router.back(backPage)
  402. }
  403. return true
  404. }
  405. }
  406. </script>
  407. <style lang="less">
  408. .mask {
  409. position: fixed;
  410. top: 0;
  411. bottom: 0;
  412. left: 0;
  413. right: 0;
  414. background-color: rgba(0, 0, 0, 0.56);
  415. flex-direction: column;
  416. align-items: center;
  417. justify-content: flex-end;
  418. z-index: 2;
  419. .charge-now {
  420. width: 450px;
  421. height: 80px;
  422. margin: 20px auto 0;
  423. border-radius: 40px;
  424. background-color: #ff6200;
  425. font-size: 28px;
  426. color: #fff;
  427. text-align: center;
  428. }
  429. .pay-item {
  430. justify-content: space-between;
  431. padding: 10px 30px;
  432. .checked {
  433. width: 40px;
  434. }
  435. .item-left {
  436. image {
  437. width: 60px;
  438. }
  439. text {
  440. font-size: 28px;
  441. font-weight: bolder;
  442. margin-left: 26px;
  443. }
  444. }
  445. }
  446. .pop-pay {
  447. height: 420px;
  448. padding: 30px 0;
  449. background-color: #fff;
  450. border-top-left-radius: 18px;
  451. width: 100%;
  452. flex-direction: column;
  453. border-top-right-radius: 18px;
  454. .title-pay {
  455. justify-content: space-between;
  456. margin-bottom: 30px;
  457. border-bottom: 2px solid #ccc;
  458. padding-bottom: 30px;
  459. padding-left: 30px;
  460. padding-right: 30px;
  461. text {
  462. color: #333;
  463. font-weight: bold;
  464. font-size: 32px;
  465. }
  466. image {
  467. width: 30px;
  468. }
  469. }
  470. }
  471. }
  472. .stack {
  473. width: 100%;
  474. flex-direction: column;
  475. align-items: center;
  476. image {
  477. width: 100%;
  478. }
  479. .charge-item {
  480. position: relative;
  481. .limit {
  482. width: 100px;
  483. height: 38px;
  484. font-size: 20px;
  485. line-height: 38px;
  486. text-align: center;
  487. background-color: #e6e6e6;
  488. color: #b3b3b3;
  489. border-bottom-left-radius: 10px;
  490. border-top-right-radius: 10px;
  491. position: absolute;
  492. right: 0;
  493. top: 0;
  494. }
  495. .checked {
  496. color: #fff;
  497. background-color: #e82b2f;
  498. }
  499. }
  500. .rule {
  501. flex-direction: column;
  502. margin-top: 30px;
  503. padding: 0 0 100px 0;
  504. width: 600px;
  505. margin-left: auto;
  506. margin-right: auto;
  507. text {
  508. text-align: left;
  509. font-size: 26px;
  510. color: #fff;
  511. padding: 10px 0;
  512. }
  513. .rule-bd {
  514. text-align: center;
  515. }
  516. }
  517. .contain {
  518. background-color: #fff;
  519. width: 700px;
  520. padding: 28px;
  521. border-radius: 14px;
  522. flex-direction: column;
  523. justify-content: center;
  524. align-items: center;
  525. .promotion-title {
  526. font-weight: bold;
  527. font-size: 28px;
  528. text-align: center;
  529. margin: 10px 0 20px 0;
  530. }
  531. .charge-button {
  532. background-color: #e82b2f;
  533. width: 600px;
  534. height: 100px;
  535. line-height: 100px;
  536. color: #fff;
  537. font-weight: bold;
  538. text-align: center;
  539. margin-top: 20px;
  540. border-radius: 60px;
  541. }
  542. .charge-item {
  543. width: 600px;
  544. background-color: #fff;
  545. border: 1px solid #e6e6e6;
  546. color: #333;
  547. flex-direction: column;
  548. text-align: center;
  549. height: 110px;
  550. justify-content: center;
  551. align-items: center;
  552. border-radius: 10px;
  553. margin: 15px 0;
  554. .title {
  555. text-align: center;
  556. font-size: 36px;
  557. font-weight: bold;
  558. span {
  559. color: #fd555d;
  560. }
  561. }
  562. .desc {
  563. text-align: center;
  564. font-size: 28px;
  565. margin-top: 5px;
  566. }
  567. }
  568. .charge-on {
  569. background-color: #ffe4c4;
  570. border: 1px solid #e82b2f;
  571. }
  572. }
  573. .loading-wrap {
  574. position: fixed;
  575. top: 0;
  576. bottom: 0;
  577. left: 0;
  578. right: 0;
  579. background-color: rgba(0, 0, 0, 0.6);
  580. justify-content: center;
  581. align-items: center;
  582. .loading-content {
  583. width: 300px;
  584. height: 100px;
  585. border-radius: 6px;
  586. background-color: #fff;
  587. flex-direction: column;
  588. justify-content: center;
  589. align-items: center;
  590. .loading-text {
  591. font-size: 26px;
  592. }
  593. }
  594. }
  595. }
  596. </style>