<!-- 检查督导组 -->
<template>
  <div class="app-container inspectSupervisorGroup">
    <div class="page-container inspectSupervisorGroupPage" 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="enable">
            <el-select v-model="queryParams.enable" 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="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-select>
          </el-form-item>
          <el-form-item label="" prop="groupName">
            <el-input
              maxLength="30"
              v-model="queryParams.groupName"
              placeholder="督导组名称"
              style="width: 200px"
            />
          </el-form-item>
          <el-form-item label="" prop="userName">
            <el-input
              maxLength="30"
              v-model="queryParams.userName"
              placeholder="成员"
              style="width: 200px"
            />
          </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-submit-common-style-button"
             style="float: right;width:130px"
             @click="tableButton(1)"
             v-hasPermiRouter="['security:group:add']"
          >创建督导组</p>
        </el-form>
      </div>
      <div class="page-content-box">
        <el-table class="table-box" v-loading="loading" border :data="dataList">
          <el-table-column label="序号" type="index" width="60"/>
          <el-table-column label="督导组名称" prop="groupName"  show-overflow-tooltip/>
          <el-table-column label="上级部门" prop="deptName" width="150" show-overflow-tooltip/>
          <el-table-column label="成员人数" prop="peopleNum" width="150" show-overflow-tooltip/>
          <el-table-column label="是否启用" prop="enable" width="185" show-overflow-tooltip>
            <template slot-scope="scope">
              <el-switch
                @click.native="tableButton(5,scope.row)"
                class="switch captcha-img"
                :active-value="true"
                :inactive-value="false"
                active-color="#0183FA"
                inactive-color="#999"
                v-model="scope.row.enable"
                active-text="启用"
                inactive-text="停用"
                disabled
              ></el-switch>
            </template>
          </el-table-column>
          <el-table-column label="操作人" prop="updateName" width="150" show-overflow-tooltip/>
          <el-table-column label="创建时间" prop="createTime" width="245" 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="200" show-overflow-tooltip >
            <template slot-scope="scope">
              <div class="table-button-box">
                <p class="table-button-null"></p>
                <p class="table-button-p"
                   @click="tableButton(2,scope.row)"
                >查看</p>
                <p class="table-button-p"
                   @click="tableButton(3,scope.row)"
                   v-hasPermiRouter="['security:group:edit']"
                >编辑</p>
                <p class="table-button-p"
                   @click="tableButton(4,scope.row)"
                   v-hasPermiRouter="['security:group:del']"
                >删除</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 {
    securityCheckGroupList,
    securityCheckGroupEnable,
    securityCheckGroupDelete,
  } from "@/api/safetyCheck/index";
  import {
    systemDeptGetLoginUserByDeptList,
  } from '@/api/commonality/permission'
  import addPage from "./addPage.vue";
  export default {
    name: 'index',
    components: {
     addPage
    },
    data () {
      return {
        //页面状态
        pageType:1,
        //页面遮罩
        loading:false,
        //下拉列表数据
        optionList:[{value:1,label:'启用'},{value:0,label:'停用'}],
        deptOptions:[],
        //查询条件
        queryParams:{
          page:1,
          pageSize:20,
          enable :null,
          deptId :null,
          groupName:"",
          userName:"",
        },
        //时间数据
        dateRange:[],
        //列表数据
        dataList:[{}],
        //数据数量
        total:0,
        //组件传参
        propsData:{},
      }
    },
    created () {
      this.systemDeptGetLoginUserByDeptList()
    },
    mounted () {
      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,
          enable :null,
          deptId :null,
          groupName:"",
          userName:"",
        });
        this.getList();
      },
      //获取数据列表
      getList(){
        this.$set(this,'loading',true);
        let obj = JSON.parse(JSON.stringify(this.queryParams))
        securityCheckGroupList(obj).then(response => {
          this.$set(this,'loading',false);
          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,'propsData',{showType:false});
          this.$set(this,'pageType',2);
        }else if(type == 2){
          //详情
          let obj = {
            groupId:row.groupId,
            showType:true,
          }
          this.$set(this,'propsData',obj);
          this.$set(this,'pageType',2);
        }else if(type == 3){
          //编辑
          let obj = {
            groupId:row.groupId,
            showType:false,
          }
          this.$set(this,'propsData',obj);
          this.$set(this,'pageType',2);
        }else if(type == 4){
          //删除
          this.$confirm('是否确认删除?', "警告", {
            confirmButtonText: "确定",
            cancelButtonText: "取消",
            type: "warning"
          }).then(function() {
          }).then(() => {
            securityCheckGroupDelete({groupId:row.groupId}).then(response => {
              self.msgSuccess(response.message)
              self.getList();
            });
          }).catch(() => {});
        }else if(type == 5){
          //启用&停用
          let text = row.enable  ? "停用" : "启用";
          this.$confirm('是否确认' + text + '?', "警告", {
            confirmButtonText: "确定",
            cancelButtonText: "取消",
            type: "warning"
          }).then(function() {
          }).then(() => {
            securityCheckGroupEnable({groupId:row.groupId,enable:!row.enable,}).then(response => {
              self.msgSuccess(response.message)
              self.getList();
            });
          }).catch(() => {});
        }else if(type == 6){
          //返回并刷新
          this.$set(this,'pageType',1);
          this.getList();
        }
      },
      /** 查询二级单位列表 */
      systemDeptGetLoginUserByDeptList() {
        systemDeptGetLoginUserByDeptList({ deptName: '', level: 2, deptType: 1 }).then(response => {
          this.$set(this, 'deptOptions', response.data)
        })
      },
    },
  }
</script>
<style scoped lang="scss">
  .inspectSupervisorGroup{
    .inspectSupervisorGroupPage{

    }
  }
</style>
