<template>
  <div class="app-container">
    <el-form v-show="showSearch" ref="queryForm" :inline="true" :model="queryParams" label-width="68px">
      <el-form-item label="位置" prop="location">
        <el-input
            v-model="queryParams.location"
            clearable
            placeholder="请输入位置"
            size="small"
            @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="位号" prop="tagNo">
        <el-input
            v-model="queryParams.tagNo"
            clearable
            placeholder="请输入位号"
            size="small"
            @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item>
        <el-button icon="el-icon-search" size="mini" type="cyan" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
            v-hasPermi="['reliability:analysis:add']"
            icon="el-icon-plus"
            size="mini"
            type="primary"
            @click="handleAdd"
        >新增
        </el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
            v-hasPermi="['reliability:analysis:edit']"
            :disabled="single"
            icon="el-icon-edit"
            size="mini"
            type="success"
            @click="handleUpdate"
        >修改
        </el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
            v-hasPermi="['reliability:analysis:remove']"
            :disabled="multiple"
            icon="el-icon-delete"
            size="mini"
            type="danger"
            @click="handleDelete"
        >删除
        </el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
            v-hasPermi="['reliability:analysis:edit']"
            icon="el-icon-upload2"
            size="mini"
            type="info"
            @click="handleImport"
        >导入
        </el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
            v-hasPermi="['reliability:analysis:export']"
            icon="el-icon-download"
            size="mini"
            type="warning"
            @click="handleExport"
        >导出
        </el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
            icon="el-icon-pie-chart"
            size="mini"
            type="primary"
            @click="openDrawer"
        >风险矩阵
        </el-button>
      </el-col>
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table v-loading="loading" :data="analysisList" :height="clientHeight" border
              @selection-change="handleSelectionChange">
      <el-table-column align="center" type="selection" width="55"/>
      <el-table-column :show-overflow-tooltip="true" align="center" label="位置" prop="location"
                       width="300"/>
      <el-table-column :show-overflow-tooltip="true" align="center" label="位号" prop="tagNo" width="200"/>
      <el-table-column :show-overflow-tooltip="true" align="center" label="描述" prop="description"
                       width="200"/>
      <el-table-column :show-overflow-tooltip="true" align="center" label="Object Type" prop="objectType" width="200"/>
      <el-table-column :show-overflow-tooltip="true" align="center" label="Catalog Profile" prop="catalogProfile"
                       width="200"/>
      <el-table-column :show-overflow-tooltip="true" align="center" label="Relevant (r)/not relevant (n)"
                       prop="relevant" width="200"/>
      <el-table-column :show-overflow-tooltip="true" align="center" label="故障频率" prop="frequencyFailure"
                       width="100"/>
      <el-table-column :show-overflow-tooltip="true" align="center" label="维护成本" prop="maintenanceCost"
                       width="100"/>
      <el-table-column :show-overflow-tooltip="true" align="center" label="生成损失" prop="productionLoss" width="100"/>
      <el-table-column :show-overflow-tooltip="true" align="center" label="维护风险" prop="maintenanceRisk"
                       width="100"/>
      <el-table-column :show-overflow-tooltip="true" align="center" label="生成风险" prop="productionRisk" width="100"/>
      <el-table-column :show-overflow-tooltip="true" align="center" label="设备类别" prop="equipmentCategory"
                       width="100"/>
      <el-table-column :show-overflow-tooltip="true" align="center" label="风险程度" prop="riskCriticality"
                       width="100"/>
      <el-table-column :show-overflow-tooltip="true" align="center" label="定量分析" prop="quantitativeAnalysis"
                       width="200"/>
      <el-table-column :show-overflow-tooltip="true" align="center" label="维修策略" prop="maintenanceStrategy"
                       width="200"/>
      <el-table-column :show-overflow-tooltip="true" align="center" label="维修策略描述" prop="msDescription"
                       width="200"/>
      <el-table-column :show-overflow-tooltip="true" align="center" label="备件策略" prop="sparepartStrategy"
                       width="200"/>
      <el-table-column :show-overflow-tooltip="true" align="center" label="备件策略描述" prop="ssDescription"
                       width="200"/>
      <el-table-column :show-overflow-tooltip="true" align="center" label="需要澄清" prop="needClarification"
                       width="200"/>
      <el-table-column :show-overflow-tooltip="true" align="center" label="备注" prop="remarks" width="200"/>
      <el-table-column align="center" class-name="small-padding fixed-width" fixed="right" label="操作" width="120">
        <template slot-scope="scope">
          <el-button
              v-hasPermi="['reliability:analysis:edit']"
              icon="el-icon-edit"
              size="mini"
              type="text"
              @click="handleUpdate(scope.row)"
          >修改
          </el-button>
          <el-button
              v-hasPermi="['reliability:analysis:remove']"
              icon="el-icon-delete"
              size="mini"
              type="text"
              @click="handleDelete(scope.row)"
          >删除
          </el-button>
        </template>
      </el-table-column>
    </el-table>

    <pagination
        v-show="total>0"
        :limit.sync="queryParams.pageSize"
        :page.sync="queryParams.pageNum"
        :total="total"
        @pagination="getList"
    />

    <el-drawer
        :visible.sync="drawer"
        size="60%"
        title="风险矩阵">

      <table class="top_table">
        <tr>
          <td></td>
          <td colspan="5" style="font-weight: bold;">Maintenance risk</td>
          <td></td>
          <td colspan="5" style="font-weight: bold;">Production risk</td>
          <td></td>
          <td colspan="5" style="font-weight: bold;">Equipment Category</td>
        </tr>
        <tr>
          <td rowspan="6" style="font-weight: bold;writing-mode: vertical-rl">Frequency</td>
          <td>high</td>
          <td class="border-lr-td border-top-td yellow">B2</td>
          <td class="border-lr-td border-top-td red">A1</td>
          <td class="border-lr-td border-top-td red">A0</td>
          <td></td>
          <td rowspan="6" style="font-weight: bold;writing-mode: vertical-lr">Frequency</td>
          <td>high</td>
          <td class="border-lr-td border-top-td yellow">B2</td>
          <td class="border-lr-td border-top-td red">A1</td>
          <td class="border-lr-td border-top-td red">A0</td>
          <td></td>
          <td rowspan="6" style="font-weight: bold;writing-mode: vertical-lr">Maintenance Cost</td>
          <td>high</td>
          <td class="border-lr-td border-top-td green">C</td>
          <td class="border-lr-td border-top-td yellow">B</td>
          <td class="border-lr-td border-top-td red">A</td>
          <td></td>
        </tr>
        <tr>
          <td>&gt;1 /a</td>
          <td class="border-lr-td  border-btm-td yellow">{{ chartData.mr.hB2 }}</td>
          <td class="border-lr-td  border-btm-td red">{{ chartData.mr.hA1 }}</td>
          <td class="border-lr-td  border-btm-td red">{{ chartData.mr.hA0 }}</td>
          <td></td>
          <td>&gt;1 /a<</td>
          <td class="border-lr-td border-btm-td yellow">{{ chartData.pr.hB2 }}</td>
          <td class="border-lr-td border-btm-td red">{{ chartData.pr.hA1 }}</td>
          <td class="border-lr-td border-btm-td red">{{ chartData.pr.hA0 }}</td>
          <td></td>
          <td>/a</td>
          <td class="border-lr-td border-btm-td green">{{ chartData.ec.hC }}</td>
          <td class="border-lr-td border-btm-td yellow">{{ chartData.ec.hB }}</td>
          <td class="border-lr-td border-btm-td red">{{ chartData.ec.hA }}</td>
          <td></td>
        </tr>
        <tr>
          <td>medium</td>
          <td class="border-lr-td border-top-td green">C2</td>
          <td class="border-lr-td border-top-td yellow">B1</td>
          <td class="border-lr-td border-top-td red">A0</td>
          <td></td>
          <td>medium</td>
          <td class="border-lr-td border-top-td green">C2</td>
          <td class="border-lr-td border-top-td yellow">B1</td>
          <td class="border-lr-td border-top-td red">A0</td>
          <td></td>
          <td>medium</td>
          <td class="border-lr-td border-top-td green">C</td>
          <td class="border-lr-td border-top-td yellow">B</td>
          <td class="border-lr-td border-top-td yellow">B</td>
          <td></td>
        </tr>
        <tr>
          <td>0.5~1 /a</td>
          <td class="border-lr-td border-btm-td green">{{ chartData.mr.mC2 }}</td>
          <td class="border-lr-td border-btm-td yellow">{{ chartData.mr.mB1 }}</td>
          <td class="border-lr-td border-btm-td red">{{ chartData.mr.mA0 }}</td>
          <td></td>
          <td>0.5~1 /a</td>
          <td class="border-lr-td border-btm-td green">{{ chartData.pr.mC2 }}</td>
          <td class="border-lr-td border-btm-td yellow">{{ chartData.pr.mB1 }}</td>
          <td class="border-lr-td border-btm-td red">{{ chartData.pr.mA0 }}</td>
          <td></td>
          <td>/a</td>
          <td class="border-lr-td border-btm-td green">{{ chartData.ec.mC }}</td>
          <td class="border-lr-td border-btm-td yellow">{{ chartData.ec.mmB }}</td>
          <td class="border-lr-td border-btm-td yellow">{{ chartData.ec.mhB }}</td>
          <td></td>
        </tr>
        <tr>
          <td>low</td>
          <td class="border-lr-td border-top-td green">C2</td>
          <td class="border-lr-td border-top-td green">C1</td>
          <td class="border-lr-td border-top-td yellow">B0</td>
          <td></td>
          <td>low</td>
          <td class="border-lr-td border-top-td green">C2</td>
          <td class="border-lr-td border-top-td green">C1</td>
          <td class="border-lr-td border-top-td yellow">B0</td>
          <td></td>
          <td>low</td>
          <td class="border-lr-td border-top-td ">D</td>
          <td class="border-lr-td border-top-td green">C</td>
          <td class="border-lr-td border-top-td yellow">B</td>
          <td></td>
        </tr>
        <tr>
          <td>&lt;0.5 /a</td>
          <td class="border-lr-td border-btm-td green">{{ chartData.mr.lC2 }}</td>
          <td class="border-lr-td border-btm-td green">{{ chartData.mr.lC1 }}</td>
          <td class="border-lr-td border-btm-td yellow">{{ chartData.mr.lB0 }}</td>
          <td></td>
          <td>&lt;0.5 /a</td>
          <td class="border-lr-td border-btm-td green">{{ chartData.pr.lC2 }}</td>
          <td class="border-lr-td border-btm-td green">{{ chartData.pr.lC1 }}</td>
          <td class="border-lr-td border-btm-td yellow">{{ chartData.pr.lB0 }}</td>
          <td></td>
          <td>/a</td>
          <td class="border-lr-td border-btm-td ">{{ chartData.ec.lD }}</td>
          <td class="border-lr-td border-btm-td green">{{ chartData.ec.lC }}</td>
          <td class="border-lr-td border-btm-td yellow">{{ chartData.ec.lB }}</td>
          <td></td>
        </tr>
        <tr>
          <td></td>
          <td></td>
          <td>low</td>
          <td>medium</td>
          <td>high</td>
          <td></td>
          <td></td>
          <td></td>
          <td>low</td>
          <td>medium</td>
          <td>high</td>
          <td></td>
          <td></td>
          <td></td>
          <td>low</td>
          <td>medium</td>
          <td>high</td>
          <td></td>
        </tr>
        <tr>
          <td></td>
          <td></td>
          <td>&lt;50k</td>
          <td>50~300k</td>
          <td>&gt;300k</td>
          <td></td>
          <td></td>
          <td></td>
          <td>&lt;0</td>
          <td>0~24</td>
          <td>&gt;24</td>
          <td></td>
          <td></td>
          <td></td>
          <td></td>
          <td></td>
          <td></td>
          <td></td>
        </tr>
        <tr>
          <td></td>
          <td colspan="5" style="font-weight: bold;">Damage</td>
          <td></td>
          <td colspan="5" style="font-weight: bold;">Damage</td>
          <td></td>
          <td colspan="5" style="font-weight: bold;">Production Lose</td>
        </tr>
      </table>
      <table class="btm_table">
        <tr>
          <td>Not relevant</td>
          <td>{{ chartData.nr }}</td>
          <td></td>
          <td></td>
          <td></td>
          <td></td>
          <td></td>
          <td>Criticality</td>
          <td>Count</td>
          <td>% of Total</td>
        </tr>
        <tr>
          <td></td>
          <td></td>
          <td></td>
          <td></td>
          <td></td>
          <td></td>
          <td></td>
          <td class="red">A</td>
          <td class="red">{{ chartData.countA }}</td>
          <td class="red">{{ chartData.totalA }}</td>
        </tr>
        <tr>
          <td></td>
          <td colspan="2">Maintenance risk</td>
          <td></td>
          <td colspan="2">Production risk</td>
          <td></td>
          <td class="yellow">B</td>
          <td class="yellow">{{ chartData.countB }}</td>
          <td class="yellow">{{ chartData.totalB }}</td>
        </tr>
        <tr>
          <td>Open</td>
          <td colspan="2">{{ chartData.omr }}</td>
          <td></td>
          <td colspan="2">{{ chartData.opr }}</td>
          <td></td>
          <td class="green">C</td>
          <td class="green">{{ chartData.countC }}</td>
          <td class="green">{{ chartData.totalC }}</td>
        </tr>
        <tr>
          <td></td>
          <td></td>
          <td></td>
          <td></td>
          <td></td>
          <td></td>
          <td></td>
          <td>D</td>
          <td>{{ chartData.countD }}</td>
          <td>{{ chartData.totalD }}</td>
        </tr>
      </table>
    </el-drawer>

    <!-- 添加或修改定性分析对话框 -->
    <el-dialog :title="title" :visible.sync="open" append-to-body width="500px">
      <el-form ref="form" :model="form" :rules="rules" label-width="80px">
        <el-form-item label="位置" prop="location">
          <el-input v-model="form.location" placeholder="请输入位置"/>
        </el-form-item>
        <el-form-item label="位号" prop="tagNo">
          <el-input v-model="form.tagNo" placeholder="请输入位号"/>
        </el-form-item>
        <el-form-item label="描述" prop="description">
          <el-input v-model="form.description" placeholder="请输入描述"/>
        </el-form-item>
        <el-form-item label="Object Type" prop="objectType">
          <el-select v-model="form.objectType" placeholder="请选择Object Type">
            <el-option label="请选择字典生成" value=""/>
          </el-select>
        </el-form-item>
        <el-form-item label="Catalog Profile" prop="catalogProfile">
          <el-input v-model="form.catalogProfile" placeholder="请输入Catalog Profile"/>
        </el-form-item>
        <el-form-item label="Relevant (r)/not relevant (n)" prop="relevant">
          <el-input v-model="form.relevant" placeholder="请输入Relevant (r)/not relevant (n)"/>
        </el-form-item>
        <el-form-item label="故障频率" prop="frequencyFailure">
          <el-input v-model="form.frequencyFailure" placeholder="请输入故障频率"/>
        </el-form-item>
        <el-form-item label="维护成本" prop="maintenanceCost">
          <el-input v-model="form.maintenanceCost" placeholder="请输入维护成本"/>
        </el-form-item>
        <el-form-item label="生成损失" prop="productionLoss">
          <el-input v-model="form.productionLoss" placeholder="请输入生成损失"/>
        </el-form-item>
        <el-form-item label="维护风险" prop="maintenanceRisk">
          <el-input v-model="form.maintenanceRisk" placeholder="请输入维护风险"/>
        </el-form-item>
        <el-form-item label="生成风险" prop="productionRisk">
          <el-input v-model="form.productionRisk" placeholder="请输入生成风险"/>
        </el-form-item>
        <el-form-item label="设备类别" prop="equipmentCategory">
          <el-input v-model="form.equipmentCategory" placeholder="请输入设备类别"/>
        </el-form-item>
        <el-form-item label="风险程度" prop="riskCriticality">
          <el-input v-model="form.riskCriticality" placeholder="请输入风险程度"/>
        </el-form-item>
        <el-form-item label="定量分析" prop="quantitativeAnalysis">
          <el-input v-model="form.quantitativeAnalysis" placeholder="请输入定量分析"/>
        </el-form-item>
        <el-form-item label="维修策略" prop="maintenanceStrategy">
          <el-input v-model="form.maintenanceStrategy" placeholder="请输入维修策略"/>
        </el-form-item>
        <el-form-item label="维修策略描述" prop="msDescription">
          <el-input v-model="form.msDescription" placeholder="请输入维修策略描述"/>
        </el-form-item>
        <el-form-item label="备件策略" prop="sparepartStrategy">
          <el-input v-model="form.sparepartStrategy" placeholder="请输入备件策略"/>
        </el-form-item>
        <el-form-item label="备件策略描述" prop="ssDescription">
          <el-input v-model="form.ssDescription" placeholder="请输入备件策略描述"/>
        </el-form-item>
        <el-form-item label="需要澄清" prop="needClarification">
          <el-input v-model="form.needClarification" placeholder="请输入需要澄清"/>
        </el-form-item>
        <el-form-item label="备注" prop="remarks">
          <el-input v-model="form.remarks" placeholder="请输入备注"/>
        </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>
    <!-- 用户导入对话框 -->
    <el-dialog  :close-on-click-modal="false" v-dialogDrag :title="upload.title" :visible.sync="upload.open" width="400px" append-to-body>
      <el-upload
          ref="upload"
          :limit="1"
          accept=".xlsx, .xls"
          :headers="upload.headers"
          :action="upload.url"
          :disabled="upload.isUploading"
          :on-progress="handleFileUploadProgress"
          :on-success="handleFileSuccess"
          :auto-upload="false"
          drag
      >
        <i class="el-icon-upload"></i>
        <div class="el-upload__text">
          {{ $t('将文件拖到此处，或') }}
          <em>{{ $t('点击上传') }}</em>
        </div>
        <div class="el-upload__tip" slot="tip">
          <!--<el-checkbox v-model="upload.updateSupport" />是否更新已经存在的用户数据-->
          <el-link type="info" style="font-size:12px" @click="importTemplate">{{ $t('下载模板') }}</el-link>
        </div>
        <form ref="downloadFileForm" :action="upload.downloadAction" target="FORMSUBMIT">
          <input name="type" :value="upload.type" hidden />
        </form>
        <div class="el-upload__tip" style="color:red" slot="tip">{{ $t('提示：仅允许导入“xls”或“xlsx”格式文件！') }}</div>
      </el-upload>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitFileForm">{{ $t('确 定') }}</el-button>
        <el-button @click="upload.open = false">{{ $t('取 消') }}</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import {
  addAnalysis,
  delAnalysis,
  exportAnalysis,
  getAnalysis,
  importTemplate,
  listAnalysis,
  riskMatrixData,
  updateAnalysis
} from "@/api/reliability/analysis";
import {treeselect} from "@/api/system/dept";
import {getToken} from "@/utils/auth";
import Treeselect from "@riophae/vue-treeselect";
import "@riophae/vue-treeselect/dist/vue-treeselect.css";

