  <!--危险源管理-->
<template>
  <div class="app-container hazard">
    <div class="page-container" v-if="pageType==1">
      <div class="page-form-title-box">
        <el-form :model="queryParams" ref="queryForm" :inline="true"  label-width="90px" class="form-box">
          <el-form-item label="" prop="name">
            <el-input
              v-model="queryParams.chName"
              placeholder="请输入危险源名称"
              clearable
              size="small"
            />
          </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="['lab:hazard:add']"
          >新增</p>
        </el-form>
      </div>
      <div class="page-content-box">
        <el-table v-loading="loading" class="table-box" border :data="dataList">
          <el-table-column label="名称" align="left" prop="chName" />
          <el-table-column label="型号" align="left" prop="hazardCode" />
          <el-table-column label="类型" align="left" prop="smallTypeName" />
          <el-table-column label="实验室危险源占比" align="left" prop="labScale" width="300" >
            <template slot-scope="scope">
              <div class="progress-box" style="margin-top: 3px">
                <el-progress :stroke-width="20" color="#52a1fe" :percentage="scope.row.labScale>100?100:scope.row.labScale"></el-progress>
              </div>
            </template>
          </el-table-column>
          <el-table-column label="查看次数" align="left" prop="scanCount" width="100" />
          <el-table-column label="二维码" align="center" width="100">
            <template slot-scope="scope">
              <div style="height:23px;" @click="dialogQrCodeOn(scope.row)">
                <vue-qr style="height:23px;width:23px;cursor:pointer;" :text="identification+'?code='+scope.row.hazardId+'&type=3'" :size="200"></vue-qr>
              </div>
            </template>
          </el-table-column>
          <el-table-column label="操作" align="left" class-name="small-padding fixed-width" width="160" 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="['lab:hazard:edit']"
                >编辑</p>
                <p class="table-button-p"
                   @click="tableButton(3,scope.row)"
                   v-hasPermiRouter="['lab:hazard: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"
                    layout="total, prev, pager, next, sizes, jumper"
                    :page.sync="queryParams.page"
                    :limit.sync="queryParams.pageSize"
                    @pagination="getList"
        />
      </div>
    </div>
    <add-laboratory v-if="pageType==2" :propsData="propsData"></add-laboratory>
    <!-- 二维码展示 -->
    <qr-code-dialog ref="qrCodeDialog" :qrCodeDialogData="qrCodeDialogData"></qr-code-dialog>
  </div>
</template>
<script>
import qrCodeDialog from "@/components/qrCodeDialog/index.vue"
import {
  laboratoryHazardList, laboratoryHazardDelete, laboratoryHazardDetail
} from '@/api/integratedManagement/index'
  import addLaboratory from "./addLaboratory.vue";
  import vueQr from 'vue-qr'
export default {
  components: {
    addLaboratory,
    vueQr,
    qrCodeDialog,
  },
  name: "Hazard",
  data() {
    return {
      tableButtonType:this.hasPermiDom(['lab:hazard:edit','lab:hazard:del']),
      // 遮罩层
      loading: false,
      // 非多个禁用
      multiple: true,
      // 总条数
      total: 0,
      // 危险源表格数据
      dataList: [],
      // 查询参数
      queryParams: {
        page: 1,
        pageSize:20,
        chName: null,
      },
      propsData:{},
      //新增危险源
      pageType:1,
      //二维码展示数据
      qrCodeDialogData:{},
      //二维码规则 服务器域名,需与微信后台开发配置内一致.
      identification: localStorage.getItem('codeOnlineAdd'),
    };
  },
  created() {
    this.getList();
  },
  methods: {
    //展示二维码
    dialogQrCodeOn(row){
      this.$set(this,'qrCodeDialogData',{
        download:true,
        type:'3',                                                     //二维码类型 用于区分二维码功能类型
        parameter:row.hazardId,                                             //二维码参数
        name:row.chName,                                                //二维码名称用于下载时命名
        codeName:row.chName,                                            //二维码图片下名称展示(非必传)
      });
      this.$refs['qrCodeDialog'].initialize();
    },
    /** 查询危险源列表 */
    getList() {
      this.$set(this,'loading',true);
      laboratoryHazardList(this.queryParams).then(response => {
        this.$set(this,'loading',false);
        this.$set(this,'dataList',response.data.records);
        this.$set(this,'total',response.data.total);
      });
    },

    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.page = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.$set(this,'queryParams',{
        page: 1,
        pageSize:20,
        chName:"",
      });
      this.handleQuery();
    },
    //操作按钮
    tableButton(type,row){
      let self = this;
      if(type == 1){
        //新增
        this.$set(this,'propsData',null);
        this.$set(this,'pageType',2);

      }else if(type == 2){
        //编辑
        laboratoryHazardDetail({hazardId:row.hazardId}).then(response => {
          this.$set(this,'propsData',response.data);
          this.$set(this,'pageType',2);
        });
      }else if(type == 3){
        //删除
        this.$confirm('是否确认删除危险源?', "警告", {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          type: "warning"
        }).then(function() {
        }).then(() => {
          laboratoryHazardDelete({hazardId:row.hazardId}).then(response => {
            self.msgSuccess(response.message)
            self.getList();
          });
        }).catch(() => {});
      }else if(type == 'out'){
        //返回
        this.$set(this,'pageType',1);
        this.getList();
      }
    },
  }
};
</script>

<style scoped lang="scss">
  .hazard {
    .progress-box{
      ::v-deep .el-progress__text{
        font-size: 14px !important;
      }
    }
  }
</style>
