list.vue 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191
  1. <template>
  2. <app-layout>
  3. <scroll-view class="auto-tab" scroll-x
  4. :scroll-into-view="'type' + (tabCurrentIndex >= 2 ? tabCurrentIndex - 2 : 0)">
  5. <view class="auto-item" v-for="(item, index) in typeList" :key="index">
  6. <view class="auto-tab-item cross-center" :id="'type' + index"
  7. :key="index"
  8. :class="tabCurrentIndex == index ? getTheme + '-m-text ' + getTheme + ' current-type' : ''"
  9. @click="tabClick(index)">{{item.name}}
  10. </view>
  11. </view>
  12. </scroll-view>
  13. <view class="empty"></view>
  14. <view>
  15. <app-special-topic-list :cat-show="false" :topic-list="list"></app-special-topic-list>
  16. </view>
  17. </app-layout>
  18. </template>
  19. <script>
  20. import {mapGetters, mapState} from "vuex";
  21. import appSpecialTopicList from "../../components/page-component/app-special-topic/app-special-topic-list.vue";
  22. let page = 1;
  23. let search = {};
  24. let is_no_more = false;
  25. let is_loading = false;
  26. export default {
  27. name: "list",
  28. components: {
  29. appSpecialTopicList,
  30. },
  31. data() {
  32. return {
  33. list: [],
  34. typeList: [],
  35. tabCurrentIndex: 0,
  36. };
  37. },
  38. computed: {
  39. ...mapState({
  40. bar_title: state => state.mallConfig.bar_title,
  41. }),
  42. ...mapGetters('mallConfig', {
  43. getTheme: 'getTheme',
  44. }),
  45. },
  46. onLoad(options) {
  47. page = 1;
  48. is_no_more = false;
  49. is_loading = false;
  50. if (typeof options.type != 'undefined') {
  51. search.type = options.type;
  52. }
  53. this.loadData();
  54. this.loadType();
  55. },
  56. onReachBottom() {
  57. if (is_no_more) {
  58. return;
  59. }
  60. this.loadData();
  61. },
  62. onShareAppMessage(object) {
  63. let route = this.$platDiff.route();
  64. let title = '专题列表';
  65. for (let i in this.bar_title) {
  66. if (this.bar_title[i].value == route) {
  67. title = this.bar_title[i].new_name;
  68. break;
  69. }
  70. }
  71. return this.$shareAppMessage({
  72. title: title,
  73. path: '/pages/topic/list',
  74. });
  75. },
  76. methods: {
  77. loadData() {
  78. if (is_loading) {
  79. return;
  80. }
  81. this.$showLoading();
  82. is_loading = true;
  83. search.page = page;
  84. this.$request({
  85. url: this.$api.topic.list,
  86. data: search
  87. }).then(response => {
  88. is_loading = false;
  89. this.$hideLoading();
  90. if (response.code === 0) {
  91. if (page === 1) {
  92. this.list = [];
  93. }
  94. if (response.data.list.length > 0) {
  95. this.list = this.list.concat(response.data.list);
  96. page++;
  97. } else {
  98. is_no_more = true;
  99. }
  100. } else {
  101. }
  102. }).catch(e => {
  103. this.$hideLoading();
  104. is_loading = false;
  105. });
  106. },
  107. loadType() {
  108. this.$request({
  109. url: this.$api.topic.type,
  110. }).then(response => {
  111. if (response.code === 0) {
  112. if (response.data.list.length > 0) {
  113. let list = [
  114. {
  115. id: 0,
  116. name: '全部'
  117. },
  118. {
  119. id: -1,
  120. name: '精选'
  121. }
  122. ];
  123. this.typeList = list.concat(response.data.list);
  124. for (let i in this.typeList) {
  125. if (this.typeList[i].id == search.type) {
  126. this.tabCurrentIndex = i;
  127. break;
  128. }
  129. }
  130. }
  131. } else {
  132. }
  133. }).catch(e => {
  134. is_loading = false;
  135. });
  136. },
  137. tabClick(index) {
  138. page = 1;
  139. is_no_more = false;
  140. let type = this.typeList[index].id;
  141. this.tabCurrentIndex = index;
  142. search = {
  143. page: page,
  144. type: type
  145. };
  146. this.loadData();
  147. }
  148. }
  149. }
  150. </script>
  151. <style scoped lang="scss">
  152. .auto-tab {
  153. position: fixed;
  154. top: 0;
  155. left: 0;
  156. background-color: #ffffff;
  157. z-index: 1500;
  158. height: #{88rpx};
  159. width: 100%;
  160. white-space: nowrap;
  161. padding: 0 #{32rpx};
  162. border-bottom: #{1rpx} solid #e2e2e2;
  163. box-shadow: 0 1px 5px rgba(0, 0, 0, 0.06);
  164. }
  165. .auto-item {
  166. display: inline-block;
  167. height: #{calc(100% - 4rpx)};
  168. }
  169. .auto-tab-item {
  170. margin-right: #{60rpx};
  171. background-color: #ffffff;
  172. height: 100%;
  173. }
  174. .auto-tab-item.current-type {
  175. border-bottom: #{4rpx} solid;
  176. }
  177. .empty {
  178. height: #{88+16rpx};
  179. width: 100%;
  180. background-color: #f7f7f7;
  181. }
  182. </style>