<!--安全信息配置-->
<template>
  <div class="safetyInfoConfig">
    <div class="approval_handle-page scrollbar-box" v-if="pageType==1">
      <div class="title-box">
        <div @click="titleClick(1)">
          <p>安全类目</p>
          <p></p>
        </div>
        <div @click="titleClick(2)">
          <p>信息配置</p>
          <p class="bottom-p-color"></p>
        </div>
      </div>
      <div class="config_main">
        <div class="config_main_l">
          <div class="config_main_l_title">
            <img  src="@/assets/ZDimages/integratedManagement/icon_xxpz_aqxxlm.png">
            安全信息类目
          </div>
          <div :class='currentIndex==index?"active":""' class="config_main_l_li"
               v-for="(item,index) in tabsList" :key="index" @click="handleTabClick(item,index)">
            {{item.brandName}}
          </div>
        </div>
        <p class="config_main_border"></p>
        <div class="approval_handle-page scrollbar-box">
          <div>
            <p class="page-submit-common-style-button"
               style="float: right;margin-bottom:20px;"
               @click="handleClick('','','add')"
               v-hasPermiRouter="['lab:infoBrand:add']"
            >新增</p>
          </div>
          <el-table class="table-box" border v-loading="loading" :data="tableData">
            <el-table-column label="排序" align="left" class-name="small-padding fixed-width" width="80">
              <template slot-scope="scope">
                <el-input
                  onkeyup="value=value.replace(/[^\d]/g,'')"
                  class="serial"
                  v-model="scope.row.orderNum"
                  @change="categorySort(scope.row)"
                  maxLength="3"
                  placeholder="序号">
                </el-input>
              </template>
            </el-table-column>
            <el-table-column label="信息名称" align="left" prop="infoName"/>
            <el-table-column label="公共信息" align="left">
              <template slot-scope="scope">
                <el-switch
                  @click.native="categoryShow(scope.row)"
                  class="switch captcha-img"
                  :active-value="true"
                  :inactive-value="false"
                  active-color="#FF9900"
                  inactive-color="#999"
                  v-model="scope.row.isCollective"
                  active-text="是"
                  inactive-text="否"
                  disabled
                ></el-switch>
              </template>
            </el-table-column>
            <el-table-column label="危险源" align="left" prop="isConfigHazard" width="100">
              <template slot-scope="scope">
                <span v-if="scope.row.isConfigHazard">已配置</span>
                <span v-if="!scope.row.isConfigHazard" style="color: #FF0000;">未配置</span>
              </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>
      </div>
    </div>
    <add-safety-info-config :propsData="propsData" v-if="pageType==2"></add-safety-info-config>
  </div>
</template>

