<template>
  <view>
    <uni-nav-bar left-icon="left" background-color="#fff" :border="false" title="患者详情" @clickRight="onClickRight">
      <template v-slot:right>
        <view class="flex nav-right">
          切换至概览 <u-image class="icon-change" src="@/static/images/change-dark.png" mode="aspectFill"></u-image>
        </view>
      </template>
    </uni-nav-bar>

    <view class="flex u-m-40 u-m-r-40 align-top content" v-if="currentPatient">
      <view class="flex-1 u-m-r-20 column">
        <uni-section type="line" title="患者信息" titleFontSize="16px">
          <template v-slot:right>
            <view class="u-tips-color">
              <text class="u-m-r-20">{{ currentPatient?.patientName }}</text>
              <text class="u-m-r-20">{{ GET_GENDER_TEXT_BY_CODE(currentPatient!.patientGender) }}</text>
              <text>{{ currentPatient?.patientAge }}</text>
            </view>
          </template>
        </uni-section>

        <view class="item-card uni-pa-10 u-m-r-20 bg-white border-success">
          <view class="flex">
            <view class="flex-1">
              <view class=" font-bold flex-1 u-tips-color u-m-b-20">
                <text class="u-m-r-20">患者基本信息</text>
              </view>
              <view>
                <u-tag class="u-m-r-20 u-m-b-12" text="姓名" type="success" size="mini" />
                <u-tag class="u-m-r-20 u-m-b-12" text="性别" type="success" size="mini" />
                <u-tag class="u-m-r-20 u-m-b-12" text="民族" type="success" size="mini" />
                <u-tag class="u-m-r-20 u-m-b-12" text="身份证" type="success" size="mini" />
                <u-tag class="u-m-r-20 u-m-b-12" text="来院方式" type="success" size="mini" />
              </view>
            </view>
            <uni-icons type="right" color="#999" size="16" />
          </view>
        </view>

        <view class="item-card u-m-r-20 u-m-t-30 bg-primary">
          <view class="flex count-wrap">
            NIHSS评分

            <view class="flex-1 flex justify-end">
              <view class="time-item">00</view> :
              <view class="time-item">00</view> :
              <view class="time-item">00</view>
            </view>
          </view>
          <view class="flex bg-white item-card-content">
            <view class="flex-1">
              <view class=" font-bold flex-1 u-tips-color u-m-b-20">
                <text class="u-m-r-20">急救信息记录</text>
              </view>
              <view>
                <u-tag class="u-m-r-20 u-m-b-12" text="身高" type="primary" size="mini" />
                <u-tag class="u-m-r-20 u-m-b-12" text="体重" type="primary" size="mini" />
                <u-tag class="u-m-r-20 u-m-b-12" text="BMI" type="primary" size="mini" />
                <u-tag class="u-m-r-20 u-m-b-12" text="脉搏" type="primary" size="mini" />
                <u-tag class="u-m-r-20 u-m-b-12" text="mRS" type="primary" size="mini" />
                <u-tag class="u-m-r-20 u-m-b-12" text="NIHSS" type="primary" size="mini" />
                <u-tag class="u-m-r-20 u-m-b-12" text="知情同意书" type="primary" size="mini" />
                <u-tag class="u-m-r-20 u-m-b-12" text="静脉溶栓" type="primary" size="mini" />
              </view>
            </view>
            <uni-icons type="right" color="#999" size="16" />
          </view>
        </view>
      </view>

      <!-- right -->
      <view class="flex-3">
        <DetailBase />
      </view>
    </view>

    <!-- float button -->
    <FloatButton />
  </view>
</template>

<script lang="ts" setup>
import { onLoad } from '@dcloudio/uni-app'
import { useServiceStore } from '@/store/modules/service';
import { computed } from 'vue';
import { GET_GENDER_TEXT_BY_CODE } from '@/config/service';

const serviceStore = useServiceStore()

const currentPatient = computed(() => serviceStore.currentPatient)


function onClickRight() {

}

onLoad((option) => {
  console.log(option);

  if (option?.firstAidId) {
    // 新建过来的
    getAidInfo(option.firstAidId)
  } else {

  }
})

// 查病历数据
async function getAidInfo(firstAidId: string) {
  try {
    const data = await uni.$u.api.getAidInfo(firstAidId)
    serviceStore.setCurrentPatient(data)
  } catch (error) {
    serviceStore.setCurrentPatient(null)
    uni.$u.alertError(error)
  }
}
</script>

<style lang="scss" scoped>
:deep(.uni-navbar__header-btns) {
  width: 200rpx !important;
}

.icon-change {
  width: 40rpx !important;
  height: 40rpx !important;
  margin-left: 0.5em;
  opacity: .9 !important;
}

.item-card {
  // padding-left: 10rpx;
  border-radius: 20rpx;
  background-color: #fff;

  .item-card-content {
    margin-left: 0.5em;
    border-radius: 10px;
    padding: 1em;
  }

  .count-wrap {
    color: #fff;
    padding: 1em;
    font-weight: bold;

    .time-item {
      background-color: #fff;
      color: $u-type-primary;
      padding: 0 2px;
      border-radius: 4px;
      margin: 0 3px;
    }
  }

}

.head {
  height: 140rpx;
  padding: 0 20px;
}

.btn-create {
  background-color: #fff;
  height: 3em;
  padding: 0 3em;
  display: flex;
  align-items: center;
  border-radius: 1.5em;

  .icon-plus {
    width: 32rpx;
    height: 32rpx;
    margin-right: 0.5em;
  }
}

.icon-doctor {
  position: relative;
  z-index: 0;
  width: 140rpx;
  height: 140rpx;
  transform: scale(1.1) translate3d(-50%, 24%, 0);
}

.content {
  position: relative;
  z-index: 99;
}
</style>
