<!--安全信息类目-->
<template>
  <div class="safetyInfoCategory">
    <div class="title-box">
      <div>
        <p class="top-p-color">安全类目</p>
        <p class="bottom-p-color"></p>
      </div>
      <div @click="titleClick(2)">
        <p>信息配置</p>
        <p></p>
      </div>
    </div>
    <div class="approval_handle-page" v-if="pageType == 1">
      <el-form :model="queryParams" ref="queryForm" style="margin-top:20px;" :inline="true">
        <el-form-item label="关键字" prop="name">
          <el-input
            v-model="queryParams.searchValue"
            placeholder="类目名称"
            clearable
            maxLength="30"
            size="small"
          />
        </el-form-item>
        <el-form-item label="添加时间" prop="dateRange">
          <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>
          <p class="inquire-button-one" @click="handleQuery">查询</p>
          <p class="reset-button-one" @click="resetQuery">重置</p>
        </el-form-item>
        <el-form-item style="float: right;">
          <el-col :span="1.5">
            <p class="inquire-button-one"
               v-hasPermi="['laboratory:classify:edit']"
               style="width:120px;margin-right:10px;"
               @click="handleClick('','','deploy')"
            >信息牌配置</p>
            <el-button
              v-hasPermi="['laboratory:classify:add']"
              type="primary"
              plain
              icon="el-icon-plus"
              size="mini"
              @click="handleClick('','','add')"
            >新增</el-button>
          </el-col>
        </el-form-item>
      </el-form>
      <el-table border v-loading="loading" :data="tableData">
        <el-table-column label="类目名称" align="left" prop="classifyName"/>
        <el-table-column label="内容类型" align="left"  prop="classifyType">
          <template slot-scope="scope">
              <span v-if="scope.row.classifyType==1">文字</span>
              <span v-if="scope.row.classifyType==2">图片</span>
          </template>
        </el-table-column>
        <el-table-column label="颜色" align="left" prop="showColour" >
          <template slot-scope="scope">
            <p :style="'width:40px;height:23px;margin:0;background:'+scope.row.showColour"></p>
          </template>
        </el-table-column>
        <el-table-column label="是否特殊类目" align="left" prop="showColour">
          <template slot-scope="scope">
            <p>{{scope.row.isSpecial==2?'是':'否'}}</p>
          </template>
        </el-table-column>
        <el-table-column label="创建人" align="left" prop="createBy"/>
        <el-table-column label="创建时间" align="left" prop="createTime"/>
        <el-table-column label="操作" align="left" class-name="small-padding fixed-width" width="120">
          <template slot-scope="scope">
            <div class="table-button-box">
              <p class="table-button-null"></p>
              <p class="table-button-p"
                 v-hasPermi="['laboratory:classify:edit']"
                 @click="handleClick('',scope.row,'edit')"
              >编辑</p>
              <p class="table-button-p"
                 v-hasPermi="['laboratory:classify:remove']"
                 @click="handleClick('',scope.row,'delete')"
              >删除</p>
              <p class="table-button-null"></p>
            </div>
          </template>
        </el-table-column>
      </el-table>
      <pagination :page-sizes="[20, 30, 40, 50]"
        :total="total"
        layout="total, prev, pager, next, sizes, jumper"
        :page.sync="queryParams.pageNum"
        :limit.sync="queryParams.pageSize"
        @pagination="getList"
      />
    </div>
    <info-Config v-if="pageType == 2"></info-Config>
    <!-- 添加或修改安全分级对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="500px" append-to-body :before-close="closeDialog" :close-on-click-modal="false">
      <el-form ref="form" :model="form" :rules="rules" label-width="80px">
        <el-form-item label="类目名称" prop="classifyName">
          <el-input v-model="form.classifyName" maxlength="30" placeholder="请输入类目名称" />
        </el-form-item>
        <el-form-item label="内容类型" prop="classifyType">
          <el-radio-group v-model="form.classifyType">
            <el-radio :label="1">文字</el-radio>
            <el-radio :label="2">图片</el-radio>
          </el-radio-group>
        </el-form-item>
        <el-form-item label="特殊类目" prop="isSpecial">
          <el-radio-group v-model="form.isSpecial">
            <el-radio :label="1">否</el-radio>
            <el-radio :label="2">是</el-radio>
          </el-radio-group>
        </el-form-item>
        <el-form-item label="类目颜色" prop="showColour">
          <el-color-picker v-model="form.showColour"></el-color-picker>
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import { getToken } from "@/utils/auth";
import { infoCategoryAdd, infoCategoryDelete, infoCategoryList, infoCategoryPut } from '@/api/laboratory/safetyInfo'
import infoConfig from "./infoConfig.vue"
export default {
  name: "Approval",
  components: {
    infoConfig
  },
  data() {
    return {
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      //页面状态
      pageType:1,
      loading:false,
      headers: {
        Authorization: "Bearer " + getToken()
      },
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize:20,
        searchValue:null,
        beginTime:null,
        endTime:null,
        remark:'time',
      },
      total:0,
      tableData:[],
      dateRange:[],
      pageData2:{},
      // 表单参数
      form: {
        classifyName:'',
        classifyType:'',
        isSpecial:'',
        showColour:'',
      },
      // 表单校验
      rules: {
        classifyName: [
          { required: true, message: "请输入类目名称", trigger: "blur" },
        ],
        classifyType: [
          { required: true, message: "请选择内容类型", trigger: "blur" },
        ],
        isSpecial: [
          { required: true, message: "请选择是否是特殊类目", trigger: "blur" },
        ],
        showColour: [
          { required: true, message: "请选择颜色", trigger: "blur" }
        ],
      }
    };


  },
  methods: {
      titleClick(type){
        this.$parent.titleClick(type);
      },
      closeDialog(){
        this.$refs['form'].clearValidate()
        this.open=false
      },
      handleClick(index,row,doType){
        let _this=this;
        if(doType=='add'){//添加
          this.title='新增安全信息类目';
          this.open = true;
          delete this.form.id
          this.form.classifyName='';
          this.form.classifyType='';
          this.form.isSpecial='';
          this.form.showColour='';
        }else if(doType=='edit'){//编辑
          this.title='编辑安全信息类目';
          this.form.id=row.id
          this.form.classifyName=row.classifyName
          this.form.classifyType=row.classifyType
          this.form.isSpecial=row.isSpecial
          this.form.showColour=row.showColour
          this.open = true;
        }else if(doType=='deploy'){//信息牌配置
          _this.pageType=2;
        }else if(doType=='delete'){//删除
         // this.msgError('请删除安全信息后再删除信息类目')
          this.$confirm('确认要删除吗?', "警告", {
            confirmButtonText: "确定",
            cancelButtonText: "取消",
            type: "warning"
          }).then(() => {
            //  确定
            infoCategoryDelete(row.id).then(response => {
              _this.msgSuccess(response.msg);
              _this.getList();
            });
          }).catch(function() {});
        }else if(doType=='back'){//返回
          _this.pageType=1;
        }
      },
      /** 搜索按钮操作 */
      handleQuery() {
        this.queryParams.pageNum = 1;
        this.getList();
      },
      /** 重置按钮操作 */
      resetQuery() {
        this.queryParams.searchValue = null;
        this.dateRange=[];
        this.queryParams.beginTime=null;
        this.queryParams.endTime=null
        this.handleQuery();
      },
      /** 取消按钮 */
      cancel() {
        this.$refs['form'].clearValidate()
        this.open=false
      },
      /** 提交按钮 */
      submitForm() {
        this.$refs["form"].validate(valid => {
          if (valid) {
            if (this.form.id != null) {
              infoCategoryPut(this.form).then( response => {
                this.msgSuccess("修改成功");
                this.open = false;
                this.getList();
              });
            } else {
              infoCategoryAdd(this.form).then( response => {
                this.msgSuccess("新增成功");
                this.open = false;
                this.getList();
              });
            }
          }
        });
      },
      getList(){
        let _this=this;
        if(this.dateRange&&this.dateRange.length>0) {
          this.queryParams.beginTime=this.dateRange[0]
          this.queryParams.endTime=this.dateRange[1]
        } else {
          this.queryParams.beginTime=null;
          this.queryParams.endTime=null
        }
        infoCategoryList(_this.queryParams).then( response => {
          let res=response.rows;
          _this.tableData=res;
          _this.total=response.total;
        });
      },
  },
  mounted() {
    this.getList()
  }
};
</script>

<style scoped lang="scss">
  .safetyInfoCategory{
    flex:1;
    display: flex!important;
    flex-direction: column;
    overflow: hidden;
    .title-box{
      display: flex;
      border-bottom:1px solid #E0E0E0;
      margin-bottom:20px;
      div{
        height:80px;
        margin-right:20px;
        cursor: pointer;
        p:nth-child(1){
          font-size:18px;
          text-align: center;
          padding:0 20px;
          margin-top:26px;
        }
        p:nth-child(2){
          width:40px;
          height:4px;
          border-radius:40px;
          margin:12px auto;
        }
        .top-p-color{
          color: #0045AF;
        }
        .bottom-p-color{
          background: #0045AF;
        }
      }
      .buttonTitleColorA{
        color:#0045AF;
      }
      .buttonTitleColorB{
        color:#999999;
      }
    }
    .approval_handle-page{
      overflow: hidden;
      flex:1;
      display: flex!important;
      flex-direction: column;
     // box-shadow: 0 0 8px 2px rgba(0, 0, 0, 0.1);
      padding:20px 20px 20px!important;
      border-radius:10px;
      .button-box{
        width:200px;
        display: flex;
      }
    }

  }
</style>
