<!--自查任务-->
<template>
  <div class="app-container selfInspectionTask">
    <div class="page-container" v-if="pageType == 1">
      <div class="page-form-title-box">
        <el-form :model="queryParams" class="form-box" ref="queryForm" :inline="true" label-width="80px">
          <div class="form-button-max-big-box">
            <div class="form-button-big-box">
              <p class="text-p" :class="queryParams.checkStatus=='0'?'checkDiv':''" @click="topLeftClickType('0')">全部</p>
              <p class="text-p" :class="queryParams.checkStatus=='1'?'checkDiv':''" @click="topLeftClickType('1')">未开始</p>
              <p class="text-p" :class="queryParams.checkStatus=='2'?'checkDiv':''" @click="topLeftClickType('2')">进行中</p>
              <p class="text-p" :class="queryParams.checkStatus=='3'?'checkDiv':''" @click="topLeftClickType('3')">已结束</p>
            </div>
          </div>
          <!--与我相关-->
          <div class="form-button-max-big-box-me">
            <div class="form-button-big-box-me">
              <div :class="queryParams.myRelated==1?'checkDiv-me':''" @click="topRightClickType">
                <p class="text-p-me">与我有关{{correlationNum}}</p>
                <p class="el-icon-check icon-p-me" v-if="queryParams.myRelated==1"></p>
              </div>
            </div>
          </div>
          <el-form-item label="" style="margin-left:10px;" prop="searchValue">
            <el-input
              maxLength="30"
              v-model="queryParams.searchValue"
              placeholder="计划标题/创建人"
              clearable
              style="width: 200px"
            />
          </el-form-item>
          <el-form-item label="" prop="dateRange" label-width="70px">
            <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" style="margin-right:10px;">查询</p>
          <p class="page-reset-common-style-button" @click="resetQuery">重置</p>
          <p class="page-add-common-style-button"
             style="width:130px;float: right;"
             @click="addDialogOpen(1)"
          >创建自查任务</p>
        </el-form>
      </div>
      <div class="page-content-box">
        <el-table class="table-box" border :data="tableList" ref="multipleTable" @sort-change="sortChange">
          <el-table-column label="序号" align="center"  type="index" width="60" />
          <el-table-column label="计划标题" align="center" prop="title" show-overflow-tooltip/>
          <el-table-column label="检查范围" align="center" prop="checkRange" show-overflow-tooltip width="120">
            <template slot-scope="scope">
              <p>{{scope.row.checkRange==1?'全校':(scope.row.checkRange==2?'学院':(scope.row.checkRange==3?'实验室':''))}}</p>
            </template>
          </el-table-column>
          <el-table-column label="检查类型" align="center" prop="checkRange" show-overflow-tooltip width="120">
            <template slot-scope="scope">
              <p>{{scope.row.checkCategory==1?'综合检查':(scope.row.checkCategory==2?'专项检查':'-')}}</p>
            </template>
          </el-table-column>
          <el-table-column label="任务周期" align="center" prop="cycleStartTime" show-overflow-tooltip width="260">
            <template slot-scope="scope">
              <p>{{scope.row.cycleStartTime}} 至 {{scope.row.cycleEndTime}}<span style="color:#EE0606;margin-left:15px;" v-if="scope.row.isOverdue==1">已逾期</span></p>
            </template>
          </el-table-column>
          <el-table-column label="状态" align="center" prop="checkStatus" show-overflow-tooltip width="80">
            <template slot-scope="scope">
              <p :class="scope.row.checkStatus==1?'checkStatus-color-1':(scope.row.checkStatus==2?'checkStatus-color-2':(scope.row.checkStatus==3?'checkStatus-color-3':''))">{{scope.row.checkStatus==1?'未开始':(scope.row.checkStatus==2?'进行中':(scope.row.checkStatus==3?'已结束':''))}}</p>
            </template>
          </el-table-column>
          <el-table-column label="检查进度" align="center" prop="checkSchedule" show-overflow-tooltip width="210"/>
          <el-table-column label="创建人" align="center" prop="createName" show-overflow-tooltip width="130"/>
          <el-table-column label="创建时间" sortable="custom" align="center" prop="createTime" show-overflow-tooltip width="157"/>
          <el-table-column label="操作" align="center" prop="deptName" width="280">
            <template slot-scope="scope">
              <div class="table-button-box">
                <p class="table-button-null"></p>
                <p class="table-button-p" v-hasPermiRouter="['security:checkPlan_1:detail']"
                   v-show="scope.row.checkStatus!=1" @click="addDialogOpen(3,scope.row)">详情</p>
                <p class="table-button-p" v-hasPermiRouter="['security:checkPlan_1:edit']"
                   v-show="scope.row.checkStatus==1&&scope.row.isSelfData == 1" @click="addDialogOpen(2,scope.row)">编辑</p>
                <p class="table-button-p" v-hasPermiRouter="['security:checkManage_3:list']"
                   @click="goPage(2,scope.row)">自查管理</p>
                <p class="table-button-p" v-hasPermiRouter="['security:checkPlan_1:del']"
                   v-show="scope.row.checkStatus==1&&scope.row.isSelfData == 1" @click="deleteObj(scope.row)">删除</p>
                <p class="table-button-p" v-show="scope.row.isAttachment == 1" @click="lookDocumentListButton(1,scope.row)">查看附件</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>
    <list-page v-if="pageType == 2" :propsListPageData="propsListPageData"></list-page>
    <add-dialog v-if="addDialogType" :addDialogData="addDialogData"></add-dialog>
    <lookDocumentListDialog v-if="lookDocumentListType" :propsLookDocumentListData="propsLookDocumentListData"></lookDocumentListDialog>
  </div>
