<template>
  <div class="app-container">
    <van-nav-bar
      title="投票"
      left-arrow
      @click-left="$router.back(-1)"
    >
      <template #right>
        <van-image
          width="18"
          height="18"
          src="../../../static/images/onlineHome/voteMenu.png"/>
      </template>
    </van-nav-bar>
    <van-list>
      <van-row v-for="(item,index) in list" :key="index" style="background:#fff;width: 96%;margin:2%;border-radius: 6px;overflow: hidden;padding-top: 10px;padding-bottom: 10px;box-shadow: 0px 3px 6px 0px rgba(0,0,0,0.16);">
        <van-col span="3" style="text-align: center;">
          <van-image
            width="18"
            height="18"
            style="display: inline-block;margin-top: 16px"
            src="../../../static/images/onlineHome/home3.png"
          />
        </van-col>
        <van-col span="17">
          <van-row>
            <h3 style="line-height: 26px">{{item.subjectName}}</h3>
          </van-row>
          <van-row>
            <p v-if="new Date(item.startTime) > new Date()" style="line-height: 26px">
              开始时间：{{item.startTime}}
            </p>
            <p v-if="new Date(item.startTime) <= new Date() && new Date(item.endTime) >= new Date()" style="line-height: 26px">
              截止时间：{{item.endTime}}
            </p>
            <p v-if="new Date(item.endTime) < new Date()" style="line-height: 26px">
              发起人：{{item.promoters}}
            </p>
          </van-row>
        </van-col>
        <van-col span="4">
          <h3 v-if="new Date(item.startTime) > new Date()" style="line-height: 50px;color: #1D6FE9" >未开始</h3>
          <h3 v-if="new Date(item.endTime) < new Date()" style="line-height: 50px;color: #1D6FE9" @click="go(item.id)">已结束</h3>
          <h3 v-if="new Date(item.startTime) <= new Date() && new Date(item.endTime) >= new Date()" style="line-height: 50px;color: #1D6FE9" @click="go(item.id)">投票中</h3>
        </van-col>
      </van-row>
    </van-list>
  </div>
</template>

<script>
    import onlineHomeIndex from "../onlineHomeIndex";
    import {getFinancialInAndOut} from "../../api/onlineHome/finacial";
    import {listPoll} from "../../api/onlineHome/poll";

    export default {
      components: {
        onlineHomeIndex
      },
        name: "homePoll",
      data() {
        return {
          activeName: 'a',
          list: [{},{}],
          loading: false,
          finished: false,
          result:[],
          // 查询参数
          queryParams: {
            // 分页
            pageNum: 1,
            pageSize: 10,
            // 查询排序
            //orderByColumn: "id",
            //isAsc: "desc",
            subjectName: null,
            status: 3
          },
        };
      },
      created() {
        this.getList();
      },
      methods: {
        go(val){
          this.$router.push({path:'/onlineHome/homePollDetail',query:{id:val}});
        },
        getList(){
          this.loading = true;
          listPoll(this.queryParams).then(response => {
            this.list = response.rows;
            this.total = response.total;
            this.loading = false;
          });
        },
      },
    }
</script>

<style scoped>
  >>>.van-col::after {
     border-bottom: none;
  }
</style>
