<template>
  <div class="app-container">
    <van-nav-bar
      title="我的报名"
      left-arrow
      fixed
      placeholder
      @click-left="goClickLeft"
    />
      <van-list
        v-model="loading"
        :finished="finished"
        finished-text="没有更多了"
        style="margin-top: 10px;"
      >
        <van-cell icon="play" v-for="(item , index) in supplyList" :key="index" :to="{path:'project/projectDetail',query:{id:item.projectId}}">
          <template #title>
             {{item.projectName}}
          </template>
          <template #label>
            <p>报名状态：<span :style="{color:item.depositStatus == '1' ? '#007E72':'#c21F3a'}">{{item.depositStatus}}</span></p>
            <p>开始时间：{{item.biddingStartTime}}</p>
            <p>结束时间：{{item.biddingStopTime}}</p>
            <p>距<span style="margin: 0 0.5em">结</span>束：
              <van-count-down :time="item.endTime">
                <template #default="timeData">{{timeData.days}}天{{timeData.hours}}时{{timeData.minutes}}分{{timeData.seconds}}秒</template>
              </van-count-down>
            </p>
          </template>
        </van-cell>
      </van-list>
  </div>
</template>

<script>
import { getMember , getSignupByMemberId , deleteSupply} from "@/api/user/index";
import { getInfo } from "@/api/login/index";
import {Dialog} from "vant";
export default {
  name: "userSupply",
  data() {
    return {
      //是否显示加载
      loading: false,
      //是否滚动到底部
      finished: false,
      //数据集合
      supplyList:[],
      //查询参数
      queryParams:{
        memberId:'',
      },
      depositStatusOptions:[]
    };
  },
  created() {
    this.getDicts("deposit_status").then(rr => {
      this.depositStatusOptions = rr.data;
      // this.accountType = this.selectDictLabel(this.depositStatusOptions,res.data.accountType);
    });
    this.getInfo();
  },
  methods: {
    goAdd(type,id){
      console.log(id)
      if (id == undefined){
        window.location='supplyAdd';
      }else{
        window.location='supplyAdd?type='+type+'&id='+id;
      }
    },
    goClickLeft(){
      window.location='user';
    },
    getInfo(){
      getInfo().then(response => {
        getMember(response.user.userId).then(response => {
          this.queryParams.memberId = response.data.id;
          this.getList();
        });
      });
    },
    getList(){
      this.loading = true;
      getSignupByMemberId(this.queryParams).then(response => {
        console.log(response)
        for (var i = 0; i < response.rows.length; i++) {
          response.rows[i].endTime = new Date(response.rows[i].biddingStopTime) - new Date();
          response.rows[i].depositStatus = this.selectDictLabel(this.depositStatusOptions,response.rows[i].depositStatus);
          this.supplyList.push(response.rows[i]);
        }
        this.finished = true;
        this.loading = false;
      });
    },
    deleteSupply(id){
      Dialog.confirm({
        title: '系统提示',
        message: '是否删除？',
        confirmButtonText: '确定',
      }).then(() => {
        deleteSupply(id).then(response => {
          Dialog.confirm({
            title: '系统提示',
            message: '删除成功',
            confirmButtonText: '确定',
            showCancelButton:false
          }).then(() => {
            this.supplyList = [];
            this.getList();
          })
        });
      })
    }

  },
};
</script>

<style scoped lang="scss">
  .van-count-down{
    color: #969799;
    font-size: 0.32rem;
    line-height: 0.48rem;
    display: inline-block;
  }
</style>
