<!--检查项--->
<template>
  <div class="page-container checkItem">
    <div class="page-container checkItem" v-if="pageType == 1">
      <div class="page-top-title-box">
        <p class="page-top-title-name-p">{{propsData.subName}}</p>
        <p class="page-top-title-out-p" @click="backPage">返回</p>
      </div>
      <div class="content-box scrollbar-box">
        <div class="page-form-title-box" style="border:none;">
          <el-form :model="queryParams" class="form-box" ref="queryForm"
                   :inline="true" style="width:100%;">
            <div class="table-school-college-toggle-box" v-if="propsData.manageStatus != 2">
              <p :class="checkStatus==null?'p-check':''" @click="tableCheck(null)">全部</p>
              <p :class="checkStatus==0?'p-check':''" @click="tableCheck(0)">待检查</p>
              <!--<p :class="checkStatus==2?'p-check':''" @click="tableCheck(2)">检查中</p>-->
              <p :class="checkStatus==1?'p-check':''" @click="tableCheck(1)">已检查</p>
            </div>
            <el-form-item label="" prop="hazardCheckPro">
              <el-cascader
                placeholder="请选择检查项目"
                style="width:200px;"
                v-model="queryParams.hazardCheckPro"
                filterable
                :show-all-levels="false"
                :options="cascaderData"
                :props="{ value: 'id', label: 'labelName',emitPath:false }"
              ></el-cascader>
            </el-form-item>
            <!--<el-form-item label="" prop="checkFlagInt" v-if="checkFlagIntType">-->
              <!--<el-select v-model="queryParams.checkFlagInt" placeholder="检查结果" style="width: 200px">-->
                <!--<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="checkUserName">
              <el-input
                maxLength="30"
                v-model="queryParams.checkUserName"
                placeholder="检查人"
                style="width: 200px"
              />
            </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>
          </el-form>
        </div>
        <div class="page-content-box" style="padding-top:0;">
          <el-table class="table-box" border :data="dataList">
            <el-table-column label="序号" type="index" width="60"/>
            <el-table-column label="检查项目" prop="name" show-overflow-tooltip>
              <template slot-scope="scope">
                <span>{{scope.row.hazardCheckCode}} {{scope.row.hazardCheckName}}</span>
              </template>
            </el-table-column>
            <el-table-column label="隐患描述" prop="hazardDescribe" width="400" show-overflow-tooltip>
              <template slot-scope="scope">
                <span v-if="scope.row.checkStatus == 0&&scope.row.checkDraftVo">{{scope.row.checkDraftVo.hazardDescribe}}</span>
                <span v-else>{{scope.row.hazardDescribe}}</span>
              </template>
            </el-table-column>
            <!--<el-table-column label="检查结果" prop="checkFlag" width="150" show-overflow-tooltip>-->
              <!--<template slot-scope="scope">-->
                <!--<span>{{scope.row.checkStatus!=1?'-':(scope.row.checkFlag?'符合':'不符合')}}</span>-->
              <!--</template>-->
            <!--</el-table-column>-->
            <el-table-column label="检查人" prop="checkUserName" width="150" show-overflow-tooltip>
              <template slot-scope="scope">
                <span>{{scope.row.checkStatus == 1?scope.row.checkUserName:'-'}}</span>
              </template>
            </el-table-column>
            <el-table-column label="检查时间" prop="createTime" width="180" show-overflow-tooltip>
              <template slot-scope="scope">
                <span>{{ scope.row.checkStatus == 1?parseTime(scope.row.checkTime,'{y}-{m}-{d} {h}:{i}'):'-' }}</span>
              </template>
            </el-table-column>
            <el-table-column label="状态" prop="checkStatus" width="150" show-overflow-tooltip>
              <template slot-scope="scope">
                <!--<span v-if="scope.row.checkStatus == 0&&scope.row.checkDraftVo">检查中</span>-->
                <!--<span v-else>{{scope.row.checkStatus == '0'?'未开始':(scope.row.checkStatus == '1'?'已完成':'')}}</span>-->
                <span v-if="scope.row.checkStatus == 0&&scope.row.checkDraftVo">待检查</span>
                <span v-else>{{scope.row.checkStatus == '0'?'待检查':(scope.row.checkStatus == '1'?'已检查':'')}}</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.checkStatus == 0 && propsData.pageType == 1"-->
                     <!--@click="tableButton(1,scope.row)"-->
                     <!--v-hasPermiRouter="['security:checkPlan:detail']"-->
                  <!--&gt;开始检查</p>-->
                  <!-- 院级 -->
                  <!--<p class="table-button-p"-->
                     <!--v-if="scope.row.checkStatus == 0 && propsData.pageType == 2"-->
                     <!--@click="tableButton(1,scope.row)"-->
                     <!--v-hasPermiRouter="['security:checkPlan_1:detail']"-->
                  <!--&gt;开始检查</p>-->
                  <!-- 校级 -->
                  <p class="table-button-p"
                     v-if="(scope.row.checkStatus == 1 && !checkSetType) && propsData.pageType == 1"
                     @click="tableButton(3,scope.row)"
                     v-hasPermiRouter="['security:checkPlan:detail']"
                  >编辑</p>
                  <!-- 院级 -->
                  <p class="table-button-p"
                     v-if="(scope.row.checkStatus == 1 && !checkSetType) && propsData.pageType == 2"
                     @click="tableButton(3,scope.row)"
                     v-hasPermiRouter="['security:checkPlan_1:detail']"
                  >编辑</p>
                  <p class="table-button-p"
                     v-if="scope.row.checkStatus == 1"
                     @click="tableButton(2,scope.row)"
                  >详情</p>
                  <p class="table-button-p"
                     v-if="scope.row.checkStatus == 1 && !checkSetType"
                     @click="tableButton(7,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="securityCheckPlanSetFindProgress"
          />
        </div>
      </div>
    </div>
    <initiateInspect v-if="pageType == 2" :initiateInspectData="initiateInspectData"></initiateInspect>
  </div>
