<!-- 学院自查 -->
<template>
  <div class="app-container selfInspectionProject">
    <div class="page-container selfInspectionProjectPage" v-if="pageType === 1">
      <div class="page-form-title-box">
        <el-form :model="queryParams" class="form-box" ref="queryForm"
                 :inline="true" style="width:100%;">
          <div class="table-school-college-toggle-box">
            <p :class="planStatus===''?'p-check':''" @click="tableCheck('')">全部</p>
            <p :class="planStatus===0?'p-check':''" @click="tableCheck(0)">未开始</p>
            <p :class="planStatus===1?'p-check':''" @click="tableCheck(1)">进行中</p>
            <p :class="planStatus===2?'p-check':''" @click="tableCheck(2)">已结束</p>
          </div>
          <el-form-item label="" prop="checkTypeValue">
            <el-select v-model="queryParams.checkTypeValue" placeholder="检查类型" style="width: 150px">
              <el-option
                v-for="dict in optionList"
                :key="dict.value"
                :label="dict.label"
                :value="dict.value"
              />
            </el-select>
          </el-form-item>
          <el-form-item label="" prop="searchValue">
            <el-input
              maxLength="30"
              v-model="queryParams.searchValue"
              placeholder="计划标题"
              style="width: 200px"
            />
          </el-form-item>
          <el-form-item label="" prop="createName">
            <el-input
              maxLength="30"
              v-model="queryParams.createName"
              placeholder="创建人"
              style="width: 150px"
            />
          </el-form-item>
          <el-form-item label="" prop="state">
            <el-date-picker
              :clearable="false"
              v-model="dateRange"
              size="small"
              style="width: 240px"
              value-format="yyyy-MM-dd"
              type="daterange"
              range-separator="-"
              start-placeholder="开始日期"
              end-placeholder="结束日期"
            ></el-date-picker>
          </el-form-item>
          <p class="page-inquire-common-style-button" @click="handleQuery">查询</p>
          <p class="page-reset-common-style-button" @click="resetQuery">重置</p>
          <p class="page-submit-common-style-button"
             style="float: right;"
             @click="tableButton(1)"
             v-if="adminIdentity == 'college'"
             v-hasPermiRouter="['security:checkPlan_1:add']"
          >创建计划</p>
        </el-form>
      </div>
      <div class="page-content-box">
        <el-table class="table-box" v-loading="loading" border :data="dataList">
          <el-table-column label="序号" type="index" width="60"/>
          <el-table-column label="计划标题" prop="planTitle"  show-overflow-tooltip/>
          <el-table-column label="检查类型" prop="checkTypeName" width="100" show-overflow-tooltip/>
          <el-table-column label="计划周期" prop="cycleStartTime" width="250" show-overflow-tooltip>
            <template slot-scope="scope">
              <span>{{ parseTime(scope.row.cycleStartTime,"{y}-{m}-{d}") }}</span>
              至
              <span>{{ parseTime(scope.row.cycleEndTime,"{y}-{m}-{d}") }}</span>
            </template>
          </el-table-column>
          <el-table-column label="检查进度" prop="checkProgress" width="175" show-overflow-tooltip>
            <template slot-scope="scope">
              <el-progress :percentage="scope.row.checkProgress"></el-progress>
            </template>
          </el-table-column>
          <!--<el-table-column label="整改进度" prop="content" width="175" show-overflow-tooltip>-->
          <!--<template slot-scope="scope">-->
          <!--<el-progress :percentage="50"></el-progress>-->
          <!--</template>-->
          <!--</el-table-column>-->
          <el-table-column label="状态" prop="state" width="100" show-overflow-tooltip>
            <template slot-scope="scope">
              {{scope.row.planStatus==0?'未开始':(scope.row.planStatus==1?'进行中':(scope.row.planStatus==2?'已结束':''))}}
            </template>
          </el-table-column>
          <el-table-column label="创建人" prop="createName" width="100" show-overflow-tooltip/>
          <el-table-column label="创建时间" prop="createTime" width="160" show-overflow-tooltip>
            <template slot-scope="scope">
              <span>{{ parseTime(scope.row.createTime,"{y}-{m}-{d} {h}:{i}") }}</span>
            </template>
          </el-table-column>
          <el-table-column label="操作" width="220" show-overflow-tooltip >
            <template slot-scope="scope">
              <div class="table-button-box">
                <p class="table-button-null"></p>
                <p class="table-button-p"
                   v-if="scope.row.planStatus!=0"
                   @click="tableButton(2,scope.row)"
                >详情</p>
                <p class="table-button-p"
                   v-if="scope.row.planStatus==0&&adminIdentity=='college'"
                   @click="tableButton(3,scope.row)"
                   v-hasPermiRouter="['security:checkPlan_1:edit']"
                >编辑</p>
                <p class="table-button-p"
                   @click="tableButton(5,scope.row)"

                >检查明细</p>
                <p class="table-button-p"
                   v-if="scope.row.planStatus==0&&adminIdentity=='college'"
                   @click="tableButton(4,scope.row)"
                   v-hasPermiRouter="['security:checkPlan_1:del']"
                >删除</p>
                <p class="table-button-null"></p>
              </div>
            </template>
          </el-table-column>
        </el-table>
        <pagination :page-sizes="[20, 30, 40, 50]"
                    v-show="total>0"
                    :total="total"
                    :page.sync="queryParams.page"
                    :limit.sync="queryParams.pageSize"
                    @pagination="getList"
        />
      </div>
    </div>
    <projectAddPage :propsData="propsData" v-if="pageType === 2"></projectAddPage>
    <inspect-statistics :propsData="propsData" v-if="pageType === 5"></inspect-statistics>
  </div>
