list.vue 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151
  1. <template>
  2. <view>
  3. <view class="search">
  4. <u-search placeholder="搜索商品名称" v-model="param.goodsName" bgColor="white" @search="refresh()" :animation="true" actionText="取消" @clear="refresh()"></u-search>
  5. <view class="clear"></view>
  6. </view>
  7. <view class="goodsList">
  8. <view class="sort-list">
  9. <view class="sort-item" :class="{ active: item.check }" v-for="(item, index) in sort" :key="index" @click="select(item, index)">
  10. <text>{{ item.name }}</text>
  11. <text v-if="index > 0 && item.isAsc == 'desc'" class="icon">&#xeb0a;</text>
  12. <text v-if="index > 0 && item.isAsc == 'asc'" class="icon">&#xeb0b;</text>
  13. </view>
  14. <view class="type omit" @click="go()">
  15. <text>{{ param.goodsType || '分类' }}</text>
  16. <text class="icon">&#xe8f2;</text>
  17. </view>
  18. </view>
  19. <view class="item animated fadeInDown" v-for="(item, index) in list" :key="index" @click="detail(item.id)">
  20. <view class="title">{{ item.merchantName }}</view>
  21. <view class="goodsType omit">{{ item.goodsType }}</view>
  22. <image src="../../../static/news.jpg" mode="aspectFill" class="pic"></image>
  23. <view class="con">
  24. <view class="productName omit">{{ item.goodsName }}</view>
  25. <view class="desc omit">
  26. <text>{{ item.grossWeight }} {{ item.goodsUnits }}</text>
  27. <text>{{ item.tradeAreaName }}</text>
  28. </view>
  29. <view class="price">¥ {{ item.price }}</view>
  30. <view class="icon buy" @click.stop="addCar(item)" v-if="user.userType == 2">&#xe604;</view>
  31. </view>
  32. <view class="clear"></view>
  33. </view>
  34. <view class="loading" v-if="loadMore"><u-loadmore :status="loadMore ? 'loading' : 'nomore'" /></view>
  35. <u-empty v-if="!loadMore && list.length == 0"></u-empty>
  36. </view>
  37. </view>
  38. </template>
  39. <script>
  40. export default {
  41. data() {
  42. return {
  43. show: false,
  44. user: this.getUser(),
  45. isAsc: 'desc',
  46. sort: [
  47. { name: '综合', sortName: 'id', isAsc: 'desc', check: false },
  48. { name: '日期', sortName: 'create_time', isAsc: 'desc', check: false },
  49. { name: '价格', sortName: 'price', isAsc: 'desc', check: false },
  50. { name: '数量', sortName: 'stock', isAsc: 'desc', check: false },
  51. ],
  52. list: [],
  53. param: { pageNo: 1, pageSize: 10 },
  54. loadMore: true
  55. };
  56. },
  57. onLoad() {
  58. this.getData();
  59. //选择商品分类
  60. uni.$on('productType', res => {
  61. this.param.goodsType = res.name;
  62. this.param.current = res.current;
  63. this.param.now = res.now;
  64. this.refresh();
  65. });
  66. },
  67. methods: {
  68. select(item, index) {
  69. this.sort.forEach(it => (it.check = false));
  70. item.check = true;
  71. if (index > 0) {
  72. this.isAsc = this.isAsc == 'desc' ? 'asc' : 'desc';
  73. item.isAsc = this.isAsc;
  74. }
  75. this.param.orderBy = item.sortName + ' ' + this.isAsc;
  76. this.refresh();
  77. },
  78. getData() {
  79. this.http.request({
  80. url: '/level-one-server/app/TbGoodsTransit/getList',
  81. data: this.param,
  82. loading: 'false',
  83. success: res => {
  84. this.loadMore = parseInt(res.data.pageCount) > this.param.pageNo;
  85. this.list.push(...res.data.data);
  86. }
  87. });
  88. },
  89. //选择分类
  90. go() {
  91. uni.navigateTo({ url: '/pages/market/productType?current=' + this.param.current + '&now=' + this.param.now });
  92. },
  93. // 添加购物车
  94. addCar(goods) {
  95. let params = {
  96. buyUserId: this.user.id,
  97. enterpriseId: goods.merchantId,
  98. shopId: goods.shopId,
  99. tradeAreaId: goods.tradeAreaId,
  100. saleGoodsInfoId: goods.id,
  101. goodsImg: goods.goodsImg,
  102. goodsName: goods.goodsName,
  103. publishGoodsId: goods.id
  104. };
  105. this.http.request({
  106. url: '/level-one-server/app/TbGoodsCart/addGoodsInShopCart',
  107. data: params,
  108. contentType: 'application/json; charset=utf-8',
  109. method: 'POST',
  110. success: res => {
  111. uni.showToast({ title: '添加成功' });
  112. }
  113. });
  114. },
  115. detail(id) {
  116. uni.navigateTo({ url: '/pages/market/one/detail?id=' + id });
  117. },
  118. //刷新数据
  119. refresh() {
  120. this.loadMore = true;
  121. this.param.pageNo = 1;
  122. this.list = [];
  123. this.getData();
  124. }
  125. },
  126. //下拉刷新
  127. onPullDownRefresh() {
  128. setTimeout(() => {
  129. this.refresh();
  130. uni.stopPullDownRefresh();
  131. }, 1000);
  132. },
  133. //上拉加载
  134. onReachBottom() {
  135. if (this.loadMore) {
  136. this.param.pageNo++;
  137. this.getData();
  138. }
  139. }
  140. };
  141. </script>
  142. <style lang="scss">
  143. page {
  144. background-color: $pg;
  145. }
  146. .search {
  147. padding: 12px 12px 0px 12px;
  148. }
  149. </style>