list.vue 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150
  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" @click="go()">
  15. <text>{{ param.goodsType || '分类' }}</text>
  16. <text class="icon">&#xe8f2;</text>
  17. </view>
  18. </view>
  19. <view class="item" 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. ],
  51. list: [],
  52. param: { pageNo: 1, pageSize: 10 },
  53. loadMore: true
  54. };
  55. },
  56. onLoad() {
  57. this.getData();
  58. //选择商品分类
  59. uni.$on('productType', res => {
  60. this.param.goodsType = res.name;
  61. this.param.current = res.current;
  62. this.param.now = res.now;
  63. this.refresh();
  64. });
  65. },
  66. methods: {
  67. select(item, index) {
  68. this.sort.forEach(it => (it.check = false));
  69. item.check = true;
  70. if (index > 0) {
  71. this.isAsc = this.isAsc == 'desc' ? 'asc' : 'desc';
  72. item.isAsc = this.isAsc;
  73. }
  74. this.param.orderBy = item.sortName + ' ' + this.isAsc;
  75. this.refresh();
  76. },
  77. getData() {
  78. this.http.request({
  79. url: '/level-one-server/app/TbGoodsTransit/getList',
  80. data: this.param,
  81. loading: 'false',
  82. success: res => {
  83. this.loadMore = parseInt(res.data.pageCount) > this.param.pageNo;
  84. this.list.push(...res.data.data);
  85. }
  86. });
  87. },
  88. //选择分类
  89. go() {
  90. uni.navigateTo({ url: '/pages/market/productType?current=' + this.param.current + '&now=' + this.param.now });
  91. },
  92. // 添加购物车
  93. addCar(goods) {
  94. let params = {
  95. buyUserId: this.user.id,
  96. enterpriseId: goods.merchantId,
  97. shopId: goods.shopId,
  98. tradeAreaId: goods.tradeAreaId,
  99. saleGoodsInfoId: goods.id,
  100. goodsImg: goods.goodsImg,
  101. goodsName: goods.goodsName,
  102. publishGoodsId: goods.id
  103. };
  104. this.http.request({
  105. url: '/level-one-server/app/TbGoodsCart/addGoodsInShopCart',
  106. data: params,
  107. contentType: 'application/json; charset=utf-8',
  108. method: 'POST',
  109. success: res => {
  110. uni.showToast({ title: '添加成功' });
  111. }
  112. });
  113. },
  114. detail(id) {
  115. uni.navigateTo({ url: '/pages/market/one/detail?id=' + id });
  116. },
  117. //刷新数据
  118. refresh() {
  119. this.loadMore = true;
  120. this.param.pageNo = 1;
  121. this.list = [];
  122. this.getData();
  123. }
  124. },
  125. //下拉刷新
  126. onPullDownRefresh() {
  127. setTimeout(() => {
  128. this.refresh();
  129. uni.stopPullDownRefresh();
  130. }, 1000);
  131. },
  132. //上拉加载
  133. onReachBottom() {
  134. if (this.loadMore) {
  135. this.param.pageNo++;
  136. this.getData();
  137. }
  138. }
  139. };
  140. </script>
  141. <style lang="scss">
  142. page {
  143. background-color: $pg;
  144. }
  145. .search {
  146. padding: 12px 12px 0px 12px;
  147. }
  148. </style>