<!--控制记录-->
<template>
  <div class="app-container control">
    <div class="scrollbar-box" v-if="pageType == 0">
      <el-form :model="param" ref="queryForm" :inline="true" label-width="80px">
        <el-form-item label="关键字" prop="name">
          <el-input
            maxlength="10"
            v-model="param.searchValue"
            placeholder="预案名称/创建人"
            clearable
            size="small"
          />
        </el-form-item>
        <el-form-item label="创建时间">
          <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 style="float: right;" v-hasPermi="['laboratory:plan:add']">
          <el-button
            style="float: left"
            type="primary"
            plain
            icon="el-icon-plus"
            size="mini"
            @click="handleClick('', '', 'add')"
          >新增预案</el-button>
        </el-form-item>
        <el-form-item>
          <p class="inquire-button-one" @click="onSearch">查询</p>
          <p class="reset-button-one" @click="resetForm">重置</p>
        </el-form-item>
      </el-form>
      <el-table v-loading="loading" border :data="tableData">
        <el-table-column label="预案名称" align="left" prop="name" />
        <el-table-column label="启动条件" align="left" prop="funNum" />
        <el-table-column label="创建人" align="left" prop="createBy" />
        <el-table-column label="创建时间" align="left" prop="createTime" />
        <el-table-column label="操作" align="center" class-name="small-padding fixed-width" width="160" v-if="tableButtonType">
          <template slot-scope="scope">
            <div class="button-box">
              <p class="table-min-button" style="margin-right:10px;" v-hasPermi="['laboratory:plan:query']"
                 @click="handleClick(scope.$index, scope.row,'detail')">查看</p>
              <el-dropdown @command="moreClick">
                <p class="table-min-button">更多>></p>
                <el-dropdown-menu slot="dropdown">
                  <el-dropdown-item style="margin:0 10px;" :command="{index:scope.$index,row:scope.row,command:1}"
                                    v-hasPermi="['laboratory:planjoin:edit']">关联实验室</el-dropdown-item>
                  <el-dropdown-item style="margin:0 10px;" :command="{index:scope.$index,row:scope.row,command:2}"
                                    v-hasPermi="['laboratory:distribution:list']">关联记录</el-dropdown-item>
                  <el-dropdown-item style="margin:0 10px;" :command="{index:scope.$index,row:scope.row,command:3}"
                                    v-show="userId==scope.row.userId"
                                    v-hasPermiAnd="['laboratory:plan:query','laboratory:plan:edit']">编辑</el-dropdown-item>
                  <el-dropdown-item style="margin:0 10px;" :command="{index:scope.$index,row:scope.row,command:4}"
                                    v-show="userId==scope.row.userId"
                                    v-hasPermi="['laboratory:plan:remove']">删除</el-dropdown-item>
                </el-dropdown-menu>
              </el-dropdown>
              <!--<p class="table-min-button" style="margin-right:10px;" v-hasPermi="['laboratory:planjoin:edit']"-->
                 <!--@click="handleClick(scope.$index, scope.row,'relevanceLab')">关联实验室</p>-->
              <!--<p class="table-min-button" style="margin-right:10px;" v-hasPermi="['laboratory:distribution:list']"-->
                 <!--@click="handleClick(scope.$index, scope.row,'relevanceRecord')">关联记录</p>-->
              <!--<p class="table-min-button" style="margin-right:10px;" v-hasPermiAnd="['laboratory:plan:query','laboratory:plan:edit']"-->
                 <!--v-show="userId==scope.row.userId" @click="handleClick(scope.$index, scope.row,'edit')">编辑</p>-->
              <!--<p class="table-min-button" v-hasPermi="['laboratory:plan:remove']"-->
                 <!--v-show="userId==scope.row.userId" @click="handleClick(scope.$index, scope.row,'delete')" >删除</p>-->
            </div>
          </template>
        </el-table-column>
      </el-table>
      <pagination
        v-show="total>0"
        :total="total"
        layout="total, prev, pager, next, sizes, jumper"
        :page.sync="param.pageNum"
        :limit.sync="param.pageSize"
        @pagination="getListPlan"
      />
    </div>
     <!--添加编辑-->
    <add-plan-page v-if="pageType == 1" :pageData="pageData"></add-plan-page>
     <!--  查看  -->
    <detail-plan-page v-if="pageType == 2" :pageData2="pageData2"></detail-plan-page>
    <!--关联实验室-->
    <association-page v-if="pageType == 4" :associationData="associationData"></association-page>
    <!--  关联记录  -->
    <el-dialog title='关联记录' @close="handleClose"  :visible.sync="dialogVisible2" width="80%">
      <relevance-record-page v-if="pageType == 3" :pageData3="pageData3"></relevance-record-page>
    </el-dialog>
  </div>
</template>

<script>
import {
  addPlan,
  updatePlan,
  listPlan,
  getUserRoleBySub,
  getLabRiskPlanRepeat,
  getLabRiskPlanJoinSub,
  riskPlanJoinSub,
  delPlan,
  getUserRoleBySubOperation
} from "@/api/laboratory/plan";
import addPlanPage from "./addPlan.vue";
import detailPlanPage from "./detailPlan.vue";
import associationPage from "./associationPage.vue";
import relevanceRecordPage from "../distribution/index";
import {listDepartments} from "@/api/system/dept";
import {listClassifiedAll} from "@/api/laboratory/classified";
import {listClasstypeAll} from "@/api/laboratory/classtype";
import {authListSubject} from "@/api/laboratory/subject";