export default {
  name: "Analysis",
  components: {Treeselect},
  data() {
    return {
      chartData: {
        mr: {
          hB2: 0, hA1: 0, hA0: 0,
          mC2: 0, mB1: 0, mA0: 0,
          lC2: 0, lC1: 0, lB0: 0
        },
        pr: {
          hB2: 0, hA1: 0, hA0: 0,
          mC2: 0, mB1: 0, mA0: 0,
          lC2: 0, lC1: 0, lB0: 0
        },
        ec: {
          hC: 0, hB: 0, hA: 0,
          mC: 0, mmB: 0, mhB: 0,
          lD: 0, lC: 0, lB: 0
        },
        nr: 0, omr: 0, opr: 0,
        countA: 0, countB: 0, countC: 0, countD: 0,
        totalA: '0%', totalB: '0%', totalC: '0%', totalD: '0%'
      },
      drawer: false,
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: false,
      // 总条数
      total: 0,
      // 定性分析表格数据
      analysisList: [],
      // 弹出层标题
      title: "",
      // 部门树选项
      deptOptions: undefined,
      clientHeight: 300,
      // 是否显示弹出层
      open: false,
      // 用户导入参数
      upload: {
        //下载模板请求地址
        downloadAction: process.env.VUE_APP_BASE_API + '/common/template',
        //下载模板类型
        type: "analysis",
        // 是否显示弹出层（用户导入）
        open: false,
        // 弹出层标题（用户导入）
        title: "",
        // 是否禁用上传
        isUploading: false,
        // 是否更新已经存在的用户数据
        updateSupport: 0,
        // 设置上传的请求头部
        headers: { Authorization: "Bearer " + getToken() },
        // 上传的地址
        url: process.env.VUE_APP_BASE_API + "/reliability/analysis/importData"
      },
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 20,
        location: null,
        tagNo: null,
        description: null,
        objectType: null,
        catalogProfile: null,
        relevant: null,
        frequencyFailure: null,
        maintenanceCost: null,
        productionLoss: null,
        maintenanceRisk: null,
        productionRisk: null,
        equipmentCategory: null,
        riskCriticality: null,
        quantitativeAnalysis: null,
        maintenanceStrategy: null,
        msDescription: null,
        sparepartStrategy: null,
        ssDescription: null,
        needClarification: null,
        remarks: null,
        createrCode: null,
        createdate: null,
        updaterCode: null,
        updatedate: null,
        deptId: null
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {}
    };
  },
  watch: {
    // 根据名称筛选部门树
    deptName(val) {
      this.$refs.tree.filter(val);
    }
  },
  created() {
    //设置表格高度对应屏幕高度
    this.$nextTick(() => {
      this.clientHeight = document.body.clientHeight - 250
    })
    this.getList();
    this.getTreeselect();
  },
  methods: {
    openDrawer() {
      this.drawer = true;
      riskMatrixData().then(response => {
        let data = response.data;
        this.chartData.mr.hB2 = data.mrhb2;
        this.chartData.mr.hA1 = data.mrha1;
        this.chartData.mr.hA0 = data.mrha0;
        this.chartData.mr.mC2 = data.mrmc2;
        this.chartData.mr.mB1 = data.mrmb1;
        this.chartData.mr.mA0 = data.mrma0;
        this.chartData.mr.lC2 = data.mrlc2;
        this.chartData.mr.lC1 = data.mrlc1;
        this.chartData.mr.lB0 = data.mrlb0;
        this.chartData.pr.hB2 = data.prhb2;
        this.chartData.pr.hA1 = data.prha1;
        this.chartData.pr.hA0 = data.prha0;
        this.chartData.pr.mC2 = data.prmc2;
        this.chartData.pr.mB1 = data.prmb1;
        this.chartData.pr.mA0 = data.prma0;
        this.chartData.pr.lC2 = data.prlc2;
        this.chartData.pr.lC1 = data.prlc1;
        this.chartData.pr.lB0 = data.prlb0;
        this.chartData.ec.hC = data.echc;
        this.chartData.ec.hB = data.echb;
        this.chartData.ec.hA = data.echa;
        this.chartData.ec.mC = data.ecmc;
        this.chartData.ec.mmB = data.ecmmb;
        this.chartData.ec.mhB = data.ecmhb;
        this.chartData.ec.lD = data.ecld;
        this.chartData.ec.lC = data.eclc;
        this.chartData.ec.lB = data.eclb;
        this.chartData.nr = data.nr;
        this.chartData.omr = data.omr;
        this.chartData.opr = data.opr;
        this.chartData.countA = data.countA;
        this.chartData.countB = data.countB;
        this.chartData.countC = data.countC;
        this.chartData.countD = data.countD;
        this.chartData.totalA = data.totalA;
        this.chartData.totalB = data.totalB;
        this.chartData.totalC = data.totalC;
        this.chartData.totalD = data.totalD;
      })
    },
    /** 查询定性分析列表 */
    getList() {
      this.loading = true;
      listAnalysis(this.queryParams).then(response => {
        this.analysisList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    /** 查询部门下拉树结构 */
    getTreeselect() {
      treeselect().then(response => {
        this.deptOptions = response.data;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        id: null,
        location: null,
        tagNo: null,
        description: null,
        objectType: null,
        catalogProfile: null,
        relevant: null,
        frequencyFailure: null,
        maintenanceCost: null,
        productionLoss: null,
        maintenanceRisk: null,
        productionRisk: null,
        equipmentCategory: null,
        riskCriticality: null,
        quantitativeAnalysis: null,
        maintenanceStrategy: null,
        msDescription: null,
        sparepartStrategy: null,
        ssDescription: null,
        needClarification: null,
        remarks: null,
        delFlag: null,
        createrCode: null,
        createdate: null,
        updaterCode: null,
        updatedate: null,
        deptId: null
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.id)
      this.single = selection.length !== 1
      this.multiple = !selection.length
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
      this.title = "添加定性分析";
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      const id = row.id || this.ids
      getAnalysis(id).then(response => {
        this.form = response.data;
        this.open = true;
        this.title = "修改定性分析";
      });
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          if (this.form.id != null) {
            updateAnalysis(this.form).then(response => {
              this.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            });
          } else {
            addAnalysis(this.form).then(response => {
              this.msgSuccess("新增成功");
              this.open = false;
              this.getList();
            });
          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const ids = row.id || this.ids;
      this.$confirm('是否确认删除?', "警告", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning"
      }).then(function () {
        return delAnalysis(ids);
      }).then(() => {
        this.getList();
        this.msgSuccess("删除成功");
      })
    },
    /** 导出按钮操作 */
    handleExport() {
      const queryParams = this.queryParams;
      this.$confirm('是否确认导出所有定性分析数据项?', "警告", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning"
      }).then(function () {
        return exportAnalysis(queryParams);
      }).then(response => {
        this.download(response.msg);
      })
    },
    /** 导入按钮操作 */
    handleImport() {
      this.upload.title = "用户导入";
      this.upload.open = true;
    },
    /** 下载模板操作 */
    importTemplate() {
      importTemplate().then(response => {
        this.download(response.msg);
      });
    },
    // 文件上传中处理
    handleFileUploadProgress(event, file, fileList) {
      this.upload.isUploading = true;
    },
    // 文件上传成功处理
    handleFileSuccess(response, file, fileList) {
      this.upload.open = false;
      this.upload.isUploading = false;
      this.$refs.upload.clearFiles();
      if (response.data[0] != null) {
        this.$alert(this.$t('成功导入') + response.msg + this.$t('条数据') + "，" + this.$t('第') + response.data + this.$t('行数据出现错误导入失败')+"。", this.$t('导入结果'), { dangerouslyUseHTMLString: true });
      }else {
        this.$alert(this.$t('成功导入') + response.msg + this.$t('条数据'), this.$t('导入结果'), { dangerouslyUseHTMLString: true });
      }
      this.getList();
    },
    // 提交上传文件
    submitFileForm() {
      this.$refs.upload.submit();
    }
  }
};
</script>
<style scoped>
table {
  border-collapse: collapse;
  width: 90%;
  margin: 5%;
}

.top_table td {
  height: 30px;
  width: 5%;
  text-align: center;
}

.btm_table {
  margin-top: 10%;
}

.btm_table td {
  height: 30px;
  width: 5%;
  text-align: center;
}

.border-lr-td {
  border-left: 1px solid black;
  border-right: 1px solid black;
}

.border-top-td {
  border-top: 1px solid black;
}

.border-btm-td {
  border-bottom: 1px solid black;
}

.yellow {
  background-color: yellow;
}

.green {
  background-color: #02ff02;
}

.red {
  background-color: red;
}
</style>
