<template>
  <div class="disease-detail">
    <div class="content">
      <div class="content-title">
        <div class="name">病例</div>
        <button class="btn" @click="copy" v-if="status!=3">复制</button>
      </div>
      <div class="content-middle">
        <p>诊断:{{ detailObj.diagnosisMedicalRecord.diagnosisSummary }}</p>
        <p>主诉:{{ detailObj.diagnosisMedicalRecord.mainAppeal }}</p>
        <p>现病:{{ detailObj.diagnosisMedicalRecord.nowMedicalHistory }}</p>
        <p>既往:{{ detailObj.diagnosisMedicalRecord.beforeMedicalHistory }}</p>
        <p>体查:{{ detailObj.diagnosisMedicalRecord.exam }}</p>
        <p>复查:{{ detailObj.diagnosisMedicalRecord.allergy }}</p>
        <p>过敏:{{ detailObj.diagnosisMedicalRecord.allergyHistory }}</p>
        <p>处置:{{ detailObj.diagnosisMedicalRecord.treatment }}</p>
      </div>
    </div>
    <div class="content">
      <div class="content-title">
        <div class="name">服务项目</div>
        <button class="btn" @click="copyItem" v-if="status!=3">复制</button>
      </div>
      <div class="content-middle">
        <div class="item" v-for="item in detailObj.itemDetail">
          <el-tooltip
              class="box-item"
              effect="dark"
              :content="item.itemName"
              placement="bottom-start"
          >
            <div class="name">{{ item.itemName }}</div>
          </el-tooltip>
          <div class="price">
            <div class="price-left">{{ item.selectedNum || 0 }}{{ item.selectedUnit }}</div>
            <div class="price-right">￥{{ item.unitPrice }}</div>
          </div>
        </div>
      </div>
    </div>
    <div class="content">
      <div class="content-title">
        <div class="name">药品耗材</div>
        <button class="btn" @click="copyGoods" v-if="status!=3">复制</button>
      </div>
      <div class="content-middle">
        <div class="item" v-for="item in detailObj.goodsDetail">
          <el-tooltip
              class="box-item"
              effect="dark"
              :content="item.name"
              placement="bottom-start"
          >
            <div class="name">{{ item.name }}</div>
          </el-tooltip>
          <div class="price">
            <div class="price-left">{{ item.selectedNum || 0 }}{{ item.selectedUnit }}</div>
            <div class="price-right">￥{{ item.selectedPrice }}</div>
          </div>
        </div>
      </div>
    </div>
    <div class="content">
      <div class="content-middle">
        <div class="item">
          <div class="name">合计</div>
          <div class="price">
            <div class="price-right">￥{{ sumPrice }}</div>
          </div>
        </div>
      </div>
    </div>
  </div>
</template>
<script setup lang="ts">
import {ref, defineProps, onMounted} from 'vue'

const {detail, status} = defineProps(['detail', 'status']);
const detailObj = ref<any>(detail)
const sumPrice = ref(0)
const emit = defineEmits(['copy', 'copyItem', 'copyGoods'])
const copy = () => {
  emit('copy', detailObj.value)
}
const copyItem = () => {
  emit('copyItem', detailObj.value)
}
const copyGoods = () => {
  emit('copyGoods', detailObj.value)
}
onMounted(() => {
  const pharmaceuticalTotalAmount = detailObj.value.itemDetail.reduce((pre: any, cur: any) => {
    return pre + cur.selectedNum * cur.selectedPrice
  }, 0);

  const serviceTotalAmount = detailObj.value.goodsDetail.reduce((pre: any, cur: any) => {
    return pre + cur.selectedNum * cur.selectedPrice
  }, 0);
  sumPrice.value = pharmaceuticalTotalAmount + serviceTotalAmount;
})
</script>
<style scoped lang="scss">
.disease-detail {
  background: #F9FAFC;
  padding: 0 21px 0 27px;

  .top {
    height: 60px;
    border-bottom: 1px solid #EAEAEC;
    display: flex;
    justify-content: space-between;
    align-items: center;

    span {
      background: #F9FAFC;
      border-radius: 8px;
      border: 1px solid #D8D8D8;
      padding: 6px 24px;
      font-weight: 400;
      font-size: 16px;
      color: #999999;
    }
  }

  .content {
    border-bottom: 1px solid #EAEAEC;

    .content-title {
      height: 46px;
      display: flex;
      align-items: center;
      justify-content: space-between;

      .name {
        font-weight: bold;
        font-size: 16px;
      }

      .btn {
        color: #4D6DE4; // 白色文字
        border: none; // 去掉边框
        font-size: 16px; // 字体大小
        cursor: pointer; // 鼠标悬停时显示手型
        background: #f9fafc;
      }
    }

    .content-middle {
      font-weight: 500;
      font-size: 14px;
      color: #999999;

      p {
        margin: 0;
        overflow: hidden;
        white-space: nowrap;
      }

      .item {
        display: flex;
        justify-content: space-between;
        margin-bottom: 8px;

        .name {
          white-space: nowrap; /* 防止文本换行 */
          overflow: hidden; /* 隐藏溢出的文本 */
          text-overflow: ellipsis; /* 显示省略号 */
          width: 100px;
        }

        .price {
          display: flex;

          .price-left {
            margin-right: 38px;
          }
        }
      }
    }
  }
}
</style>