123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430 |
- <template>
- <div
- class="wrapper"
- ref="returnWrapper">
- <ul>
- <li
- :class="{'static': isRefresh}"
- class="pulldown-wrapper">
- <van-loading
- v-show="isRefresh"
- size="24px"
- type="spinner">加载中...
- </van-loading>
- <div
- v-show="!isRefresh"
- class="van-loading">
- <span
- class="van-loading__text">下拉刷新</span>
- </div>
- </li>
- <li
- v-for="(item, index) in list"
- :key="index"
- class="list-item border-bottom-1px"
- @click="getOrderDetail(item.goods_id)">
- <div class="photo">
- <img
- :src="item.goods_thumb_url"
- alt="">
- </div>
- <div class="info">
- <div
- class="top">
- <p>{{ item.goods_name }}</p>
- </div>
- <div class="middle">
- <div class="price-wrap">
- <p class="price">
- <span>¥</span>
- <span>{{ item.price && (item.price * 1).toFixed(2) }}</span>
- </p>
- <p class="origin">¥{{ item.market_price && (item.market_price * 1).toFixed(2) }}</p>
- </div>
- <!--暂时不用这个字段-->
- <!--<div class="sale-count">-->
- <!--<span>已售</span>-->
- <!--<span>0</span>-->
- <!--</div>-->
- </div>
- <div class="card" v-show="item.discount > 0 && item.commission > 0">
- <p class="coupon" v-show="item.discount > 0">
- <span>券</span>
- <span>¥{{ item.discount }}</span>
- </p>
- <p class="profit" v-show="item.commission > 0">
- <span>分享赚</span>
- <span>¥ {{ item.commission | fen2Yuan }}</span>
- </p>
- </div>
- <!--暂时不用这个字段-->
- <!--<div class="shop">-->
- <!--<img src="" alt="">-->
- <!--<p>店名店名店名店名店名店名店名店名店名店名店名店名店名店名店名店名店名店名店名店名店名店名店名店名店名店名店名</p>-->
- <!--</div>-->
- </div>
- </li>
- <li class="pullup-wrapper">
- <van-loading
- v-show="!finished"
- size="24px"
- type="spinner">加载中...
- </van-loading>
- <div
- v-show="finished"
- class="van-loading">
- <span
- class="van-loading__text">没有更多了</span>
- </div>
- </li>
- </ul>
- </div>
- </template>
- <script>
- import BScroll from 'better-scroll'
- import { Toast, Loading } from 'vant'
- import { apiGoodsList } from '../api/api'
- export default {
- components: {
- 'van-loading': Loading
- },
- props: {
- source: {
- type: String,
- default: ''
- },
- catId: {
- type: [String, Number],
- default: ''
- }
- },
- data () {
- return {
- finished: false, // 所有数据是否加载完
- isRefresh: false, // 是否下拉刷新
- isFetchLock: false, // 接口调用加锁
- pagenum: 0,
- pagesize: 20,
- list: [],
- scroll: null
- }
- },
- methods: {
- init () {
- this.finished = false
- this.isRefresh = false
- this.isFetchLock = false
- this.pagenum = 0
- this.pagesize = 20
- this.list = []
- if (this.scroll) {
- this.scroll.scrollTo(0, 0)
- }
- this.getList()
- },
- onRefresh () {
- this.pagenum = 0
- this.pagesize = 20
- this.finished = false
- this.isRefresh = true
- this.getList()
- },
- async getList () {
- if (this.finished) {
- return
- }
- if (this.isFetchLock) {
- return
- }
- this.isFetchLock = true
- this.pagenum++
- try {
- const { status, data, msg } = await apiGoodsList({
- page: this.pagenum,
- page_size: this.pagesize,
- source: this.source,
- cat_id: this.catId
- })
- if (status) {
- const { list } = data
- // 下拉刷新数据清空
- if (this.isRefresh) {
- this.isRefresh = false
- this.list = []
- }
- // 没有数据返回了
- if (Array.isArray(list) && !list.length) {
- this.finished = true
- }
- if (Array.isArray(list) && list.length) {
- // 总页数小于等于1页时
- if (list.length < this.pagesize) {
- this.finished = true
- }
- this.list = this.list.concat(list)
- this.$nextTick(() => {
- if (!this.scroll) {
- this.scroll = new BScroll(this.$refs.returnWrapper, {
- click: true,
- pullDownRefresh: {
- threshold: 50, // 顶部下拉的距离
- stop: 20 // 回弹停留的距离
- },
- pullUpLoad: {
- threshold: -20
- },
- scrollbar: true
- })
- this.scroll.on('pullingDown', () => {
- this.onRefresh()
- })
- this.scroll.on('pullingUp', () => {
- this.getList()
- })
- } else {
- this.scroll.finishPullDown()
- this.scroll.finishPullUp()
- this.scroll.refresh()
- }
- })
- }
- } else {
- Toast(msg)
- }
- this.isFetchLock = false
- } catch (err) {
- this.isFetchLock = false
- }
- },
- getOrderDetail (id) {
- this.$router.push({
- name: 'CategoryDetail',
- params: {
- source: this.source,
- goodsId: id
- }
- })
- }
- },
- beforeDestroy () {
- this.scroll && this.scroll.destroy()
- }
- }
- </script>
- <style lang="scss" scoped>
- .wrapper {
- position: absolute;
- left: 0;
- top: 95px;
- right: 0;
- bottom: 0;
- width: 100%;
- overflow: hidden;
- ul {
- display: flex;
- flex-direction: column;
- align-items: center;
- width: 100%;
- padding: 0 0 102px;
- }
- }
- .pulldown-wrapper {
- position: absolute;
- left: 0;
- top: -43px;
- width: 100%;
- text-align: center;
- margin-bottom: 10px;
- &.static {
- position: static;
- left: 0;
- top: 0;
- }
- }
- .pullup-wrapper {
- width: 100%;
- text-align: center;
- .van-loading {
- margin-top: 16px;
- }
- }
- .list-item {
- display: flex;
- width: 355px;
- min-height: 138px;
- background: #FEFEFE;
- border-radius: 5px;
- margin-bottom: 10px;
- padding: 9px;
- }
- .photo {
- width: 121px;
- height: 121px;
- margin-right: 10px;
- border-radius: 6px;
- overflow: hidden;
- img {
- display: block;
- width: 100%;
- }
- }
- .info {
- width: 206px;
- padding-top: 6px;
- }
- .top {
- p {
- display: -webkit-box;
- font-size: 14px;
- font-weight: bold;
- color: #333333;
- line-height: 18px;
- -webkit-line-clamp: 2;
- -webkit-box-orient: vertical;
- overflow: hidden;
- }
- }
- .middle {
- display: flex;
- align-items: flex-end;
- justify-content: space-between;
- margin-top: 8px;
- }
- .price-wrap {
- display: flex;
- align-items: flex-end;
- }
- .price {
- margin-right: 8px;
- font-size: 0;
- span {
- &:nth-of-type(1) {
- margin-right: 4px;
- font-size: 12px;
- font-weight: bold;
- color: #EA483F;
- line-height: 18px;
- }
- &:nth-of-type(2) {
- font-size: 16px;
- font-weight: bolder;
- color: #EA483F;
- line-height: 18px;
- }
- }
- }
- .origin {
- font-size: 10px;
- text-decoration: line-through;
- color: #999999;
- line-height: 18px;
- }
- .sale-count {
- font-size: 0;
- span {
- font-size: 10px;
- color: #999999;
- line-height: 18px;
- &:nth-of-type(1) {
- margin-right: 4px;
- }
- }
- }
- .card {
- display: flex;
- align-items: center;
- margin-top: 4px;
- }
- .coupon {
- display: flex;
- justify-content: center;
- align-items: center;
- min-width: 57px;
- height: 18px;
- background: url("../image/ic_coupon.png") center center/100% 100% no-repeat;
- margin-right: 11px;
- span {
- font-size: 11px;
- font-weight: bold;
- color: #FFFFFF;
- line-height: 18px;
- &:nth-of-type(1) {
- margin-right: 2px;
- }
- }
- }
- .profit {
- display: flex;
- justify-content: center;
- align-items: center;
- min-width: 82px;
- height: 19px;
- background: #FBF4F4;
- padding: 0 8px;
- border-radius: 3px;
- span {
- font-size: 10px;
- font-weight: 500;
- color: #D64136;
- line-height: 18px;
- &:nth-of-type(1) {
- margin-right: 2px;
- }
- }
- }
- .shop {
- display: flex;
- align-items: center;
- margin-top: 8px;
- img {
- width: 12px;
- height: 11px;
- margin-right: 6px;
- }
- p {
- width: calc(100% - 18px);
- font-size: 12px;
- font-weight: 500;
- color: #999999;
- line-height: 22px;
- overflow: hidden;
- white-space: nowrap;
- text-overflow: ellipsis;
- }
- }
- </style>
|