index.ux 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220
  1. <import name="x-book" src="../../components/book/book.ux"></import>
  2. <import name="x-loading" src="../../components/loading/loading.ux"></import>
  3. <template>
  4. <div class="category-wrap">
  5. <div class="page_title"><text>分类</text></div>
  6. <div class="tab_bar">
  7. <div class="filter-item">
  8. <div class="filter-item__list">
  9. <block for="channel">
  10. <div class="filter-item_warp">
  11. <text
  12. class="filter-item__item {{$item.key === filter.channel_id ? 'cur_bar' : ''}}"
  13. @click="filterChange('channel_id', $item.key)"
  14. >{{ $item.name }}</text
  15. >
  16. <text
  17. class="choose-bar"
  18. show="{{$item.key === filter.channel_id }}"
  19. ></text>
  20. </div>
  21. </block>
  22. <div class="filter-item_warp" @click="toPage('Free')">
  23. <text>限时免费</text>
  24. </div>
  25. </div>
  26. </div>
  27. </div>
  28. <list class="list-content" @scrollbottom="onReachBottom">
  29. <!-- <list-item type="tab" class="tab_bar"> </list-item> -->
  30. <!-- <list-item type="search" class="search-bar">
  31. <div class="search-bar__wrap">
  32. <input
  33. id="search"
  34. type="text"
  35. enterkeytype="search"
  36. placeholder="请输入书名或者作者"
  37. @enterkeyclick="bookSearch"
  38. />
  39. <image
  40. src="https://yueduyun.oss-cn-hangzhou.aliyuncs.com/xiaochengxu/img/search.png"
  41. ></image>
  42. </div>
  43. </list-item> -->
  44. <list-item type="filter" class="filter-wrap">
  45. <div class="filter-item">
  46. <!-- <text class="filter-item__name">类型</text> -->
  47. <div class="filter-item__list">
  48. <block
  49. for="(category[filter.channel_id] && category[filter.channel_id].children)"
  50. >
  51. <text
  52. class="filter-item__item {{$item.id === filter.category_id ? 'cur': ''}}"
  53. @click="filterChange('category_id', $item.id)"
  54. >{{ $item.name }}</text
  55. >
  56. </block>
  57. </div>
  58. </div>
  59. <div class="filter-item">
  60. <!-- <text class="filter-item__name">是否完结</text> -->
  61. <div class="filter-item__list">
  62. <block for="status">
  63. <text
  64. class="filter-item__item {{$item.value === filter.status ? 'cur' : ''}}"
  65. @click="filterChange('status', $item.value)"
  66. >{{ $item.name }}</text
  67. >
  68. </block>
  69. </div>
  70. </div>
  71. </list-item>
  72. <list-item type="loading" if="!list.length">
  73. <x-loading text="{{loadingText}}" empty="{{empty}}"></x-loading>
  74. </list-item>
  75. <block for="list">
  76. <list-item
  77. type="books-item"
  78. class="books-item__wrap {{$idx === 0 ? 'book-item__wrap--first' : ''}}"
  79. >
  80. <x-book multi="{{true}}" width="{{150}}" book="{{$item}}">
  81. <div class="book-info">
  82. <text class="name">{{ $item.book_name }}</text>
  83. <text class="intro">{{ $item.book_summary }}</text>
  84. <!-- <text class="status">豪门虐情 完结</text>
  85. <text class="words">字数:1231231</text>
  86. <div class="update">
  87. <text>最新:</text>
  88. <text class="lastest">第213章 我是最后一章</text>
  89. <image src="../../assets/imgs/book-vip.png"></image>
  90. </div> -->
  91. </div>
  92. </x-book>
  93. </list-item>
  94. </block>
  95. <list-item style="height:120px;"></list-item>
  96. </list>
  97. </div>
  98. </template>
  99. <script>
  100. import { getCategory, getBooksList } from '../../api'
  101. import { pageLoad } from '../../helper'
  102. import storage from '@system.storage'
  103. import router from '@system.router'
  104. export default {
  105. data() {
  106. return {
  107. channel: [],
  108. category: [],
  109. list: [],
  110. status: [
  111. {
  112. name: '完结',
  113. value: 1
  114. },
  115. {
  116. name: '连载',
  117. value: 0
  118. }
  119. ],
  120. filter: {
  121. key: '',
  122. channel_id: '',
  123. category_id: '',
  124. order_field: 'recommend_index',
  125. order_seq: 'asc',
  126. page_size: 100,
  127. page: 1,
  128. status: 1
  129. },
  130. meta: {},
  131. empty: false,
  132. loadingText: '加载ing...'
  133. }
  134. },
  135. onReachBottom() {
  136. // 请求更多数据
  137. this.getBooksArray()
  138. },
  139. async getCategory() {
  140. this.category = this.initCategory(await getCategory())
  141. console.log("this.category:", this.category);
  142. await this.initChannel(this.category)
  143. this.getBooksArray()
  144. },
  145. async initChannel(category) {
  146. this.filter.channel_id = +(await storage.get({ key: 'sex' })).data
  147. this.filter.category_id = category[this.filter.channel_id].id
  148. this.channel = category.map((c, i) => {
  149. return {
  150. name: c.name,
  151. id: c.id,
  152. key: i
  153. }
  154. });
  155. console.log("this.channel:", this.channel);
  156. },
  157. initCategory(category) {
  158. category.forEach(cate => {
  159. cate.children.unshift({
  160. id: cate.id,
  161. name: '全部'
  162. })
  163. })
  164. return category
  165. },
  166. filterChange(field, value) {
  167. this.filter[field] = value
  168. if (field === 'channel_id')
  169. this.filter.category_id = this.category[value].id
  170. this.getBooksArray(false)
  171. },
  172. bookSearch(iptValue) {
  173. this.filter.key = iptValue.value
  174. this.getBooksArray(false)
  175. this.$element('search').focus({ focus: false })
  176. },
  177. getBooksArray(isLoad = true) {
  178. this.empty = false
  179. this.loadingText = '加载ing...'
  180. this.filter.page = (this.meta.current_page || 0) + 1
  181. if (!isLoad) {
  182. this.filter.page = 1
  183. this.meta = {}
  184. }
  185. let params = this.filter
  186. pageLoad(this.meta, getBooksList, params)
  187. .then(ret => {
  188. let newList = isLoad ? this.list : []
  189. let dataList = ret.list
  190. newList.push(...dataList)
  191. this.meta = ret.meta
  192. this.list = newList
  193. if (!this.list.length)
  194. (this.loadingText = '没有更多数据'), (this.empty = true)
  195. })
  196. .catch(e => {
  197. })
  198. }, toPage(page) {
  199. router.push({
  200. uri: '/views/' + page,
  201. params: {
  202. sex: this.filter.channel_id
  203. }
  204. })
  205. },
  206. onInit() {
  207. this.getCategory()
  208. }
  209. }
  210. </script>
  211. <style lang="less">
  212. @import '../../assets/less/category.less';
  213. </style>