<template>
  <div class="app-container home">
    <!-- <h3 class="toolbar">
      <span class="title">数据累计</span>
    </h3> -->
    <div class="page01-con page04-con mt20">
      <h1 class="page01-title">
        <img src="../assets/images/icon15.png"/>数据累计
      </h1>
    </div>
    <template v-if="userType == 'ADMIN'">
      <el-row :gutter="20">
        <el-col :span="8">
          <div class="stat_box">
            <i class="icon icon_1"></i>
            <span class="num">{{info.entSumCnt || 0}}</span>
            <span class="label">企业总数</span>
          </div>
        </el-col>
        <el-col :span="8">
          <div class="stat_box">
            <i class="icon icon_9"></i>
            <span class="num">{{info.entValidCnt || 0}}</span>
            <span class="label">服务中企业</span>
          </div>
        </el-col>
        <el-col :span="8">
          <div class="stat_box">
            <i class="icon icon_8"></i>
            <span class="num">{{info.entExpiredCnt || 0}}</span>
            <span class="label">服务已到期企业</span>
          </div>
        </el-col>
        <el-col :span="8">
          <router-link to="project/project">
            <div class="stat_box">
              <i class="icon icon_5"></i>
              <span class="num">{{info.proSumCnt || 0}}</span>
              <span class="label">项目总数</span>
            </div>
          </router-link>
        </el-col>
        <el-col :span="8">
          <div class="stat_box">
            <i class="icon icon_6"></i>
            <span class="num">{{info.proFinishCnt || 0}}</span>
            <span class="label">已完成项目</span>
          </div>
        </el-col>
        <el-col :span="8">
          <div class="stat_box">
            <i class="icon icon_7"></i>
            <span class="num">{{info.proUnfinishCnt || 0}}</span>
            <span class="label">待完成项目</span>
          </div>
        </el-col>
      </el-row>
    </template>
    <template v-if="userType == 'GOV_PROV' || userType == 'GOV_CITY' || userType == 'GOV_DISTRI'">
      <el-row :gutter="20">
        <el-col :span="8">
          <div class="stat_box">
            <i class="icon icon_1"></i>
            <span class="num">{{info.entSumCnt || 0}}</span>
            <span class="label">企业总数</span>
          </div>
        </el-col>
        <el-col :span="8">
          <div class="stat_box">
            <i class="icon icon_1"></i>
            <span class="num">{{info.proFinishCnt || 0}}</span>
            <span class="label">项目申报数</span>
          </div>
        </el-col>
      </el-row>
    </template>
    <template v-if="userType == 'ENT_ADMIN' || userType == 'ENT_TECH' || userType == 'ENT_ADMIN_TECH' || userType == 'ENT_FIN' || userType == 'ENT_ADMIN_FIN'">
      <el-row :gutter="20">
        <el-col :span="8">
          <router-link to="project/project-declare">
            <div class="stat_box">
              <i class="icon icon_5"></i>
              <span class="num">{{info.proSumCnt || 0}}</span>
              <span class="label">项目总数</span>
            </div>
          </router-link>

        </el-col>
        <el-col :span="8">
          <div class="stat_box">
            <i class="icon icon_6"></i>
            <span class="num">{{info.proFinishCnt || 0}}</span>
            <span class="label">已完成项目</span>
          </div>
        </el-col>
        <el-col :span="8">
          <div class="stat_box">
            <i class="icon icon_7"></i>
            <span class="num">{{info.proUnfinishCnt || 0}}</span>
            <span class="label">待完成项目</span>
          </div>
        </el-col>
      </el-row>
    </template>
    <template v-if="roleTypeFlag">
      <!-- <h3 class="toolbar">
        <span class="title">年度信息管理</span>
        <div class="tool">
          <el-button type="primary" plain icon="el-icon-plus" size="mini" @click="handleYear">添加加计年度基本信息</el-button>
        </div>
      </h3> -->
      <div class="page01-con page04-con">
        <h1 class="page01-title">
          <img src="../assets/images/icon15.png"/>年度信息管理
          <!-- <a>更多</a> -->
          <a @click="handleYear">
            <img src="../assets/images/icon16.png"/>
            添加年度基本信息
          </a>
        </h1>
      </div>
      <el-table v-loading="loading" :data="list" border>
        <el-table-column label="申报年度" prop="projectYear"></el-table-column>
        <el-table-column label="企业名称" prop="entName" align="center" width="180"/>
        <el-table-column label="职工数" prop="totoalPersons" align="center" width="180" />
        <el-table-column label="销售收入" prop="sales"></el-table-column>
        <el-table-column label="研发收入" prop="techInvest"></el-table-column>
        <el-table-column label="占销售收入比例" prop="techRate"></el-table-column>
        <el-table-column label="操作" align="center" width="200" class-name="small-padding fixed-width" fixed="right">
          <template slot-scope="scope">
            <!-- <template v-if="!roleTypeFlag && (scope.row.reportState == 1 || scope.row.reportState == 2)"> -->
              <el-button type="text" @click="handleEdit(scope.row)">编辑</el-button>
            <!-- </template> -->
          </template>
        </el-table-column>
      </el-table>
      <!-- <h3 class="toolbar mt10">
        <span class="title">已申报项目</span>
        <div class="tool">
          <el-button type="text" size="mini" @click="$router.push('/project/project-declare')">查看更多</el-button>
        </div>
      </h3> -->
      <div class="page01-con page04-con mt20">
        <h1 class="page01-title">
          <img src="../assets/images/icon15.png"/>已申报项目
          <a @click="$router.push('/project/project-declare')">更多</a>
        </h1>
      </div>

      <el-table v-loading="loading" :data="declareList" border>
        <el-table-column label="申报年度" prop="projectYear"></el-table-column>
        <el-table-column label="项目起止时间" align="center">
          <template slot-scope="scope">
            <span>{{scope.row.projectStartDate}} - {{scope.row.projectEndDate}}</span>
          </template>
        </el-table-column>
        <el-table-column label="项目名称" prop="projectName" align="center"/>
      </el-table>
    </template>

  </div>
