list.vue 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492
  1. <template>
  2. <mescroll-body ref="mescrollRef" :sticky="true" @init="mescrollInit" :down="{ native: true }" @down="downCallback"
  3. :up="upOption" @up="upCallback">
  4. <!-- 页面头部 -->
  5. <view class="header">
  6. <search class="search" :tips="options.search ? options.search : '搜索商品'" @event="handleSearch" />
  7. </view>
  8. <!-- 排序标签 -->
  9. <view class="store-sort">
  10. <view class="sort-item" :class="{ active: sortType === 'all' }" @click="handleSortType('all')">
  11. <text>综合</text>
  12. </view>
  13. <view class="sort-item" :class="{ active: sortType === 'sales' }" @click="handleSortType('sales')">
  14. <text>销量</text>
  15. </view>
  16. <view class="sort-item sort-item-price" :class="{ active: sortType === 'price' }" @click="handleSortType('price')">
  17. <text>价格</text>
  18. <view class="price-arrow">
  19. <view class="icon up" :class="{ active: sortType === 'price' && !sortPrice }">
  20. <text class="iconfont icon-arrow-up"></text>
  21. </view>
  22. <view class="icon down" :class="{ active: sortType === 'price' && sortPrice }">
  23. <text class="iconfont icon-arrow-down"></text> </view>
  24. </view>
  25. </view>
  26. </view>
  27. <!-- 商品列表 -->
  28. <view class="goods-list clearfix" v-if="list.content" :class="['column-1']">
  29. <view class="goods-item" v-for="(item, index) in list.content" :key="index" @click="onTargetDetail(item.id, item.type)">
  30. <!-- 单列显示 -->
  31. <view v-if="showView" class="dis-flex">
  32. <!-- 商品图片 -->
  33. <view class="goods-item_left">
  34. <image class="image" :src="item.logo"></image>
  35. </view>
  36. <view class="goods-item_right">
  37. <!-- 商品名称 -->
  38. <view class="goods-name twolist-hidden">
  39. <text>{{ item.name }}</text>
  40. </view>
  41. <view class="goods-item_desc">
  42. <!-- 商品卖点 -->
  43. <view class="desc-selling_point dis-flex">
  44. <text class="onelist-hidden">{{ item.salepoint }}</text>
  45. </view>
  46. <view class="coupon-attr">
  47. <view class="attr-l">
  48. <!-- 销量 -->
  49. <view class="desc-goods_sales dis-flex">
  50. <text>已售{{ item.initSale }}</text>
  51. </view>
  52. <!-- 价格 -->
  53. <view class="desc_footer">
  54. <text class="price_x">¥{{ item.price }}</text>
  55. <text class="price_y col-9" v-if="item.linePrice > 0">¥{{ item.linePrice }}</text>
  56. </view>
  57. </view>
  58. <view class="attr-r">
  59. <!--购买按钮-->
  60. <view class="receive">
  61. <text>去购买</text>
  62. </view>
  63. </view>
  64. </view>
  65. </view>
  66. </view>
  67. </view>
  68. </view>
  69. </view>
  70. </mescroll-body>
  71. </template>
  72. <script>
  73. import MescrollBody from '@/components/mescroll-uni/mescroll-body.vue'
  74. import MescrollMixin from '@/components/mescroll-uni/mescroll-mixins'
  75. import * as GoodsApi from '@/api/goods'
  76. import { getEmptyPaginateObj, getMoreListData } from '@/utils/app'
  77. import Search from '@/components/search'
  78. const pageSize = 15
  79. const showViewKey = 'GoodsList-ShowView';
  80. export default {
  81. components: {
  82. MescrollBody,
  83. Search
  84. },
  85. mixins: [MescrollMixin],
  86. data() {
  87. return {
  88. isLoading: false,
  89. showView: true, // 列表显示方式 (true列表、false平铺)
  90. sortType: 'all', // 排序类型
  91. sortPrice: false, // 价格排序 (true高到低 false低到高)
  92. options: {}, // 当前页面参数
  93. list: getEmptyPaginateObj(), // 商品列表数据
  94. // 上拉加载配置
  95. upOption: {
  96. // 首次自动执行
  97. auto: true,
  98. // 每页数据的数量; 默认10
  99. page: { size: pageSize },
  100. // 数量要大于4条才显示无更多数据
  101. noMoreSize: 4,
  102. }
  103. }
  104. },
  105. /**
  106. * 生命周期函数--监听页面加载
  107. */
  108. onLoad(options) {
  109. // 记录options
  110. this.options = options;
  111. // 设置默认列表显示方式
  112. this.setShowView();
  113. },
  114. methods: {
  115. /**
  116. * 上拉加载的回调 (页面初始化时也会执行一次)
  117. * 其中page.num:当前页 从1开始, page.size:每页数据条数,默认10
  118. * @param {Object} page
  119. */
  120. upCallback(page) {
  121. const app = this
  122. // 设置列表数据
  123. app.getGoodsList(page.num)
  124. .then(list => {
  125. const curPageLen = list.content ? list.content.length : 0;
  126. const totalSize = list.totalElements;
  127. app.mescroll.endBySize(curPageLen, totalSize);
  128. })
  129. .catch(() => app.mescroll.endErr())
  130. },
  131. // 设置默认列表显示方式
  132. setShowView() {
  133. this.showView = uni.getStorageSync(showViewKey) || true
  134. },
  135. // 点击跳转到首页
  136. onTargetIndex() {
  137. this.$navTo('pages/index/index');
  138. },
  139. /**
  140. * 获取商品列表
  141. * @param {number} pageNo 页码
  142. */
  143. getGoodsList(pageNo = 1) {
  144. const app = this
  145. console.log(app.options)
  146. const param = {
  147. sortType: app.sortType,
  148. sortPrice: Number(app.sortPrice),
  149. cateId: app.options.categoryId || 0,
  150. name: app.options.search || '',
  151. page: pageNo
  152. }
  153. return new Promise((resolve, reject) => {
  154. GoodsApi.search(param)
  155. .then(result => {
  156. // 合并新数据
  157. const newList = result.data;
  158. app.list.content = getMoreListData(newList, app.list, pageNo)
  159. resolve(newList)
  160. })
  161. .catch(reject)
  162. })
  163. },
  164. // 切换排序方式
  165. handleSortType(newSortType) {
  166. const app = this
  167. const newSortPrice = newSortType === 'price' ? !app.sortPrice : true
  168. app.sortType = newSortType
  169. app.sortPrice = newSortPrice
  170. // 刷新列表数据
  171. app.list = getEmptyPaginateObj()
  172. app.mescroll.resetUpScroll()
  173. },
  174. // 切换列表显示方式
  175. handleShowView() {
  176. const app = this
  177. app.showView = !app.showView
  178. uni.setStorageSync(showViewKey, app.showView)
  179. },
  180. // 跳转商品详情页
  181. onTargetDetail(goodsId, type) {
  182. this.$navTo(`pages/goods/detail`, { goodsId })
  183. },
  184. //商品搜索
  185. handleSearch() {
  186. const searchPageUrl = 'pages/search/index'
  187. // 判断来源页面
  188. let pages = getCurrentPages()
  189. if (pages.length > 1 &&
  190. pages[pages.length - 2].route === searchPageUrl) {
  191. uni.navigateBack()
  192. return
  193. }
  194. // 跳转到卡券搜索页
  195. this.$navTo(searchPageUrl)
  196. }
  197. },
  198. /**
  199. * 设置分享内容
  200. */
  201. onShareAppMessage() {
  202. // 构建分享参数
  203. return {
  204. title: "全部分类",
  205. path: "/pages/category/index?" + this.$getShareUrlParams()
  206. }
  207. },
  208. /**
  209. * 分享到朋友圈
  210. * 本接口为 Beta 版本,暂只在 Android 平台支持,详见分享到朋友圈 (Beta)
  211. * https://developers.weixin.qq.com/miniprogram/dev/framework/open-ability/share-timeline.html
  212. */
  213. onShareTimeline() {
  214. // 构建分享参数
  215. return {
  216. title: "全部分类",
  217. path: "/pages/category/index?" + this.$getShareUrlParams()
  218. }
  219. }
  220. }
  221. </script>
  222. <style lang="scss" scoped>
  223. // 页面头部
  224. .header {
  225. display: block;
  226. align-items: center;
  227. background-color: #fff;
  228. height: 103rpx;
  229. // 搜索框
  230. .search {
  231. flex: 1;
  232. }
  233. // 切换显示方式
  234. .show-view {
  235. width: 60rpx;
  236. height: 60rpx;
  237. line-height: 60rpx;
  238. font-size: 36rpx;
  239. color: #505050;
  240. }
  241. }
  242. // 空数据按钮
  243. .empty-ipt {
  244. width: 220rpx;
  245. margin: 20rpx auto;
  246. font-size: 28rpx;
  247. height: 64rpx;
  248. line-height: 64rpx;
  249. text-align: center;
  250. color: #fff;
  251. border-radius: 5rpx;
  252. background: linear-gradient(to right, $fuint-theme, $fuint-theme);
  253. }
  254. // 排序组件
  255. .store-sort {
  256. position: sticky;
  257. top: var(--window-top);
  258. display: flex;
  259. padding: 20rpx 0;
  260. font-size: 28rpx;
  261. background: #fff;
  262. color: #000;
  263. z-index: 99;
  264. .sort-item {
  265. flex-basis: 33.3333%;
  266. display: flex;
  267. justify-content: center;
  268. align-items: center;
  269. height: 50rpx;
  270. &.active {
  271. color: #e49a3d;
  272. }
  273. }
  274. .sort-item-price .price-arrow {
  275. margin-left: 20rpx;
  276. font-size: 24rpx;
  277. color: #000;
  278. .icon {
  279. &.active {
  280. color: #e49a3d;
  281. }
  282. &.up {
  283. margin-bottom: -16rpx;
  284. }
  285. &.down {
  286. margin-top: -16rpx;
  287. }
  288. }
  289. }
  290. }
  291. // 商品列表
  292. .goods-list {
  293. padding: 4rpx;
  294. box-sizing: border-box;
  295. }
  296. // 单列显示
  297. .goods-list.column-1 {
  298. .goods-item {
  299. width: 100%;
  300. height: 280rpx;
  301. margin-bottom: 12rpx;
  302. padding: 20rpx;
  303. box-sizing: border-box;
  304. background: #fff;
  305. line-height: 1.6;
  306. &:last-child {
  307. margin-bottom: 0;
  308. }
  309. }
  310. .goods-item_left {
  311. display: flex;
  312. width: 300rpx;
  313. background: #fff;
  314. align-items: center;
  315. .image {
  316. display: block;
  317. width: 220rpx;
  318. height: 200rpx;
  319. border-radius: 10rpx;
  320. }
  321. }
  322. .goods-item_right {
  323. position: relative;
  324. // width: 450rpx;
  325. flex: 1;
  326. .goods-name {
  327. margin-top: 10rpx;
  328. height: 64rpx;
  329. line-height: 1.3;
  330. white-space: normal;
  331. color: #484848;
  332. font-size: 26rpx;
  333. }
  334. }
  335. .goods-item_desc {
  336. margin-top: 8rpx;
  337. .coupon-attr {
  338. .attr-l {
  339. float:left;
  340. width: 60%;
  341. }
  342. .attr-r {
  343. margin-top:20rpx;
  344. float:left;
  345. }
  346. }
  347. }
  348. .desc-selling_point {
  349. width: 400rpx;
  350. font-size: 24rpx;
  351. color: #e49a3d;
  352. }
  353. .receive {
  354. color: #FFFFFF;
  355. float: right;
  356. margin-right: 20rpx;
  357. border: solid 1rpx $fuint-theme;
  358. background: $fuint-theme;
  359. padding: 8rpx 20rpx 8rpx 20rpx;
  360. border-radius: 5rpx;
  361. display: block;
  362. &.state {
  363. border: none;
  364. color: #cccccc;
  365. background: #F5F5F5;
  366. }
  367. }
  368. .desc-goods_sales {
  369. color: #999;
  370. font-size: 24rpx;
  371. }
  372. .desc_footer {
  373. font-size: 24rpx;
  374. .price_x {
  375. margin-right: 16rpx;
  376. color: #f03c3c;
  377. font-size: 30rpx;
  378. }
  379. .price_y {
  380. text-decoration: line-through;
  381. }
  382. }
  383. }
  384. // 平铺显示
  385. .goods-list.column-2 {
  386. .goods-item {
  387. width: 50%;
  388. }
  389. }
  390. .goods-item {
  391. float: left;
  392. box-sizing: border-box;
  393. padding: 6rpx;
  394. .goods-image {
  395. position: relative;
  396. width: 100%;
  397. height: 0;
  398. padding-bottom: 100%;
  399. overflow: hidden;
  400. background: #fff;
  401. &:after {
  402. content: '';
  403. display: block;
  404. margin-top: 100%;
  405. }
  406. .image {
  407. position: absolute;
  408. width: 100%;
  409. height: 100%;
  410. top: 0;
  411. left: 0;
  412. -o-object-fit: cover;
  413. object-fit: cover;
  414. }
  415. }
  416. .detail {
  417. padding: 8rpx;
  418. background: #fff;
  419. .goods-name {
  420. height: 64rpx;
  421. line-height: 32rpx;
  422. white-space: normal;
  423. color: #484848;
  424. font-size: 26rpx;
  425. }
  426. .detail-price {
  427. .goods-price {
  428. margin-right: 8rpx;
  429. }
  430. .line-price {
  431. text-decoration: line-through;
  432. }
  433. }
  434. }
  435. }
  436. </style>