list.vue 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  1. <template>
  2. <view>
  3. <view class="search">
  4. <u-search placeholder="搜索商品名称" v-model="param.customerName" 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" @click="show = true">
  15. <text>分类</text>
  16. <text class="icon">&#xe8f2;</text>
  17. </view>
  18. <view class="clear"></view>
  19. </view>
  20. <view class="item" v-for="(item, index) in list" :key="index" @click="detail(item.id)">
  21. <view class="title">{{item.merchantName}}</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. sort: [{ name: '综合' }, { name: '日期' }, { name: '价格' }],
  46. list: [],
  47. param: { pageNo: 1, pageSize: 10 },
  48. loadMore: true
  49. };
  50. },
  51. onLoad() {
  52. this.getData();
  53. },
  54. methods: {
  55. getData() {
  56. this.http.request({
  57. url: '/level-one-server/app/TbGoodsTransit/getList',
  58. data: this.param,
  59. loading: 'false',
  60. success: res => {
  61. this.loadMore = parseInt(res.data.pageCount) > this.param.pageNo;
  62. this.list.push(...res.data.data);
  63. }
  64. });
  65. },
  66. // 添加购物车
  67. addCar(goods) {
  68. let params = {
  69. buyUserId: this.user.id,
  70. enterpriseId: goods.merchantId,
  71. shopId: goods.shopId,
  72. tradeAreaId: goods.tradeAreaId,
  73. saleGoodsInfoId: goods.id,
  74. goodsImg: goods.goodsImg,
  75. goodsName: goods.goodsName,
  76. publishGoodsId: goods.id
  77. };
  78. this.http.request({
  79. url: '/level-one-server/app/TbGoodsCart/addGoodsInShopCart',
  80. data: params,
  81. contentType: 'application/json; charset=utf-8',
  82. method: 'POST',
  83. success: res => {
  84. uni.showToast({ title: '添加成功' });
  85. }
  86. });
  87. },
  88. detail(id) {
  89. uni.navigateTo({ url: '/pages/market/one/detail?id=' + id });
  90. },
  91. //刷新数据
  92. refresh() {
  93. this.loadMore = true;
  94. this.param.pageNo = 1;
  95. this.list = [];
  96. this.getData();
  97. }
  98. },
  99. //下拉刷新
  100. onPullDownRefresh() {
  101. setTimeout(() => {
  102. this.refresh();
  103. uni.stopPullDownRefresh();
  104. }, 1000);
  105. },
  106. //上拉加载
  107. onReachBottom() {
  108. if (this.loadMore) {
  109. this.param.pageNo++;
  110. this.getData();
  111. }
  112. }
  113. };
  114. </script>
  115. <style lang="scss">
  116. page {
  117. background-color: $pg;
  118. }
  119. .search {
  120. padding: 12px 12px 0px 12px;
  121. }
  122. </style>