list.vue 7.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253
  1. <template>
  2. <app-layout>
  3. <view class="sort-rule">
  4. <app-sort-rule @sort="setSort" :theme="getTheme" @setStyle="setStyle"></app-sort-rule>
  5. </view>
  6. <view class="product-list" v-if="goods_list.length > 0">
  7. <app-product-list :isShowAttr="false" :theme="getTheme" @routeGo="routeGo" :listStyle="listStyle" :goods_list="goods_list"></app-product-list>
  8. </view>
  9. <view class="u-loading-list" v-show="loading">加载中...</view>
  10. <view class="no-goods dir-left-nowrap cross-center main-center" v-if="noGoods">
  11. <view class="symbol"></view>
  12. <view class="u-no-icon"></view>
  13. <text class="u-text">暂无更多商品</text>
  14. <view class="symbol"></view>
  15. </view>
  16. <view class="app-no-goods" v-if="goods_list.length === 0 && !first_req">
  17. <app-no-goods background="#f7f7f7"></app-no-goods>
  18. </view>
  19. <view class="quick-box dir-top-nowrap" :style="{bottom: tabbarbool ? '180rpx' : '40rpx'}">
  20. <app-jump-button url="/pages/cart/cart" open_type="redirect" v-if="isShowCartFly == 1">
  21. <image class="quick-btn" src="./image/goods-list-card.png"></image>
  22. </app-jump-button>
  23. <app-jump-button v-if="isShowScoreTop == 1">
  24. <image @click="backTop" class="quick-btn" src="./image/back-top.png"></image>
  25. </app-jump-button>
  26. </view>
  27. </app-layout>
  28. </template>
  29. <script>
  30. import {mapGetters, mapState} from 'vuex';
  31. import appProductList from '../../components/page-component/app-product-list/app-product-list.vue';
  32. import appSortRule from '../../components/page-component/app-sort-rule/app-sort-rule.vue';
  33. import appNoGoods from '../../components/page-component/app-no-goods/app-no-goods.vue';
  34. export default {
  35. name: "list",
  36. data() {
  37. return {
  38. goods_list: [],
  39. page_count: 1,
  40. coupon_id: 0,
  41. page: 1,
  42. cat_id: 0,
  43. sort: 1,
  44. sort_type: 1,
  45. first_req: true,
  46. listStyle: false,
  47. noGoods: false,
  48. loading: false,
  49. sign: '',
  50. }
  51. },
  52. onLoad(options) { this.$commonLoad.onload(options);
  53. if(options.cat_id > 0) {
  54. this.cat_id = options.cat_id;
  55. }
  56. if(options.coupon_id > 0) {
  57. this.coupon_id = options.coupon_id
  58. }
  59. this.sign = options.sign ? options.sign : '';
  60. this.request().then(() => {
  61. this.first_req = false;
  62. if (this.page < this.page_count) {
  63. this.loading = true;
  64. }
  65. });
  66. },
  67. computed: {
  68. ...mapGetters('mallConfig', {
  69. getVideo: 'getVideo',
  70. getTheme: 'getTheme',
  71. }),
  72. ...mapState({
  73. isShowCartFly: state => state.mallConfig.mall.setting.is_show_cart_fly,
  74. isShowScoreTop: state => state.mallConfig.mall.setting.is_show_score_top,
  75. platform: function(state) {
  76. return state.gConfig.systemInfo.platform;
  77. }
  78. })
  79. },
  80. onReachBottom() {
  81. if (this.page < this.page_count) {
  82. this.page++;
  83. this.noGoods = false;
  84. this.request();
  85. } else {
  86. this.loading = false;
  87. this.noGoods = true;
  88. }
  89. },
  90. methods: {
  91. routeGo(e) {
  92. if (e.video_url && this.getVideo == 1) {
  93. // #ifdef MP
  94. uni.navigateTo({
  95. url: `/pages/goods/video?goods_id=${e.id}`
  96. });
  97. // #endif
  98. // #ifdef H5
  99. uni.navigateTo({
  100. url: e.page_url
  101. });
  102. // #endif
  103. } else {
  104. uni.navigateTo({
  105. url: e.page_url
  106. });
  107. }
  108. },
  109. // 数据请求
  110. async request(status) {
  111. const res = await this.$request({
  112. url: this.$api.default.goods_list,
  113. method: 'get',
  114. data: {
  115. page: this.page,
  116. cat_id: this.cat_id,
  117. sort: this.sort,
  118. sort_type: this.sort_type,
  119. keyword: '',
  120. coupon_id: this.coupon_id,
  121. sign: this.sign,
  122. }
  123. });
  124. if (res.code === 0) {
  125. this.page_count = res.data.pagination.page_count;
  126. if (status === 0) {
  127. this.goods_list= res.data.list;
  128. } else {
  129. this.goods_list.push(...res.data.list);
  130. }
  131. if (this.page === 1 && this.page_count === 1) {
  132. this.noGoods = true;
  133. }
  134. } else {
  135. uni.showModal({
  136. title: '提示',
  137. content: res.msg,
  138. })
  139. }
  140. },
  141. setSort({data, type}) {
  142. this.first_req = true;
  143. this.sort = data;
  144. this.page = 1;
  145. this.sort_type = type;
  146. this.goods_list=[];
  147. this.request(0).then(() => {
  148. this.first_req = false;
  149. this.backTop();
  150. if (this.page_count > 1) {
  151. this.loading = true;
  152. } else {
  153. this.loading = false;
  154. }
  155. });
  156. },
  157. backTop() {
  158. uni.pageScrollTo({
  159. scrollTop: 0,
  160. duration: 300
  161. });
  162. },
  163. setStyle(data) {
  164. this.listStyle = data;
  165. },
  166. splitData() {
  167. if (!this.compList.length) return;
  168. this.goods_list.push.apply(this.goods_list, this.compList.splice(0, 10));
  169. if (this.compList.length) {
  170. this.compTime = setTimeout(() => {
  171. this.splitData();
  172. }, 200);
  173. }
  174. }
  175. },
  176. components: {
  177. 'app-product-list': appProductList,
  178. 'app-sort-rule': appSortRule,
  179. 'app-no-goods': appNoGoods,
  180. },
  181. // #ifdef MP
  182. onShareAppMessage() {
  183. return this.$shareAppMessage({
  184. path: '/pages/goods/list',
  185. params: {
  186. cat_id: this.cat_id,
  187. }
  188. });
  189. }
  190. // #endif
  191. }
  192. </script>
  193. <style scoped lang="scss">
  194. .sort-rule {
  195. width: #{750upx};
  196. position: fixed;
  197. top: 0;
  198. left: 0;
  199. z-index: 1500;
  200. }
  201. .product-list {
  202. margin-top: #{188upx};
  203. }
  204. .quick-box {
  205. position: fixed;
  206. bottom: #{40rpx};
  207. right: #{48rpx};
  208. z-index: 100;
  209. }
  210. .quick-btn {
  211. width: #{80rpx};
  212. height: #{80rpx};
  213. margin-top: #{32rpx};
  214. }
  215. .app-no-goods {
  216. margin-top: 200upx;
  217. }
  218. .no-goods {
  219. width: 750upx;
  220. margin: 20upx 0;
  221. }
  222. .u-no-icon {
  223. width: 18upx;
  224. height: 20upx;
  225. background-image: url("./image/no.png");
  226. background-repeat: no-repeat;
  227. background-size: 100% 100%;
  228. margin: 0 10upx 0 15upx;
  229. }
  230. .symbol {
  231. width: 30upx;
  232. height: 2upx;
  233. background-color: #d2d2d2;
  234. }
  235. .u-text {
  236. font-size: 24upx;
  237. color: #b0b0b0;
  238. margin-right: 15upx;
  239. }
  240. .u-loading-list {
  241. height: 64upx;
  242. line-height: 64upx;
  243. text-align: center;
  244. color: #b0b0b0;
  245. font-size: 24upx;
  246. }
  247. </style>