<!--自查任务-->
<template>
  <div class="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.buttonType==1?'checkDiv':''" @click="topLeftClickType(1)">
                <p class="text-p">全部</p>
                <p class="el-icon-check icon-p" v-if="queryParams.buttonType==1"></p>
              </div>
              <div :class="queryParams.buttonType==2?'checkDiv':''" @click="topLeftClickType(2)">
                <p class="text-p">待检查</p>
                <p class="el-icon-check icon-p" v-if="queryParams.buttonType==2"></p>
              </div>
              <div :class="queryParams.buttonType==3?'checkDiv':''" @click="topLeftClickType(3)">
                <p class="text-p">检查中</p>
                <p class="el-icon-check icon-p" v-if="queryParams.buttonType==3"></p>
              </div>
              <div :class="queryParams.buttonType==4?'checkDiv':''" @click="topLeftClickType(4)">
                <p class="text-p">已检查</p>
                <p class="el-icon-check icon-p" v-if="queryParams.buttonType==4"></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;">
            <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="deptName" show-overflow-tooltip/>
          <el-table-column label="检查范围" align="center" prop="deptName" show-overflow-tooltip width="120"/>
          <el-table-column label="检查周期" align="center" prop="deptName" show-overflow-tooltip width="280"/>
          <el-table-column label="检查状态" align="center" prop="deptName" show-overflow-tooltip width="130"/>
          <el-table-column label="检查进度" align="center" prop="deptName" show-overflow-tooltip width="220"/>
          <el-table-column label="创建人" align="center" prop="deptName" show-overflow-tooltip width="130"/>
          <el-table-column label="创建时间" sortable align="center" prop="deptName" show-overflow-tooltip width="157"/>
          <el-table-column label="操作" align="center" prop="deptName" width="200">
            <template slot-scope="scope">
              <div class="table-button-box">
                <p class="table-button-p" @click="addDialogOpen(2,scope.row)">编辑</p>
                <p class="table-button-p">删除</p>
                <p class="table-button-p" @click="addDialogOpen(3,scope.row)">详情</p>
                <p class="table-button-p" @click="goPage(2,scope.row)">自查管理</p>
                <!--<p class="table-button-p">查看附件</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>
    <add-dialog ref="addDialog"></add-dialog>
    <list-page v-if="pageType == 2"></list-page>
  </div>
</template>

<script>
  import addDialog from './addDialog.vue'
  import listPage from './listPage.vue'
  export default {
    name: 'index',
    components: {
      addDialog,
      listPage
    },
    data(){
      return{
        pageType:1,
        queryParams:{
          pageNum:1,
          pageSize:20,
          buttonType:1,
          timeType:0,
          searchValue:"",
          data1:""
        },
        dateRange:[],
        tableList:[{}],
        total:0,
      }
    },
    created(){

    },
    mounted(){

    },
    methods:{
      goPage(type){
        if(this.pageType != type){
          this.$set(this,'pageType',type);
        }
      },
      //弹窗开启
      addDialogOpen(type,data){
        if(type==1){
          this.$refs.addDialog.addDialogOpen(type);
        }else if(type==2){
          this.$refs.addDialog.addDialogOpen(type,data);
        }else{
          this.$refs.addDialog.addDialogOpen(type,data);
        }
      },
      //范围选择
      topLeftClickType(type){
        if(this.queryParams.buttonType != type){
          this.$set(this.queryParams,'buttonType',type);
          this.getList();
        }
      },
      //时间排序方法
      sortChange(val){
        //ascending 上    descending 下    null  无
        console.log('val',val.order)
        this.$set(this.queryParams,'timeType',val.order=='ascending'?1:(val.order=='descending'?2:''));
      },
      //获取数据列表
      getList(){
        // this.queryParamsData = JSON.parse(JSON.stringify(this.queryParams));
        // this.queryParamsData.type = 'RFID_RECOGNIZER';
        // listHardware(this.queryParamsData).then(response => {
        //   this.total = response.total;
        //   this.tableList = response.rows;
        // });
      },
      /** 搜索按钮操作 */
      handleQuery() {
        this.$set(this.queryParams,'pageNum',1);
        this.getList();
      },
      /** 重置按钮操作 */
      resetQuery() {
        this.$set(this,'dateRange',[]);
        this.$set(this,'queryParams',{
          pageNum:1,
          pageSize:20,
          buttonType:1,
          timeType:0,
          searchValue:"",
          data1:""
        });
        this.handleQuery();
      },
      /*==========上传相关==========*/

      handleAvatarSuccess(res) {
        if(this.dialogUpList.length>9){
          this.msgError('已到达上传数量上限')
          return
        }
        let suffixName= this.upDataName.split('.')[this.upDataName.split('.').length - 2]
        //判断文件名中是否有逗号和分号
        if(suffixName.indexOf(',')==-1 && suffixName.indexOf(';')==-1){
        }else{
          this.$message.info('文件名里包含逗号或分号，请修改后重新上传！')
          return
        }
        let obj ={
          name:this.upDataName,
          url:res.data.url,
        };
        this.dialogUpList.push(obj);
        this.$forceUpdate()
      },
      beforeAvatarUpload(file) {
        console.log('file',file)
        let type = false;
        if (file.type == 'application/pdf' || file.type == 'application/msword' || file.type == 'application/vnd.openxmlformats-officedocument.wordprocessingml.document'|| file.type == 'application/vnd.ms-excel' || file.type == 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet') {
          this.upDataName = file.name;
          type = true;
        }else{
          this.$message.error('只能上传png/jpeg/gif/doc/docx格式');
          type = false;
        }
        return type;
      },
    }
  }
</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;
      }
    }
  }
</style>
