<template>
  <div class="detail">
    <div class="detail-info">
      <h2>健康状况</h2>
      <div class="detail-info__item">
        <div class="left">
          <label>当前体温</label>
        </div>
        <div class="right">
          <span :style="{color: info.temperature >= 37.3 ? '#FF4466' : '#42D784'}">{{ info.temperature }}℃</span>
        </div>
      </div>
      <div class="detail-info__item">
        <div class="left">
          <label>14天内是否接触新冠确诊或疑似患者</label>
        </div>
        <div class="right">
          <span :style="{color: info.touchInFourteen === '0' ? '#42D784' : '#FF4466'}">{{ $dict.getLabel('epidemicTouchInFourteen', info.touchInFourteen) }}</span>
        </div>
      </div>
      <div class="detail-info__item">
        <div class="left">
          <label>当前健康状况</label>
        </div>
        <div class="right">
          <span :style="{color: !info.isHealth ? '#42D784' : '#FF4466'}">{{ info.healthName }}</span>
        </div>
      </div>
    </div>
    <div class="detail-info">
      <h2>核酸检测信息</h2>
      <div class="detail-info__item">
        <div class="left">
          <label>核酸检测日期</label>
        </div>
        <div class="right">
          <span>{{ info.checkTime.split(' ')[0] }}</span>
        </div>
      </div>
      <div class="detail-info__item">
        <div class="left">
          <label>核酸检测结果</label>
        </div>
        <div class="right">
          <span :style="{color: info.checkResult === '0' ? '#42D784' : '#FF4466'}">{{ $dict.getLabel('epidemicRecentTestResult', info.checkResult) }}</span>
        </div>
      </div>
      <div class="detail-info__item">
        <div class="left">
          <label>健康码状态</label>
        </div>
        <div class="right">
          <span :style="{color: info.healthCode === '0' || info.healthCode === '1' ? '#42D784' : '#FF4466'}">{{ $dict.getLabel('epidemicHealthCode', info.healthCode) }}</span>
        </div>
      </div>
      <div class="detail-info__item">
        <div class="left">
          <label>已接种疫苗次数</label>
        </div>
        <div class="right">
          <span>{{ $dict.getLabel('epidemicVaccineTime', info.vaccine) }}</span>
        </div>
      </div>
      <div class="detail-info__item detail-info__item--img">
        <div class="left">
          <label>本人健康码截图</label>
        </div>
        <div class="right">
          <image :src="item.url" @click="preview(item.url)" v-for="(item, index) in info.checkPhoto" :key="index" />
        </div>
      </div>
    </div>
  </div>
</template>

<script>
  export default {
    appName:"上报详情",
    data () {
      return {
        info: {},
        pageShow: false
      }
    },

    onLoad (query) {
      this.$loading()
      this.$dict.load(['epidemicTouchInFourteen', 'epidemicRecentHealth', 'epidemicRecentTestResult', 'epidemicHealthCode', 'epidemicVaccineTime']).then(() => {
        this.getInfo(query.id)
      })
    },

    methods: {
      preview (url) {
        uni.previewImage({
          urls: this.info.checkPhoto.map(v => v.url),
          current: url
        })
      },

      getInfo (id) {
        this.$instance.post(`/app/appepidemichealthreport/queryDetailById?id=${id}`).then(res => {
          if (res.code === 0) {
            this.info = res.data
            this.info.checkPhoto = JSON.parse(res.data.checkPhoto)
            let healthName = ''
            this.info.isHealth = false
            res.data.health.split(',').forEach(v => {
              if (v > 0) {
                this.info.isHealth = true
              }
              healthName = healthName + this.$dict.getLabel('epidemicRecentHealth', v)
            })
            this.info.healthName = healthName

            this.$nextTick(() => {
              this.pageShow = true
            })
          }

          this.$hideLoading()
        })
      },

      call (phone) {
        uni.makePhoneCall({
          phoneNumber: phone
        })
      }
    }
  }
</script>

<style lang="scss">
  .detail {
    padding-bottom: 40px;

    .detail-header {
      padding: 32px;
      background: #fff;

      h2 {
        margin-bottom: 32px;
        color: #333333;
        font-size: 40px;
        font-weight: 600;
      }

      .item-info {
        .item-info__item {
          display: flex;
          align-items: center;
          margin-bottom: 8px;

          &:last-child {
            margin-bottom: 0;
          }

          image {
            width: 32px;
            height: 32px;
            margin-right: 16px;
          }

          span {
            color: #333;
            font-size: 28px;
          }
        }
      }
    }

    .detail-info {
      margin-top: 24px;
      padding: 0 32px;
      background: #fff;

      & > h2 {
        height: 116px;
        line-height: 116px;
        font-size: 38px;
        font-weight: 600;
        color: #333;
      }

      .detail-info__item {
        display: flex;
        justify-content: space-between;
        padding: 34px 0;
        border-bottom: 1px solid #DDDDDD;

        &:last-child {
          border: none;
        }

        .left {
          display: flex;
          line-height: 1.3;
          max-width: 360px;

          label {
            position: relative;
            color: #999999;
            font-size: 32px;
          }
        }

        .right {
          display: flex;
          max-width: 450px;

          span {
            color: #333333;
            font-size: 32px;
            text-align: right;
          }

          image {
            width: 40px;
            height: 40px;
          }
        }
      }

      .detail-info__item--img {
        display: block;

        .right {
          flex-wrap: wrap;
          max-width: 100%;
          margin-top: 34px;

          image {
            width: 226px;
            height: 226px;
            margin: 0 9px 9px 0;

            &:nth-of-type(3n) {
              margin-right: 0;
            }
          }
        }
      }
    }
  }
</style>