</template>

<script>
  import {getIndexDataApi} from "@/api/common/common.js"
  import {yearListApi,listProjectApi} from "@/api/enterprise/project/project"
export default {
  name: "Index",
  computed: {
    userType() {
      return this.$store.state.user.userType
    },
    roleTypeFlag() {
      let roleType = this.$store.state.user.roles.join(',')
      return ['entAdmin'].includes(roleType) //判断是否为技术负责人，财务负责人
    }
  },
  data() {
    return {
      // 版本号
      version: "1.0.0",
      info: {},
      list: [],
      declareList: [],
      total: 0,
      queryParams: {
        pageNum: 1,
        pageSize: 10,
      },
      params: {
        reportState: '4'
      }
    };
  },
  created() {
    this.getData()
    this.getList()
    this.getDeclareList()
  },
  methods: {
    goTarget(href) {
      window.open(href, "_blank");
    },
    getData() {
      getIndexDataApi().then(res => {
        this.info = res.data || {}
      })
    },
    getList() {
      this.loading = true;
      yearListApi(this.queryParams).then(response => {
        this.list = response.data.records;
        // this.total = response.data.total;
        this.loading = false;
      });
    },
    //添加年度信息 type用来区分tab页是否可以切换
    handleYear() {
      this.$router.push({name: 'editProject', query: {type: 'year'}})
    },
    //编辑
    handleEdit(row) {
      this.$router.push({name: 'editProject', query: {year: row.projectYear, entId: row.entId, type: 'update', activeName: '1', source: 'add'}})
    },
    getDeclareList() {
      this.loading = true;
      listProjectApi(this.params).then(response => {
        this.declareList = response.data.records;
        this.total = response.data.total;
        this.loading = false;
      });
    },
  }
};
</script>

<style scoped lang="scss">

  img {
    border: none;
    vertical-align: middle;
    max-width: 100%;
  }
  .page04-con h1{
  	text-align:left;
    padding-left:20px;
    padding-right:50px;
  }
  .page04-con h1 img{
  	display:inline-block;
    margin-right:10px;
  }
  .page04-con h1 span{
  	float:right;
    font-weight:normal;
    margin-right:20px;
    cursor:pointer;
  }
  .page04-con h1 a{
  	float:right;
    color:#fff;
    font-weight:700;
  }
  .page01-title{
  	background:#4882b5;
    font-size:18px;
    color:#fff;
    font-weight:700;
    margin-bottom:5px;
  	text-align:center;
    line-height:48px;
    border-radius:6px;
    display:block;
  }
.home {
  blockquote {
    padding: 10px 20px;
    margin: 0 0 20px;
    font-size: 17.5px;
    border-left: 5px solid #eee;
  }
  hr {
    margin-top: 20px;
    margin-bottom: 20px;
    border: 0;
    border-top: 1px solid #eee;
  }
  .col-item {
    margin-bottom: 20px;
  }

  ul {
    padding: 0;
    margin: 0;
  }

  font-family: "open sans", "Helvetica Neue", Helvetica, Arial, sans-serif;
  font-size: 13px;
  color: #676a6c;
  overflow-x: hidden;

  ul {
    list-style-type: none;
  }

  h4 {
    margin-top: 0px;
  }

  h2 {
    margin-top: 10px;
    font-size: 26px;
    font-weight: 100;
  }

  p {
    margin-top: 10px;

    b {
      font-weight: 700;
    }
  }

  .update-log {
    ol {
      display: block;
      list-style-type: decimal;
      margin-block-start: 1em;
      margin-block-end: 1em;
      margin-inline-start: 0;
      margin-inline-end: 0;
      padding-inline-start: 40px;
    }
  }
}
</style>
