<template>
  <div class="pa-3 white fill-height d-flex flex-column">
    <challenge-search @getInnovativeServiceSearch="getInnovativeServiceSearch" />
    <challenge-date :pagination="pagination" :lists="lists" @getInnovativeServiceSearch="getInnovativeServiceSearch" />
  </div>
</template>

<script>
import ChallengeSearch from 'components/Challenge/ChallengeSearch.vue';
import ChallengeDate from 'components/Challenge/ChallengeDate.vue';
import { getInnovativeServiceSearch } from 'config/api';

export default {
  name: 'InnovationChallenge',
  components: {
    ChallengeSearch,
    ChallengeDate,
  },

  data() {
    return {
      lists: {},
      pagination: { current: 1, pageSize: 10 },
    };
  },

  created() {
    this.getInnovativeServiceSearch();
  },

  methods: {
    async getInnovativeServiceSearch(condition) {
      try {
        const params = {
          param: {
            name: condition && condition.name ? condition.name : '',
            recStatus: condition && condition.status111 !== '' ? condition.status111 : '',
            serviceType: 2,
            pageNum: (condition && condition.current) || 1,
            pageSize: (condition && condition.pageSize) || 10,
          },
        };
        console.log('params', params);
        const res = await getInnovativeServiceSearch(params);
        const { code, msg, data } = res.data;
        if (code === 200) {
          this.lists = data;
          console.log(this.lists);

          const paper = { ...this.pagination };
          paper.current = data.pageNum;
          paper.total = +data.total;
          paper.pageSize = data.pageSize;
          this.pagination = paper;
        } else {
          throw msg || '获取失败';
        }
      } catch (error) {
        this.$message.error(error);
      }
    },
  },
};
</script>