<script>
import addSafetyInfoConfig from "./addSafetyInfoConfig";
import { getToken } from "@/utils/auth";
import {
  laboratoryInfoBrandList,
  laboratoryBrandDetailAdd,
  laboratoryBrandDetailList,
  laboratoryBrandDetailUpdate,
  laboratoryBrandDetailDelete,
  laboratoryBrandDetailDetail, laboratoryClassTypeUpdate
} from '@/api/integratedManagement/index'
export default {
  name: "Approval",
  components: {
    addSafetyInfoConfig,
  },
  data() {
    return {
      tableButtonType:this.hasPermiDom(['lab:infoBrand:edit','lab:infoBrand:del',]),
      uploadImgUrl: this.uploadUrl(), // 上传的图片服务器地址
      //页面状态
      pageType:1,
      loading:false,
      headers: {
        Authorization: getToken()
      },
      // 查询参数
      queryParams: {
        page: 1,
        pageSize:20,
        brandId:'',
      },
      total:0,
      tableData:[],
      dateRange:[],
      pageData2:{},
      tabsList:[],
      categoryList:[],
      //组件传参
      propsData:{},
      // 表单参数
      infoType:null,

      currentIndex:0,

    };


  },
  methods: {
      titleClick(type){
        this.$parent.titleClick(type);
      },
      handleTabClick(item,index){
        this.currentIndex = index
        this.queryParams.page=1;
        this.queryParams.brandId=item.brandId;
        this.infoType=item.brandType;
        this.getList()
      },
      handleClick(index,row,doType){
        let self=this;
        if(doType=='add'){//添加
          let obj={
            brandId:this.queryParams.brandId,
            infoType:this.infoType,
            listHazardModel:[],
          }
          this.$set(this,'propsData',obj)
          this.$set(this,'pageType',2)
        }else if(doType=='edit'){//编辑

          laboratoryBrandDetailDetail({detailId:row.detailId}).then( response => {
             if (response.code==200){
               let obj={
                 detailId:response.data.detailId,
                 brandId:response.data.brandId,
                 infoName:response.data.infoName,
                 infoType:response.data.infoType,
                 infoContent:response.data.infoContent,
                 isCollective:response.data.isCollective,
                 orderNum:response.data.orderNum,
                 listHazardModel:response.data.listHazardModel,
               }
               this.$set(this,'propsData',obj)
               this.$set(this,'pageType',2)
             }
          });

        }else if(doType=='deploy'){//信息牌配置
          //self.pageType=2;
        }else if(doType=='delete'){//删除
          this.$confirm('确认要删除吗?', "警告", {
            confirmButtonText: "确定",
            cancelButtonText: "取消",
            type: "warning"
          }).then(() => {
            //  确定
            laboratoryBrandDetailDelete({detailId:row.detailId}).then(response => {
              this.msgSuccess(response.message);
              self.getList();
            });
          }).catch(function() {});
        }else if(doType=='back'){//返回
          this.$set(this,'pageType',1)
          self.getList();
        }
      },
      categorySort(row){
        let obj={
          detailId:row.detailId,
          brandId:row.brandId,
          infoName:row.infoName,
          infoType:row.infoType,
          infoContent:row.infoContent,
          isCollective:row.isCollective,
          orderNum:row.orderNum,
        }
        laboratoryBrandDetailUpdate(obj).then( response => {
          this.msgSuccess(response.message);
          this.open = false;
          this.getList();
        });
      },
      categoryShow(row){
        //启用&停用
        let text = row.isCollective  ? "停用" : "启用";
        this.$confirm('是否确认' + text + '?', "警告", {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          type: "warning"
        }).then(function() {
        }).then(() => {
          let obj={
            detailId:row.detailId,
            brandId:row.brandId,
            infoName:row.infoName,
            infoType:row.infoType,
            infoContent:row.infoContent,
            isCollective:!row.isCollective,
            orderNum:row.orderNum,
          }
          laboratoryBrandDetailUpdate(obj).then( response => {
            this.msgSuccess(response.message);
            this.open = false;
            this.getList();
          });
        }).catch(() => {});
      },
      categoryClick(){
        let _this=this;
        this.form.infoContent='';
        this.categoryList.forEach(function(item) {
          if(item.brandId==_this.form.brandId){
            _this.$set(_this.form,'infoType',item.brandType);
          }
        })

      },
      /** 搜索按钮操作 */
      handleQuery() {
        this.queryParams.page = 1;
        this.getList();
      },
      /** 重置按钮操作 */
      resetQuery() {
        this.handleQuery();
      },
      /** 取消按钮 */
      cancel() {
        this.$refs['form'].clearValidate()
        this.open = false;
      },
      //查询信息类目列表
      getCategoryList(){
        let obj={
          page: 1,
          pageSize:100,
          isShow:1,
        }
        laboratoryInfoBrandList(obj).then( response => {
          this.$set(this,'tabsList',response.data.records);
          this.$set(this,'categoryList',response.data.records);
          this.$set(this.queryParams,'brandId',response.data.records[0]?response.data.records[0].brandId+'':'');
          this.$set(this,'infoType',response.data.records[0]?response.data.records[0].brandType+'':'');
          this.getList()

        });
      },
      getList(){
        let _this=this;
        laboratoryBrandDetailList(_this.queryParams).then( response => {
          this.$set(this,'tableData',response.data.records);
          this.$set(this,'total',response.data.total);
        });
      },
  },
  mounted() {
    this.getCategoryList()

  }
};
</script>

<style scoped lang="scss">
  .safetyInfoConfig {
    overflow: hidden;
    flex:1;
    display: flex!important;
    flex-direction: column;
    .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;
      }
    }
    .config_main{
        overflow: hidden;
        flex:1;
        display: flex;
        overflow: hidden;
       .config_main_l{
         flex: 1;
         padding-left: 42px;
         padding-top: 20px;
         .config_main_l_title{
           font-size: 16px;
           font-weight: 400;
           color: #0183FA;
           >img{
             width: 16px;
             height: 13px;
             margin-right: 12px;
           }
         }
         .config_main_l_li{
           font-size: 14px;
           font-family: Microsoft YaHei-Regular, Microsoft YaHei;
           font-weight: 400;
           color: #333333;
           line-height: 68px;
           cursor: pointer;
         }
         .active{
           color: #0183FA;
         }
       }
       .config_main_border{
         border-right: 1px dashed #A2A2A2;
         margin: 20px 35px 36px 0;
       }
      /*表格*/
      .approval_handle-page{
        display: flex!important;
        flex-direction: column;
        width: 1264px;
        padding:0px 20px 20px!important;
        .button-box{
          width:200px;
          display: flex;
        }
      }
    }

    .table-box{
      ::v-deep .el-input--medium .el-input__inner {
        height: 26px;
        line-height: 26px;
        width: 55px;
        text-align: center;
        padding: 0 10px;
      }
    }

  }

</style>
