product.vue 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237
  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. :bar-width="tabwidth"
  17. :active-color="theme.bgColor"
  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" :bar-width="tabwidth" :active-color="theme.bgColor" name="title" :is-scroll="true" :current="current" @change="change"></u-tabs>
  26. <!-- #endif -->
  27. </view>
  28. <view class="u-flex u-flex-wrap u-p-30">
  29. <view class="product-item" v-for="(item, index) in archivesList" :key="index" @click="goDetail(item.id)">
  30. <u-image width="100%" border-radius="8" height="210" :src="item.image"></u-image>
  31. <view class="title">{{ item.title }}</view>
  32. </view>
  33. </view>
  34. <!-- 为空 -->
  35. <view class="u-m-t-60 u-p-t-60" v-if="is_empty"><u-empty text="暂无内容展示" mode="list"></u-empty></view>
  36. <!-- 加载更多 -->
  37. <view class="u-p-b-30" v-if="archivesList.length"><u-loadmore bg-color="#f4f6f8" :status="status" /></view>
  38. <!-- 回到顶部 -->
  39. <u-back-top :scroll-top="scrollTop" :icon-style="{ color: theme.bgColor }" :custom-style="{ backgroundColor: lightColor }"></u-back-top>
  40. <!-- 底部导航 -->
  41. <fa-tabbar></fa-tabbar>
  42. </view>
  43. </template>
  44. <script>
  45. export default {
  46. computed: {
  47. is_order() {
  48. return this.filterList.length > 0 || this.orderList.length > 0;
  49. }
  50. },
  51. data() {
  52. return {
  53. tabwidth: 40,
  54. current: 0,
  55. status: 'nomore',
  56. page: 1,
  57. channel_id: 0,
  58. filterList: [],
  59. orderList: [],
  60. archivesList: [],
  61. has_more: false,
  62. scrollTop: 0,
  63. is_update: false,
  64. is_show: false,
  65. params: {},
  66. query: {},
  67. isTab: false,
  68. tabList: [],
  69. is_empty: false,
  70. channel: {}
  71. };
  72. },
  73. onLoad(e) {
  74. let query = this.$Route.query;
  75. if (JSON.stringify(query) == '{}') {
  76. query = e;
  77. }
  78. if (query && JSON.stringify(query) != '{}') {
  79. this.params = query;
  80. } else {
  81. this.params = {
  82. channel: -1,
  83. model: -1,
  84. menu_index: 2
  85. };
  86. }
  87. this.getCategory();
  88. this.getArchives();
  89. },
  90. onShow() {
  91. // #ifdef MP-BAIDU
  92. if(this.channel){
  93. this.setPagesInfo();
  94. }
  95. // #endif
  96. },
  97. methods: {
  98. change(index) {
  99. //重设Bar宽度
  100. this.tabwidth = this.$util.strlen(this.tabList[index].title) * 30;
  101. this.current = index;
  102. this.channel_id = this.tabList[index].id;
  103. this.is_update = true;
  104. this.page = 1;
  105. this.getArchives();
  106. },
  107. goOrderBy(e) {
  108. this.page = 1;
  109. this.is_update = true;
  110. this.query = e;
  111. this.getArchives();
  112. },
  113. getArchives: async function() {
  114. let data = {
  115. page: this.page,
  116. ...this.params,
  117. ...this.query
  118. };
  119. if (this.channel_id) {
  120. data.channel = this.channel_id;
  121. }
  122. let res = await this.$api.getArchives(data);
  123. this.status = 'nomore';
  124. uni.stopPullDownRefresh();
  125. if (!res.code) {
  126. this.$u.toast(res.msg);
  127. return;
  128. }
  129. let { filterList, orderList, pageList, channel } = res.data;
  130. this.filterList = filterList;
  131. this.orderList = orderList;
  132. this.channel = channel;
  133. // #ifdef MP-BAIDU
  134. if(this.channel){
  135. this.setPagesInfo();
  136. }
  137. // #endif
  138. if (this.is_update) {
  139. this.archivesList = [];
  140. this.is_update = false;
  141. }
  142. this.is_show = true;
  143. this.has_more = pageList.current_page < pageList.last_page;
  144. this.archivesList = [...this.archivesList, ...pageList.data];
  145. this.is_empty = !this.archivesList.length;
  146. },
  147. // #ifdef MP-BAIDU
  148. setPagesInfo() {
  149. swan.setPageInfo({
  150. title:this.channel.seotitle,
  151. keywords: this.channel.keywords,
  152. description:this.channel.description,
  153. releaseDate: this.$u.timeFormat(this.channel.createtime, 'yyyy-mm-dd hh:MM:ss'),
  154. image: this.channel.image,
  155. success: res => {
  156. console.log('setPageInfo success', res);
  157. },
  158. fail: err => {
  159. console.log('setPageInfo fail', err);
  160. }
  161. });
  162. },
  163. // #endif
  164. goDetail(id) {
  165. this.$Router.push({
  166. path: '/pages/product/detail',
  167. query: { id: id }
  168. });
  169. },
  170. getCategory() {
  171. this.$api.getCategory({ ...this.params }).then(res => {
  172. if (res.code == 1) {
  173. this.tabList = res.data;
  174. this.isTab = true; //百度小程序要先有值
  175. } else {
  176. this.$u.toast(res.msg);
  177. }
  178. });
  179. }
  180. },
  181. onPageScroll(e) {
  182. this.scrollTop = e.scrollTop;
  183. },
  184. //下拉刷新
  185. onPullDownRefresh() {
  186. this.is_update = true;
  187. this.page = 1;
  188. this.getArchives();
  189. },
  190. onReachBottom() {
  191. if (this.has_more) {
  192. this.status = 'loading';
  193. this.page = ++this.page;
  194. this.getArchives();
  195. }
  196. }
  197. };
  198. </script>
  199. <style lang="scss">
  200. page {
  201. background-color: #f4f6f8;
  202. }
  203. .product-item {
  204. width: 50%;
  205. position: relative;
  206. .title {
  207. position: absolute;
  208. font-size: 22rpx;
  209. bottom: 20rpx;
  210. background: #000;
  211. width: auto;
  212. max-width: 100%;
  213. color: #f8f8f8;
  214. opacity: 0.7;
  215. height: 50rpx;
  216. line-height: 50rpx;
  217. overflow: hidden;
  218. text-align: center;
  219. border-top-right-radius: 6rpx;
  220. border-bottom-right-radius: 6rpx;
  221. }
  222. }
  223. .product-item:nth-child(2n + 1) {
  224. padding-right: 15rpx;
  225. }
  226. .product-item:nth-child(2n) {
  227. padding-left: 15rpx;
  228. }
  229. .product-item:not(:last-child) {
  230. margin-bottom: 30rpx;
  231. }
  232. </style>