<template>
  <div class="new-meeting">
    <div class="mdt-panel-head">
        <p :class="{ active: current == 0 }">
          <span @click="changeTab(0)">当前MDT会议</span>
        </p>
        <p :class="{ active: current == 1 }">
          <span @click="changeTab(1)">既往MDT会议</span>
        </p>
    </div>
    <div class="mdt-panel-con" v-if="current == 0">
      <el-empty style="margin-top:10%" :image="require('@/assets/images/empty.png')" :description="isCoreTeam ? '抱歉，当前暂无MDT会议' : '请先分配团队'" v-if="topObj.step == 0 || topObj.step == 6">
        <el-button size="mini" type="primary" :class="{'btn-lv-gray': !(topObj.isPower >= 1 && topObj.isPower <= 3 && topObj.isRoute)}" @click="handleMeeting(1,true)" :disabled="!(topObj.isPower >= 1 && topObj.isPower <= 3)" >召集会议</el-button>
      </el-empty>
      <!--会议信息编辑回显组件-->
      <meetingTemp
      :item="$attrs.meetingInfo"
      v-else v-bind="$attrs"
      v-on="$listeners"
      v-model="edit"
      :isEdit="isEdit"
      :step="step"/>
    </div>
    <div class="mdt-panel-con past" v-if="current == 1">
      <!--既往历史组件-->
      <PastHostory
      :patientId="topObj.patientId"
      :oldMdtId="topObj.oldMdtId"
      :step="step"
      ref="pastHistory"
      v-bind="$attrs"
      v-on="$listeners"/>
    </div>
  </div>
</template>
<script>
import meetingTemp from '../components/meeting-temp.vue'
import PastHostory from './past-meeting.vue'
import {DonMessage} from '../../../examples/axios/message.js'
import { getMeetingNode,getCoreList } from '@/request/mdt.js'
const $message = new DonMessage()
export default {
  inheritAttrs: true,
  components: { PastHostory, meetingTemp },
  props: {
    step: {
      type: [Number, String],
    },
    // oldMdtId: [Number, String],
  },
  inject: ['topObj'],
  data () {
    return {
      isCoreTeam: true,//是否存在核心团队
      current: 0,
      edit: false,
    }
  },
  mounted() {
    this.current = (this.step == 6) || this.topObj?.oldMdtId ? 1 : this.current; 

  },
  computed: {
    //用于会议信息编辑状态显示
    isEdit() {
      if(!this.topObj.isRoute) return false;
      if(this.topObj?.isPower < 4) {
        if(this.topObj?.step <= 1) {
          return true
        } else {
          return this.edit
        }
      } else {
        return false
      }
    },
  },
  watch: {
    'topObj.step': {
      handler(v,o){
        this.current = (v == 6 && o == 5) ? 1 : this.current;
        if(v == 4 && o == 5){
          getMeetingNode(this.topObj?.mdtId).then(res1 => {
            if(res1 && res1.data == 7){
              if(this.$refs.pastHistory) this.$refs.pastHistory.getMeetingInfo();
            } else {
              this.$emit('refresh')
            }
          })
        }
        if(v == 7) this.current = 1
      },
      immediate: true
    }
  },
  methods: {
    handleMeeting(n,status) {
      this.$emit('changeStep', {step:n,status: status || 0})
    },
    // mdt核心成员，判断是否有核心团队或者说核心团队是否有三人
    async getCoreList() {
      const res = await getCoreList(this.topObj?.patientId);
      if (res.code === 0) {
          if(res.data.length < 3){
            this.isCoreTeam = false
          } else {
            this.isCoreTeam = true
          }
      } else {
          this.$message.error(res.msg);
      }
    },
    //tab切换，当前会议需要刷新顶层的数据，获取该患者当前最新的会议
    changeTab(n) {
      this.current = n;
      this.topObj.handleOption(2,'')
      if(!n) this.$emit('refresh')
    }
  }
}
</script>
<style lang="less" scoped>
.new-meeting {
  width: 477px;
  height: 100%;
  background-color: #fff;
  // display: flex;
  // flex-direction: column;
  overflow: hidden;
  .mdt-panel-con {
    width: 477px;
    height: calc(100% - 50px);
    // flex:  1 1 auto;
    overflow: hidden;
    // height: 100%;
    padding-top: 10px;
    box-sizing: border-box;
    &.past {
      padding-top: 0;
    }
  }

    .mdt-panel-head {
    // border-bottom: 1px solid rgba(151, 151, 151, 0.2);
    display: flex;
    justify-content: center;
    height: 50px;
    // flex: 0 0 50px;
    padding-right: 20px;
    padding-left: 20px;
    position: relative;
    &::after {
      position: absolute;
      bottom: 0;
      content: '';
      display: inline-block;
      height: 1px;
      width: calc(100% - 40px);
       border-bottom: 1px solid rgba(151, 151, 151, 0.2);
    }
    p {
      opacity: 0.7;
      font-size: 16px;
      text-align: left;
      color: rgba(0, 0, 0, 0.85);
      font-family: PingFangSC, PingFangSC-Regular;
      padding: 0 30px;
      line-height: 53px;
      // transition: all 0.3s;
      margin: 0;
      display: flex;
      span {
        cursor: pointer;
      }
    }
    p.active {
      opacity: 1;
      font-weight: 600;
      color: rgba(0, 0, 0, 0.85);
      font-family: PingFangSC, PingFangSC-Semibold;
      position: relative;
      // transition: all 0.3s;
    }
    p.active::after {
      content: "";
      display: block;
      position: absolute;
      bottom: 0;
      left: 55px;
      background-color: #1890ff;
      width: 44px;
      height: 3px;
    }
  }


}
</style>
