<!-- 检查依据 -->
<template>
  <div class="app-container snapshot">
    <div class="page-container snapshotPage" 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="queryParamsData2">-->
            <!--<el-select v-model="queryParams.queryParamsData2" placeholder="检查类型" style="width: 160px">-->
              <!--<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="searchValue">
            <el-input
              maxLength="30"
              v-model="queryParams.searchValue"
              placeholder="依据名称/操作人"
              style="width: 160px"
            />
          </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>
          <p class="page-submit-common-style-button"
             style="float: right;"
             @click="tableButton(1)"
             v-hasPermiRouter="['security:basis: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="basisName"  show-overflow-tooltip/>
          <el-table-column label="三级检查项目数" prop="hazardCheckNum" width="200" show-overflow-tooltip/>
          <el-table-column label="操作人" prop="updateName" width="200" show-overflow-tooltip/>
          <el-table-column label="操作时间" prop="updateTime" 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="130" show-overflow-tooltip v-if="tableButtonType">
            <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)"
                   v-hasPermiRouter="['security:basis:edit']"
                >编辑</p>
                <p class="table-button-p"
                   @click="tableButton(4,scope.row)"
                   v-hasPermiRouter="['security:basis: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 { getDicts } from "@/api/commonality/noPermission";
  //import { systemUserSelect } from "@/api/commonality/permission";
  import {
    securityCheckBasisList,securityCheckBasisDelete
  } from '@/api/safetyCheck/index'
  import addPage from "./addPage.vue";
  export default {
    name: 'index',
    components: {
      addPage,
    },
    data () {
      return {
        tableButtonType:this.hasPermiDom(['security:basis:edit','security:basis:del']),
        //页面状态
        pageType:1,
        //整改状态选项卡
        tableButtonCheckType:1,
        //页面遮罩
        loading:false,
        //下拉列表数据
        optionList:[{value:true,label:'启用'},{value:false,label:'停用'}],
        //查询条件
        queryParams:{
          page:1,
          pageSize:20,
          searchValue:"",
        },
        //时间数据
        dateRange:[],
        //列表数据
        dataList:[],
        //数据数量
        total:0,
        //组件传参
        propsData:{},
      }
    },
    created () {

    },
    mounted () {
      this.getList();
    },
    methods: {
      //整改状态选项卡切换
      tableCheck(type){
        if (this.tableButtonCheckType !== type){
          this.$set(this,'tableButtonCheckType',type);
          this.resetQuery();
        }
      },
      //查询按钮
      handleQuery(){
        this.$set(this.queryParams,'page',1);
        this.getList();
      },
      //重置按钮
      resetQuery(){
        this.$set(this,'dateRange',[])
        this.$set(this,'queryParams',{
          page:1,
          pageSize:20,
          searchValue:"",
        });
        this.getList();
      },
      //获取数据列表
      getList(){
        this.$set(this,'loading',true);
        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 = "";
        }
        securityCheckBasisList(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,'pageType',2);
          this.$set(this,'propsData',{});
        }else if(type == 2){
          //编辑
          let obj = JSON.parse(JSON.stringify(row))
          this.$set(this,'propsData',obj);
          this.$set(this,'pageType',2);
        }else if(type == 4){
          //删除
          this.$confirm('是否确认删除?', "警告", {
            confirmButtonText: "确定",
            cancelButtonText: "取消",
            type: "warning"
          }).then(function() {
          }).then(() => {
            securityCheckBasisDelete({basisId:row.basisId}).then(response => {
              self.msgSuccess(response.message)
              self.getList();
            });
          }).catch(() => {});
        }else if(type == 'back'){
          //返回并刷新
          this.$set(this,'pageType',1);
          this.getList();
        }
      },
    },
  }
</script>
<style scoped lang="scss">
  .snapshot{
    .snapshotPage{
      .table-school-college-toggle-box{
        overflow: hidden;
        display: inline-block;
        margin-right:10px;
        p{
          display: inline-block;
          text-align: center;
          width:100px;
          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(4){
          border-top-right-radius: 4px;
          border-bottom-right-radius: 4px;
          /*border-left:none;*/
        }
        .p-check{
          border:1px solid #0183FA;
          background-color: #0183FA;
          color:#fff;
        }
      }
    }
  }
</style>
