<!--安全信息类目-->
<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.brandName"
            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>
        <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="handleClick('','','add')"
           v-hasPermiRouter="['lab:infoBrand:add']"
        >新增</p>
        <p class="page-add-common-style-button"
           style="float: right;margin-right:20px;width:110px;"
           @click="handleClick('','','deploy')"
           v-hasPermiRouter="['lab:infoBrand:edit']"
        >信息牌配置</p>
      </el-form>
      <el-table class="table-box" border v-loading="loading" :data="tableData">
        <el-table-column label="类目名称" align="left" prop="brandName"/>
        <el-table-column label="内容类型" align="left"  prop="brandType">
          <template slot-scope="scope">
              <span v-if="scope.row.brandType==1">文字</span>
              <span v-if="scope.row.brandType==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?'是':'否'}}</p>
          </template>
        </el-table-column>
        <el-table-column label="创建人" align="left" prop="createName"/>
        <el-table-column label="创建时间" align="left" prop="createTime">
          <template slot-scope="scope">
            <span>{{ parseTime(scope.row.createTime,"{y}-{m}-{d} {h}:{i}") }}</span>
          </template>
        </el-table-column>
        <el-table-column label="操作" align="left" class-name="small-padding fixed-width" width="120" v-if="tableButtonType">
          <template slot-scope="scope">
            <div class="table-button-box">
              <p class="table-button-null"></p>
              <p class="table-button-p"
                 v-hasPermiRouter="['lab:infoBrand:edit']"
                 @click="handleClick('',scope.row,'edit')"
              >编辑</p>
              <p class="table-button-p"
                 v-hasPermiRouter="['lab:infoBrand:del']"
                 @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.page"
        :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="brandName">
          <el-input v-model="form.brandName" maxlength="30" placeholder="请输入类目名称" />
        </el-form-item>
        <el-form-item label="内容类型" prop="brandType">
          <el-radio-group v-model="form.brandType">
            <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="false">否</el-radio>
            <el-radio :label="true">是</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 dialog-footer-box">
        <p class="dialog-footer-button-null"></p>
        <p class="dialog-footer-button-info" @click="cancel">取消</p>
        <p class="dialog-footer-button-primary" @click="submitForm">提交</p>
        <p class="dialog-footer-button-null"></p>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import { getToken } from "@/utils/auth";
import { laboratoryInfoBrandAdd, laboratoryInfoBrandDelete, laboratoryInfoBrandList, laboratoryInfoBrandUpdate } from '@/api/integratedManagement/index'
import infoConfig from "./infoConfig.vue"
export default {
  name: "Approval",
  components: {
    infoConfig
  },
  data() {
    return {
      tableButtonType:this.hasPermiDom(['lab:infoBrand:edit','lab:infoBrand:del',]),
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      //页面状态
      pageType:1,
      loading:false,
      headers: {
        Authorization: "Bearer " + getToken()
      },
      // 查询参数
      queryParams: {
        page: 1,
        pageSize:20,
        brandName:'',
      },
      total:0,
      tableData:[],
      dateRange:[],
      pageData2:{},
      // 表单参数
      form: {
        brandName:'',
        brandType:'',
        isSpecial:'',
        showColour:'',
      },
      // 表单校验
      rules: {
        brandName: [
          { required: true, message: "请输入类目名称", trigger: "blur" },
        ],
        brandType: [
          { 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.$set(this,'form',{
            brandName:'',
            brandType:'',
            isSpecial:'',
            showColour:'',
          });
          this.open = true;
        }else if(doType=='edit'){//编辑
          this.title='编辑安全信息类目';
          this.$set(this,'form',{
            brandId:row.brandId,
            brandName:row.brandName,
            brandType:row.brandType,
            isSpecial:row.isSpecial,
            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(() => {
            //  确定
            laboratoryInfoBrandDelete({brandId:row.brandId}).then(response => {
              _this.msgSuccess(response.message);
              _this.getList();
            });
          }).catch(function() {});
        }else if(doType=='back'){//返回
          _this.pageType=1;
        }
      },
      /** 搜索按钮操作 */
      handleQuery() {
        this.queryParams.page = 1;
        this.getList();
      },
      /** 重置按钮操作 */
      resetQuery() {
        this.$set(this,'queryParams',{
          page: 1,
          pageSize:20,
          brandName:'',
        });
        this.$set(this,'dateRange',[]);
        this.handleQuery();
      },
      /** 取消按钮 */
      cancel() {
        this.$refs['form'].clearValidate()
        this.open=false
      },
      /** 提交按钮 */
      submitForm() {
        this.$refs["form"].validate(valid => {
          if (valid) {
            if (this.form.brandId) {
              laboratoryInfoBrandUpdate(this.form).then( response => {
                this.msgSuccess(response.message);
                this.open = false;
                this.getList();
              });
            } else {
              laboratoryInfoBrandAdd(this.form).then( response => {
                this.msgSuccess(response.message);
                this.open = false;
                this.getList();
              });
            }
          }
        });
      },
      getList(){
        let obj = JSON.parse(JSON.stringify(this.queryParams))
        if(this.dateRange[0]) {
          obj.beginTime=this.dateRange[0]+'T00:00:00';
          obj.endTime=this.dateRange[1]+'T23:59:59';
        } else {
          obj.beginTime='';
          obj.endTime='';
        }
        this.loading = true;
        laboratoryInfoBrandList(obj).then( response => {
          this.$set(this,'tableData',response.data.records);
          this.$set(this,'total',response.data.total);
          this.loading = false;
        });
      },
  },
  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;
      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:0 20px 20px!important;
      border-radius:10px;
      .button-box{
        width:200px;
        display: flex;
      }
    }

  }
</style>
