<template>
  <div>
    <LHeader :text="text"></LHeader>
    <!-- 内容列表 -->
    <div class="con-list">
      <van-tabs
        v-model="active"
        @click="onClick"
        title-inactive-colo="#d0d1d1"
        color="#247df7"
        title-active-color="#000000"
      >
        <van-tab title="指标评估">
          <target ref="target"></target>
        </van-tab>
        <van-tab title="条件评估">
          <condition ref="condition"></condition>
        </van-tab>
      </van-tabs>

      <div style="background-color: white; padding: 16px">
        <van-button round block type="info" @click.native="onDefine"
          >确认</van-button
        >
        <br />
        <van-button round block type="warning" @click.native="cancel"
          >取消</van-button
        >
      </div>
    </div>
  </div>
</template>

<script>
import LHeader from "@/components/header.vue";
import {getFun,postFun} from "@/service/table.js";
import Target from "./target.vue";
import Condition from "./condition.vue";
import { postCalRiskLevel } from "@/service/risk";
export default {
  name: "matrix-grad",
  components: {
    LHeader,
    Target,
    Condition
  },
  data() {
    return {
      text: "矩阵式定级",
      active: "0"
    };
  },


  methods: {
    onClick(val) {
    },
    onDefine() {
      if (this.active == 0) {
        let objDataTarget = this.$refs.target.compute();
        if (objDataTarget) {
          let { a, b } = objDataTarget;
          this.getLevel(a, b);
        }
      } else {
        let objDatacondition = this.$refs.condition.compute();
        if (objDatacondition) {
          let { a, b } = objDatacondition;
          this.getLevel(a, b);
        }
      }
    },
    // 计算风险等级的接口
    getLevel(possibilityLevel, consequenceLevel) {
      this.$toast.loading({
        message: "提交中...",
        forbidClick: true,
        loadingType: "spinner",
        duration: 0
      });
      postCalRiskLevel(
        `/riskMain/calRiskLevel?possibilityLevel=${possibilityLevel}&consequenceLevel=${consequenceLevel}`
      )
        .then(res => {
          this.$toast.clear();
          this.$toast.success({
            message: "提交成功",
            duration: 2000
          });
          
          this.$bus.$emit("riskLevelBus", res.data.evaluateLevel)
          history.go(-1);
        })
        .catch(() => {
          this.$toast.clear();
          this.$toast.fail("提交失败,请稍后再试");
        });
    },

    cancel() {
      this.$bus.$emit("riskLevelBus", 0)
      this.$router.go(-1);

    }
  }
};
</script>
<style lang="less" scoped>
/* @import url(); 引入css类 */
.con-list {
  background-color: #f0f1f5;
}
</style>