</template>

<script>
  //import { getDicts } from "@/api/commonality/noPermission";
  //import { systemUserSelect } from "@/api/commonality/permission";
  import {
    securityCheckOptionList,
    securityCheckSetOptionList,
    securityCheckPlanSetFindProgress,
    securityCheckSetOptionClearOptionData
  } from '@/api/safetyCheck/index'
  import initiateInspect from '@/views/safetyCheck/components/initiateInspect/initiateInspect.vue'

  export default {
    name: 'checkItem',
    components: {
      initiateInspect
    },
    props: {
      propsData: {}
    },
    data() {
      return {
        //页面状态
        pageType: 1,
        //状态选项卡
        checkStatus: null,
        checkFlagIntType: true,
        //下拉列表数据
        optionList: [
          { value: 1, label: '符合' },
          { value: 0, label: '不符合' },
          // { value: 2, label: '草稿' }
        ],
        cascaderData: [],
        //查询条件
        queryParams: {
          page: 1,
          pageSize: 20,
          hazardCheckPro: null,
          // checkFlagInt: null,
          checkUserName: ''
        },
        //时间数据
        dateRange: [],
        //列表数据
        dataList: [],
        //数据数量
        total: 0,
        //批次是否完成
        checkSetType: false,
        //组件传参
        initiateInspectData: {}
      }
    },
    created() {
      this.securityCheckOptionList()
      this.securityCheckPlanSetFindProgress()
    },
    mounted() {

    },
    methods: {
      //选项卡切换
      tableCheck(type) {
        if (this.checkStatus !== type) {
          if (type == null) {
            //全部
            this.$set(this, 'optionList',[{ value: 1, label: '符合' },{ value: 0, label: '不符合' },{ value: 2, label: '草稿' }])
            this.$set(this, 'checkFlagIntType',true)
          } else if (type == 0) {
            //待检查
            this.$set(this, 'checkFlagIntType',false)
          } else if (type == 2) {
            //草稿
            this.$set(this, 'checkFlagIntType',false)
          } else if (type == 1) {
            //已检查
            this.$set(this, 'optionList', [{ value: 1, label: '符合' },{ value: 0, label: '不符合' }])
            this.$set(this, 'checkFlagIntType',true)
          }
          this.$set(this, 'checkStatus', type)
          this.resetQuery()
        }
      },
      // 返回按钮
      backPage() {
        this.$parent.tableButton(6)
      },
      //查询按钮
      handleQuery() {
        this.$set(this.queryParams, 'page', 1)
        this.securityCheckPlanSetFindProgress()
      },
      //重置按钮
      resetQuery() {
        this.$set(this, 'dateRange', [])
        this.$set(this, 'queryParams', {
          page: 1,
          pageSize: 20,
          hazardCheckPro: null,
          // checkFlagInt: null,
          checkUserName: ''
        })
        this.securityCheckPlanSetFindProgress()
      },
      //获取数据列表
      getList() {
        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.manageId = this.propsData.manageId
        if(this.propsData.manageStatus == 2){
          obj.checkStatus = 1
        }else{
          obj.checkStatus = this.checkStatus
        }
        securityCheckSetOptionList(obj).then(response => {
          this.$set(this, 'dataList', response.data.records)
          this.$set(this, 'total', response.data.total)
        })
      },
      //查询检查批次是否完成
      securityCheckPlanSetFindProgress() {
        securityCheckPlanSetFindProgress({ planSetId: this.propsData.planSetId }).then(response => {
          this.$set(this, 'checkSetType', response.data)
          this.getList()
        })
      },
      //检查项列表
      securityCheckOptionList() {
        securityCheckOptionList({}).then(response => {
          let list = this.getCascaderData(response.data)
          this.$set(this, 'cascaderData', list)
        })
      },
      getCascaderData(list) {
        let self = this
        for (let i = 0; i < list.length; i++) {
          list[i].labelName = list[i].code ? list[i].code + ' ' + list[i].name : list[i].name
          if (list[i].children) {
            if (list[i].children[0]) {
              list[i].children = self.getCascaderData(list[i].children)
            } else {
              if (list[i].level != 3) {
                list.splice(i, 1)
                i--
              } else {
                delete list[i].children
              }
            }
          } else {
            if (list[i].level != 3) {
              list.splice(i, 1)
              i--
            } else {
              delete list[i].children
            }
          }
        }
        for (let i = 0; i < list.length; i++) {
          list[i].labelName = list[i].code ? list[i].code + ' ' + list[i].name : list[i].name
          if (list[i].children) {
            if (list[i].children[0]) {
              list[i].children = self.getCascaderData(list[i].children)
            } else {
              if (list[i].level != 3) {
                list.splice(i, 1)
                i--
              } else {
                delete list[i].children
              }
            }
          } else {
            if (list[i].level != 3) {
              list.splice(i, 1)
              i--
            } else {
              delete list[i].children
            }
          }
        }
        for (let i = 0; i < list.length; i++) {
          list[i].labelName = list[i].code ? list[i].code + ' ' + list[i].name : list[i].name
          if (list[i].children) {
            if (list[i].children[0]) {
              list[i].children = self.getCascaderData(list[i].children)
            } else {
              if (list[i].level != 3) {
                list.splice(i, 1)
                i--
              } else {
                delete list[i].children
              }
            }
          } else {
            if (list[i].level != 3) {
              list.splice(i, 1)
              i--
            } else {
              delete list[i].children
            }
          }
        }
        return list
      },
      //操作按钮
      tableButton(type, row) {
        let self = this
        if (type == 1) {
          //开始检查
          this.$set(this, 'pageType', 2)
          let obj = JSON.parse(JSON.stringify(row))
          obj.manageId = this.propsData.manageId
          obj.showType = false
          obj.orderTitle = '开始检查'
          obj.orderType = '1'
          this.$set(this, 'initiateInspectData', obj)
        } else if (type == 2) {
          //详情
          this.$set(this, 'pageType', 2)
          let obj = JSON.parse(JSON.stringify(row))
          obj.manageId = this.propsData.manageId
          obj.showType = true
          obj.orderTitle = '检查详情'
          obj.orderType = '2'
          this.$set(this, 'initiateInspectData', obj)
        } else if (type == 3) {
          //编辑
          this.$set(this, 'pageType', 2)
          let obj = JSON.parse(JSON.stringify(row))
          obj.manageId = this.propsData.manageId
          obj.showType = false
          obj.orderType = '1'
          this.$set(this, 'initiateInspectData', obj)
        } else if (type == 6) {
          //返回并刷新
          this.$set(this, 'pageType', 1)
          this.securityCheckPlanSetFindProgress()
        } else if (type == 7) {
          //清除提交记录
          this.$confirm('确认清除该隐患信息?', "警告", {
            confirmButtonText: "确定",
            cancelButtonText: "取消",
            type: "warning"
          }).then(function() {
          }).then(() => {
            securityCheckSetOptionClearOptionData({setOptionId:row.setOptionId}).then(response => {
              self.msgSuccess(response.message)
              self.getList();
            });
          }).catch(() => {});
        }
      }
    }
  }
</script>

<style scoped lang="scss">
  .checkItem {
    .content-box {
      flex: 1;
      display: flex;
      flex-direction: column;
      overflow: hidden;
      .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(3) {
          border-top-right-radius: 4px;
          border-bottom-right-radius: 4px;
          /*border-left:none;*/
        }
        .p-check {
          border: 1px solid #0183FA;
          background-color: #0183FA;
          color: #fff;
        }
      }
      .form-button-max-big-box-me {
        display: inline-block;
        overflow: hidden;
        margin-right: 10px;
        .form-button-big-box-me {
          display: flex;
          div {
            position: relative;
            height: 40px;
            width: 100px;
            line-height: 40px;
            text-align: center;
            color: #999;
            font-size: 14px;
            border: 1px solid #999;
            border-radius: 4px;
            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;
          }
        }
      }
    }
  }
</style>
