list.vue 7.6 KB

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