<template>
  <div id="index">
    <el-row>
      <el-col :span="24" class="main">
        <div class="w_1200">
          <el-col :span="24" class="one">
            <el-col :span="24" class="list" v-for="(item, index) in list" :key="index">
              <el-col :span="24" class="title">
                {{ item.title }}
                <el-button type="primary" size="mini" @click="btn(item)">答卷</el-button>
              </el-col>
              <el-col :span="24" class="other">
                <el-col :span="24" class="otherInfo">
                  发布时间:<span>{{ item.create_time || '暂无' }}</span>
                </el-col>
              </el-col>
              <el-col :span="24" class="brief">
                {{ item.brief }}
              </el-col>
            </el-col>
          </el-col>
          <el-col :span="24" class="two">
            <el-pagination
              @current-change="searchPage"
              :current-page="currentPage"
              layout="total, prev, pager, next, jumper"
              :total="total"
              :page-size="pageSize"
            >
            </el-pagination>
          </el-col>
        </div>
      </el-col>
    </el-row>
  </div>
</template>

<script>
import { mapState, createNamespacedHelpers } from 'vuex';
const { mapActions: questionnaire } = createNamespacedHelpers('questionnaire');
export default {
  name: 'index',
  props: {},
  components: {},
  data: function() {
    return {
      list: [],
      total: 0,
      currentPage: 1,
      pageSize: 5,
    };
  },
  created() {
    this.search();
  },
  methods: {
    ...questionnaire(['query']),
    async search({ skip = 0, limit = 5, ...info } = {}) {
      let res = await this.query({ skip, limit, ...info });
      if (this.$checkRes(res)) {
        this.$set(this, `list`, res.data);
        this.$set(this, `total`, res.total);
      }
    },
    searchPage(page = 1) {
      this.currentPage = page;
      const skip = (this.currentPage - 1) * this.pageSize;
      let condition = { skip, limit: this.pageSize };
      this.search(condition);
    },
    // 答卷
    btn(data) {
      console.log(data);
      if (data.column == '定制问卷') {
        if (data.title == '『科研助企』活动企业调查问卷') {
          this.$router.push({ path: '/twoweb/service/helpCompany/detail', query: { id: data.id } });
        } else if (data.title == '企业科技创新能力评价调查问卷') {
          this.$router.push({ path: '/twoweb/service/made/detail', query: { id: data.id } });
        } else if (data.title == '“院省合作”-企业需求调查表 -2021') {
          this.$router.push({ path: '/twoweb/service/comDemand/detail', query: { id: data.id } });
        }
      } else {
        this.$router.push({ path: '/twoweb/service/question/detail', query: { id: data.id } });
      }
      // if (data.column == '定制问卷') {
      //   if (data.title == '『科研助企』活动企业调查问卷') {
      //     this.$router.push({ path: '/twoweb/service/helpCompany/detail', query: { id: data.id } });
      //   } else {
      //     this.$router.push({ path: '/twoweb/service/made/detail', query: { id: data.id } });
      //   }
      // } else {
      //   if (data.title == '『科研助企』活动企业调查问卷') {
      //     this.$router.push({ path: '/twoweb/service/helpCompany/detail', query: { id: data.id } });
      //   } else {
      //
      //   }
      // }
    },
  },
  computed: {
    ...mapState(['user']),
  },
  metaInfo() {
    return { title: this.$route.meta.title };
  },
  watch: {
    test: {
      deep: true,
      immediate: true,
      handler(val) {},
    },
  },
};
</script>

<style lang="less" scoped>
.main {
  padding: 10px 0;
  .one {
    height: 600px;
    overflow: hidden;
    .list {
      padding: 10px 0;
      border-bottom: 1px dashed #ccc;
      .title {
        font-size: 16px;
        font-weight: bold;
        margin: 0 0 5px 0;
      }
      .other {
        margin: 0 0 5px 0;
        .otherInfo {
          font-size: 14px;
          color: #666;
          span {
            color: #000;
          }
        }
      }
      .brief {
        overflow: hidden;
        text-overflow: ellipsis;
        -webkit-line-clamp: 2;
        word-break: break-all;
        display: -webkit-box;
        -webkit-box-orient: vertical;
        font-size: 14px;
      }
    }
  }
  .two {
    text-align: center;
    margin: 10px 0;
  }
}
</style>
