searchList.vue 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295
  1. <template>
  2. <view>
  3. <u-sticky offset-top="0">
  4. <view class="sticky">
  5. <view class="nav">
  6. <block v-for="(item,index) in filterData" :key="index">
  7. <text :class="item.checked?'active':''" class="name"
  8. @click="checkTab(item)"
  9. >
  10. {{ item.name }}
  11. </text>
  12. </block>
  13. </view>
  14. </view>
  15. </u-sticky>
  16. <view class="u-p-l-10 u-p-r-10 waterfall">
  17. <u-waterfall ref="uWaterfall" v-model="flowList">
  18. <template v-slot:left="{leftList}">
  19. <view v-for="(item, index) in leftList" :key="index" class="demo-warter">
  20. <u-lazy-load :image="item.image" :index="index" border-radius="12" threshold="750"
  21. @click="clickImage(item.id)"></u-lazy-load>
  22. <view class="item-title">{{ item.goodsName }}</view>
  23. <view class="item-bottom">
  24. <view class="item-price">
  25. <view class="new-price">¥{{ item.newPrice }}</view>
  26. <view class="old-price">¥{{ item.oldPrice }}</view>
  27. </view>
  28. <view class="right">
  29. 免邮费
  30. </view>
  31. </view>
  32. </view>
  33. </template>
  34. <template v-slot:right="{rightList}">
  35. <view v-for="(item, index) in rightList" :key="index" class="demo-warter">
  36. <u-lazy-load :image="item.image" :index="index" border-radius="10" threshold="750"
  37. @click="clickImage(item.id)"></u-lazy-load>
  38. <view class="item-title">{{ item.goodsName }}</view>
  39. <view class="item-bottom">
  40. <view class="item-price">
  41. <view class="new-price">¥{{ item.newPrice }}</view>
  42. <view class="old-price">¥{{ item.oldPrice }}</view>
  43. </view>
  44. <view class="right">
  45. 免邮费
  46. </view>
  47. </view>
  48. </view>
  49. </template>
  50. </u-waterfall>
  51. <u-loadmore v-show="loading" :status="loadStatus" bg-color="rgb(250, 250, 250)" style="padding:10rpx 0;"
  52. @loadmore="findGoodsList"></u-loadmore>
  53. <u-back-top :scroll-top="scrollTop" top="1000"></u-back-top>
  54. <u-no-network></u-no-network>
  55. </view>
  56. </view>
  57. </template>
  58. <script>
  59. import config from "@/common/config.js" // 全局配置文件
  60. export default {
  61. data() {
  62. return {
  63. loading: true,
  64. indexArr: [],
  65. valueArr: [],
  66. defaultSelected: [],
  67. filterData: [{
  68. name: '综合排序',
  69. checked: true
  70. },
  71. {
  72. name: '销量',
  73. checked: false
  74. },
  75. {
  76. name: '价格',
  77. checked: false,
  78. },
  79. {
  80. name: '好评率',
  81. checked: false
  82. }
  83. ],
  84. pageNum: 1,
  85. pageSize: 20,
  86. scrollTop: 0,
  87. loadStatus: 'loadmore',
  88. flowList: [],
  89. }
  90. },
  91. onLoad() {
  92. // 获取数据
  93. this.findGoodsList();
  94. },
  95. onPageScroll(e) {
  96. this.scrollTop = e.scrollTop;
  97. },
  98. onReachBottom() {
  99. this.loadStatus = 'loading';
  100. // 获取数据
  101. this.findGoodsList()
  102. },
  103. // 下拉刷新
  104. onPullDownRefresh() {
  105. // 获取数据
  106. this.pageNum = 1
  107. this.flowList = []
  108. this.$refs.uWaterfall.clear();
  109. this.findGoodsList();
  110. // 关闭刷新
  111. uni.stopPullDownRefresh();
  112. },
  113. methods: {
  114. findGoodsList() {
  115. let url = "/api/mallApi/findGoodsList";
  116. this.$u.get(url, {
  117. pageNum: this.pageNum,
  118. pageSize: this.pageSize,
  119. orderByColumn: 'create_time',
  120. isAsc: 'desc'
  121. }).then(result => {
  122. // 商品数据
  123. const goodsList = result.rows;
  124. if (this.pageNum > 1 && goodsList.length < this.pageSize) {
  125. return this.loadStatus = 'nomore';
  126. }
  127. for (let i = 0; i < goodsList.length; i++) {
  128. // 先转成字符串再转成对象,避免数组对象引用导致数据混乱
  129. let item = goodsList[i]
  130. item.image = config.staticUrl + item.goodsFaceUrl
  131. this.flowList.push(item);
  132. }
  133. ++this.pageNum
  134. this.loadStatus = 'loadmore';
  135. });
  136. },
  137. clickImage(goodsId) {
  138. this.$u.route({
  139. url: '/pages/detail/detail',
  140. params: {
  141. goodsId: goodsId
  142. }
  143. })
  144. },
  145. //接收菜单结果
  146. confirm(e) {
  147. this.indexArr = e.index;
  148. console.log(this.indexArr);
  149. this.valueArr = e.value;
  150. console.log(this.valueArr);
  151. console.log(e);
  152. },
  153. code() {
  154. this.$mytip.toast('请咨询技术支持')
  155. },
  156. checkTab(item) {
  157. if (!item.isSort) {
  158. this.filterData.filter(data => {
  159. data.checked = false
  160. })
  161. item.checked = true
  162. } else {
  163. if (!item.asc) {
  164. item.asc = true
  165. item.desc = false
  166. } else {
  167. item.desc = true
  168. item.asc = false
  169. }
  170. }
  171. }
  172. }
  173. }
  174. </script>
  175. <style>
  176. page {
  177. background-color: #fff;
  178. }
  179. </style>
  180. <style lang="scss" scoped>
  181. .nav {
  182. width: 100%;
  183. height: 88 rpx;
  184. border-bottom: solid 1 rpx #eee;
  185. z-index: 12;
  186. background-color: #ffffff;
  187. display: flex;
  188. justify-content: space-around;
  189. align-items: center;
  190. font-size: 15px;
  191. color: $u-main-color;
  192. box-shadow: 4 rpx 0 10 rpx rgba(0, 0, 0, .06);
  193. .name {
  194. width: 120 rpx;
  195. height: 44 rpx;
  196. text-align: center;
  197. text-overflow: clip;
  198. overflow: hidden;
  199. position: relative;
  200. .sort {
  201. display: flex;
  202. flex-direction: column;
  203. position: absolute;
  204. height: 40 rpx;
  205. line-height: 40 rpx;
  206. right: 0;
  207. top: 0;
  208. }
  209. }
  210. .active {
  211. color: $base-color;
  212. border-bottom: 2px solid $base-color;
  213. height: 28px;
  214. line-height: 28px;
  215. font-weight: 600;
  216. }
  217. }
  218. .nomore {
  219. background-color: $u-bg-color;
  220. }
  221. .demo-warter {
  222. border-radius: 8px;
  223. margin-top: 3px;
  224. background-color: $u-bg-color;
  225. padding: 3px;
  226. position: relative;
  227. box-shadow: 4 rpx 0 10 rpx rgba(0, 0, 0, .06);
  228. }
  229. .item-title {
  230. font-size: 28 rpx;
  231. color: $u-main-color;
  232. font-weight: bold;
  233. padding-top: 10 rpx;
  234. padding-left: 10 rpx;
  235. background-color: #fff;
  236. }
  237. .item-bottom {
  238. background-color: #fff;
  239. display: flex;
  240. justify-content: space-between;
  241. align-items: center;
  242. .item-price {
  243. display: flex;
  244. align-items: center;
  245. width: 220 rpx;
  246. max-width: 220 rpx;
  247. text-overflow: ellipsis;
  248. overflow: hidden;
  249. white-space: nowrap;
  250. .new-price {
  251. font-weight: normal;
  252. font-size: 16px;
  253. color: $base-color;
  254. padding: 5px 0 5px 2px;
  255. }
  256. .old-price {
  257. font-weight: normal;
  258. font-size: 13px;
  259. text-decoration: line-through;
  260. color: $u-tips-color;
  261. padding: 5px 0 5px 5px;
  262. }
  263. }
  264. .right {
  265. color: #fff;
  266. background-image: linear-gradient(to left, rgba(#ff536f, 1), rgba(#ff536f, 0.6));
  267. padding: 2 rpx 12 rpx;
  268. border-radius: 30 rpx;
  269. margin-right: 5 rpx;
  270. }
  271. }
  272. .item-desc {
  273. font-weight: normal;
  274. font-size: 26 rpx;
  275. color: $u-tips-color;
  276. padding-bottom: 5 rpx;
  277. padding-left: 10 rpx;
  278. background-color: #fff;
  279. }
  280. </style>