index.vue 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176
  1. <template>
  2. <view>
  3. <view class="top">
  4. <!--商品搜索-->
  5. <view class="search">
  6. <u-search v-model="param.title" :animation="true" action-text="取消" placeholder="输入搜索内容" shape="square" @search="search" @clear="clear"></u-search>
  7. </view>
  8. <!--分类筛选-->
  9. <view class="menu">
  10. <u-dropdown>
  11. <u-dropdown-item v-model="options.value1" title="分类" :options="options1" @change="change($event, 1)"></u-dropdown-item>
  12. <u-dropdown-item v-model="options.value2" title="排序" :options="options2" @change="change($event, 2)"></u-dropdown-item>
  13. <u-dropdown-item v-model="options.value3" title="筛选" :options="options3" @change="change($event, 3)"></u-dropdown-item>
  14. </u-dropdown>
  15. </view>
  16. </view>
  17. <!--列表数据-->
  18. <view class="list">
  19. <view class="goods_item" v-for="(item, index) in list" :key="index" @click="detail(item)">
  20. <image :src="ip + item.pic" mode="aspectFill"></image>
  21. <view class="title omit">
  22. <text>{{ item.title }}</text>
  23. </view>
  24. <view class="price">
  25. <text>¥{{ item.price }}</text>
  26. <text class="day">/天</text>
  27. <text class="icon" v-show="item.mType == 0">&#xe61e;</text>
  28. <text class="icon" v-show="item.mType == 1">&#xe61c;</text>
  29. </view>
  30. </view>
  31. <view class="clear"></view>
  32. <view class="loading"><u-loadmore :status="loadMore ? 'loading' : 'nomore'" /></view>
  33. </view>
  34. </view>
  35. </template>
  36. <script>
  37. export default {
  38. data() {
  39. return {
  40. ip: this.$http.urls.ip,
  41. list: [],
  42. param: { pageNum: 1, orderByColumn: 'id', isAsc: 'desc', mType: '' },
  43. loadMore: true,
  44. options: { value1: '', value2: 'id-desc', value3: '' }, //options选中项的value值
  45. //商品分类
  46. options1: [{ label: '全部分类', value: '' }],
  47. //综合排序
  48. options2: [
  49. {
  50. label: '综合排序',
  51. value: 'id-desc'
  52. },
  53. {
  54. label: '时间降序',
  55. value: 'createTime-desc'
  56. },
  57. {
  58. label: '时间升序',
  59. value: 'createTime-asc'
  60. },
  61. {
  62. label: '价格降序',
  63. value: 'price-desc'
  64. },
  65. {
  66. label: '价格升序',
  67. value: 'price-asc'
  68. }
  69. ],
  70. //筛选
  71. options3: [
  72. {
  73. label: '智能推荐',
  74. value: 'id-desc'
  75. }
  76. ]
  77. };
  78. },
  79. onLoad() {
  80. this.getData();
  81. this.getType();
  82. },
  83. methods: {
  84. getType() {
  85. this.$http.request({
  86. url: this.$http.urls.dictType + 'm_type',
  87. loading: 'false',
  88. success: res => {
  89. console.log('zx:' + JSON.stringify(res));
  90. res.data.data.forEach(item => {
  91. this.options1.push({ label: item.dictLabel, value: item.dictValue });
  92. });
  93. }
  94. });
  95. },
  96. //获取数据
  97. getData() {
  98. this.$http.request({
  99. url: this.$http.urls.goods_list,
  100. data: this.param,
  101. loading: 'false',
  102. success: res => {
  103. this.loadMore = res.data.pages > this.param.pageNum ? true : false;
  104. res.data.rows.forEach(item => {
  105. this.list.push(item);
  106. });
  107. }
  108. });
  109. },
  110. //点击下拉菜单, tag当前点击标识(1,商品分类,2,综合排序和筛选)
  111. change(e, tag) {
  112. if (tag === 1) {
  113. this.param.mType = e;
  114. } else {
  115. this.param.orderByColumn = e.split('-')[0];
  116. this.param.isAsc = e.split('-')[1];
  117. }
  118. this.refresh();
  119. },
  120. //点击键盘搜索按钮触发
  121. search() {
  122. this.param.mType = '';
  123. this.refresh();
  124. },
  125. //清空搜索内容
  126. clear() {
  127. this.refresh();
  128. },
  129. //详情
  130. detail(item) {
  131. uni.navigateTo({ url: '/pages/goods/detail?id=' + item.id });
  132. },
  133. //刷新数据
  134. refresh() {
  135. this.loadMore = true;
  136. this.param.pageNum = 1;
  137. this.list = [];
  138. this.getData();
  139. }
  140. },
  141. //下拉刷新
  142. onPullDownRefresh() {
  143. setTimeout(() => {
  144. uni.stopPullDownRefresh();
  145. this.refresh();
  146. }, 1000);
  147. },
  148. //上拉加载
  149. onReachBottom() {
  150. if (this.loadMore) {
  151. this.param.pageNum++;
  152. this.getData();
  153. }
  154. }
  155. };
  156. </script>
  157. <style lang="scss">
  158. page {
  159. background-color: $page;
  160. }
  161. .top {
  162. background-color: white;
  163. .search {
  164. padding: 12px;
  165. }
  166. .menu {
  167. background-color: white;
  168. border-bottom: 1px solid #d8d8d8;
  169. }
  170. }
  171. .list {
  172. padding: 0px 10px 20px 10px;
  173. }
  174. </style>