CommonStoreList.vue 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563
  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-store-list">
  3. <view class="div ui-storelist-filter">
  4. <view class="ul filter-list">
  5. <view class="li item"
  6. v-for='(item, index) in sortkey'
  7. v-bind:key='item.id'
  8. v-on:click='setActiveSortkey(item, index)'
  9. v-bind:class="{'sortactive': item.id == currentSortKey.id, 'sortnormal' : item.id != currentSortKey.id}">
  10. <text class="a" v-if='!item.isMore'>{{item.name}}</text>
  11. <text class="a" v-else>{{sort.name}}</text>
  12. <text class="span iconfont" :class="isShowMore?'active':''" v-if="item.isMore">&#xe6ea;</text>
  13. </view>
  14. </view>
  15. <view class="div sort-model" v-if='isShowMore' >
  16. <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}">
  17. <text class="a">{{item.name}}</text>
  18. <text class="span iconfont" v-if="item.id == sort.id">&#xe69b;</text>
  19. </view>
  20. </view>
  21. </view>
  22. <view class="scroll-view div storelist-body show-store-list" style="position:relative">
  23. <!-- 无限加载滚动列表 -->
  24. <scroll-view style="position: absolute;top:0;right:0;left:0;bottom:0" class="scroll-view div flex-wrapper" @scrolltolower="getMore" scroll-y="true">
  25. <view class="div ui-product-body"
  26. v-for='(item, index) in storeList'
  27. v-bind:key='index'
  28. >
  29. <view class="div list-wrapper" v-on:click='goDetail(item.store_id)'>
  30. <view class="div list">
  31. <view class="div ui-image-wrapper">
  32. <image mode="aspectFit" class="img product-img" :src="item.store_avatar">
  33. </view>
  34. <view class="div flex-right">
  35. <view class="div product-header">
  36. <text class="h3 title clear-bottom">{{ item.store_name }}</text>
  37. </view>
  38. <view class="div store-info-wrapper">
  39. <view class="div store-info">
  40. <view class="div collect-info">已有 {{item.store_collect}} 人关注</view>
  41. <view class="div sub-title">
  42. <uni-rate :size="18" :readonly="true" :value="parseInt(item.store_credit_percent/100*5)"/>
  43. </view>
  44. </view>
  45. <view class="div">
  46. <view class="div btn" :class="{'active':item.is_favorate}"><text class="i iconfont">&#xe610;</text>关注</view>
  47. <view class="div distance" v-if="params.sort_key=='distance'">{{item.distance}}m</view>
  48. </view>
  49. </view>
  50. </view>
  51. </view>
  52. <view class="div goods-list" v-if="item.goods_list && item.goods_list.length">
  53. <view class="div goods-item" v-for="(goods,gindex) in item.goods_list" :key="gindex">
  54. <view class="div goods-image"><image mode="aspectFit" class="img" :src="goods.goods_image_url"></view>
  55. <view class="div goods-price">¥{{goods.goods_price}}</view>
  56. </view>
  57. </view>
  58. </view>
  59. </view>
  60. <view class="div loading-wrapper" v-if="storeList.length > 0">
  61. <view class="p common-no-more" v-if='!isMore'>没有更多了</view>
  62. <uni-load-more status="loading" color='#e93b3d' v-if='isMore'></uni-load-more>
  63. </view>
  64. <empty-record v-if='storeList.length <= 0 && !isMore'></empty-record>
  65. </scroll-view>
  66. </view>
  67. </view>
  68. </view>
  69. </template>
  70. <script>
  71. import { urlencode } from '@/util/common'
  72. import EmptyRecord from '../../EmptyRecord'
  73. import { mapState } from 'vuex'
  74. import { getStoreList,getStoreNearbyList } from '../../../api/homesearch'
  75. export default {
  76. name: 'CommonStoreList',
  77. props: [],
  78. components: {
  79. EmptyRecord
  80. },
  81. data(){
  82. return {
  83. dialog:{},
  84. query:{},
  85. sortkey: [
  86. {
  87. key: '',
  88. name: '综合排序',
  89. isMore: true,
  90. id: 0,
  91. child: [
  92. {
  93. key: '',
  94. name: '综合排序',
  95. isMore: false,
  96. id: 3
  97. },
  98. {
  99. key: 'distance',
  100. name: '距离排序',
  101. isMore: false,
  102. id: 4
  103. }
  104. ]
  105. },
  106. {
  107. key: 'store_sales',
  108. name: '销量排序',
  109. isMore: false,
  110. id: 1
  111. },
  112. {
  113. key: 'store_credit',
  114. name: '评分最高',
  115. isMore: false,
  116. id: 2
  117. }
  118. ], // 排序数据
  119. currentSortKey: {}, // 当前选中的排序
  120. childSort: [], // 综合筛选
  121. sort: {}, // 综合筛选子集
  122. isShowMore: false, // 是否显示筛选模态框
  123. params: {
  124. brand: '',
  125. category: '',
  126. is_exchange: 0,
  127. is_hot: 0,
  128. activity: null, // TODO: 确认activity的值
  129. sort_key: '',
  130. sort_value: 2,
  131. page: 0,
  132. keyword: ''
  133. },
  134. storeList: [], // 商品列表
  135. loading: false, // 是否加载更多
  136. isMore: true // 是否有更多
  137. }
  138. },
  139. computed: {
  140. ...mapState({
  141. member_point: state => state.member.point,
  142. token: state => state.member.token,
  143. })
  144. },
  145. mounted(){
  146. var pages = getCurrentPages()
  147. var page = pages[pages.length - 1]
  148. this.query = page.options
  149. this.params.brand=this.query.brand ? this.query.brand : ''
  150. this.params.category=this.query.storeclass_id ? this.query.storeclass_id : ''
  151. this.params.sort_key=this.query.sort_key ? this.query.sort_key : ''
  152. this.params.keyword=this.query.keywords ? this.query.keywords : ''
  153. this.currentSortKey = this.sortkey[0]
  154. this.childSort = this.currentSortKey.child
  155. this.sort = this.childSort[0]
  156. this.getMore()
  157. },
  158. methods:{
  159. closeDialog(){
  160. },
  161. confirmDialog(value){
  162. uni.navigateTo({url:'/pages/home/map/Map'})
  163. },
  164. // closeFiler: 关闭下拉筛选模态框
  165. closeFiler () {
  166. this.isShowMore = false
  167. },
  168. // isShowDroupMenu: 点击显示下拉框, 并且显示模态框
  169. isShowDroupMenu () {
  170. let item = this.currentSortKey
  171. if (item.isMore) {
  172. this.isShowMore = true
  173. } else {
  174. this.isShowMore = false
  175. }
  176. },
  177. /**
  178. * setActiveSortkey: 点击切换数据并设置选中的样式
  179. * @param: item 当前选中的item
  180. */
  181. setActiveSortkey (item, index) {
  182. this.currentSortKey = item
  183. if (item.isMore) {
  184. this.isShowMore = !this.isShowMore
  185. } else {
  186. this.closeFiler()
  187. this.getValue()
  188. }
  189. },
  190. /**
  191. * getValue: 向父级组件发送改变列表事件, 并传递当前的sort_key, sort_value
  192. */
  193. getValue () {
  194. let data = this.getSortValue()
  195. let res = data
  196. this.params.page = 1
  197. this.storeList = []
  198. this.loading = false
  199. this.setParamsByData(res)
  200. if(data.sort_key=='distance'){
  201. if(!this.member_point.lng || !this.member_point.lat){
  202. this.dialog={content:'我们需要先获取您的位置信息',cancelButtonText: '拒绝', confirmButtonText: '同意'}
  203. this.$refs.confirm.open()
  204. }else{
  205. this.getStoreList(false,true)
  206. }
  207. }else{
  208. this.getStoreList()
  209. }
  210. },
  211. /**
  212. * getSortValue: 获取排序值
  213. */
  214. getSortValue () {
  215. let sort = this.currentSortKey
  216. let value = { 'sort_key': '', 'sort_value': '' }
  217. if (sort.isMore) {
  218. value.sort_key = this.sort.key
  219. } else {
  220. value.sort_key = sort.key
  221. }
  222. return value
  223. },
  224. /**
  225. * getSortChild: 获取综合筛选的子集, 关闭父级的阴影模态框, 关闭子集, 获取列表数据
  226. * @param: item 模态框的item
  227. */
  228. getSortChild (item) {
  229. this.sort = item
  230. this.isShowMore = !this.isShowMore
  231. this.getValue()
  232. },
  233. /*
  234. * getMore: 无限滚动加载
  235. */
  236. getMore () {
  237. this.loading = true
  238. this.params.page = ++this.params.page
  239. if (this.isMore) {
  240. this.loading = false
  241. this.getStoreList(true)
  242. }
  243. },
  244. /**
  245. * getStoreList: 获取商品列表
  246. * @param: ispush ? true :false 是否需要向商品列表追加数据
  247. */
  248. getStoreList (ispush=false,nearby=false) {
  249. let data = this.params
  250. if(nearby){
  251. getStoreNearbyList(
  252. data.brand,
  253. data.category,
  254. data.keyword,
  255. this.member_point.lng,
  256. this.member_point.lat,
  257. data.sort_key,
  258. data.page,
  259. this.token
  260. ).then(res => {
  261. this.buildData(ispush, res)
  262. })
  263. }else{
  264. getStoreList(
  265. data.brand,
  266. data.category,
  267. data.keyword,
  268. 0,
  269. 0,
  270. data.sort_key,
  271. data.page,
  272. this.token
  273. ).then(res => {
  274. this.buildData(ispush, res)
  275. })
  276. }
  277. },
  278. /**
  279. * getList: 构建数据
  280. * @param: ispush 是否改变向元数据追加数据
  281. * @param: res 接口请求返回的数据
  282. */
  283. buildData (ispush, res) {
  284. if (res) {
  285. if (ispush) {
  286. this.storeList = this.storeList.concat(res.result.store_list)
  287. } else {
  288. this.storeList = res.result.store_list
  289. }
  290. this.isMore = res.result.hasmore
  291. }
  292. },
  293. /**
  294. * 根据事件传递的值来对请求列表重新赋值
  295. * @param data 事件传递的参数
  296. * @returns {params|{brand, category, is_exchange, is_hot, activity, sort_key, sort_value, page, per_page, keyword}}
  297. */
  298. setParamsByData (data) {
  299. let params = this.params
  300. for (let item in params) {
  301. for (let list in data) {
  302. if (item === list) {
  303. params[item] = data[list]
  304. }
  305. }
  306. }
  307. return params
  308. },
  309. goDetail (store_id) {
  310. uni.navigateTo({url: '/pages/home/storedetail/Storedetail'+'?'+urlencode( { 'id': store_id } )})
  311. }
  312. }
  313. }
  314. </script>
  315. <style lang='scss' scoped>
  316. .scroll-view-wrapper{display: flex;flex-direction: column;}
  317. .scroll-view{flex:1}
  318. .ui-storelist-filter {
  319. width: auto;
  320. background: #fff;
  321. .ul.filter-list{
  322. display: flex;
  323. width: auto;
  324. justify-content: space-around;
  325. align-content: center;
  326. align-items: center;
  327. border: 0;
  328. border-top: 1px solid #E8EAED;
  329. border-bottom: 1px solid #E8EAED;
  330. .li{
  331. font-size:$subFontSize;
  332. color: #333;
  333. border-bottom: 0.1rem solid transparent;
  334. position: relative;
  335. flex-basis: 5rem;
  336. text-align: center;
  337. height: 2.1rem;
  338. padding: 0;
  339. line-height: 2.1rem;
  340. .a {
  341. height: 2.1rem;
  342. display: inline-block;
  343. }
  344. .img {
  345. height: 0.2rem;
  346. width: 0.4rem;
  347. vertical-align: middle;
  348. }
  349. .iconfont{display: inline-block}
  350. }
  351. .li.sortactive {
  352. border-bottom-color:$primaryColor;
  353. .a {
  354. color:$primaryColor;
  355. }
  356. .iconfont{color:$primaryColor;}
  357. .iconfont.active{transform: rotate(180deg);}
  358. }
  359. .li.sortnormal {
  360. border-bottom-color: transparent;
  361. .a {
  362. color: #333;
  363. }
  364. }
  365. .arrow-icon {
  366. width: 0.6rem;
  367. height: 0.6rem;
  368. }
  369. }
  370. .sort-model {
  371. position: absolute;
  372. left: 0;
  373. width: 100%;
  374. z-index: 10;
  375. .div {
  376. color: #333;
  377. padding: 0.75rem;
  378. font-size:$fontSize;
  379. background-color: #fff;
  380. margin: 0;
  381. border-bottom: 1px solid #E8EAED;
  382. cursor: pointer;
  383. display: flex;
  384. width: auto;
  385. justify-content: space-between;
  386. align-content: center;
  387. align-items: center;
  388. .img {
  389. float: right;
  390. width: 0.8rem;
  391. height: 0.8rem;
  392. }
  393. &.active {
  394. color: $primaryColor;
  395. }
  396. }
  397. }
  398. }
  399. .ui-product-body {
  400. .goods-list{padding:.8rem .5rem;border-top:1px dashed #eee;overflow: hidden;background:#fff;
  401. .goods-item{float:left;width:25%;text-align: center;
  402. .goods-image {margin-bottom:.2rem;
  403. .img{width:3.5rem;height: 3.5rem;border-radius:.3rem;}
  404. }
  405. .goods-price{color:$primaryColor;font-size:$subFontSize;white-space: nowrap;overflow: hidden;text-overflow:ellipsis;width:100%}
  406. }
  407. }
  408. .list-wrapper{margin-bottom:.5rem;}
  409. .list {
  410. display: flex;
  411. width: auto;
  412. align-items: center;
  413. justify-content: space-between;
  414. padding:0.5rem;
  415. position: relative;
  416. background:#fff;
  417. .div.ui-image-wrapper {
  418. width: 3rem;
  419. height: 3rem;
  420. position: relative;
  421. display: flex;
  422. justify-content: center;
  423. align-content: center;
  424. align-items: center;
  425. flex-basis: 3rem;
  426. flex-shrink: 0;
  427. background-position:center center!important;
  428. background-size:5rem 5rem;
  429. background-repeat:no-repeat;
  430. -webkit-background-size: cover;
  431. -moz-background-size: cover;
  432. -o-background-size: cover;
  433. background-size: cover;
  434. .img.product-img{
  435. width: 3rem;
  436. height: 3rem;
  437. flex-basis: 3rem;
  438. flex-shrink: 0;
  439. border-radius:.3rem;
  440. }
  441. .span {
  442. position: absolute;
  443. height:1rem;
  444. background:rgba(243,244,245,1);
  445. line-height: 1rem;
  446. text-align: center;
  447. font-size:$subFontSize;
  448. color:$primaryColor;
  449. width: 5.5rem;
  450. bottom: 0;
  451. left: 0;
  452. }
  453. }
  454. .flex-right {
  455. padding-top:.5rem;
  456. padding-left: 0.7rem;
  457. width: 100%;
  458. position:relative;
  459. .title {
  460. color: #333;
  461. font-size:$subFontSize;
  462. font-weight: normal;
  463. display:-moz-box;
  464. display:-webkit-box;
  465. -webkit-line-clamp: 2;
  466. -moz-line-clamp: 2;
  467. -moz-box-orient:vertical;
  468. -webkit-box-orient:vertical;
  469. box-orient:vertical;
  470. overflow: hidden;
  471. margin-bottom: 0.4rem;
  472. &.clear-bottom {
  473. margin-bottom: 0;
  474. }
  475. }
  476. .store-info-wrapper{display: flex;
  477. .store-info{flex:1}
  478. .btn{float:right;width:3rem;font-size:$subFontSize;color:#e1e1e1;text-align: center;border:1px solid #e1e1e1;border-radius:1rem;height: 1rem;line-height: 1rem;}
  479. .btn.active{border-color:$primaryColor;background:$primaryColor;color:#fff}
  480. .distance{font-size:$subFontSize;color:#999}
  481. }
  482. .product-header {
  483. display: flex;
  484. align-items: center;
  485. }
  486. .collect-info{font-size:$fontSize;color:#999}
  487. .sub-title {
  488. color: #55595F;
  489. font-size:$subFontSize;
  490. display:-moz-box;
  491. display:-webkit-box;
  492. -webkit-line-clamp: 1;
  493. -moz-line-clamp: 1;
  494. -moz-box-orient:vertical;
  495. -webkit-box-orient:vertical;
  496. box-orient:vertical;
  497. overflow: hidden;
  498. margin-bottom: 0.4rem;
  499. }
  500. .price {
  501. margin-bottom: 0.4rem;
  502. .span {
  503. &:first-child {
  504. color: $primaryColor;
  505. font-size:$h2;
  506. }
  507. &:last-child {
  508. color: #A4AAB3;
  509. font-size:$fontSize;
  510. text-decoration: line-through;
  511. }
  512. }
  513. }
  514. .sendway {
  515. display: flex;
  516. justify-content: space-between;
  517. align-items: center;
  518. font-size:$fontSize;
  519. font-weight: 'Regular';
  520. .span{
  521. color: #7C7F88;
  522. &.self-support {
  523. font-size:$h6;
  524. color: $primaryColor;
  525. border: 1px solid $primaryColor;
  526. border-radius: 0.1rem;
  527. width: 1.6rem;
  528. height: 0.8rem;
  529. line-height: 0.8rem;
  530. text-align: center;
  531. }
  532. }
  533. }
  534. }
  535. }
  536. }
  537. </style>