<!-- 条件设置 -->
<template>
  <div class="app-container conditionsSettings">
    <div class="page-container conditionsSettingsPage" v-if="pageType === 1">
      <div class="page-form-title-box">
        <el-form :model="queryParams" class="form-box" ref="queryForm"
                 :inline="true" style="width:100%;">
          <el-form-item label="" prop="name">
            <el-input
              maxLength="30"
              v-model="queryParams.name"
              placeholder="管控名称"
              style="width: 200px"
            />
          </el-form-item>
          <el-form-item label="" prop="deptId">
            <el-select v-model="queryParams.deptId" placeholder="二级单位" style="width: 200px">
              <el-option
                v-for="dict in deptOptions"
                :key="dict.deptId"
                :label="dict.deptName"
                :value="dict.deptId"
              ></el-option>
            </el-select>
          </el-form-item>
          <el-form-item label="" prop="typeId">
            <el-select v-model="queryParams.typeId" placeholder="安全分类" style="width: 200px">
              <el-option
                v-for="dict in typeList"
                :key="dict.typeId"
                :label="dict.typeName"
                :value="dict.typeId"
              ></el-option>
            </el-select>
          </el-form-item>
          <el-form-item label="" prop="levelId">
            <el-select v-model="queryParams.levelId" placeholder="安全分级" style="width: 200px">
              <el-option
                v-for="dict in levelList"
                :key="dict.levelId"
                :label="dict.levelName"
                :value="dict.levelId"
              ></el-option>
            </el-select>
          </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-add-common-style-button"
             style="float: right;"
             @click="tableButton(1)"
          >新增</p>
        </el-form>
      </div>
      <div class="page-content-box">
        <el-table class="table-box" v-loading="loading" border :data="dataList">
          <el-table-column label="管控名称" prop="name"  show-overflow-tooltip/>
          <el-table-column label="二级单位" prop="deptName" width="200" show-overflow-tooltip/>
          <el-table-column label="安全分类" prop="typeName" width="200" show-overflow-tooltip/>
          <el-table-column label="安全分级" prop="levelName" width="200" show-overflow-tooltip/>
          <el-table-column label="执行状态" prop="status" width="120" show-overflow-tooltip>
            <template slot-scope="scope">
              <span :class="scope.row.status == 1?'colorA':'colorB'">{{scope.row.status == 1?'已执行':'未执行'}}</span>
            </template>
          </el-table-column>
          <el-table-column label="创建人" prop="createUser" width="200" show-overflow-tooltip/>
          <el-table-column label="创建时间" prop="createTime" width="200" 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="140" 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.status == 0"
                   @click="tableButton(2,scope.row)"
                >编辑</p>
                <p class="table-button-p"
                   v-if="scope.row.status == 0"
                   @click="tableButton(3,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>
    <add-page :propsData="propsData" v-if="pageType === 2"></add-page>
  </div>
</template>
<script>
  import {
    getDeptDropList,
    laboratoryClassTypeGetList,
    laboratoryClassLevelGetList,
  } from '@/api/commonality/permission'
  import { laboratoryGradeManageList,laboratoryGradeManageDelete } from "@/api/hierarchicalControl/index";
  import addPage from "./addPage.vue";
  export default {
    name: 'index',
    components: {
     addPage
    },
    data () {
      return {
        //页面状态
        pageType:1,
        //页面遮罩
        loading:false,
        //下拉列表数据
        deptOptions:[],
        typeList:[],
        levelList:[],
        //查询条件
        queryParams:{
          page:1,
          pageSize:20,
          name:"",
          deptId :null,
          typeId :null,
          levelId :null,
        },
        //列表数据
        dataList:[],
        //数据数量
        total:0,
        //组件传参
        propsData:{},
      }
    },
    created () {

    },
    mounted () {
      this.getDeptDropList();
      this.laboratoryClassTypeGetList();
      this.laboratoryClassLevelGetList();
      this.getList();
    },
    methods: {
      //查询按钮
      handleQuery(){
        this.$set(this.queryParams,'page',1);
        this.getList();
      },
      //重置按钮
      resetQuery(){
        this.$set(this,'dateRange',[])
        this.$set(this,'queryParams',{
          page:1,
          pageSize:20,
          name:"",
          deptId :null,
          typeId :null,
          levelId :null,
        });
        this.getList();
      },
      //获取数据列表
      getList(){
        laboratoryGradeManageList(this.queryParams).then(response => {
          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',{});
        }else if(type == 2){
          //编辑
          this.$set(this,'pageType',2);
          let obj = JSON.parse(JSON.stringify(row))
          obj.showType = false;
          this.$set(this,'propsData',obj);
        }else if(type == 3){
          //删除
          this.$confirm('是否确认删除?', "警告", {
            confirmButtonText: "确定",
            cancelButtonText: "取消",
            type: "warning"
          }).then(function() {
          }).then(() => {
            laboratoryGradeManageDelete({manageId:row.id}).then(response => {
              self.msgSuccess(response.message)
              self.getList();
            });
          }).catch(() => {});
        }else if(type == 6){
          //返回并刷新
          this.$set(this,'pageType',1);
          this.getList();
        }
      },
      /** 查询二级单位列表 */
      getDeptDropList() {
        getDeptDropList({ deptName: '', level: 2, deptType: 1 }).then(response => {
          this.$set(this, 'deptOptions', response.data)
        })
      },
      //查询安全分级
      laboratoryClassLevelGetList() {
        laboratoryClassLevelGetList({}).then(response => {
          this.$set(this, 'levelList', response.data)
        })
      },
      //查询安全分类
      laboratoryClassTypeGetList() {
        laboratoryClassTypeGetList({}).then(response => {
          this.$set(this, 'typeList', response.data)
        })
      },
    },
  }
</script>
<style scoped lang="scss">
  .conditionsSettings{
    .conditionsSettingsPage{

      .colorA{
        color:#0183FA;
      }
      .colorB{
        color: #c88400;
      }
    }
  }
</style>
