list.vue 2.46 KB
<template>
  <LayoutApp :show-back="true" title="二手" class="list-wrapper">
    <LayoutScroll
      ref="scrolllist"
      @scroll="onScroll"
      @scroll-end="scrollEndHandler"
      @pulling-up="fetchSkupList(isMore)"
      v-if="skupList.list.length"
      class="list-scroll-bg"
    >
      <SecondList ref="second" :list="skupList.list" :yasParams="yasParams"></SecondList>
    </LayoutScroll>

    <UfoNoItem class="empty" :tip="`暂无数据`" v-else></UfoNoItem>
  </LayoutApp>
</template>

<script>
import SecondList from './components/second-list';
import UfoNoItem from '../../components/ufo-no-item';

import { createNamespacedHelpers } from 'vuex';

const { mapState, mapActions } = createNamespacedHelpers('second/skupList');

export default {
  name: 'UfoSecondListPage',
  components: {
    SecondList,
    UfoNoItem
  },
  data() {
    return {
      isFetch: true,
      scrollY: 0,
      yasParams: {
        P_NAME: 'XY_UFOSecondList',
        TYPE_ID: 5,
        TAB_ID: '',
        TAB_NAME: '',
        P_PARAM: [].toString()
      }
    };
  },
  computed: {
    ...mapState(['skupList', 'isMore'])
  },
  methods: {
    ...mapActions(['fetchSecondSkupList']),

    async fetchSkupList(isMore) {
      if (this.isMore) {
        await this.fetchSecondSkupList({ isReset: false });
      }
    },
    onScroll({ y }) {
      this.scrollY = -y;
    },
    scrollEndHandler({ y }) {
      this.scrollY = -y;
      this.$refs.second.yasShowEvent(-y);
    },

    yasShowPage() {
      let { total, list } = this.skupList;
      let PRD_LIST = [];

      for (let item of list) {
        PRD_LIST.push(item.product_id);
      }
      PRD_LIST = PRD_LIST.toString();
      this.$store.dispatch('reportYas', {
        params: {
          param: { ...this.yasParams, TOTAL: total, PRD_LIST },
          appop: 'XY_UFO_PRD_LIST_L'
        }
      });
    },
  },
  beforeRouteLeave (to, from, next) {
    this.isFetch = to.name !== 'SecondProductDetail'
    next();
  },
  activated: function() {
    if(this.isFetch) {
      this.scrollY = 0;
      this.fetchSecondSkupList({ isReset: true });
    }
    this.$nextTick(()=> {
      this.$refs.scrolllist.scrollTo(this.scrollY);
      this.$refs.second.yasShowEvent(this.scrollY);
      this.yasShowPage();
    })
  }
};
</script>

<style lang="scss" scoped>
.list-wrapper {
  /deep/ .layout-context {
    display: flex;
    flex-direction: column;
  }

  .empty {
    flex: 1;
  }
}

.list-scroll-bg {
  background-color: #f5f5f5;
  flex: 1;
}
</style>