GroupBuyList.vue 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450
  1. <template><page-meta :root-font-size="fontSize+'px'"></page-meta>
  2. <home-base :show="false"><view style="position: absolute;top:0;right:0;left:0;bottom:0" class="scroll-view-wrapper div container">
  3. <view class="div common-header-wrap">
  4. <view class="status-holder"></view>
  5. <view :style="'height:'+navHeight+'px'"></view>
  6. <view class="common-header-holder"></view>
  7. <view class="common-header-fixed">
  8. <title-header />
  9. <uni-nav-bar title="抢购活动" class="common-header" left-icon="back" @clickLeft="goBack()">
  10. </uni-nav-bar>
  11. </view>
  12. </view>
  13. <view class="div ui-goodslist-filter">
  14. <view class="ul filter-list">
  15. <view class="li item"
  16. v-for='(item, index) in sortkey'
  17. v-bind:key='item.id'
  18. v-on:click='setActiveSortkey(item, index)'
  19. v-bind:class="{'sortactive': item.id == currentSortKey.id, 'sortnormal' : item.id != currentSortKey.id}">
  20. {{item.name}}
  21. </view>
  22. <view class="li item" @click="showPopup('showAttribute')">
  23. <text class="a">筛选</text>
  24. </view>
  25. </view>
  26. </view>
  27. <view class="scroll-view div goodslist-body show-goods-list" style="position:relative">
  28. <!-- 无限加载滚动列表 -->
  29. <scroll-view style="position: absolute;top:0;right:0;left:0;bottom:0" class="div flex-wrapper" @scrolltolower="loadMore" scroll-y="true">
  30. <view class="div" v-if="groupbuyList">
  31. <view class="div ui-product-body"
  32. v-for='(item, index) in groupbuyList'
  33. v-bind:key='index'
  34. >
  35. <view class="div list" v-on:click='goDetail(item)'>
  36. <view class="div ui-image-wrapper">
  37. <image mode="aspectFit" class="img product-img" :src="item.groupbuy_image">
  38. </view>
  39. <view class="div flex-right">
  40. <view class="div product-header">
  41. <text class="h3 title clear-bottom">{{ item.groupbuy_name }}</text>
  42. </view>
  43. <view class="div btn-wrapper">
  44. <view class="div p-price">
  45. <text class="span strong">¥{{ item.groupbuy_price }}</text><text class="span groupbuy_limit_number">¥{{item.goods_price}}</text>
  46. </view>
  47. <view class="div common-btn btn" :class="{'disable':!item.cancelable}">{{item.button_text}}</view>
  48. </view>
  49. </view>
  50. </view>
  51. </view>
  52. <view class="div loading-wrapper" v-if="groupbuyList.length > 0">
  53. <view class="p common-no-more" v-if='!isMore'>没有更多了</view>
  54. <uni-load-more status="loading" color='#e93b3d' v-if='isMore'></uni-load-more>
  55. </view>
  56. <empty-record v-if='groupbuyList.length <= 0 && !isMore'></empty-record>
  57. </view>
  58. </scroll-view>
  59. </view>
  60. <!--属性筛选Begin-->
  61. <uni-popup background-color="#fff" ref="showAttribute" type="right" >
  62. <view :style="'width:'+(screenWidth*.8)+'px'" class="common-popup-wrapper">
  63. <view class="div filter-attribute">
  64. <view class="dl" v-if="groupbuy_classes">
  65. <view class="dt">分类</view>
  66. <view class="dd clearfix" v-if="params.class && groupbuy_classes.children[params.class]">
  67. <text class="a" :class="{'selected':classId==params.s_class}" v-for="(classId,index) in groupbuy_classes.children[params.class]" :key="index" @click="setFilter('s_class',classId)">{{groupbuy_classes.name[classId]}}</text>
  68. </view>
  69. <view class="dd clearfix" v-else>
  70. <text class="a" :class="{'selected':classId==params.class}" v-for="(classId,index) in groupbuy_classes.children[0]" :key="index" @click="setFilter('class',classId)">{{groupbuy_classes.name[classId]}}</text>
  71. </view>
  72. </view>
  73. <view class="dl" v-if="groupbuy_price">
  74. <view class="dt">价格</view>
  75. <view class="dd clearfix">
  76. <text class="a" :class="{'selected':priceItem.gprange_id==params.groupbuy_price}" v-for="(priceItem,index) in groupbuy_price" :key="index" @click="setFilter('groupbuy_price',priceItem.gprange_id)">{{priceItem.gprange_name}}</text>
  77. </view>
  78. </view>
  79. <view class="dl">
  80. <view class="dt">排序</view>
  81. <view class="dd clearfix">
  82. <text class="a" :class="{'selected':params.groupbuy_order_key==1}" @click="setFilter('groupbuy_order_key',1)">价格<text class="i" :class="{'up':params.groupbuy_order_key==1 && params.groupbuy_order==1}"></text></text>
  83. <text class="a" :class="{'selected':params.groupbuy_order_key==2}" @click="setFilter('groupbuy_order_key',2)">折扣<text class="i" :class="{'up':params.groupbuy_order_key==2 && params.groupbuy_order==1}"></text></text>
  84. <text class="a" :class="{'selected':params.groupbuy_order_key==3}" @click="setFilter('groupbuy_order_key',3)">销量<text class="i" :class="{'up':params.groupbuy_order_key==3 && params.groupbuy_order==1}"></text></text>
  85. </view>
  86. </view>
  87. </view>
  88. <view class="div common-btn ds-button-large mt-10" @click="confirmAttribute()">确定</view>
  89. <view class="div common-btn ds-button-large default mt-10" @click="cancelAttribute()">重置</view>
  90. </view>
  91. </uni-popup>
  92. <!--属性筛选End-->
  93. </view></home-base>
  94. </template>
  95. <script>
  96. import {getFontSize} from '@/util/common'
  97. import TitleHeader from '../../TitleHeader'
  98. import { urlencode } from '@/util/common'
  99. import HomeBase from '../HomeBase'
  100. import EmptyRecord from '../../EmptyRecord'
  101. import { getGroupbuyList, getGroupbuyFilter } from '../../../api/homesearch'
  102. export default {
  103. name: 'GroupbuyList',
  104. components:{
  105. TitleHeader,
  106. HomeBase,
  107. EmptyRecord
  108. },
  109. computed:{
  110. fontSize(){
  111. return getFontSize()
  112. },
  113. },
  114. data(){
  115. return {
  116. navHeight: 0,
  117. screenWidth:0,
  118. sortkey: [
  119. {
  120. key: 'online',
  121. name: '正在进行',
  122. isMore: true,
  123. id: 0
  124. },
  125. {
  126. key: 'soon',
  127. name: '即将开始',
  128. isMore: false,
  129. id: 1
  130. },
  131. {
  132. key: 'history',
  133. name: '已经结束',
  134. isMore: false,
  135. id: 2
  136. }
  137. ], // 排序数据
  138. currentSortKey: { id: 0 }, // 当前选中的排序
  139. groupbuyList: false,
  140. params: { 'page': 0, 'per_page': 10 },
  141. loading: false, // 是否加载更多
  142. isMore: true, // 是否有更多
  143. groupbuy_price: false,
  144. groupbuy_classes: false
  145. }
  146. },
  147. created: function () {
  148. getGroupbuyFilter().then(res => {
  149. this.groupbuy_price = res.result.groupbuy_price
  150. this.groupbuy_classes = res.result.groupbuy_classes
  151. })
  152. this.loadMore()
  153. },
  154. mounted(){
  155. // #ifdef MP-WEIXIN
  156. this.navHeight = uni.getMenuButtonBoundingClientRect().height
  157. // #endif
  158. this.screenWidth=uni.getSystemInfoSync().screenWidth
  159. },
  160. methods:{
  161. showPopup(id){
  162. this.$refs[id].open()
  163. },
  164. hidePopup(id){
  165. this.$refs[id].close()
  166. },
  167. goBack(){uni.navigateBack({delta:1})},
  168. loadMore () {
  169. if (this.loading) {
  170. return
  171. }
  172. this.params.page = ++this.params.page
  173. if (this.isMore) {
  174. this.getGroupbuyList(true)
  175. }
  176. },
  177. reload () {
  178. // 重新加载数据
  179. this.params.page = 0
  180. this.isMore = true
  181. this.loading = false
  182. this.groupbuyList = false
  183. this.loadMore()
  184. },
  185. getGroupbuyList () {
  186. this.loading = true
  187. getGroupbuyList(this.params).then(res => {
  188. if (res.result.hasmore) {
  189. this.isMore = true
  190. } else {
  191. this.isMore = false
  192. }
  193. if (this.groupbuyList) {
  194. this.groupbuyList = this.groupbuyList.concat(res.result.groupbuy_list)
  195. } else {
  196. this.groupbuyList = res.result.groupbuy_list
  197. }
  198. this.loading = false
  199. }).catch(function (error) {
  200. uni.hideLoading()
  201. uni.showToast({icon:'none',title: error.message})
  202. this.loading = false
  203. })
  204. },
  205. goDetail (item) {
  206. uni.navigateTo({ url: '/pages/home/goodsdetail/Goodsdetail'+'?'+urlencode( { 'goods_id': item.goods_id } )})
  207. },
  208. setActiveSortkey (item, index) {
  209. this.currentSortKey = item
  210. this.getValue()
  211. },
  212. getValue () {
  213. let data = this.getSortValue()
  214. this.params = data
  215. this.reload()
  216. },
  217. getSortValue () {
  218. let sort = this.currentSortKey
  219. let value = { 'sort_key': '' }
  220. value.sort_key = sort.key
  221. return value
  222. },
  223. setFilter (name, value) {
  224. if (name == 'groupbuy_order_key') {
  225. if (value == this.params[name]) {
  226. this.params['groupbuy_order'] = this.params['groupbuy_order'] == 2 ? 1 : 2
  227. } else {
  228. this.params['groupbuy_order'] = 2
  229. }
  230. }
  231. this.params[name] = value
  232. this.$forceUpdate()
  233. },
  234. confirmAttribute () {
  235. this.hidePopup('showAttribute')
  236. this.params.page = 0
  237. this.params.per_page = 10
  238. this.reload()
  239. },
  240. cancelAttribute () {
  241. this.params = { 'page': 0, 'per_page': 10 }
  242. this.reload()
  243. }
  244. }
  245. }
  246. </script>
  247. <style scoped lang='scss'>
  248. .scroll-view-wrapper{display: flex;flex-direction: column;}
  249. .scroll-view{flex:1}
  250. .ui-goodslist-filter {
  251. width: auto;
  252. background: #fff;
  253. .ul.filter-list{
  254. display: flex;
  255. width: auto;
  256. justify-content: space-around;
  257. align-content: center;
  258. align-items: center;
  259. border: 0;
  260. .li{
  261. font-size:$subFontSize;
  262. color: #333;
  263. border-bottom: .1rem solid transparent;
  264. position: relative;
  265. flex-basis: 4.54rem;
  266. text-align: center;
  267. height: 1.9rem;
  268. padding: 0;
  269. line-height: 1.9rem;
  270. .a {
  271. height: 1.9rem;
  272. display: inline-block;
  273. }
  274. .img {
  275. height: .18rem;
  276. width: .36rem;
  277. vertical-align: middle;
  278. }
  279. .iconfont{display: inline-block}
  280. }
  281. .li.sortactive {color:$primaryColor;
  282. &::after{background-color:$primaryColor;width:1rem;height: 2px;content:'';display: block;margin: 0 auto;}
  283. .a {
  284. color:$primaryColor;
  285. }
  286. .iconfont{color:$primaryColor;}
  287. .iconfont.active{transform: rotate(180deg);}
  288. }
  289. .li.sortnormal {
  290. border-bottom-color: transparent;
  291. .a {
  292. color: #333;
  293. }
  294. }
  295. }
  296. }
  297. .ui-product-body {
  298. background:#fff;
  299. margin-bottom:.5rem;
  300. .list {
  301. display: flex;
  302. width: auto;
  303. align-items: center;
  304. justify-content: space-between;
  305. padding:0.5rem;
  306. position: relative;
  307. .div.ui-image-wrapper {
  308. width: 5.5rem;
  309. height: 5.5rem;
  310. position: relative;
  311. display: flex;
  312. justify-content: center;
  313. align-content: center;
  314. align-items: center;
  315. flex-basis: 5.5rem;
  316. flex-shrink: 0;
  317. background-position:center center!important;
  318. background-size:5rem 5rem;
  319. background-repeat:no-repeat;
  320. -webkit-background-size: cover;
  321. -moz-background-size: cover;
  322. -o-background-size: cover;
  323. background-size: cover;
  324. .img.product-img{
  325. width:5.5rem;
  326. height:5.5rem;
  327. border-radius:.4rem;
  328. flex-basis:5.5rem;
  329. flex-shrink: 0;
  330. }
  331. .img.product-img[lazy=loading] {
  332. width:1.5rem;
  333. height:1.5rem;
  334. }
  335. .img.product-im[lazy=error] {
  336. width:1.5rem;
  337. height:1.5rem;
  338. }
  339. .img.product-img[lazy=loaded] {
  340. width:5.5rem;
  341. height:5.5rem;
  342. flex-basis:5.5rem;
  343. flex-shrink: 0;
  344. background:rgba(255,255,255,1);
  345. }
  346. .span {
  347. position: absolute;
  348. height:1rem;
  349. background:rgba(243,244,245,1);
  350. line-height:1rem;
  351. text-align: center;
  352. font-size:$subFontSize;
  353. color:$primaryColor;
  354. width:5.5rem;
  355. bottom: 0;
  356. left: 0;
  357. }
  358. }
  359. .flex-right {
  360. padding-left:0.7rem;
  361. flex: 1;
  362. overflow: hidden;
  363. position:relative;
  364. height: 5.5rem;
  365. display: flex;
  366. flex-direction: column;
  367. justify-content: space-around;
  368. .title {
  369. color: #333;
  370. font-size:$subFontSize;
  371. line-height:1rem;
  372. font-weight: normal;
  373. height:2rem;
  374. line-height:1rem;
  375. font-weight: normal;
  376. display:-moz-box;
  377. display:-webkit-box;
  378. -webkit-line-clamp: 2;
  379. -moz-line-clamp: 2;
  380. -moz-box-orient:vertical;
  381. -webkit-box-orient:vertical;
  382. box-orient:vertical;
  383. overflow: hidden;
  384. margin-bottom:0.4rem;
  385. &.clear-bottom {
  386. margin-bottom: 0;
  387. }
  388. }
  389. .product-header {
  390. margin-bottom:.4rem;
  391. display: flex;
  392. align-items: center;
  393. }
  394. .p-price {font-size:$fontSize;color:#999;
  395. .strong{
  396. color: $primaryColor;
  397. font-size:$h2;
  398. line-height:.8rem;
  399. margin-right:.2rem;
  400. }
  401. }
  402. .groupbuy_limit_number{font-size:$fontSize;color:#999;text-decoration: line-through}
  403. .btn-wrapper{display: flex;justify-content: space-between;margin-top:1rem;}
  404. .btn{color: #fff;background: $primaryColor;
  405. &.disable{background: #eee;}
  406. }
  407. }
  408. }
  409. }
  410. .filter-attribute{padding:0.5rem;}
  411. .filter-attribute .dl{width:100%;}
  412. .filter-attribute .dt{height:1.2rem;width:100%;overflow: hidden;font-size:$h2;color: #333;}
  413. .filter-attribute .dd{}
  414. .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%;}
  415. .filter-attribute .dd .a.selected{color: $primaryColor;background-color: #fdf0f0;}
  416. .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;}
  417. .filter-attribute .dd .a .i {
  418. width: 0px; /* 宽高设置为0,很重要,否则达不到效果 */
  419. height: 0px;
  420. border-width:5px;
  421. border-style: solid;
  422. border-top-color:transparent;
  423. border-bottom-color: #999; /* 设置透明背景色 */
  424. border-left-color: transparent;
  425. border-right-color: transparent;
  426. top: -.5rem;
  427. position: relative;
  428. margin-left: .2rem;
  429. }
  430. .filter-attribute .dd .a.selected .i.up{
  431. border-bottom-color: transparent;
  432. border-top-color: $primaryColor;
  433. top: .6rem;
  434. }
  435. .filter-attribute .dd .a.selected .i{
  436. border-bottom-color:$primaryColor;
  437. border-top-color: transparent;
  438. }
  439. </style>