</template>

<script>
  import addDialog from './addDialog.vue'
  import listPage from './listPage.vue'
  import lookDocumentListDialog from '@/components/lookDocumentDialog/lookDocumentListDialog.vue'
  import { checkPlanList,checkPlanDelete,getFindByCheckPlanId } from '@/api/safetyCheck/indexTow'
  export default {
    name: 'index',
    components: {
      addDialog,
      listPage,
      lookDocumentListDialog
    },
    data(){
      return{
        //子组件数据
        lookDocumentListType:false,
        propsLookDocumentListData:{},
        propsListPageData:{},
        addDialogType:false,
        addDialogData:{},
        pageType:1,
        queryParams:{
          page:1,
          pageSize:20,
          checkStatus:0,
          createTimeSort:0,
          searchValue:"",
          checkType:2,
          myRelated:1,
        },
        dateRange:[],
        tableList:[],
        total:0,
        correlationNum:'',
      }
    },
    created(){

    },
    mounted(){
      this.getList();
    },
    methods:{
      //获取相关数量
      getCorrelationNum(){
        checkPlanList({
          page:1,
          pageSize:20,
          createTimeSort:0,
          checkType:2,
          myRelated:1,
          checkStatus:this.queryParams.checkStatus,
          searchValue:this.queryParams.searchValue,
          cycleStartTime:this.dateRange[0]?this.dateRange[0]:'',
          cycleEndTime:this.dateRange[1]?this.dateRange[1]:'',
        }).then(response => {
          this.$set(this,'correlationNum',response.data.total>999?' 999+':(response.data.total<1?'':' '+response.data.total));
        });
      },
      //与我相关按钮
      topRightClickType(){
        this.$set(this.queryParams,'myRelated',this.queryParams.myRelated==1?0:1);
        this.handleQuery();
      },
      //切换页面
      goPage(type,data){
        if(this.pageType != type){
          if(type == 2){
            this.$set(this,'propsListPageData',data);
            this.$set(this,'pageType',type);
          }else if(type == 1){
            this.$set(this,'pageType',type);
          }else if(type == 3){
            this.$set(this,'pageType',1);
            this.getList();
          }
        }
      },
      //弹窗开启
      addDialogOpen(type,data){
        if(type==1){
          this.$set(this,'addDialogData',{
            title:"创建自查任务",
            lookInfoType:false,
            addType:true,
          })
          this.$set(this,'addDialogType',true);
        }else if(type==2){
          this.$set(this,'addDialogData',{
            title:"编辑自查任务",
            id:data.id,
            lookInfoType:false,
            addType:false,
          })
          this.$set(this,'addDialogType',true);
        }else if(type==3){
          this.$set(this,'addDialogData',{
            title:"自查任务详情",
            id:data.id,
            lookInfoType:true,
            addType:false,
          })
          this.$set(this,'addDialogType',true);
        }else if(type==4){
          this.$set(this,'addDialogType',false);
        }else if(type == 5){
          this.$set(this,'addDialogType',false);
          this.getList();
        }
      },
      //范围选择
      topLeftClickType(type){
        if(this.queryParams.checkStatus != type){
          this.$set(this.queryParams,'checkStatus',type);
          this.handleQuery();
        }
      },
      //时间排序方法
      sortChange(val){
        if(val.prop == 'createTime'){
          this.$set(this.queryParams,'createTimeSort',val.order=='ascending'?'1':(val.order=='descending'?'2':'0'));
          this.handleQuery();
        }
      },
      //获取数据列表
      getList(){
        let obj = JSON.parse(JSON.stringify(this.queryParams))
        if(this.dateRange[0]){
          obj.cycleStartTime = this.dateRange[0];
        }else{
          obj.cycleStartTime = "";
        }
        if(this.dateRange[1]){
          obj.cycleEndTime = this.dateRange[1];
        }else{
          obj.cycleEndTime = "";
        }
        let self = this;
        setTimeout(function(){
          self.getCorrelationNum();
        },500);
        checkPlanList(obj).then(response => {
          this.total = response.data.total;
          this.tableList = response.data.records;
        });
      },
      /** 搜索按钮操作 */
      handleQuery() {
        this.$set(this.queryParams,'page',1);
        this.getList();
      },
      /** 重置按钮操作 */
      resetQuery() {
        this.$set(this,'dateRange',[]);
        this.$set(this,'queryParams',{
          page:1,
          pageSize:20,
          checkStatus:0,
          createTimeSort:0,
          searchValue:"",
          checkType:2,
          myRelated:1,
        });
        this.handleQuery();
      },
      //删除
      deleteObj(obj){
        let self = this;
        this.$confirm('是否确认删除?', "警告", {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          type: "warning"
        }).then(function() {
          checkPlanDelete({id:obj.id,checkType:obj.checkType}).then(response => {
            self.msgSuccess(response.message)
            self.getList();
          })
        }).then(() => {
        }).catch(() => {});
      },
      //查看多个文档
      lookDocumentListButton(type,row){
        if(type==1){
          getFindByCheckPlanId({checkPlanId:row.id}).then(response => {
            let list = [];
            for(let i=0;i<response.data.length;i++){
              let obj = {
                name:response.data[i].fileName,
                url:response.data[i].fileUrl,
              }
              list.push(obj);
            }
            this.$set(this,'propsLookDocumentListData',{
              title:"查看附件",
              list:list
            });
            this.$set(this,'lookDocumentListType',true);
          });
        }else{
          this.$set(this,'lookDocumentListType',false);
        }
      },
    }
  }
