GoodslistBody.vue 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667
  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:0" 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. this.isMore = res.result.hasmore
  341. }
  342. },
  343. /**
  344. * 根据事件传递的值来对请求列表重新赋值
  345. * @param data 事件传递的参数
  346. */
  347. setParamsByData (data) {
  348. let params = this.params
  349. for (let item in params) {
  350. for (let list in data) {
  351. if (item === list) {
  352. params[item] = data[list]
  353. }
  354. }
  355. }
  356. return params
  357. },
  358. goDetail (goods_id) {
  359. uni.navigateTo({url: '/pages/home/goodsdetail/Goodsdetail'+'?'+urlencode( { 'goods_id': goods_id } )})
  360. },
  361. //切换商品展示
  362. Changeshow(){
  363. if(this.showstate == false){
  364. this.showstate = true
  365. }else{
  366. this.showstate = false
  367. }
  368. }
  369. }
  370. }
  371. </script>
  372. <style lang='scss' scoped>
  373. .scroll-view-wrapper{display: flex;flex-direction: column;}
  374. .scroll-view{flex:1}
  375. .common-goods-list{}
  376. .ui-goodslist-filter {
  377. width: auto;
  378. padding-top:.5rem;
  379. background: #fff;
  380. .ul.filter-list{
  381. display: flex;
  382. width: auto;
  383. justify-content: space-around;
  384. align-content: center;
  385. align-items: center;
  386. border: 0;
  387. .li{
  388. font-size: $subFontSize;
  389. color: #333;
  390. border-bottom: .1rem solid transparent;
  391. position: relative;
  392. flex-basis: 4.54rem;
  393. text-align: center;
  394. height: 1.9rem;
  395. padding: 0;
  396. line-height: 1.9rem;
  397. .a {
  398. height: 1.9rem;
  399. display: inline-block;
  400. }
  401. .img {
  402. height: .18rem;
  403. width: .36rem;
  404. vertical-align: middle;
  405. }
  406. .iconfont{display: inline-block}
  407. }
  408. .li.sortactive {
  409. .a {
  410. color:$primaryColor;
  411. }
  412. .iconfont{color:$primaryColor;}
  413. .iconfont.active{transform: rotate(180deg);}
  414. }
  415. .li.sortnormal {
  416. border-bottom-color: transparent;
  417. .a {
  418. color: #333;
  419. }
  420. }
  421. .arrow-icon {
  422. width: .54rem;
  423. height: .54rem;
  424. }
  425. }
  426. .sort-model {
  427. position: absolute;
  428. left: 0;
  429. width: 100%;
  430. z-index: 10;
  431. .div {
  432. color: #333;
  433. padding: .68rem;
  434. font-size: $fontSize;
  435. background-color: #fff;
  436. margin: 0;
  437. border-bottom: .045rem solid #E8EAED;
  438. cursor: pointer;
  439. display: flex;
  440. width: auto;
  441. justify-content: space-between;
  442. align-content: center;
  443. align-items: center;
  444. .img {
  445. float: right;
  446. width: .7rem;
  447. height: .7rem;
  448. }
  449. &.active {
  450. color: $primaryColor;
  451. }
  452. }
  453. }
  454. }
  455. .goodslist-body{background: #fff}
  456. .flex-wrapper.goodslist{
  457. .product-list{
  458. padding-right: .6rem;
  459. .ui-product-body {
  460. .list {
  461. display: flex;
  462. width: auto;
  463. align-items: center;
  464. justify-content: space-between;
  465. margin: .5rem $pageSpace;
  466. position: relative;
  467. box-shadow: 0px 4px 4px #f7f7f7;
  468. .div.ui-image-wrapper {
  469. width: 6rem;
  470. height: 6rem;
  471. position: relative;
  472. display: flex;
  473. justify-content: center;
  474. align-content: center;
  475. align-items: center;
  476. flex-basis: 6rem;
  477. flex-shrink: 0;
  478. background-position:center center!important;
  479. background-size:4.54rem 4.54rem;
  480. background-repeat:no-repeat;
  481. -webkit-background-size: cover;
  482. -moz-background-size: cover;
  483. -o-background-size: cover;
  484. background-size: cover;
  485. .img.product-img{
  486. width: 6rem;
  487. height: 6rem;
  488. flex-basis: 6rem;
  489. flex-shrink: 0;
  490. border-radius: .4rem;
  491. }
  492. .img.product-img[lazy=loading] {
  493. width: 1.36rem;
  494. height: 1.36rem;
  495. }
  496. .img.product-im[lazy=error] {
  497. width: 1.36rem;
  498. height: 1.36rem;
  499. }
  500. .img.product-img[lazy=loaded] {
  501. width: 6rem;
  502. height: 6rem;
  503. flex-basis: 6rem;
  504. flex-shrink: 0;
  505. background:rgba(255,255,255,1);
  506. }
  507. .span {
  508. position: absolute;
  509. height:.9rem;
  510. background:rgba(243,244,245,1);
  511. line-height: .9rem;
  512. text-align: center;
  513. font-size:$fontSize;
  514. color:$primaryColor;
  515. width: 6rem;
  516. bottom: 0;
  517. left: 0;
  518. }
  519. }
  520. .flex-right {
  521. padding-left: .63rem;
  522. width: 100%;
  523. position:relative;
  524. .title {
  525. color: #333;
  526. font-size:$subFontSize;
  527. height:2rem;
  528. line-height:1rem;
  529. height:2rem;
  530. font-weight: normal;
  531. overflow: hidden;
  532. margin-bottom: .4rem;
  533. &.clear-bottom {
  534. margin-bottom: 0;
  535. }
  536. }
  537. .product-header {
  538. margin-bottom: .5rem;
  539. display: flex;
  540. align-items: center;
  541. }
  542. .p-price {
  543. color: $primaryColor;
  544. font-size:$fontSize;
  545. flex:1;
  546. .price{font-size:$mainFontSize}
  547. }
  548. .goods_salenum{font-size:$fontSize;color:$descTextColor;}
  549. .p-info {
  550. display: flex;
  551. align-items: center;
  552. margin-top:.5rem;
  553. .platform_store{font-size:$h6;color: #fff;background: $primaryColor;border-radius: .13rem;padding:.1rem .2rem;margin-right: .5rem;}
  554. }
  555. }
  556. }
  557. }
  558. }
  559. }
  560. .flex-wrapper.goodsimg{
  561. .product-list{
  562. display: flex;
  563. flex-wrap: wrap;
  564. padding-right: .6rem;
  565. .ui-product-body{
  566. flex-direction: column;
  567. justify-content: flex-end;
  568. width:50%;box-sizing:border-box;
  569. .list{
  570. box-shadow: 0px 2px 4px #ececec;
  571. margin-left:$pageSpace;
  572. margin-bottom:.5rem;
  573. border-radius:.4rem;
  574. .ui-image-wrapper{
  575. .product-img{
  576. align-self: center;
  577. width:100%;
  578. box-sizing:border-box;
  579. border-radius:.4rem;
  580. }
  581. }
  582. .flex-right{
  583. padding:0 .3rem;
  584. .product-header{
  585. color: $formInputColor;
  586. font-size: $subFontSize;
  587. line-height:.8rem;
  588. height:1.6rem;
  589. margin-top: 0.4rem;
  590. overflow: hidden;
  591. display: -webkit-box;
  592. -webkit-box-orient: vertical;
  593. -webkit-line-clamp: 2;
  594. }
  595. .goods_salenum{
  596. color: #A2A6AD;
  597. font-size: 0.6rem;
  598. margin: .2rem 0;
  599. }
  600. .p-info{
  601. display: flex;
  602. justify-content: space-between;
  603. padding-bottom:.5rem;
  604. .p-price{
  605. color: $primaryColor;
  606. font-size:$fontSize;
  607. .price{
  608. font-size:$mainFontSize
  609. }
  610. }
  611. .platform_store{
  612. font-size: 0.5rem;
  613. color: #fff;
  614. background: #FB2630;
  615. border-radius: 0.13rem;
  616. padding: 0.1rem 0.2rem;
  617. margin-right: 0.5rem;
  618. }
  619. }
  620. }
  621. }
  622. }
  623. }
  624. }
  625. .filter-attribute{padding:0.5rem;height: 100%;overflow: hidden;overflow-y: scroll}
  626. .filter-attribute .dl{width:100%;}
  627. .filter-attribute .dt{height:1.2rem;width:100%;overflow: hidden;font-size:$h2;color: #333;}
  628. .filter-attribute .dd{}
  629. .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%;}
  630. .filter-attribute .dd .a.selected{color: $primaryColor;background-color: #fdf0f0;}
  631. .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;}
  632. .loading-wrapper{text-align: center}
  633. .show-wrapper{
  634. position: fixed;
  635. right: 10px;
  636. bottom: 100px;
  637. z-index: 101;
  638. width: 1.6rem;
  639. height: 1.6rem;
  640. background: #000;
  641. line-height: 1.6rem;
  642. background: hsla(0,0%,100%,.9) no-repeat 50%;
  643. border: 1px solid #ccc;
  644. border-radius: 50%;
  645. overflow: hidden;
  646. clear: both;
  647. }
  648. .showimg{
  649. background-image: url("../../../static/image/home/row.png");
  650. background-size: 16px;
  651. }
  652. .showlist{
  653. background-image: url("../../../static/image/home/square.png");
  654. background-size: 16px;
  655. }
  656. </style>