list.vue 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193
  1. <template>
  2. <app-layout>
  3. <view class="sort-rule">
  4. <app-sort-rule @sort="setSort" theme="default"></app-sort-rule>
  5. </view>
  6. <view class="product-list" v-if="goods_list.length > 0">
  7. <app-product-list @routeGo="routeGo" theme="default" :goods_list="goods_list"></app-product-list>
  8. </view>
  9. <view class="app-no-goods" v-if="goods_list.length === 0 && !first_req">
  10. <app-no-goods background="#f7f7f7"></app-no-goods>
  11. </view>
  12. <view class="quick-box dir-top-nowrap" :style="{bottom: tabbarbool ? '180rpx' : '40rpx'}">
  13. <app-jump-button url="/pages/cart/cart" open_type="redirect" v-if="isShowCartFly == 1">
  14. <image class="quick-btn" src="/static/image/icon/goods-list-card.png"></image>
  15. </app-jump-button>
  16. <app-jump-button v-if="isShowScoreTop == 1">
  17. <image @click="backTop" class="quick-btn" src="/static/image/icon/back-top.png"></image>
  18. </app-jump-button>
  19. </view>
  20. </app-layout>
  21. </template>
  22. <script>
  23. import {mapGetters, mapState} from 'vuex';
  24. import appProductList from '../../components/page-component/app-product-list/app-product-list.vue';
  25. import appSortRule from '../../components/page-component/app-sort-rule/app-sort-rule.vue';
  26. import appNoGoods from '../../components/page-component/app-no-goods/app-no-goods.vue';
  27. export default {
  28. name: "list",
  29. data() {
  30. return {
  31. // 商品数据
  32. goods_list: [],
  33. // 总页数
  34. page_count: 1,
  35. coupon_id: 0,
  36. page: 1,
  37. cat_id: 0,
  38. sort: 1,
  39. sort_type: 1,
  40. first_req: true
  41. }
  42. },
  43. onLoad(options) {
  44. this.cat_id = options.cat_id;
  45. if(options.coupon_id > 0) {
  46. this.coupon_id = options.coupon_id
  47. }
  48. this.request().then(() => {
  49. this.first_req = false;
  50. });
  51. },
  52. computed: {
  53. ...mapGetters('mallConfig', {
  54. getVideo: 'getVideo'
  55. }),
  56. ...mapState({
  57. isShowCartFly: state => state.mallConfig.mall.setting.is_show_cart_fly,
  58. isShowScoreTop: state => state.mallConfig.mall.setting.is_show_score_top,
  59. }),
  60. },
  61. onReachBottom() {
  62. if (this.page < this.page_count) {
  63. this.page++;
  64. this.request();
  65. } else {
  66. uni.showToast({
  67. title: '暂无更多商品',
  68. icon: 'none'
  69. })
  70. }
  71. },
  72. methods: {
  73. routeGo(e) {
  74. if (e.video_url && this.getVideo == 1) {
  75. uni.navigateTo({
  76. url: `/pages/goods/video?goods_id=${e.id}`
  77. });
  78. } else {
  79. uni.navigateTo({
  80. url: e.page_url
  81. });
  82. }
  83. },
  84. // 数据请求
  85. async request(status) {
  86. const res = await this.$request({
  87. url: this.$api.default.goods_list,
  88. method: 'get',
  89. data: {
  90. page: this.page,
  91. cat_id: this.cat_id,
  92. sort: this.sort,
  93. sort_type: this.sort_type,
  94. keyword: '',
  95. coupon_id: this.coupon_id,
  96. sign: '',
  97. }
  98. });
  99. if (res.code === 0) {
  100. if (status === 0) this.goods_list=[];
  101. this.dataProcessing(res.data.list);
  102. this.page_count = res.data.pagination.page_count;
  103. } else {
  104. uni.showModal({
  105. title: '提示',
  106. content: res.msg,
  107. })
  108. }
  109. },
  110. // 处理数据
  111. dataProcessing(list) {
  112. for (let i = 0; i < list.length; i+=2) {
  113. if (i+1 !== list.length) {
  114. this.goods_list.push([list[i], list[i+1]]);
  115. } else {
  116. this.goods_list.push([list[i]]);
  117. }
  118. }
  119. },
  120. setSort(data, sort_type) {
  121. this.first_req = true;
  122. this.sort = data;
  123. this.page = 1;
  124. this.sort_type = sort_type;
  125. this.goods_list=[];
  126. this.request(0).then(() => {
  127. this.first_req = false;
  128. this.backTop();
  129. });
  130. },
  131. backTop() {
  132. uni.pageScrollTo({
  133. scrollTop: 0,
  134. duration: 300
  135. });
  136. },
  137. },
  138. components: {
  139. 'app-product-list': appProductList,
  140. 'app-sort-rule': appSortRule,
  141. 'app-no-goods': appNoGoods,
  142. },
  143. onShareAppMessage() {
  144. return this.$shareAppMessage({
  145. path: '/pages/goods/list',
  146. params: {
  147. cat_id: this.cat_id,
  148. }
  149. });
  150. },
  151. }
  152. </script>
  153. <style scoped lang="scss">
  154. .sort-rule {
  155. width: #{750upx};
  156. position: fixed;
  157. top: 0;
  158. left: 0;
  159. z-index: 1500;
  160. }
  161. .product-list {
  162. margin-top: #{96upx};
  163. }
  164. .quick-box {
  165. position: fixed;
  166. bottom: #{40rpx};
  167. right: #{48rpx};
  168. }
  169. .quick-btn {
  170. width: #{80rpx};
  171. height: #{80rpx};
  172. margin-top: #{32rpx};
  173. }
  174. .app-no-goods {
  175. margin-top: #{110upx};
  176. }
  177. </style>