</script>

<style scoped lang="scss">
  .selfInspectionTask{
    .page-container{
      .page-form-title-box{
        .form-button-max-big-box{
          display: inline-block;
          overflow: hidden;
          .form-button-big-box{
            display: flex;
            p:nth-child(1){
              border-top-left-radius: 4px;
              border-bottom-left-radius: 4px;
              border-top:1px solid #E0E0E0;
              border-bottom:1px solid #E0E0E0;
            }
            p:nth-child(2){
              border-top:1px solid #E0E0E0;
              border-bottom:1px solid #E0E0E0;
            }
            p:nth-child(3){
              border-top:1px solid #E0E0E0;
              border-bottom:1px solid #E0E0E0;
            }
            p:nth-child(4){
              border-top-right-radius: 4px;
              border-bottom-right-radius: 4px;
              border-top:1px solid #E0E0E0;
              border-bottom:1px solid #E0E0E0;
              border-right:1px solid #E0E0E0;
            }
            p{
              height:40px;
              width:80px;
              line-height: 40px;
              text-align: center;
              color:#666666;
              font-size:14px;
              font-weight:500;
              cursor: pointer;
              border-left:1px solid #E0E0E0;
            }
            .checkDiv{
              color:#fff!important;
              border:1px solid #0183FA!important;
              background-color: #0183FA;
            }
          }
        }
        .form-button-max-big-box-me{
          display: inline-block;
          overflow: hidden;
          .form-button-big-box-me{
            display: flex;
            div{
              position: relative;
              height:40px;
              width:130px;
              line-height: 40px;
              text-align: center;
              color:#999;
              font-size:14px;
              border:1px solid #999;
              border-radius:4px;
              margin-left:10px;
              font-weight:500;
              cursor: pointer;
              .icon-p-me{
                width:15px;
                height:15px;
                line-height:15px;
                text-align: center;
                position: absolute;
                right:0;
                bottom:0;
                color:#fff;
                background: #0183fa;
                border-top-left-radius:4px;
              }
            }
            .checkDiv-me{
              color:#0183FA!important;
              border:1px solid #0183FA!important;
            }
          }
        }
      }
      .page-content-box{
        .checkStatus-color-1{
          color:#0183FA;
        }
        .checkStatus-color-2{
          color:#EE0606;
        }
        .checkStatus-color-3{
          color:#23B303;
        }
      }
    }
  }
</style>
