GoodslistBody.vue 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479
  1. <template>
  2. <view class="scroll-view-wrapper div common-goods-list">
  3. <view class="scroll-view-wrapper scroll-view div goodslist-body show-goods-list" >
  4. <view class="div ui-goodslist-filter">
  5. <view class="ul filter-list">
  6. <view class="li item"
  7. v-for='(item, index) in sortkey'
  8. v-bind:key='item.id'
  9. v-on:click='setActiveSortkey(item, index)'
  10. v-bind:class="{'sortactive': item.id == currentSortKey.id, 'sortnormal' : item.id != currentSortKey.id}">
  11. <text class="a" v-if='!item.isMore'>{{item.name}}</text>
  12. <text class="a" v-else>{{sort.name}}</text>
  13. <text class="span iconfont" :class="isShowMore?'active':''" v-if="item.isMore">&#xe6ea;</text>
  14. </view>
  15. </view>
  16. <view class="div sort-model" v-if='isShowMore' >
  17. <view class="div" v-for='(item, index) in childSort' v-bind:key='item.id' v-on:click='getSortChild(item)' v-bind:class="{'active': item.id == sort.id}">
  18. <text class="a">{{item.name}}</text>
  19. <text class="span iconfont" v-if="item.id == sort.id">&#xe69b;</text>
  20. </view>
  21. </view>
  22. </view>
  23. <!-- 无限加载滚动列表 -->
  24. <scroll-view class="scroll-view div flex-wrapper" @scrolltolower="getMore" scroll-y="true">
  25. <view class="div ui-product-body"
  26. v-for='(item, index) in goodsList'
  27. v-bind:key='index'
  28. >
  29. <view class="div list" v-on:click='goDetail(item.goods_id)'>
  30. <view class="div ui-image-wrapper">
  31. <image mode="aspectFit" class="img product-img" :src="item.goods_image_url">
  32. </view>
  33. <view class="div flex-right">
  34. <view class="div product-header">
  35. <text class="h3 title clear-bottom">{{ item.goods_name }}</text>
  36. </view>
  37. <view class="div goods_salenum">销量:{{ item.goods_salenum }}</view>
  38. <view class="div p-info">
  39. <text class="span platform_store" v-if="item.is_platform_store">自营</text>
  40. <view class="div p-price">¥<text class="span price">{{ item.goods_price }}</text></view>
  41. </view>
  42. </view>
  43. </view>
  44. </view>
  45. <view class="div loading-wrapper" v-if="goodsList.length > 0">
  46. <view class="p common-no-more" v-if='!isMore'>没有更多了</view>
  47. <uni-load-more status="loading" color='#e93b3d' v-if='isMore'></uni-load-more>
  48. </view>
  49. </scroll-view>
  50. </view>
  51. <empty-record v-if='goodsList.length <= 0 && !isMore'></empty-record>
  52. </view>
  53. </template>
  54. <script>
  55. import { urlencode } from '@/util/common'
  56. import EmptyRecord from '../../EmptyRecord'
  57. import { mapState } from 'vuex'
  58. import { getStoreGoodsList } from '../../../api/homestoredetail'
  59. export default {
  60. name: 'CommonGoodsList',
  61. props: [],
  62. components: {
  63. EmptyRecord
  64. },
  65. data () {
  66. return {
  67. query:{},
  68. sortkey: [
  69. {
  70. key: '',
  71. order: '',
  72. name: '综合排序',
  73. isMore: true,
  74. id: 0,
  75. child: [
  76. {
  77. key: '5',
  78. order: '',
  79. name: '综合排序',
  80. isMore: false,
  81. id: 3
  82. },
  83. {
  84. key: '4',
  85. order: '',
  86. name: '人气最高',
  87. isMore: false,
  88. id: 4
  89. },
  90. {
  91. key: '2',
  92. order: '',
  93. name: '价格高到低',
  94. isMore: false,
  95. id: 5
  96. },
  97. {
  98. key: '2',
  99. order: '1',
  100. name: '价格低到高',
  101. isMore: false,
  102. id: 6
  103. }
  104. ]
  105. },
  106. {
  107. key: '3',
  108. order: '',
  109. name: '销量排序',
  110. isMore: false,
  111. id: 1
  112. },
  113. {
  114. key: '1',
  115. order: '',
  116. name: '新品',
  117. isMore: false,
  118. id: 2
  119. }
  120. ], // 排序数据
  121. currentSortKey: {}, // 当前选中的排序
  122. childSort: [], // 综合筛选
  123. sort: {}, // 综合筛选子集
  124. isShowMore: false, // 是否显示筛选模态框
  125. params: {
  126. store_id: '',
  127. gc_id: '',
  128. is_exchange: 0,
  129. is_hot: 0,
  130. activity: null,
  131. sort_key: '', // 排序键
  132. sort_order: '', // 排序键, //排序值
  133. page: 0,
  134. keyword: ''
  135. },
  136. goodsList: [], // 商品列表
  137. loading: false, // 是否加载更多
  138. isMore: true // 是否有更多
  139. }
  140. },
  141. computed: {
  142. ...mapState({
  143. })
  144. },
  145. mounted(){
  146. var pages = getCurrentPages()
  147. var page = pages[pages.length - 1]
  148. this.query = page.options
  149. this.params.store_id=this.query.id ? this.query.id : ''
  150. this.params.gc_id=this.query.gc_id ? this.query.gc_id : ''
  151. this.params.sort_key=this.query.sort_key ? this.query.sort_key : ''
  152. this.params.sort_order=this.query.sort_order ? this.query.sort_order : ''
  153. this.params.keyword=this.query.keyword ? this.query.keyword : ''
  154. this.currentSortKey = this.sortkey[0]
  155. this.childSort = this.currentSortKey.child
  156. this.sort = this.childSort[0]
  157. this.getMore()
  158. },
  159. methods: {
  160. // closeFiler: 关闭下拉筛选模态框
  161. closeFiler () {
  162. this.isShowMore = false
  163. },
  164. // isShowDroupMenu: 点击显示下拉框, 并且显示模态框
  165. isShowDroupMenu () {
  166. let item = this.currentSortKey
  167. if (item.isMore) {
  168. this.isShowMore = true
  169. } else {
  170. this.isShowMore = false
  171. }
  172. },
  173. /**
  174. * setActiveSortkey: 点击切换数据并设置选中的样式
  175. * @param: item 当前选中的item
  176. */
  177. setActiveSortkey (item, index) {
  178. this.currentSortKey = item
  179. if (item.isMore) {
  180. this.isShowMore = !this.isShowMore
  181. } else {
  182. this.closeFiler()
  183. this.getValue()
  184. }
  185. },
  186. /**
  187. * getValue: 向父级组件发送改变列表事件, 并传递当前的sort_key, sort_order
  188. */
  189. getValue () {
  190. let data = this.getSortValue()
  191. let res = data
  192. this.params.page = 1
  193. this.goodsList = []
  194. this.loading = false
  195. this.params=this.setParamsByData(res)
  196. this.getGoodsList()
  197. },
  198. /**
  199. * getSortValue: 获取排序值
  200. */
  201. getSortValue () {
  202. let sort = this.currentSortKey
  203. let value = { 'sort_key': '', 'sort_order': '' }
  204. if (sort.isMore) {
  205. value.sort_key = this.sort.key
  206. value.sort_order = this.sort.order
  207. } else {
  208. value.sort_key = sort.key
  209. value.sort_order = sort.order
  210. }
  211. return value
  212. },
  213. /**
  214. * getSortChild: 获取综合筛选的子集, 关闭父级的阴影模态框, 关闭子集, 获取列表数据
  215. * @param: item 模态框的item
  216. */
  217. getSortChild (item) {
  218. this.sort = item
  219. this.isShowMore = !this.isShowMore
  220. this.getValue()
  221. },
  222. /*
  223. * getMore: 无限滚动加载
  224. */
  225. getMore () {
  226. this.loading = true
  227. this.params.page = ++this.params.page
  228. if (this.isMore) {
  229. this.loading = false
  230. this.getGoodsList(true)
  231. }
  232. },
  233. /**
  234. * getGoodsList: 获取商品列表
  235. * @param: ispush ? true :false 是否需要向商品列表追加数据
  236. */
  237. getGoodsList (ispush) {
  238. getStoreGoodsList(
  239. this.params
  240. ).then(res => {
  241. this.buildData(ispush, res)
  242. })
  243. },
  244. /**
  245. * getList: 构建数据
  246. * @param: ispush 是否改变向元数据追加数据
  247. * @param: res 接口请求返回的数据
  248. */
  249. buildData (ispush, res) {
  250. if (res) {
  251. if (ispush) {
  252. this.goodsList = this.goodsList.concat(res.result.goods_list)
  253. } else {
  254. this.goodsList = res.result.goods_list
  255. }
  256. this.isMore = res.result.hasmore
  257. }
  258. },
  259. /**
  260. * 根据事件传递的值来对请求列表重新赋值
  261. * @param data 事件传递的参数
  262. */
  263. setParamsByData (data) {
  264. let params = this.params
  265. for (let item in params) {
  266. for (let list in data) {
  267. if (item === list) {
  268. params[item] = data[list]
  269. }
  270. }
  271. }
  272. return params
  273. },
  274. goDetail (goods_id) {
  275. uni.navigateTo({url: '/pages/home/goodsdetail/Goodsdetail'+'?'+urlencode( { 'goods_id': goods_id } )})
  276. }
  277. }
  278. }
  279. </script>
  280. <style lang='scss' scoped>
  281. .scroll-view-wrapper{display: flex;flex-direction: column;}
  282. .scroll-view{flex:1}
  283. .goodslist-body{background: #fff;}
  284. .ui-goodslist-filter {
  285. width: auto;
  286. padding-top:.5rem;
  287. .ul.filter-list{
  288. display: flex;
  289. width: auto;
  290. justify-content: space-around;
  291. align-content: center;
  292. align-items: center;
  293. border: 0;
  294. .li{
  295. font-size:$subFontSize;
  296. color: #333;
  297. border-bottom:0.1rem solid transparent;
  298. position: relative;
  299. flex-basis:5rem;
  300. text-align: center;
  301. height:2.1rem;
  302. padding: 0;
  303. line-height:2.1rem;
  304. .a {
  305. height:2.1rem;
  306. display: inline-block;
  307. }
  308. .img {
  309. height:0.2rem;
  310. width:0.4rem;
  311. vertical-align: middle;
  312. }
  313. .iconfont{display: inline-block}
  314. }
  315. .li.sortactive {
  316. .a {
  317. color:$primaryColor;
  318. }
  319. .iconfont{color:$primaryColor;}
  320. .iconfont.active{transform: rotate(180deg);}
  321. }
  322. .li.sortnormal {
  323. border-bottom-color: transparent;
  324. .a {
  325. color: #333;
  326. }
  327. }
  328. .arrow-icon {
  329. width: 0.6rem;
  330. height: 0.6rem;
  331. }
  332. }
  333. .sort-model {
  334. position: absolute;
  335. left: 0;
  336. width: 100%;
  337. z-index: 10;
  338. .div {
  339. color: #333;
  340. padding:0.75rem;
  341. font-size:$fontSize;
  342. background-color: #fff;
  343. margin: 0;
  344. border-bottom: 1px solid #E8EAED;
  345. cursor: pointer;
  346. display: flex;
  347. width: auto;
  348. justify-content: space-between;
  349. align-content: center;
  350. align-items: center;
  351. .img {
  352. float: right;
  353. width:0.8rem;
  354. height:0.8rem;
  355. }
  356. &.active {
  357. color: $primaryColor;
  358. }
  359. }
  360. }
  361. }
  362. .ui-product-body {
  363. .list {
  364. display: flex;
  365. width: auto;
  366. align-items: center;
  367. justify-content: space-between;
  368. margin:0.55rem $pageSpace;
  369. position: relative;
  370. box-shadow: 0px 4px 4px #f7f7f7;
  371. .div.ui-image-wrapper {
  372. width:6rem;
  373. height:6rem;
  374. position: relative;
  375. display: flex;
  376. justify-content: center;
  377. align-content: center;
  378. align-items: center;
  379. flex-basis: 6rem;
  380. flex-shrink: 0;
  381. background-position:center center!important;
  382. background-size:5rem 5rem;
  383. background-repeat:no-repeat;
  384. -webkit-background-size: cover;
  385. -moz-background-size: cover;
  386. -o-background-size: cover;
  387. background-size: cover;
  388. .img.product-img{
  389. width: 6rem;
  390. height: 6rem;
  391. flex-basis: 6rem;
  392. flex-shrink: 0;
  393. border-radius: .4rem;
  394. }
  395. .img.product-img[lazy=loading] {
  396. width: 1.5rem;
  397. height: 1.5rem;
  398. }
  399. .img.product-im[lazy=error] {
  400. width: 1.5rem;
  401. height: 1.5rem;
  402. }
  403. .img.product-img[lazy=loaded] {
  404. width: 6rem;
  405. height: 6rem;
  406. flex-basis: 6rem;
  407. flex-shrink: 0;
  408. background:rgba(255,255,255,1);
  409. }
  410. .span {
  411. position: absolute;
  412. height:1rem;
  413. background:rgba(243,244,245,1);
  414. line-height: 1rem;
  415. text-align: center;
  416. font-size:$subFontSize;
  417. color:$primaryColor;
  418. width: 6rem;
  419. bottom: 0;
  420. left: 0;
  421. }
  422. }
  423. .flex-right {
  424. padding-left: 0.7rem;
  425. width: 100%;
  426. position:relative;
  427. .title {
  428. color: #333;
  429. font-size:$subFontSize;
  430. height:2rem;
  431. line-height:1rem;
  432. font-weight: normal;
  433. display:-moz-box;
  434. display:-webkit-box;
  435. -webkit-line-clamp: 2;
  436. -moz-line-clamp: 2;
  437. -moz-box-orient:vertical;
  438. -webkit-box-orient:vertical;
  439. box-orient:vertical;
  440. overflow: hidden;
  441. margin-bottom:0.4rem;
  442. &.clear-bottom {
  443. margin-bottom: 0;
  444. }
  445. }
  446. .product-header {
  447. margin-bottom: .5rem;
  448. display: flex;
  449. align-items: center;
  450. }
  451. .p-price {
  452. color: $primaryColor;
  453. font-size:$fontSize;
  454. flex:1;
  455. .price{font-size:$mainFontSize}
  456. }
  457. .goods_salenum{font-size:$fontSize;color:$descTextColor;}
  458. .p-info {
  459. display: flex;
  460. align-items: center;
  461. margin-top:.5rem;
  462. .platform_store{font-size:$h6;color: #fff;background: $primaryColor;border-radius: .13rem;padding:.1rem .2rem;margin-right: .2rem;}
  463. }
  464. .add-cart{
  465. background: $primaryColor;border-radius: 50%;text-align:center;position: absolute;right: .8rem;bottom:.2rem;width:2rem;height:2rem;line-height:2rem;
  466. .i{font-size:$h1;color:#fff;}
  467. }
  468. }
  469. }
  470. }
  471. </style>