<!--自查任务-->
<template>
  <div class="app-container selfInspectionTask">
    <div class="selfInspectionTask-page" v-if="pageType == 1">
      <div class="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" style="margin-left:10px;">
              <div :class="queryParams.checkStatus==0?'checkDiv':''" @click="topLeftClickType(0)">
                <p class="text-p">全部</p>
                <p class="el-icon-check icon-p" v-if="queryParams.checkStatus==0"></p>
              </div>
              <div :class="queryParams.checkStatus==1?'checkDiv':''" @click="topLeftClickType(1)">
                <p class="text-p">未开始</p>
                <p class="el-icon-check icon-p" v-if="queryParams.checkStatus==1"></p>
              </div>
              <div :class="queryParams.checkStatus==2?'checkDiv':''" @click="topLeftClickType(2)">
                <p class="text-p">进行中</p>
                <p class="el-icon-check icon-p" v-if="queryParams.checkStatus==2"></p>
              </div>
              <div :class="queryParams.checkStatus==3?'checkDiv':''" @click="topLeftClickType(3)">
                <p class="text-p">已结束</p>
                <p class="el-icon-check icon-p" v-if="queryParams.checkStatus==3"></p>
              </div>
            </div>
          </div>
          <el-form-item label="关键字" prop="searchValue">
            <el-input
              maxLength="30"
              v-model="queryParams.searchValue"
              placeholder="计划标题/创建人"
              clearable
              style="width: 200px"
            />
          </el-form-item>
          <el-form-item label="检查周期" prop="dateRange" style="margin-left:10px;" 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>
          <el-form-item>
            <p class="inquire-button-one" @click="handleQuery" style="margin-right:10px;">查询</p>
            <p class="reset-button-one" @click="resetQuery">重置</p>
          </el-form-item>
          <el-form-item style="float: right;" v-hasPermi="['security:checkPlan_1:add']">
            <el-col :span="1.5">
              <p class="inquire-button-one"
                 style="width:130px;"
                 @click="addDialogOpen(1)"
              ><i class="el-icon-plus"></i> 创建自查任务</p>
            </el-col>
          </el-form-item>
        </el-form>
      </div>
      <div class="content-box">
        <el-table  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="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-hasPermi="['security:checkPlan_1:query']"
                   v-show="scope.row.checkStatus!=1" @click="addDialogOpen(3,scope.row)">详情</p>
                <p class="table-button-p" v-hasPermiAnd="['security:checkPlan_1:query','security:checkPlan_1:edit']"
                   v-show="scope.row.checkStatus==1" @click="addDialogOpen(2,scope.row)">编辑</p>
                <p class="table-button-p" v-hasPermi="['security:checkManage_3:list']"
                   @click="goPage(2,scope.row)">自查管理</p>
                <p class="table-button-p" v-hasPermi="['security:checkPlan_1:remove']"
                   v-show="scope.row.checkStatus==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.pageNum"
                    :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/index'
  export default {
    name: 'index',
    components: {
      addDialog,
      listPage,
      lookDocumentListDialog
    },
    data(){
      return{
        //子组件数据
        lookDocumentListType:false,
        propsLookDocumentListData:{},
        propsListPageData:{},
        addDialogType:false,
        addDialogData:{},
        pageType:1,
        queryParams:{
          pageNum:1,
          pageSize:20,
          checkStatus:0,
          createTimeSort:0,
          searchValue:"",
          checkType:2,
        },
        dateRange:[],
        tableList:[],
        total:0,
      }
    },
    created(){

    },
    mounted(){
      this.getList();
    },
    methods:{
      //切换页面
      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 = "";
        }
        checkPlanList(obj).then(response => {
          this.total = response.data.total;
          this.tableList = response.data.records;
        });
      },
      /** 搜索按钮操作 */
      handleQuery() {
        this.$set(this.queryParams,'pageNum',1);
        this.getList();
      },
      /** 重置按钮操作 */
      resetQuery() {
        this.$set(this,'dateRange',[]);
        this.$set(this,'queryParams',{
          pageNum:1,
          pageSize:20,
          checkStatus:0,
          createTimeSort:0,
          searchValue:"",
          checkType:2,
        });
        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.msg)
            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{
    flex: 1;
    display: flex !important;
    flex-direction: column;
    overflow: hidden;
    .selfInspectionTask-page{
      flex: 1;
      display: flex !important;
      flex-direction: column;
      overflow: hidden;
      .title-box{
        padding-top:20px;
        border-bottom:1px solid #dedede;
        .form-button-max-big-box{
          display: inline-block;
          .form-button-big-box{
            display: flex;
            div{
              position: relative;
              height:40px;
              width:80px;
              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{
                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{
              color:#0183FA;
              border:1px solid #0183FA;
            }
          }
        }
      }
      .content-box{
        flex: 1;
        display: flex;
        flex-direction: column;
        padding:20px;
        overflow: hidden;
        .checkStatus-color-1{
          color:#0183FA;
        }
        .checkStatus-color-2{
          color:#EE0606;
        }
        .checkStatus-color-3{
          color:#23B303;
        }
      }
    }
  }
</style>
