GroupBuyList.vue 15 KB

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