index.ux 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398
  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 src="https://cdn-novel.iycdm.com/h5/channelActivity/activity-2020-04-17/20200417173207-bg.jpeg"></image>
  6. <div class="contain">
  7. <text class="promotion-title" if="{{activity.isForever!=='1'}}">活动时间:{{activity.startTime.substring(0,10)}} 至 {{activity.endTime.substring(0,10)}}</text>
  8. <div class="charge-item {{currentIdx==$idx?'charge-on':''}}" for="{{activity.products}}" @click="chooseItem($item,$idx)">
  9. <block if="{{$item.type=='YEAR_ORDER'}}">
  10. <text class="limit {{currentIdx==$idx?'checked':''}}">限充{{$item.limit}}次</text>
  11. <text class="title"><span>365包年</span></text>
  12. <text class="desc">全站小说免费阅读</text>
  13. </block>
  14. <block elif="{{$item.type=='QUARTER'}}">
  15. <text class="limit {{currentIdx==$idx?'checked':''}}">限充{{$item.limit}}次</text>
  16. <text class="title"><span>98元包季</span></text>
  17. <text class="desc">全站小说免费阅读</text>
  18. </block>
  19. <block else>
  20. <text class="limit {{currentIdx==$idx?'checked':''}}">限充{{$item.limit}}次</text>
  21. <text class="title">充<span>{{$item.price}}元</span>得<span>{{$item.total}}书币</span></text>
  22. <text class="desc">多得{{$item.given}}书币</text>
  23. </block>
  24. </div>
  25. <text class="charge-button" @click="wantCharge">
  26. 立即充值
  27. </text>
  28. </div>
  29. <div class="rule">
  30. <text class="rule-bd">活动说明</text>
  31. <text>1.此充值为书币充值,1元=100书币</text>
  32. <text>2.书币为虚拟物品,一经充值不得退款</text>
  33. <text>3.活动期间不限充值次数</text>
  34. </div>
  35. </div>
  36. <!-- <div class="loading-wrap" if="showLoading">
  37. <div class="loading-content">
  38. <progress type="circular"></progress>
  39. <text class="loading-text">{{loadingText}}</text>
  40. </div>
  41. </div> -->
  42. <div class="mask" if={{showPay}} @click="closeMask">
  43. <div class="pop-pay">
  44. <div class="title-pay"><text class="index"></text><text>支付方式</text>
  45. <image src="../../assets/imgs/close.png" @click="closeMask"></image>
  46. </div>
  47. <div class="pay-item" @click="changePayType(0)" if="{{activity.payChannels.wechat=='1'}}">
  48. <div class="item-left">
  49. <image src="../../assets/imgs/wechat.png"></image><text>微信支付</text>
  50. </div>
  51. <image src="../../assets/imgs/pay_checked.png" class="checked" if={{!payType}}></image>
  52. <image src="../../assets/imgs/rank_grey.png" class="checked" if={{payType}}></image>
  53. </div>
  54. <div class="pay-item" @click="changePayType(1)" if="{{activity.payChannels.ali=='1'}}">
  55. <div class="item-left">
  56. <image src="../../assets/imgs/zfb.png"></image><text>支付宝支付</text>
  57. </div>
  58. <image src="../../assets/imgs/rank_grey.png" class="checked" if={{!payType}}></image>
  59. <image src="../../assets/imgs/pay_checked.png" class="checked" if={{payType}}></image>
  60. </div>
  61. <text class="charge-now" @click="goPay">确认充值</text>
  62. </div>
  63. </div>
  64. </div>
  65. </template>
  66. <script>
  67. import { configWxPay, configAliPay } from "../../helper";
  68. import { getAcitivity, getUserInfo, checkWxOrder } from "../../api";
  69. import { getAppConfig, getToken } from '../../api/utils';
  70. import router from '@system.router';
  71. import prompt from '@system.prompt';
  72. export default {
  73. public: {
  74. token: '',
  75. send_order_id: '',
  76. },
  77. private: {
  78. showPay: false,
  79. activity: null,
  80. payType: 0,
  81. currentProduct: null,
  82. currentIdx:0,
  83. showLoading: false,
  84. },
  85. onInit() {
  86. console.log('sssss')
  87. //getAppConfig(this);
  88. this.getUserInfo();
  89. setTimeout(()=>{
  90. this.getAcitvy();
  91. },1000)
  92. },
  93. changePayType(type,evt) {
  94. evt.stopPropagation();
  95. this.payType = type;
  96. return false;
  97. },
  98. closeMask() {
  99. let a = 'this.token'
  100. this.showPay = false;
  101. },
  102. async getAcitvy() {
  103. let activity = await getAcitivity('8148bcb29074dafe1edd21dc06db9249');
  104. this.activity = activity;
  105. this.currentProduct = this.activity.products[0];
  106. },
  107. wantCharge() {
  108. this.showPay = true;
  109. },
  110. async getUserInfo() {
  111. let userinfo = await getUserInfo();
  112. this.send_order_id = userinfo.send_order_id || this.send_order_id;
  113. },
  114. chooseItem(product,idx) {
  115. this.currentProduct = product;
  116. this.currentIdx = idx;
  117. },
  118. async goPay(evt) {
  119. evt.stopPropagation();
  120. let cur_pay_type = this.payType;
  121. let product_id = this.currentProduct.product_id;
  122. let ret = null;
  123. if (cur_pay_type == 1) {
  124. ret = await configAliPay({ product_id: product_id, send_order_id: this.send_order_id, activity_token:this.token });
  125. }
  126. else {
  127. ret = await configWxPay({ product_id: product_id, send_order_id: this.send_order_id, activity_token:this.token});
  128. }
  129. // 成功支付后的回调操作
  130. if (ret.code === "9000") this.showWaitingWrap(ret);
  131. else this.showToastByCode(ret.code);
  132. },
  133. checkOrder(order_info) {
  134. this.showLoading = true;
  135. let { data, order } = order_info;
  136. let times = 10;
  137. /* this.loadingText = `订单查询中...${times}s`;
  138. this.timer = setInterval(async () => {
  139. if (times === 0) clearInterval(this.timer), this.showToastByCode("6004");
  140. else {
  141. times--;
  142. this.loadingText = `订单查询中...${times}s`;
  143. let fb = await checkWxOrder(order);
  144. if (fb && typeof fb === "object") clearInterval(this.timer), this.showToastByCode("9000");
  145. }
  146. }, 1000); */
  147. setTimeout(()=>{
  148. if (router.getLength() === 1) {
  149. router.replace({ uri: "/views/Index" });
  150. return true;
  151. } else {
  152. router.back()
  153. }
  154. },2000)
  155. },
  156. showToastByCode(code) {
  157. this.showLoading = false;
  158. let msg = "支付成功!";
  159. switch (code) {
  160. case "9000": (msg = "支付成功!", router.back()); break;
  161. case "8000": msg = "订单已提交,请等待结果"; break;
  162. case "4000": msg = "订单支付失败!"; break;
  163. case "5000": msg = "订单重复!"; break;
  164. case "6001": msg = "您已取消支付"; break;
  165. case "6002": msg = "网络错误!"; break;
  166. case "6004": msg = "请联系客服查询订单"; break;
  167. default: msg = "请联系客服" + code;
  168. }
  169. prompt.showToast({ message: msg });
  170. },
  171. showWaitingWrap(order) {
  172. prompt.showDialog({
  173. title: "支付结果",
  174. message: "请确认支付结果",
  175. buttons: [
  176. {
  177. text: "已支付",
  178. color: "#EF5952"
  179. },
  180. {
  181. text: "重新选择金额",
  182. color: "#999"
  183. }
  184. ],
  185. success: (data) => {
  186. if (data.index === 0) this.checkOrder(order);
  187. },
  188. cancel: () => {
  189. console.log("cancel");
  190. }
  191. });
  192. },
  193. }
  194. </script>
  195. <style lang="less">
  196. .mask {
  197. position: fixed;
  198. top: 0;
  199. bottom: 0;
  200. left: 0;
  201. right: 0;
  202. background-color: rgba(0, 0, 0, 0.56);
  203. flex-direction: column;
  204. align-items: center;
  205. justify-content: flex-end;
  206. z-index: 2;
  207. .charge-now {
  208. width: 450px;
  209. height: 80px;
  210. margin: 20px auto 0;
  211. border-radius: 40px;
  212. background-color: #ff6200;
  213. font-size: 28px;
  214. color: #fff;
  215. text-align: center;
  216. }
  217. .pay-item {
  218. justify-content: space-between;
  219. padding: 10px 30px;
  220. .checked {
  221. width: 40px;
  222. }
  223. .item-left {
  224. image {
  225. width: 60px;
  226. }
  227. text {
  228. font-size: 28px;
  229. font-weight: bolder;
  230. margin-left: 26px;
  231. }
  232. }
  233. }
  234. .pop-pay {
  235. height: 420px;
  236. padding: 30px 0;
  237. background-color: #fff;
  238. border-top-left-radius: 18px;
  239. width: 100%;
  240. flex-direction: column;
  241. border-top-right-radius: 18px;
  242. .title-pay {
  243. justify-content: space-between;
  244. margin-bottom: 30px;
  245. border-bottom: 2px solid #ccc;
  246. padding-bottom: 30px;
  247. padding-left: 30px;
  248. padding-right: 30px;
  249. text {
  250. color: #333;
  251. font-weight: bold;
  252. font-size: 32x;
  253. }
  254. image {
  255. width: 30px;
  256. }
  257. }
  258. }
  259. }
  260. .stack {
  261. width: 100%;
  262. flex-direction: column;
  263. align-items: center;
  264. image {
  265. width: 100%;
  266. }
  267. .charge-item{
  268. position: relative;
  269. .limit{
  270. width: 100px;
  271. height: 38px;
  272. font-size: 20px;
  273. line-height: 38px;
  274. text-align: center;
  275. background-color: #E6E6E6;
  276. color: #B3B3B3;
  277. border-bottom-left-radius: 10px;
  278. border-top-right-radius: 10px;
  279. position: absolute;
  280. right:0;
  281. top:0;
  282. }
  283. .checked{
  284. color:#fff;
  285. background-color: #E82B2F;
  286. }
  287. }
  288. .rule {
  289. flex-direction: column;
  290. margin-top: 30px;
  291. padding: 0 0 100px 0;
  292. width: 600px;
  293. margin-left: auto;
  294. margin-right: auto;
  295. text {
  296. text-align: left;
  297. font-size: 26px;
  298. color: #fff;
  299. padding: 10px 0;
  300. }
  301. .rule-bd {
  302. text-align: center;
  303. }
  304. }
  305. .contain {
  306. background-color: #fff;
  307. width: 700px;
  308. padding: 28px;
  309. border-radius: 14px;
  310. flex-direction: column;
  311. justify-content: center;
  312. align-items: center;
  313. .promotion-title {
  314. font-weight: bold;
  315. font-size: 28px;
  316. text-align: center;
  317. margin: 10px 0 20px 0;
  318. }
  319. .charge-button {
  320. background-color: #e82b2f;
  321. width: 600px;
  322. height: 100px;
  323. line-height: 100px;
  324. color: #fff;
  325. font-weight: bold;
  326. text-align: center;
  327. margin-top: 20px;
  328. border-radius: 60px;
  329. }
  330. .charge-item {
  331. width: 600px;
  332. background-color:#fff;
  333. border:1px solid #e6e6e6;
  334. color: #333;
  335. flex-direction: column;
  336. text-align: center;
  337. height: 110px;
  338. justify-content: center;
  339. align-items: center;
  340. border-radius: 10px;
  341. margin: 15px 0;
  342. .title {
  343. text-align: center;
  344. font-size: 36px;
  345. font-weight: bold;
  346. span {
  347. color: #fd555d;
  348. }
  349. }
  350. .desc {
  351. text-align: center;
  352. font-size: 28px;
  353. margin-top: 5px;
  354. }
  355. }
  356. .charge-on{
  357. background-color: #ffe4c4;
  358. border: 1px solid #e82b2f;
  359. }
  360. }
  361. .loading-wrap {
  362. position: fixed;
  363. top: 0;
  364. bottom: 0;
  365. left: 0;
  366. right: 0;
  367. background-color: rgba(0, 0, 0, .6);
  368. justify-content: center;
  369. align-items: center;
  370. .loading-content {
  371. width: 300px;
  372. height: 100px;
  373. border-radius: 6px;
  374. background-color: #fff;
  375. flex-direction: column;
  376. justify-content: center;
  377. align-items: center;
  378. .loading-text {
  379. font-size: 26px;
  380. }
  381. }
  382. }
  383. }
  384. </style>