123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248 |
- <template>
- <div class="report-home" ref="wrapper">
- <div v-if="listState.list.length && listState.list.length > 0">
- <van-pull-refresh v-model="isLoading" @refresh="onRefresh">
- <van-list
- v-model="listState.loading"
- :finished="listState.finished"
- :immediate-check="false"
- finished-text="没有更多了"
- @load="onLoad"
- :offset="50"
- >
- <ul class="list">
- <li class="item" v-for="item in listState.list" :key="item.id" @click="goDetail(item)">
- <div class="item-img">
- <img :src="item.img" alt="">
- </div>
- <div class="item-cont">
- <p class="ellipsis-2 title">{{item.title}}</p>
- <div class="desc">
- <div class="left">{{item.publishtime* 1000 | dateFormatter('yyyy/MM/dd')}}</div>
- <div class="right">
- <span class="before-price">¥ <em>{{item.before_price}}</em></span>
- <span class="current-price">¥ <em>{{item.price}}</em> </span>
- </div>
- </div>
- </div>
- </li>
- </ul>
- </van-list>
- </van-pull-refresh>
- </div>
- <Empty v-else>
- <div class="tip-sub-text">暂无数据</div>
- </Empty>
- </div>
- </template>
- <script lang="ts">
- import { Component, Vue } from 'vue-property-decorator'
- import { mapState, mapMutations, mapActions } from 'vuex'
- import { PullRefresh, List, Toast } from 'vant'
- import Empty from '@/components/common/Empty.vue'
- @Component({
- name: 'home',
- components: {
- [PullRefresh.name]: PullRefresh,
- [List.name]: List,
- Empty
- },
- methods: {
- ...mapState('home', {
- reportList: (state: any) => state.reportList
- }),
- ...mapMutations({
- saveList: 'home/saveReportList',
- clearList: 'home/clearReportList'
- }),
- ...mapActions({
- getList: 'home/getReportList'
- })
- }
- })
- export default class Home extends Vue {
- protected reportList!: any
- protected getList!: any
- protected saveList!: any
- protected clearList!: any
- isLoading = false
- listState = {
- list: [],
- loading: false,
- finished: false,
- currentPage: 1,
- totalPage: 0,
- scroll: 0
- }
- beforeRouteEnter (to, from, next) {
- if (from.name === 'detail') {
- to.meta.isBack = true
- } else {
- to.meta.isBack = false
- }
- next()
- }
- activated () {
- if (!this.$route.meta.isBack) {
- this.listState = {
- list: [],
- loading: false,
- finished: false,
- currentPage: 1,
- totalPage: 0,
- scroll: 0
- }
- this.getReportList()
- return
- }
- this.$route.meta.isBack = false
- this.listState = this.reportList()
- this.$nextTick(() => {
- ;(this.$refs.wrapper as any).scrollTop = this.reportList().scroll
- })
- }
- beforeRouteLeave (to, form, next) {
- this.listState.scroll = (this.$refs.wrapper as any).scrollTop
- this.saveList(this.listState)
- next()
- }
- getReportList () {
- this.listState.loading = true
- this.getList(`page_index=${this.listState.currentPage}`).then((res: any) => {
- if (res.error_code === 0 && res.data.list) {
- const rows = res.data.list
- this.listState.loading = false
- this.listState.totalPage = res.data.page_count
- if (rows === null || rows.length === 0) {
- this.listState.finished = true
- return
- }
- if (this.listState.currentPage >= this.listState.totalPage) {
- this.listState.finished = true
- }
- if (this.listState.currentPage === 1) {
- this.listState.list = rows
- } else {
- this.listState.list = this.listState.list.concat(rows)
- }
- } else {
- this.listState.finished = true
- }
- }).catch(() => {
- this.listState.finished = true
- })
- }
- onLoad () {
- this.listState.currentPage++
- this.getReportList()
- }
- goDetail (item) {
- this.$router.push(`/detail/${item.id}`)
- }
- onRefresh () {
- setTimeout(() => {
- this.isLoading = false
- this.clearList()
- this.$nextTick(() => {
- this.listState = {
- list: [],
- loading: false,
- finished: false,
- currentPage: 1,
- totalPage: 0,
- scroll: 0
- }
- this.getReportList()
- Toast('刷新成功')
- })
- }, 1000)
- }
- }
- </script>
- <style lang="scss">
- .report-home {
- .list{
- .item{
- position: relative;
- display: flex;
- padding: 20px 16px;
- background-color: #fff;
- &:after{
- position: absolute;
- box-sizing: border-box;
- content: ' ';
- pointer-events: none;
- right: 16px;
- bottom: 0;
- left: 16px;
- border-bottom: 1px solid rgba(0, 0, 0, 0.02);
- // -webkit-transform: scaleY(0.5);
- // transform: scaleY(0.5);
- }
- .item-img{
- width: 80px;
- height: 80px;
- border-radius: 4px;
- margin-right: 16px;
- overflow: hidden;
- img{
- width: 100%;
- height: 100%;
- }
- }
- .item-cont{
- flex: 1;
- .title{
- font-size: 16px;
- line-height: 24px;
- color: #171826;
- }
- .desc{
- display: flex;
- justify-content: space-between;
- align-items: center;
- margin-top: 13px;
- .left{
- font-size: 12px;
- line-height: 18px;
- color: #9B9CA3;
- }
- .right{
- display: flex;
- align-items: center;
- }
- .before-price{
- font-size: 12px;
- line-height: 18px;
- color: #9B9CA3;
- margin-right: 6px;
- em{
- text-decoration: line-through;
- }
- }
- .current-price{
- display: flex;
- align-items: center;
- color: #FB483D;
- font-size: 14px;
- line-height: 20px;
- em{
- margin-left: 2px;
- font-size: 16px;
- line-height: 24px;
- }
- }
- }
- }
- }
- }
- }
- </style>
|