list.vue 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164
  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)">
  20. <view class="title">{{ item.createName }}</view>
  21. <image src="../../../static/news.jpg" mode="aspectFill" class="pic"></image>
  22. <view class="con">
  23. <view class="productName omit">{{ item.goodsName }}</view>
  24. <view class="price">¥ {{ item.resalePrice }}</view>
  25. <view class="icon btn" v-if="user.userType == 3" @click.stop="addCar(item)">&#xe600;</view>
  26. <view class="btn" v-if="user.userType == 3" @click.stop="buy(item)">购买</view>
  27. </view>
  28. </view>
  29. <view class="loading" v-if="loadMore"><u-loadmore :status="loadMore ? 'loading' : 'nomore'" /></view>
  30. <u-empty v-if="!loadMore && list.length == 0"></u-empty>
  31. </view>
  32. <productType v-model="show"></productType>
  33. <button class="addBtn" @click="goCar()">
  34. <text class="icon">&#xe600;</text>
  35. <view class="bag animated" :class="{ bounce: add }" v-if="cars > 0">{{ cars }}</view>
  36. </button>
  37. </view>
  38. </template>
  39. <script>
  40. export default {
  41. data() {
  42. return {
  43. user: this.getUser(),
  44. show: false,
  45. isAsc: 'desc',
  46. cars: 0,
  47. add: false,
  48. sort: [
  49. { name: '综合', sortName: 'id', isAsc: 'desc', check: false },
  50. { name: '日期', sortName: 'create_time', isAsc: 'desc', check: false },
  51. { name: '数量', sortName: 'goods_quantity', isAsc: 'desc', check: false }
  52. ],
  53. list: [],
  54. param: { pageNo: 1, pageSize: 10 },
  55. loadMore: true
  56. };
  57. },
  58. onLoad(e) {
  59. this.getData();
  60. //选择商品分类
  61. uni.$on('productType', res => {
  62. this.param.goodsType = res.name;
  63. this.param.current = res.current;
  64. this.param.now = res.now;
  65. this.refresh();
  66. });
  67. },
  68. methods: {
  69. select(item, index) {
  70. this.sort.forEach(it => (it.check = false));
  71. item.check = true;
  72. if (index > 0) {
  73. this.isAsc = this.isAsc == 'desc' ? 'asc' : 'desc';
  74. item.isAsc = this.isAsc;
  75. }
  76. this.param.orderBy = item.sortName + ' ' + this.isAsc;
  77. this.refresh();
  78. },
  79. getData() {
  80. this.http.request({
  81. url: '/level-two-server/app/TbOrders/getLevelTwoList',
  82. data: this.param,
  83. loading: 'false',
  84. success: res => {
  85. this.loadMore = parseInt(res.data.pageCount) > this.param.pageNo;
  86. this.list.push(...res.data.data);
  87. }
  88. });
  89. },
  90. //选择分类
  91. go() {
  92. uni.navigateTo({ url: '/pages/market/productType?current=' + this.param.current + '&now=' + this.param.now });
  93. },
  94. detail(item) {
  95. uni.navigateTo({ url: '/pages/market/two/detail?orderId=' + item.id });
  96. },
  97. addCar(item) {
  98. this.add = true;
  99. this.http.request({
  100. url: '/level-two-server/app/TbOrdersCart/add',
  101. method: 'POST',
  102. data: { orderId: item.id },
  103. success: res => {
  104. this.cars++;
  105. setTimeout(() => {
  106. this.add = false;
  107. }, 500);
  108. uni.showToast({ title: '添加成功' });
  109. }
  110. });
  111. },
  112. goCar() {
  113. uni.navigateTo({ url: '/pages/market/two/purchaser/order/cart' });
  114. },
  115. buy(item) {
  116. uni.navigateTo({ url: '/pages/market/two/purchaser/buy/buy?orderId=' + item.id });
  117. },
  118. //刷新数据
  119. refresh() {
  120. this.loadMore = true;
  121. this.param.pageNum = 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.pageNum++;
  137. this.getData();
  138. }
  139. }
  140. };
  141. </script>
  142. <style lang="scss">
  143. page {
  144. background-color: $pg;
  145. }
  146. .con {
  147. .btn {
  148. float: right;
  149. background-color: $main-color;
  150. color: #000;
  151. height: 20px;
  152. position: relative;
  153. color: white;
  154. padding: 5px 20px;
  155. margin-left: 10px;
  156. }
  157. .icon {
  158. line-height: 30px;
  159. line-height: 20px;
  160. }
  161. }
  162. </style>