export default {
  components: {
    addPlanPage,
    detailPlanPage,
    relevanceRecordPage,
    associationPage
  },
  name: "Plan",
  data() {
    return {
      tableButtonType:this.hasPermiDom(['laboratory:plan:query','laboratory:planjoin:edit','laboratory:distribution:list','laboratory:plan:query','laboratory:plan:edit','laboratory:plan:remove']),
      //页面状态
      pageType:0,
      // 遮罩层
      loading: false,
      dateRange: [],
      // 查询参数
      param: {
        pageNum: 1,
        pageSize:20,
        name: null,
        searchValue: null,
        createName: null,
        beginTime: null,
        endTime: null
      },
      tableData: [],
      total: 0,
      pageData:{},
      pageData2:{},
      pageData3:{},
      //关联实验室
      dialogVisible:false,
      //关联记录
      dialogVisible2:false,
      deptOptions:[],
      typeList:[],
      levelList:[],
      dialogTable:[],
      checkedLabList:[],//需要选中的实验室
      joinSubOper:[],
      userId:localStorage.getItem('userId'),
      associationData:{},
    };
  },
  methods: {
    //查询
    onSearch() {
      this.param.pageNo = 1;
      this.getListPlan();
    },
    //重置
    resetForm() {
      this.dateRange=[];
      this.param.searchValue = '';
      this.param.name = '';
      this.param.createName = '';
      this.param.beginTime = '';
      this.param.endTime = '';
      this.onSearch();
    },
    moreClick(data){
      if(data.command=='3'){//编辑
        this.pageType = 1;
        this.pageData = data.row;
      }else if(data.command=='4'){//删除
        const ids = data.row.id || this.ids;
        this.$confirm('是否确认删除风险预案?', "警告", {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          type: "warning"
        }).then(function() {
          return delPlan(ids);
        }).then(() => {
          this.getListPlan();
          this.msgSuccess("删除成功");
        }).catch(() => {});
      }else if(data.command=='1'){
        this.pageType = 4;
        this.$set(this,'associationData',data)
      }else if(data.command=='2'){//关联记录
        this.dialogVisible2=true;
        this.pageData3.id=data.row.id
        this.pageType=3;
      }
    },
    handleClick(index, row, doType) {
      let _this = this;
      if(doType == 'add'){//定制预案
        this.pageType = 1;
        this.pageData = null
      }else if(doType=='detail'){//查看
        this.pageType = 2;
        this.pageData2.id = row.id
      }else if(doType=='back'){
        this.dialogVisible=false;
        this.pageType = 0;
        this.propsType = true;
        this.getListPlan();
      }
      this.$forceUpdate();
    },
    //监听关联记录弹窗关闭
    handleClose(){
      this.pageType=0
    },
    /** 查询学院列表 */
    getDeptListTow() {
      listDepartments().then(response => {
        // this.deptOptionsTwo = response.data;
        this.$set(this, 'deptOptions', response.data)
      });
    },
    /**获取分级*/
    getListClassifiedAll(){
      listClassifiedAll().then(response=>{
        if(response.code==200){
          this.levelList = response.data
        }
      })
    },
    /**获取分类*/
    getListClasstypeAll(){
      listClasstypeAll().then(response=>{
        if(response.code==200){
          this.typeList = response.data;
        }
      });
    },
    /** 查询风险预案列表 */
    getListPlan() {
      let _this=this;
      this.loading = true;
      if(this.dateRange&&this.dateRange.length>0){
        this.param.beginTime=this.dateRange[0]
        this.param.endTime=this.dateRange[1]
      }else{
        this.param.beginTime=null;
        this.param.endTime=null
      }
      listPlan(this.param).then(response => {
        this.$set(this,'tableData',response.rows)
        // this.tableData = response.rows;
        this.total = response.total;
        this.loading = false;
         // this.getList();
      });
    },
  },
  mounted(){
    this.getDeptListTow();
    this.getListClassifiedAll();
    this.getListClasstypeAll();
    this.getListPlan();
  },
}
</script>
<style scoped lang="scss">
/*#app .app-container{
  background: #fff;
  border-radius: 0px;
  overflow: hidden;
  padding: 10px;
  margin: 0;
  box-shadow:none;

}*/


  .control{
    display: flex!important;
    flex-direction: column;
    box-shadow: 0 0 8px 2px rgba(0, 0, 0, 0.1);
    padding:20px!important;
    .scrollbar-box{
      display: flex!important;
      flex-direction: column;
      height: 100%;
      width: 100%;
      padding-bottom: 20px;
      box-sizing: border-box;
     /* box-shadow: 0 0 8px 2px rgba(0, 0, 0, 0.1);
      padding:20px!important;*/
    }
    .button-box{
      width:auto;
      display: flex;
      justify-content: center;
    }
    .form-box{
      display:flex;
      .null-p{
        flex:1;
      }
    }
  }
</style>

