<template>
  <div class="tumor-board-box">
    <!--Tumor Board会议意见-->
    <el-scrollbar tag="div" class="mdt-consult-item tumor-borad">
      <div class="consult-item-head">
        <div class="item-left">
          <span class="iconfont iconH1"></span>
          <p>Tumor Board备忘录</p>
        </div>
      </div>
      <div class="consult-item-con">
        <div class="tumor-borad-item">
          <p class="title">
            <i class="dot"></i>是否经过Ⅱ级MDT讨论？<sup style="color: red"
              >*</sup
            >
          </p>
          <p class="input" style="padding-left: 15px">
            <el-radio-group
              v-model="tumorBoard.secondLevelDiscussion"
              @change="clearConsult('secondLevelDiscussion')"
            >
              <el-radio :label="1">是</el-radio>
              <el-radio :label="0">否</el-radio>
            </el-radio-group>
          </p>
        </div>
        <div
          class="tumor-borad-item"
          v-show="tumorBoard.secondLevelDiscussion === 1"
        >
          <p class="title">
            <i class="dot"></i>是否与Ⅱ级MDT结论建议相同？<sup style="color: red"
              >*</sup
            >
          </p>
          <p class="input" style="padding-left: 15px">
            <el-radio-group
              v-model="tumorBoard.secondLevelResult"
              @change="clearConsult('secondLevelResult')"
            >
              <el-radio :label="1">是</el-radio>
              <el-radio :label="0">否</el-radio>
            </el-radio-group>
          </p>
        </div>
        <div
          class="tumor-borad-item"
          v-show="tumorBoard.secondLevelResult === 0"
        >
          <p class="title"><i class="dot"></i>不认同原因</p>
          <p class="input">
            <el-input
              placeholder="请输入内容"
              v-model="tumorBoard.disagreeReason"
              :rows="4"
              type="textarea"
              show-word-limit
              maxlength="5000"
              resize="none"
            ></el-input>
          </p>
        </div>
        <div class="tumor-borad-item">
          <p class="title"><i class="dot"></i>总结</p>
          <p class="input">
            <el-input
              placeholder="请输入内容"
              v-model="tumorBoard.threeLevelConclusion"
              :rows="4"
              type="textarea"
              show-word-limit
              maxlength="5000"
              resize="none"
            ></el-input>
          </p>
        </div>
      </div>
    </el-scrollbar>
    <!--Tumor Board会议意见结束-->
    <div class="add">
      <el-button
        type="primary"
        size="small"
        @click="tumorBoardSaves"
        :loading="loading"
        >保存</el-button
      >
    </div>
  </div>
</template>
<script>
import { debounce } from "lodash";
import {
  tumorBoardContent,
  newTbSave
} from "@/request/mdt";
export default {
  props: ["healthNum","mdtId"],
  name: 'SpTumorBord',
  data() {
    return {
      mdtMember: "", //小组成员
      patientCase: {}, //患者信息
      tumorBoard: {
        secondLevelDiscussion: null, // 是否经过二级讨论  0:否  1:是
        secondLevelResult: null, // 是否认同二级结果 0:否  1:是
        disagreeReason: "", // 不认同原因
        threeLevelConclusion: "", //三级会议总结
      },
      loading: false,
    };
  },
  created() {
    this.tumorBoardContent();
  },
//   computed: {
//     ...mapGetters(["mdtId","mdtIdCom"]),
//   },
  watch: {
    mdtId(v) {
      if(v) this.tumorBoardContent()
    }
  },
  methods: {
    // 选项改变清空填写内容
    clearConsult(k) {
      if (k == "secondLevelDiscussion") {
        this.tumorBoard.secondLevelResult = null;
        this.tumorBoard.disagreeReason = "";
      }
      if (k == "secondLevelResult") {
        this.tumorBoard.disagreeReason = "";
      }
    },
    // tumor board 修改
    tumorBoardSaves: debounce(
      function () {
        this.newTbSave();
      },
      5000,
      {
        leading: true,
        trailing: false,
      }
    ),
        //路由跳转
    routeToBoard() {
        this.$store.commit("patientMdt/vx_closeCurMdtTimeTag", "consult");
        this.$store.commit("patientMdt/changeCurMdtTimeI", 'A001');
        this.$emit('submitSuccess')
    },
    //保存
    async newTbSave() {
      if (
        this.tumorBoard.secondLevelDiscussion === null ||
        (this.tumorBoard.secondLevelDiscussion &&
          this.tumorBoard.secondLevelResult === null)
      ) {
        this.$message({
          message: "内容不能为空",
          type: "warning",
        });
        return false;
      }

      let data = {
        dto: {
          id: this.mdtId,
          ...this.tumorBoard,
        },
        paramDTO: {
          id: this.mdtId,
          healthCardNo: this.healthNum,
        },
      };
      this.loading = true;
      let res = await newTbSave(data);
      if (res.code === 0) {
        this.$message({
          message: "保存成功",
          type: "success",
        });
        this.$emit('handle', 'submitSuccess')
        // this.routeToBoard()
        this.loading = false;
      } else {
        this.$message.error(res.msg);
        this.loading = false;
      }
    },
    // tumor board 查询
    async tumorBoardContent() {
      let res = await tumorBoardContent(this.mdtId);
      if (res.code === 0) {
        if(res.data){
          this.tumorBoard = {
            secondLevelDiscussion: res.data.secondLevelDiscussion,
            secondLevelResult:
              res.data.secondLevelDiscussion == 0
                ? null
                : res.data.secondLevelResult,
            disagreeReason: res.data.disagreeReason,
            threeLevelConclusion: res.data.threeLevelConclusion,
          };
        } else {
          this.tumorBoard = {
            secondLevelDiscussion: null, // 是否经过二级讨论  0:否  1:是
            secondLevelResult: null, // 是否认同二级结果 0:否  1:是
            disagreeReason: "", // 不认同原因
            threeLevelConclusion: "", //三级会议总结
          }
        }
      } else {
        this.$message.error(res.msg);
        this.tumorBoard = {
          secondLevelDiscussion: null,
          secondLevelResult: null,
          disagreeReason: "",
          threeLevelConclusion: "",
        };
      }
    }
  },
};
</script>
<style lang="less">
.tumor-borad {
  .el-scrollbar__wrap {
    overflow-x: hidden;
  }
}
</style>
<style lang="less" scoped>
.tumor-board-box {
  height: 100%;
  display: flex;
  flex-direction: column;
  .mdt-consult-item .consult-item-head {
    height: 50px;
  }
}
.add {
  padding: 0;
  display: flex;
  justify-content: flex-end;
}

.tumor-borad {
  min-height: calc(100% - 48px);
  flex: 1;
  margin-bottom: 0;
  .little-tips {
    font-size: 12px;
    color: #ccc;
    margin-left: 30px;
  }
  .tumor-borad-item {
    width: 100%;
    display: flex;
    align-items: center;
    flex-wrap: wrap;

    p {
      margin: 0;
    }
    p:first-child {
      margin-right: 20px;
      padding: 8px 0;
    }

    .input {
      width: 100%;
      padding: 0px 0 10px;
    }
    .dot {
      display: inline-block;
      width: 5px;
      height: 5px;
      border-radius: 50%;
      background-color: rgba(62, 152, 255, 1);
      margin-right: 5px;
      margin-left: 5px;
    }
  }
}
</style>