sort.vue 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165
  1. <template>
  2. <view>
  3. <view class="search-box">
  4. <view class="search ddflex" @click="search()">
  5. <image src="../../static/images/ssico.png"></image>
  6. <input class="fflex" placeholder="搜索产品名称或标签" v-model="searchVal" @input="search" @confirm="search"/>
  7. </view>
  8. </view>
  9. <scroll-view scroll-X="true" class="tab">
  10. <view :class="'li ' + (currents == -1 ? 'active' : '')" @tap="cateTabs(-1,'')" >全部</view>
  11. <block v-for="(item, index) in cates" :key="index">
  12. <view :class="'li ' + (currents == index ? 'active' : '')" @tap="cateTabs(index,item.id)">{{item.title}}</view>
  13. </block>
  14. </scroll-view>
  15. <view style="height: 190rpx;"></view>
  16. <view class="sort">
  17. <block v-for="(item, index) in pageList" :key="index">
  18. <view class="li dflex" @tap="toDetail(item.id)">
  19. <view class="proimgs">
  20. <image :src="item.pic" mode="aspectFill" class="proimg"
  21. lazy-load="true"></image>
  22. <image src="../../static/pages/images/shouqing.png" class="shouqing" v-if="item.stock < 1">
  23. </image>
  24. </view>
  25. <view class="flex">
  26. <view class="proname tovers" style="font-weight: bold;font-size: 32rpx;line-height: 38rpx;">{{item.title}}</view>
  27. <view class="pronames tovers">
  28. {{item.brief?item.brief:''}}
  29. </view>
  30. <view class="operate dflex">
  31. <view class="ddflex fflex">
  32. <block v-if="item.label">
  33. <view class="tag" v-for="it,idx in item.label.split(',')" :key="idx">{{it}}</view>
  34. </block>
  35. </view>
  36. <!-- <view class="price">
  37. 已售:<text>{{item.salePrice}}件</text>
  38. </view> -->
  39. <!-- <view class="add-cart">
  40. <image src="../static/product/image/you.png">
  41. </image>
  42. </view> -->
  43. </view>
  44. </view>
  45. </view>
  46. </block>
  47. <view class="nodata nosp bgfff" v-if="show">
  48. <image :src="picUrlss+'empty_sp.png'"></image>
  49. <text>暂无产品</text>
  50. </view>
  51. </view>
  52. </view>
  53. </template>
  54. <script>
  55. // pages/sort/sort.js
  56. //获取应用实例
  57. const app = getApp();
  58. const req = require("../../utils/request.js");
  59. let scrollDdirection = 0; // 用来计算滚动的方向
  60. export default {
  61. data() {
  62. return {
  63. picUrlss: req.public.picUrls,
  64. cates: [],//产品一级分类列表
  65. currents: -1,
  66. page: 1,
  67. limit:10,
  68. isload: false,
  69. isUpdate: false // 是否更新消息
  70. ,
  71. pageList: [],
  72. cateid: '',
  73. searchVal:''
  74. };
  75. },
  76. components: {},
  77. props: {},
  78. onLoad: async function(options) {
  79. this.category();
  80. },
  81. onShow() {
  82. this.setData({
  83. isUpdate: !this.isUpdate
  84. });
  85. },
  86. onReachBottom() {
  87. this.page++;
  88. if (this.currents > -1) {
  89. this.getList(this.cateid);
  90. } else {
  91. this.getList(this.id);
  92. }
  93. },
  94. methods: {
  95. category() {
  96. //产品分类
  97. let that = this;
  98. // console.log(id, dataName, listId);
  99. let from = {
  100. page: 1,
  101. size: 1000
  102. };
  103. req.getRequest('/api/v1/category/list', from, res => {
  104. this.cates = res
  105. this.getList();
  106. });
  107. },
  108. cateTabs(index,id) {
  109. if(this.currents == index) return false
  110. this.setData({
  111. currents: index,
  112. page: 1,
  113. cateid: id
  114. });
  115. this.getList();
  116. },
  117. getList() {
  118. // console.log("====================")
  119. //产品列表
  120. let that = this;
  121. let from = {
  122. page: that.page,
  123. limit: that.limit,
  124. categoryId: that.cateid
  125. };
  126. if(this.searchVal) from.searchTitle = this.searchVal
  127. req.getRequest('/api/v1/product/list', from, res => {
  128. if(that.page==1) that.pageList = []
  129. if (res && res.length >= that.limit) that.isLoad = true;
  130. if (that.page > 1) res = that.pageList.concat(res);
  131. if (res.length <= 0) {
  132. that.setData({
  133. show: true
  134. })
  135. } else {
  136. that.setData({
  137. show: false
  138. })
  139. }
  140. that.setData({
  141. pageList: res
  142. });
  143. });
  144. },
  145. toDetail(id) {
  146. app.globalData.openPage("product/detail/detail?id=" + id);
  147. },
  148. search() {
  149. this.page = 1
  150. this.getList();
  151. }
  152. }
  153. };
  154. </script>
  155. <style>
  156. @import "./sort.css";
  157. </style>