GoodslistBody.vue 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670
  1. <template>
  2. <view style="position: absolute;top:0;right:0;left:0;bottom:0"><view style="height:100%" 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 class="li item" @click="showPopup('showAttribute')" v-if="attribute.attr_array.length!=0 || attribute.brand_array.length!=0">
  16. <text class="a">筛选</text>
  17. </view>
  18. </view>
  19. <view class="div sort-model" v-if='isShowMore' >
  20. <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}">
  21. <text class="a">{{item.name}}</text>
  22. <text class="span iconfont" v-if="item.id == sort.id">&#xe69b;</text>
  23. </view>
  24. </view>
  25. </view>
  26. <view class="scroll-view div" style="position:relative">
  27. <!-- 无限加载滚动列表 -->
  28. <scroll-view style="position: absolute;top:0;right:0;left:0;bottom:0position: absolute;" class="div flex-wrapper" :class="showstate?'goodslist':'goodsimg'" @scrolltolower="getMore" scroll-y="true">
  29. <view class="product-list">
  30. <view class="div ui-product-body"
  31. v-for='(item, index) in goodsList'
  32. v-bind:key='index'
  33. >
  34. <view class="div list" v-on:click='goDetail(item.goods_id)'>
  35. <view class="div ui-image-wrapper" v-if="showstate == false" :style="'width:'+windowWidth+'px;height:'+windowWidth+'px'">
  36. <image mode="aspectFit" class="img product-img" :src="item.goods_image_url">
  37. </view>
  38. <view class="div ui-image-wrapper" v-else>
  39. <image mode="aspectFit" class="img product-img" :src="item.goods_image_url">
  40. </view>
  41. <view class="div flex-right">
  42. <view class="div product-header">
  43. <text class="h3 title clear-bottom">{{ item.goods_name }}</text>
  44. </view>
  45. <view class="div goods_salenum">销量:{{ item.goods_salenum }}</view>
  46. <view class="div p-info">
  47. <view class="div p-price">
  48. ¥<text class="span price">{{ item.goods_price }}</text>
  49. </view>
  50. <text v-if="item.is_platform_store" class="span platform_store">自营</text>
  51. </view>
  52. </view>
  53. </view>
  54. </view>
  55. </view>
  56. <view class="div loading-wrapper" v-if="goodsList.length > 0">
  57. <view class="p common-no-more" v-if='!isMore'>没有更多了</view>
  58. <uni-load-more status="loading" color='#e93b3d' v-if='isMore'></uni-load-more>
  59. </view>
  60. <empty-record v-if='goodsList.length <= 0 && !isMore'></empty-record>
  61. </scroll-view>
  62. </view>
  63. <view class="show-wrapper" :class="showstate?'showlist':'showimg'" @click='Changeshow()'></view>
  64. </view>
  65. <!--属性筛选Begin-->
  66. <uni-popup background-color="#fff" ref="showAttribute" type="right">
  67. <view :style="'width:'+(screenWidth*.8)+'px'" class="common-popup-wrapper">
  68. <view class="div filter-attribute">
  69. <view class="dl" v-if="attribute.brand_array.length!=0">
  70. <view class="dt">品牌</view>
  71. <view class="dd clearfix">
  72. <text class="a" v-for="(item, index) in attribute.brand_array" :key="index" :class="{'selected':params.b_id==item.brand_id}" @click="checkBrand(item)">{{item.brand_name}}</text>
  73. </view>
  74. </view>
  75. <view class="dl" v-for="(attr_info, attr_info_key, attr_info_index) in attribute.attr_array" :key="attr_info_key">
  76. <view class="dt">
  77. {{attr_info.name}}
  78. </view>
  79. <view class="dd clearfix">
  80. <text class="a" v-for="(item,index) in attr_info.value" :key="index" :class="{'selected':checked_attribute[attr_info_index]==item.attrvalue_id}" @click="checkAttribute(attr_info_index,item)">{{item.attrvalue_name}}</text>
  81. </view>
  82. </view>
  83. <view class="div common-btn ds-button-large mt-10" @click="confirmAttribute()">确定</view>
  84. <view class="div common-btn ds-button-large default mt-10" @click="cancelAttribute()">重置</view>
  85. </view>
  86. </view>
  87. </uni-popup>
  88. <!--属性筛选End-->
  89. </view>
  90. </view>
  91. </template>
  92. <script>
  93. import { urlencode,getFontSize } from '@/util/common'
  94. import EmptyRecord from '../../EmptyRecord'
  95. import { mapState } from 'vuex'
  96. import { searchGoodsList, getAttribute } from '../../../api/homesearch'
  97. export default {
  98. name: 'CommonGoodsList',
  99. props: [],
  100. components: {
  101. EmptyRecord
  102. },
  103. data(){
  104. return {
  105. query:{},
  106. screenWidth:0,
  107. sortkey: [
  108. {
  109. key: '',
  110. order: '',
  111. name: '综合排序',
  112. isMore: true,
  113. id: 0,
  114. child: [
  115. {
  116. key: '',
  117. order: '',
  118. name: '综合排序',
  119. isMore: false,
  120. id: 3
  121. },
  122. {
  123. key: 'goods_click',
  124. order: '',
  125. name: '人气最高',
  126. isMore: false,
  127. id: 4
  128. },
  129. {
  130. key: 'goods_price',
  131. order: '',
  132. name: '价格高到低',
  133. isMore: false,
  134. id: 5
  135. },
  136. {
  137. key: 'goods_price',
  138. order: 'asc',
  139. name: '价格低到高',
  140. isMore: false,
  141. id: 6
  142. }
  143. ]
  144. },
  145. {
  146. key: 'goods_salenum',
  147. order: '',
  148. name: '销量排序',
  149. isMore: false,
  150. id: 1
  151. },
  152. {
  153. key: 'goods_addtime',
  154. order: '',
  155. name: '新品',
  156. isMore: false,
  157. id: 2
  158. }
  159. ], // 排序数据
  160. showstate: false, //显示状态
  161. currentSortKey: {}, // 当前选中的排序
  162. childSort: [], // 综合筛选
  163. sort: {}, // 综合筛选子集
  164. isShowMore: false, // 是否显示筛选模态框
  165. params: {
  166. b_id: '',
  167. cate_id: '',
  168. a_id: '', // 规格属性
  169. is_exchange: 0,
  170. is_hot: 0,
  171. activity: null,
  172. sort_key: '', // 排序键
  173. sort_order: '', // 排序键, //排序值
  174. page: 0,
  175. keyword: '',
  176. xianshi: ''
  177. },
  178. // 当前商品分类所对应的属性
  179. attribute: {
  180. brand_array: [],
  181. attr_array: []
  182. },
  183. checked_attribute: [], // 当前已选择的属性对应的值
  184. goodsList: [], // 商品列表
  185. loading: false, // 是否加载更多
  186. isMore: true // 是否有更多
  187. }
  188. },
  189. computed: {
  190. windowWidth: function () {
  191. const res = uni.getSystemInfoSync()
  192. var width=res.windowWidth
  193. var size=getFontSize()
  194. return (width-3*.6*size)/2
  195. },
  196. },
  197. mounted(){
  198. var pages = getCurrentPages()
  199. var page = pages[pages.length - 1]
  200. this.query = page.options
  201. this.params.b_id=this.query.b_id ? this.query.b_id : ''
  202. this.params.cate_id=this.query.cate_id ? this.query.cate_id : ''
  203. this.params.a_id=this.query.a_id ? this.query.a_id : ''
  204. this.params.sort_key=this.query.sort_key ? this.query.sort_key : ''
  205. this.params.sort_order=this.query.sort_order ? this.query.sort_order : ''
  206. this.params.keyword=this.query.keywords ? this.query.keywords : ''
  207. this.params.xianshi=this.query.xianshi ? this.query.xianshi : ''
  208. this.screenWidth=uni.getSystemInfoSync().screenWidth
  209. this.currentSortKey = this.sortkey[0]
  210. this.childSort = this.currentSortKey.child
  211. this.sort = this.childSort[0]
  212. // 获取属性参数
  213. getAttribute(this.params).then(res => {
  214. this.attribute = res.result
  215. })
  216. this.getMore()
  217. },
  218. methods:{
  219. showPopup(id){
  220. this.$refs[id].open()
  221. },
  222. hidePopup(id){
  223. this.$refs[id].close()
  224. },
  225. // 品牌筛选
  226. checkBrand (item) {
  227. this.params.b_id = item.brand_id
  228. },
  229. // 属性筛选
  230. checkAttribute (index, item) {
  231. this.checked_attribute.splice(index, 1, item.attrvalue_id)
  232. this.params.a_id = this.checked_attribute.join('_')
  233. },
  234. confirmAttribute () {
  235. this.hidePopup('showAttribute')
  236. this.getGoodsList()
  237. },
  238. cancelAttribute () {
  239. this.checked_attribute = []
  240. this.params.a_id = ''
  241. this.params.b_id = ''
  242. },
  243. // closeFiler: 关闭下拉筛选模态框
  244. closeFiler () {
  245. this.isShowMore = false
  246. },
  247. // isShowDroupMenu: 点击显示下拉框, 并且显示模态框
  248. isShowDroupMenu () {
  249. let item = this.currentSortKey
  250. if (item.isMore) {
  251. this.isShowMore = true
  252. } else {
  253. this.isShowMore = false
  254. }
  255. },
  256. /**
  257. * setActiveSortkey: 点击切换数据并设置选中的样式
  258. * @param: item 当前选中的item
  259. */
  260. setActiveSortkey (item, index) {
  261. this.currentSortKey = item
  262. if (item.isMore) {
  263. this.isShowMore = !this.isShowMore
  264. } else {
  265. this.closeFiler()
  266. this.getValue()
  267. }
  268. },
  269. /**
  270. * getValue: 向父级组件发送改变列表事件, 并传递当前的sort_key, sort_order
  271. */
  272. getValue () {
  273. let data = this.getSortValue()
  274. let res = data
  275. this.params.page = 1
  276. this.goodsList = []
  277. this.loading = false
  278. this.isMore = true
  279. this.setParamsByData(res)
  280. this.getGoodsList()
  281. },
  282. /**
  283. * getSortValue: 获取排序值
  284. */
  285. getSortValue () {
  286. let sort = this.currentSortKey
  287. let value = { 'sort_key': '', 'sort_order': '' }
  288. if (sort.isMore) {
  289. value.sort_key = this.sort.key
  290. value.sort_order = this.sort.order
  291. } else {
  292. value.sort_key = sort.key
  293. value.sort_order = sort.order
  294. }
  295. return value
  296. },
  297. /**
  298. * getSortChild: 获取综合筛选的子集, 关闭父级的阴影模态框, 关闭子集, 获取列表数据
  299. * @param: item 模态框的item
  300. */
  301. getSortChild (item) {
  302. this.sort = item
  303. this.isShowMore = !this.isShowMore
  304. this.getValue()
  305. },
  306. /*
  307. * getMore: 无限滚动加载
  308. */
  309. getMore () {
  310. this.loading = true
  311. this.params.page = ++this.params.page
  312. if (this.isMore) {
  313. this.loading = false
  314. this.getGoodsList(true)
  315. }
  316. },
  317. /**
  318. * getGoodsList: 获取商品列表
  319. * @param: ispush ? true :false 是否需要向商品列表追加数据
  320. */
  321. getGoodsList (ispush) {
  322. searchGoodsList(
  323. this.params
  324. ).then(res => {
  325. this.buildData(ispush, res)
  326. })
  327. },
  328. /**
  329. * getList: 构建数据
  330. * @param: ispush 是否改变向元数据追加数据
  331. * @param: res 接口请求返回的数据
  332. */
  333. buildData (ispush, res) {
  334. if (res) {
  335. if (ispush) {
  336. this.goodsList = this.goodsList.concat(res.result.goods_list)
  337. } else {
  338. this.goodsList = res.result.goods_list
  339. }
  340. // for (var i=0;i< this.goodsList.length;i++) {
  341. // console.log("item",this.goodsList[i]);
  342. // }
  343. this.isMore = res.result.hasmore
  344. }
  345. },
  346. /**
  347. * 根据事件传递的值来对请求列表重新赋值
  348. * @param data 事件传递的参数
  349. */
  350. setParamsByData (data) {
  351. let params = this.params
  352. for (let item in params) {
  353. for (let list in data) {
  354. if (item === list) {
  355. params[item] = data[list]
  356. }
  357. }
  358. }
  359. return params
  360. },
  361. goDetail (goods_id) {
  362. uni.navigateTo({url: '/pages/home/goodsdetail/Goodsdetail'+'?'+urlencode( { 'goods_id': goods_id } )})
  363. },
  364. //切换商品展示
  365. Changeshow(){
  366. if(this.showstate == false){
  367. this.showstate = true
  368. }else{
  369. this.showstate = false
  370. }
  371. }
  372. }
  373. }
  374. </script>
  375. <style lang='scss' scoped>
  376. .scroll-view-wrapper{display: flex;flex-direction: column;}
  377. .scroll-view{flex:1}
  378. .common-goods-list{}
  379. .ui-goodslist-filter {
  380. width: auto;
  381. padding-top:.5rem;
  382. background: #fff;
  383. .ul.filter-list{
  384. display: flex;
  385. width: auto;
  386. justify-content: space-around;
  387. align-content: center;
  388. align-items: center;
  389. border: 0;
  390. .li{
  391. font-size: $subFontSize;
  392. color: #333;
  393. border-bottom: .1rem solid transparent;
  394. position: relative;
  395. flex-basis: 4.54rem;
  396. text-align: center;
  397. height: 1.9rem;
  398. padding: 0;
  399. line-height: 1.9rem;
  400. .a {
  401. height: 1.9rem;
  402. display: inline-block;
  403. }
  404. .img {
  405. height: .18rem;
  406. width: .36rem;
  407. vertical-align: middle;
  408. }
  409. .iconfont{display: inline-block}
  410. }
  411. .li.sortactive {
  412. .a {
  413. color:$primaryColor;
  414. }
  415. .iconfont{color:$primaryColor;}
  416. .iconfont.active{transform: rotate(180deg);}
  417. }
  418. .li.sortnormal {
  419. border-bottom-color: transparent;
  420. .a {
  421. color: #333;
  422. }
  423. }
  424. .arrow-icon {
  425. width: .54rem;
  426. height: .54rem;
  427. }
  428. }
  429. .sort-model {
  430. position: absolute;
  431. left: 0;
  432. width: 100%;
  433. z-index: 10;
  434. .div {
  435. color: #333;
  436. padding: .68rem;
  437. font-size: $fontSize;
  438. background-color: #fff;
  439. margin: 0;
  440. border-bottom: .045rem solid #E8EAED;
  441. cursor: pointer;
  442. display: flex;
  443. width: auto;
  444. justify-content: space-between;
  445. align-content: center;
  446. align-items: center;
  447. .img {
  448. float: right;
  449. width: .7rem;
  450. height: .7rem;
  451. }
  452. &.active {
  453. color: $primaryColor;
  454. }
  455. }
  456. }
  457. }
  458. .goodslist-body{background: #fff}
  459. .flex-wrapper.goodslist{
  460. .product-list{
  461. padding-right: .6rem;
  462. .ui-product-body {
  463. .list {
  464. display: flex;
  465. width: auto;
  466. align-items: center;
  467. justify-content: space-between;
  468. margin: .5rem $pageSpace;
  469. position: relative;
  470. box-shadow: 0px 4px 4px #f7f7f7;
  471. .div.ui-image-wrapper {
  472. width: 6rem;
  473. height: 6rem;
  474. position: relative;
  475. display: flex;
  476. justify-content: center;
  477. align-content: center;
  478. align-items: center;
  479. flex-basis: 6rem;
  480. flex-shrink: 0;
  481. background-position:center center!important;
  482. background-size:4.54rem 4.54rem;
  483. background-repeat:no-repeat;
  484. -webkit-background-size: cover;
  485. -moz-background-size: cover;
  486. -o-background-size: cover;
  487. background-size: cover;
  488. .img.product-img{
  489. width: 6rem;
  490. height: 6rem;
  491. flex-basis: 6rem;
  492. flex-shrink: 0;
  493. border-radius: .4rem;
  494. }
  495. .img.product-img[lazy=loading] {
  496. width: 1.36rem;
  497. height: 1.36rem;
  498. }
  499. .img.product-im[lazy=error] {
  500. width: 1.36rem;
  501. height: 1.36rem;
  502. }
  503. .img.product-img[lazy=loaded] {
  504. width: 6rem;
  505. height: 6rem;
  506. flex-basis: 6rem;
  507. flex-shrink: 0;
  508. background:rgba(255,255,255,1);
  509. }
  510. .span {
  511. position: absolute;
  512. height:.9rem;
  513. background:rgba(243,244,245,1);
  514. line-height: .9rem;
  515. text-align: center;
  516. font-size:$fontSize;
  517. color:$primaryColor;
  518. width: 6rem;
  519. bottom: 0;
  520. left: 0;
  521. }
  522. }
  523. .flex-right {
  524. padding-left: .63rem;
  525. width: 100%;
  526. position:relative;
  527. .title {
  528. color: #333;
  529. font-size:$subFontSize;
  530. height:2rem;
  531. line-height:1rem;
  532. height:2rem;
  533. font-weight: normal;
  534. overflow: hidden;
  535. margin-bottom: .4rem;
  536. &.clear-bottom {
  537. margin-bottom: 0;
  538. }
  539. }
  540. .product-header {
  541. margin-bottom: .5rem;
  542. display: flex;
  543. align-items: center;
  544. }
  545. .p-price {
  546. color: $primaryColor;
  547. font-size:$fontSize;
  548. flex:1;
  549. .price{font-size:$mainFontSize}
  550. }
  551. .goods_salenum{font-size:$fontSize;color:$descTextColor;}
  552. .p-info {
  553. display: flex;
  554. align-items: center;
  555. margin-top:.5rem;
  556. .platform_store{font-size:$h6;color: #fff;background: $primaryColor;border-radius: .13rem;padding:.1rem .2rem;margin-right: .5rem;}
  557. }
  558. }
  559. }
  560. }
  561. }
  562. }
  563. .flex-wrapper.goodsimg{
  564. .product-list{
  565. display: flex;
  566. flex-wrap: wrap;
  567. padding-right: .6rem;
  568. .ui-product-body{
  569. flex-direction: column;
  570. justify-content: flex-end;
  571. width:50%;box-sizing:border-box;
  572. .list{
  573. box-shadow: 0px 2px 4px #ececec;
  574. margin-left:$pageSpace;
  575. margin-bottom:.5rem;
  576. border-radius:.4rem;
  577. .ui-image-wrapper{
  578. .product-img{
  579. align-self: center;
  580. width:100%;
  581. box-sizing:border-box;
  582. border-radius:.4rem;
  583. }
  584. }
  585. .flex-right{
  586. padding:0 .3rem;
  587. .product-header{
  588. color: $formInputColor;
  589. font-size: $subFontSize;
  590. line-height:.8rem;
  591. height:1.6rem;
  592. margin-top: 0.4rem;
  593. overflow: hidden;
  594. display: -webkit-box;
  595. -webkit-box-orient: vertical;
  596. -webkit-line-clamp: 2;
  597. }
  598. .goods_salenum{
  599. color: #A2A6AD;
  600. font-size: 0.6rem;
  601. margin: .2rem 0;
  602. }
  603. .p-info{
  604. display: flex;
  605. justify-content: space-between;
  606. padding-bottom:.5rem;
  607. .p-price{
  608. color: $primaryColor;
  609. font-size:$fontSize;
  610. .price{
  611. font-size:$mainFontSize
  612. }
  613. }
  614. .platform_store{
  615. font-size: 0.5rem;
  616. color: #fff;
  617. background: #FB2630;
  618. border-radius: 0.13rem;
  619. padding: 0.1rem 0.2rem;
  620. margin-right: 0.5rem;
  621. }
  622. }
  623. }
  624. }
  625. }
  626. }
  627. }
  628. .filter-attribute{padding:0.5rem;height: 100%;overflow: hidden;overflow-y: scroll}
  629. .filter-attribute .dl{width:100%;}
  630. .filter-attribute .dt{height:1.2rem;width:100%;overflow: hidden;font-size:$h2;color: #333;}
  631. .filter-attribute .dd{}
  632. .filter-attribute .dd .a{position: relative;display:inline-block;color: #666;font-size:$fontSize;text-align:center;background-color: #f7f7f7;border-radius:0.2rem;height:1.5rem;line-height:1.5rem;margin:0.5rem 1.5%;width:30%;}
  633. .filter-attribute .dd .a.selected{color: $primaryColor;background-color: #fdf0f0;}
  634. .filter-attribute .dd .a.selected::after{content: "";position: absolute;right: 0;bottom: 0;width: 15px;height: 15px;border-radius: 0 0 2px 0;background: url("../../../static/image/home/attribute_selected.png") no-repeat;background-size: 15px auto;overflow: hidden;z-index: 1;}
  635. .loading-wrapper{text-align: center}
  636. .show-wrapper{
  637. position: fixed;
  638. right: 10px;
  639. bottom: 100px;
  640. z-index: 101;
  641. width: 1.6rem;
  642. height: 1.6rem;
  643. background: #000;
  644. line-height: 1.6rem;
  645. background: hsla(0,0%,100%,.9) no-repeat 50%;
  646. border: 1px solid #ccc;
  647. border-radius: 50%;
  648. overflow: hidden;
  649. clear: both;
  650. }
  651. .showimg{
  652. background-image: url("../../../static/image/home/row.png");
  653. background-size: 16px;
  654. }
  655. .showlist{
  656. background-image: url("../../../static/image/home/square.png");
  657. background-size: 16px;
  658. }
  659. </style>