richarticle.vue 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198
  1. <template>
  2. <view>
  3. <!-- 顶部导航 -->
  4. <fa-navbar :title="vuex_table_title || '资讯'"></fa-navbar>
  5. <view class="u-p-20 u-bg-white u-flex u-col-center" v-if="is_show">
  6. <view class="u-flex-1"><fa-search :mode="2"></fa-search></view>
  7. <view class="u-p-l-15 u-p-r-5 u-flex u-col-center" v-if="is_order">
  8. <fa-orderby-select :filterList="filterList" :orderList="orderList" :multiple="true" @change="goOrderBy"></fa-orderby-select>
  9. </view>
  10. </view>
  11. <!-- 分类 -->
  12. <view class="u-border-top" v-if="isTab">
  13. <!-- #ifdef MP-BAIDU -->
  14. <fa-u-tabs
  15. :list="tabList"
  16. :active-color="theme.bgColor"
  17. :bar-width="tabwidth"
  18. name="title"
  19. :is-scroll="true"
  20. :current="current"
  21. @change="change"
  22. ></fa-u-tabs>
  23. <!-- #endif -->
  24. <!-- #ifndef MP-BAIDU -->
  25. <u-tabs :list="tabList" :active-color="theme.bgColor" :bar-width="tabwidth" name="title" :is-scroll="true" :current="current" @change="change"></u-tabs>
  26. <!-- #endif -->
  27. </view>
  28. <!-- 列表 -->
  29. <fa-article-item :archives-list="archivesList"></fa-article-item>
  30. <!-- 加载更多 -->
  31. <view class="u-p-30" v-if="archivesList.length"><u-loadmore bg-color="#f4f6f8" :status="status" /></view>
  32. <!-- 为空 -->
  33. <view class="u-m-t-60 u-p-t-60" v-if="is_empty"><u-empty text="暂无内容展示" mode="list"></u-empty></view>
  34. <!-- 回到顶部 -->
  35. <u-back-top :scroll-top="scrollTop" :icon-style="{ color: theme.bgColor }" :custom-style="{ backgroundColor: lightColor }"></u-back-top>
  36. <!-- 底部导航 -->
  37. <fa-tabbar></fa-tabbar>
  38. </view>
  39. </template>
  40. <script>
  41. export default {
  42. computed: {
  43. is_order() {
  44. return this.filterList.length > 0 || this.orderList.length > 0;
  45. }
  46. },
  47. data() {
  48. return {
  49. tabwidth: 40,
  50. current: 0,
  51. status: 'nomore',
  52. page: 1,
  53. channel_id: 0,
  54. filterList: [],
  55. orderList: [],
  56. archivesList: [],
  57. is_show: false,
  58. has_more: false,
  59. scrollTop: 0,
  60. is_update: false,
  61. params: {},
  62. query: {},
  63. isTab: false,
  64. tabList: [],
  65. is_empty: false,
  66. channel:{}
  67. };
  68. },
  69. onLoad(e) {
  70. //模型id
  71. let query = this.$Route.query;
  72. if (JSON.stringify(query) == '{}') {
  73. query = e;
  74. }
  75. if (query && JSON.stringify(query) != '{}') {
  76. this.params = query;
  77. } else {
  78. this.params = {
  79. channel: -1,
  80. model: -1,
  81. menu_index: 1
  82. };
  83. }
  84. this.getCategory();
  85. this.getArchives();
  86. },
  87. onShow() {
  88. // #ifdef MP-BAIDU
  89. if(this.channel){
  90. this.setPagesInfo();
  91. }
  92. // #endif
  93. },
  94. methods: {
  95. change(index) {
  96. //重设Bar宽度s
  97. this.tabwidth = this.$util.strlen(this.tabList[index].title) * 30;
  98. this.current = index;
  99. this.channel_id = this.tabList[index].id;
  100. this.is_update = true;
  101. this.page = 1;
  102. this.getArchives();
  103. },
  104. goOrderBy(e) {
  105. this.page = 1;
  106. this.is_update = true;
  107. this.query = e;
  108. this.getArchives();
  109. },
  110. getArchives: async function() {
  111. let data = {
  112. page: this.page,
  113. ...this.params,
  114. ...this.query
  115. };
  116. if (this.channel_id) {
  117. data.channel = this.channel_id;
  118. }
  119. console.log(data)
  120. let res = await this.$api.getArchives(data);
  121. this.status = 'nomore';
  122. uni.stopPullDownRefresh();
  123. if (!res.code) {
  124. this.$u.toast(res.msg);
  125. return;
  126. }
  127. let { filterList, orderList, pageList, channel } = res.data;
  128. this.filterList = filterList;
  129. this.orderList = orderList;
  130. this.channel = channel;
  131. // #ifdef MP-BAIDU
  132. if(this.channel){
  133. this.setPagesInfo();
  134. }
  135. // #endif
  136. if (this.is_update) {
  137. this.archivesList = [];
  138. this.is_update = false;
  139. }
  140. this.is_show = true;
  141. this.has_more = pageList.current_page < pageList.last_page;
  142. this.archivesList = [...this.archivesList, ...pageList.data];
  143. this.is_empty = !this.archivesList.length;
  144. },
  145. // #ifdef MP-BAIDU
  146. setPagesInfo() {
  147. swan.setPageInfo({
  148. title:this.channel.seotitle,
  149. keywords: this.channel.keywords,
  150. description:this.channel.description,
  151. releaseDate: this.$u.timeFormat(this.channel.createtime, 'yyyy-mm-dd hh:MM:ss'),
  152. image: this.channel.image,
  153. success: res => {
  154. console.log('setPageInfo success', res);
  155. },
  156. fail: err => {
  157. console.log('setPageInfo fail', err);
  158. }
  159. });
  160. },
  161. // #endif
  162. getCategory() {
  163. this.$api.getCategory({ ...this.params }).then(res => {
  164. if (res.code == 1) {
  165. this.tabList = res.data;
  166. this.isTab = true; //百度小程序要先有值
  167. } else {
  168. this.$u.toast(res.msg);
  169. }
  170. });
  171. }
  172. },
  173. onPageScroll(e) {
  174. this.scrollTop = e.scrollTop;
  175. },
  176. //下拉刷新
  177. onPullDownRefresh() {
  178. this.is_update = true;
  179. this.page = 1;
  180. this.getArchives();
  181. },
  182. onReachBottom() {
  183. if (this.has_more) {
  184. this.status = 'loading';
  185. this.page = ++this.page;
  186. this.getArchives();
  187. }
  188. }
  189. };
  190. </script>
  191. <style lang="scss">
  192. page {
  193. background-color: #f4f6f8;
  194. }
  195. </style>