shop.vue 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201
  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. <u-sticky>
  10. <!--分类筛选-->
  11. <view class="menu">
  12. <u-dropdown>
  13. <u-dropdown-item v-model="options.value1" title="全部分类" :options="options1" @change="change($event, 1)"></u-dropdown-item>
  14. <u-dropdown-item v-model="options.value2" title="综合排序" :options="options2" @change="change($event, 2)"></u-dropdown-item>
  15. <u-dropdown-item v-model="options.value3" title="筛选" :options="options3" @change="change($event, 3)"></u-dropdown-item>
  16. </u-dropdown>
  17. </view>
  18. </u-sticky>
  19. </view>
  20. <!--列表数据-->
  21. <view class="list">
  22. <view class="item" v-for="(item, index) in list" :key="index" @click="detail(item)">
  23. <image :src="ip + item.pic"></image>
  24. <view class="title omit">{{ item.title }}</view>
  25. <view class="price">¥{{ item.price }}</view>
  26. </view>
  27. <view class="clear"></view>
  28. <view class="loading" v-show="showLoadMore"><u-loading></u-loading></view>
  29. <u-empty class="noData" text="没有数据" :show="list.length == 0"></u-empty>
  30. </view>
  31. </view>
  32. </template>
  33. <script>
  34. export default {
  35. data() {
  36. return {
  37. ip: this.$http.urls.ip,
  38. list: [],
  39. param: { pageNum: 1, orderByColumn: 'id', isAsc: 'desc', typeId: '' },
  40. showLoadMore: true,
  41. options: { value1: 1, value2: 2, value3: 3 }, //options选中项的value值
  42. //商品分类
  43. options1: [{ label: '全部分类', value: '' }],
  44. //综合排序
  45. options2: [
  46. {
  47. label: '综合排序',
  48. value: 'id-desc'
  49. },
  50. {
  51. label: '时间降序',
  52. value: 'createTime-desc'
  53. },
  54. {
  55. label: '时间升序',
  56. value: 'createTime-asc'
  57. },
  58. {
  59. label: '价格降序',
  60. value: 'price-desc'
  61. },
  62. {
  63. label: '价格升序',
  64. value: 'price-asc'
  65. }
  66. ],
  67. //筛选
  68. options3: [
  69. {
  70. label: '按销量',
  71. value: 'sells-desc'
  72. }
  73. ]
  74. };
  75. },
  76. onLoad() {
  77. this.getData();
  78. this.getType();
  79. },
  80. methods: {
  81. getType() {
  82. this.$http.request({
  83. url: this.$http.urls.goods_type,
  84. loading: 'false',
  85. success: res => {
  86. res.data.data.forEach(item => {
  87. this.options1.push({ label: item.name, value: item.id });
  88. });
  89. }
  90. });
  91. },
  92. //获取数据
  93. getData() {
  94. this.$http.request({
  95. url: this.$http.urls.goods_list,
  96. data: this.param,
  97. loading: 'false',
  98. success: res => {
  99. this.showLoadMore = res.data.pages > this.param.pageNum ? true : false;
  100. res.data.rows.forEach(item => {
  101. this.list.push(item);
  102. });
  103. }
  104. });
  105. },
  106. //点击下拉菜单, tag当前点击标识(1,商品分类,2,综合排序和筛选)
  107. change(e, tag) {
  108. if (tag === 1) {
  109. this.param.typeId = e;
  110. } else {
  111. this.param.orderByColumn = e.split('-')[0];
  112. this.param.isAsc = e.split('-')[1];
  113. }
  114. this.refresh();
  115. },
  116. //点击键盘搜索按钮触发
  117. search() {
  118. this.param.typeId = '';
  119. this.refresh();
  120. },
  121. //清空搜索内容
  122. clear() {
  123. this.refresh();
  124. },
  125. //详情
  126. detail(item) {
  127. console.log("item.tbGoodsType.name:"+item.tbGoodsType.name);
  128. uni.navigateTo({
  129. url: 'details?id=' + item.id + '&goodsType=' + item.tbGoodsType.name
  130. });
  131. },
  132. //刷新数据
  133. refresh() {
  134. this.param.pageNum = 1;
  135. this.list = [];
  136. this.getData();
  137. }
  138. },
  139. //下拉刷新
  140. onPullDownRefresh() {
  141. setTimeout(() => {
  142. uni.stopPullDownRefresh();
  143. this.refresh();
  144. }, 1000);
  145. },
  146. //上拉加载
  147. onReachBottom() {
  148. if (this.showLoadMore) {
  149. this.param.pageNum++;
  150. this.getData();
  151. }
  152. }
  153. };
  154. </script>
  155. <style lang="scss">
  156. .top {
  157. background-color: white;
  158. .search {
  159. padding: 12px;
  160. }
  161. .menu {
  162. background-color: white;
  163. border-bottom: 1px solid #d8d8d8;
  164. }
  165. }
  166. .list {
  167. padding: 0px 10px 20px 10px;
  168. .item {
  169. background-color: white;
  170. margin-top: 5px;
  171. border-radius: 3px;
  172. width: 49%;
  173. padding: 10px;
  174. float: left;
  175. text-align: center;
  176. margin-right: 5px;
  177. image {
  178. width: 100px;
  179. height: 100px;
  180. border-radius: 7px;
  181. }
  182. &.item:nth-child(even) {
  183. margin-right: 0px;
  184. }
  185. .title {
  186. padding-top: 8px;
  187. font-size: 13px;
  188. text-align: left;
  189. color: #252525;
  190. }
  191. .price {
  192. padding-top: 8px;
  193. font-size: 15px;
  194. text-align: left;
  195. color: $theme-color;
  196. }
  197. }
  198. }
  199. </style>