index.ux 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  1. <import name="x-page" src="../../components/page/page.ux"></import>
  2. <template>
  3. <div class="consume-record__wrap">
  4. <div class="tabbar-wrap">
  5. <block for="(index, tab) in tabs">
  6. <div class="tab-item" @click="tabChange(index)">
  7. <text class="{{index === curTab ? 'active' : ''}}">{{tab}}</text>
  8. <text class="tab-active__border {{index === curTab ? 'tab-active__border--active' : ''}}"></text>
  9. </div>
  10. </block>
  11. </div>
  12. <list class="consume-wrap">
  13. <block if="curTab === 0">
  14. <block for="{{chapter.list}}">
  15. <list-item type="chapter" class="consume-item">
  16. <div class="consume-info">
  17. <text class="name">{{$item.book_name}}</text>
  18. <text class="chapter">{{$item.chapter_name}}</text>
  19. <text class="create">{{$item.created_at}}</text>
  20. </div>
  21. <text class="consume-price">{{$item.fee}}书币</text>
  22. </list-item>
  23. </block>
  24. </block>
  25. <block elif="curTab === 1">
  26. <block for="{{book.list}}">
  27. <list-item type="book" class="consume-item">
  28. <div class="consume-info">
  29. <text class="name">{{$item.book_name}}</text>
  30. <text class="create">{{$item.created_at}}</text>
  31. </div>
  32. <text class="consume-price">{{$item.fee}}书币</text>
  33. </list-item>
  34. </block>
  35. </block>
  36. <list-item type="page" class="consume-wrap">
  37. <x-page current="{{currentPage.current}}" total="{{currentPage.total}}" @prev="prev" @next="next"></x-page>
  38. </list-item>
  39. </list>
  40. </div>
  41. </template>
  42. <script>
  43. import { chapterApi, bookApi } from "../../api/index";
  44. export default {
  45. private: {
  46. curTab: 0,
  47. tabs: ["章节", "整本"],
  48. chapter: {
  49. list: [],
  50. page: {
  51. total: 0,
  52. current: 1
  53. },
  54. },
  55. book: {
  56. list: [],
  57. page: {
  58. total: 0,
  59. current: 1
  60. },
  61. },
  62. currentPage: {
  63. total: 0,
  64. current: 1
  65. }
  66. },
  67. onInit() {
  68. this.getOrderChapter();
  69. },
  70. async getOrderChapter(page = 1, page_size = 10) {
  71. let res = await chapterApi({ page: page, page_size });
  72. let { list, meta } = res;
  73. let pages = { total: meta.last_page, current: meta.current_page };
  74. this.chapter = { ...this.chapter, list, page: pages };
  75. this.currentPage = pages;
  76. },
  77. async getOrderBook(page = 1, page_size = 2) {
  78. let res = await bookApi({ page: page, page_size });
  79. let { list, meta } = res;
  80. let pages = { total: meta.last_page, current: meta.current_page };
  81. this.book = { ...this.book, list, page: pages };
  82. this.currentPage = pages;
  83. },
  84. tabChange(index) {
  85. this.curTab = index;
  86. switch (index) {
  87. case 0:
  88. this.getOrderChapter();
  89. break;
  90. case 1:
  91. this.getOrderBook();
  92. break;
  93. }
  94. },
  95. prev() {
  96. switch (this.curTab) {
  97. case 0:
  98. this.getOrderChapter(--this.currentPage.current);
  99. break;
  100. case 1:
  101. this.getOrderBook(--this.currentPage.current);
  102. break;
  103. }
  104. },
  105. next() {
  106. switch (this.curTab) {
  107. case 0:
  108. this.getOrderChapter(++this.currentPage.current);
  109. break;
  110. case 1:
  111. this.getOrderBook(++this.currentPage.current);
  112. break;
  113. }
  114. }
  115. }
  116. </script>
  117. <style lang="less">
  118. @import "../../assets/less/consume.less";
  119. </style>