</template>
<script>
  import {
    securityCheckPlanList,
    securityCheckPlanDelete,
  } from '@/api/safetyCheck/indexDemoOne'
  import projectAddPage from "@/views/safetyCheck/components/projectAddPage.vue";
  import inspectStatistics from "@/views/safetyCheck/components/inspectStatistics.vue";
  export default {
    name: 'index',
    components: {
      projectAddPage,
      inspectStatistics,
    },
    data () {
      return {
        tableButtonType:this.hasPermiDom(['demo:demo:detail','demo:demo:edit','demo:demo:del',]),
        adminIdentity: localStorage.getItem('adminIdentity'),
        //页面状态
        pageType:1,
        //计划状态选项卡
        planStatus:'',
        //页面遮罩
        loading:false,
        //下拉列表数据
        optionList:[],
        //查询条件
        queryParams:{
          page:1,
          pageSize:20,
          checkCategory:2,
          checkTypeValue:"",
          searchValue :"",
          createName :"",
        },
        //时间数据
        dateRange:[],
        //列表数据
        dataList:[],
        //数据数量
        total:0,
        //组件传参
        propsData:{},
      }
    },
    created () {
      //检查类型字典
      this.getDicts("check_type").then(response => {
        this.$set(this,'optionList',response.data);
      });
    },
    mounted () {
      this.getList();
    },
    methods: {
      //整改状态选项卡切换
      tableCheck(type){
        if (this.planStatus !== type){
          this.$set(this,'planStatus',type);
          this.resetQuery();
        }
      },
      //查询按钮
      handleQuery(){
        this.$set(this.queryParams,'page',1);
        this.getList();
      },
      //重置按钮
      resetQuery(){
        this.$set(this,'dateRange',[])
        this.$set(this,'queryParams',{
          page:1,
          pageSize:20,
          checkCategory:2,
          checkTypeValue:"",
          searchValue :"",
          createName :"",
        });
        this.getList();
      },
      //获取数据列表
      getList(){
        this.$set(this,'loading',true);
        let obj = JSON.parse(JSON.stringify(this.queryParams))
        if(this.dateRange[0]){
          obj.startTime = this.dateRange[0]+'T00:00:00'
          obj.endTime = this.dateRange[1]+'T23:59:59'
        }else{
          obj.startTime = "";
          obj.endTime = "";
        }
        obj.planStatus = this.planStatus;
        securityCheckPlanList(obj).then(response => {
          this.$set(this,'loading',false);
          this.$set(this,'dataList',response.data.records);
          this.$set(this,'total',response.data.total);
        });
      },
      //操作按钮
      tableButton(type,row){
        let self = this;
        if(type == 1){
          //新增
          this.$set(this,'pageType',2);
          this.$set(this,'propsData',{
            rank:'college'
          });
        }else if(type == 2){
          //详情
          this.$set(this,'pageType',2);
          let obj = JSON.parse(JSON.stringify(row))
          obj.showType = true;
          obj.rank = 'college';
          this.$set(this,'propsData',obj);
        }else if(type == 3){
          //编辑
          this.$set(this,'pageType',2);
          let obj = JSON.parse(JSON.stringify(row))
          obj.rank = 'college';
          this.$set(this,'propsData',obj);
        }else if(type == 4){
          //删除
          this.$confirm('是否确认删除?', "警告", {
            confirmButtonText: "确定",
            cancelButtonText: "取消",
            type: "warning"
          }).then(function() {
          }).then(() => {
            securityCheckPlanDelete({planId:row.planId}).then(response => {
              self.msgSuccess(response.message)
              self.getList();
            });
          }).catch(() => {});
        }else if(type == 5){
          //检查明细
          this.$set(this,'pageType',5);
          let obj = JSON.parse(JSON.stringify(row))
          obj.showType = true;
          obj.rank = 'college';
          this.$set(this,'propsData',obj);
        }else if(type == 6){
          //返回并刷新
          this.$set(this,'pageType',1);
          this.getList();
        }
      },
    },
  }
</script>
<style scoped lang="scss">
  .selfInspectionProject{
    .selfInspectionProjectPage{
      .table-school-college-toggle-box{
        overflow: hidden;
        display: inline-block;
        margin-right:10px;
        p{
          display: inline-block;
          text-align: center;
          width:80px;
          line-height:40px;
          height:40px;
          color:#333;
          background-color: #fff;
          border:1px solid #E0E0E0;
          font-size:14px;
          cursor: pointer;
        }
        p:nth-child(1){
          border-top-left-radius: 4px;
          border-bottom-left-radius: 4px;
          /*border-right:none;*/
        }
        p:nth-child(4){
          border-top-right-radius: 4px;
          border-bottom-right-radius: 4px;
          /*border-left:none;*/
        }
        .p-check{
          border:1px solid #0183FA;
          background-color: #0183FA;
          color:#fff;
        }
      }
    }
  }
</style>
