<template>
  <div class="UserDetail">
    <div class="info">
      <div class="title">基本信息</div>
      <div class="item-flex">
        <div class="label">姓名</div>
        <div class="value">{{ data.name }}</div>
      </div>
      <div class="item-flex">
        <div class="label">身份证号</div>
        <div class="value">{{ data.idNumber }}</div>
      </div>
      <div class="item-flex">
        <div class="label">联系方式</div>
        <div class="value" style="color: #4181ff">
          <img :src="$cdn + 'common/phone.png'" alt="" @click="callPhone(data.phone)" class="phone-icon" />
          {{ data.phone }}
        </div>
      </div>
      <div class="item-flex">
        <div class="label">本地地区</div>
        <div class="value">{{ data.areaName }}</div>
      </div>

      <div class="item-flex">
        <div class="label">本地地址</div>
        <div class="value">{{ data.address }}</div>
      </div>
    </div>

    <div class="line-bg"></div>
    <div class="info">
      <div class="title">健康状况</div>
      <div class="item-flex">
        <div class="label">当前体温</div>
        <div class="value temperature" :style="{ color: userList.temperature * 1 >= 37.3 ? '#FF4466' : '#42D784' }">{{ userList.temperature }}℃</div>
      </div>
      <div class="item-flex">
        <div class="label" style="width: 360px">14天内是否接触新冠确诊或疑似患者</div>
        <div class="value" :style="userList.touchInFourteen == 1 ? 'color:#42D784;' : userList.touchInFourteen == 2 ? 'color:##FF4466' : 'color:#4181FF'">{{ $dict.getLabel('epidemicTouchInFourteen', userList.touchInFourteen) }}</div>
      </div>
      <div class="item-flexs">
        <div class="label">当前健康状况</div>
        <div class="healths">
          <span v-for="(item, index) in userList.health" :key="index" :style="item != 0 ? 'color:#FF4466;' : ''">
            <span v-if="index > 0"> ; </span>
            <span>
              {{ $dict.getLabel('epidemicRecentHealth', item) }}
            </span>
          </span>
        </div>
      </div>
    </div>

    <div class="line-bg"></div>
    <div class="info">
      <div class="title">核酸检测信息</div>
      <div class="item-flex">
        <div class="label">核酸检测日期</div>
        <div class="value">{{ userList.checkTime && userList.checkTime.substring(0, 10) }}</div>
      </div>

      <div class="item-flex">
        <div class="label">核酸检测结果</div>
        <div class="value" :style="userList.checkResult == 1 ? 'color:#f46;' : 'color:#42D784;'">{{ $dict.getLabel('epidemicRecentTestResult', userList.checkResult) }}</div>
      </div>

      <div class="item-flex">
        <div class="label">健康码</div>
        <div class="value" :style="{ color: userList.healthCode == '3' ? '#FF4466 ' : '' }">{{ $dict.getLabel('epidemicHealthCode', userList.healthCode) }}</div>
      </div>

      <div class="item-flex">
        <div class="label">已接种试剂</div>
        <div class="value">{{ userList.vaccine }}次</div>
      </div>

      <div class="item-flex checkPhotos">
        <div style="color: #999">本人健康码截图或核酸检测报告</div>
      </div>
      <div class="img-list">
        <img :src="item.url" alt="" v-for="(item, index) in userList.checkPhoto" :key="index" @click="previewImage(userList.checkPhoto, item.url)" />
      </div>
    </div>

    <div class="line-bg" v-if="userList.status == 0"></div>
    <div class="info" v-if="userList.status == 0">
      <div class="title">异常处理情况</div>

      <div class="item-record">
        <div class="label">异常情况记录</div>
        <div class="error-list" v-if="datas.length">
          <div class="records" v-for="(item, index) in datas" :key="index">
            <p>{{ item.content }}</p>

            <div>
              <span>{{ item.createTime }}</span>
              <span class="names">{{ item.createUserName }}</span>
            </div>
          </div>
        </div>

        <AiEmpty description="暂无数据" class="emptyWrap" v-else></AiEmpty>
      </div>

      <div class="item-flex">
        <div class="label">异常解除人</div>
        <div class="value">{{ userList.releaseName }}</div>
      </div>

      <div class="item-flex">
        <div class="label">异常解除时间</div>
        <div class="value">{{ userList.releaseTime && userList.releaseTime.substring(0, 10) }}</div>
      </div>
    </div>

    <div class="line-bg"></div>
  </div>
</template>

<script>
import { mapState } from 'vuex'

export default {
  name: 'UserDetail',
  components: {},
  props: {},
  data() {
    return {
      id: '',
      userList: {},
      data: [],
      datas: [],
    }
  },
  computed: {
    ...mapState(['user']),
  },
  onLoad(o) {
    console.log(o)
    this.$dict.load('epidemicMemberType', 'epidemicRecentTravel', 'epidemicTouchInFourteen', 'epidemicRecentTestResult', 'epidemicRecentHealth', 'epidemicHealthCode').then(() => {
      this.id = o.id
      this.userList = o
      this.userList.checkPhoto = JSON.parse(o.checkPhoto)
      this.userList.health = o.health.split(',')

      this.userList.releaseName = o.releaseName
      this.getUser()
      if (this.userList.releaseName) {
        this.getRecord()
      }
    })
  },
  onShow() {
    document.title = '健康上报'
  },
  methods: {
    getUser() {
      this.$loading()
      this.$http
        .post(`/app/appepidemicreportmember/queryDetailById?id=${this.userList.memberId}`)
        .then((res) => {
          if (res.code == 0) {
            this.data = res.data
            this.$hideLoading()
          } else {
            this.$hideLoading()
          }
        })
        .catch(() => {
          this.$hideLoading()
        })
    },

    // 异常情况记录
    getRecord() {
      this.$loading()
      this.$http
        .post(`/app/appepidemicunusuallog/list?recordId=${this.userList.memberId}`)
        .then((res) => {
          if (res.code == 0) {
            this.datas = this.current > 1 ? [...this.datas, ...res.data.records] : res.data.records
            this.$hideLoading()
          } else {
            this.$hideLoading()
          }
        })
        .catch(() => {
          this.$hideLoading()
        })
    },

    callPhone(phone) {
      uni.makePhoneCall({ phoneNumber: phone })
    },

    previewImage(images, img) {
      uni.previewImage({
        urls: images.map((v) => v.url),
        current: img,
      })
    },
  },
}
</script>

<style scoped lang="scss">
.UserDetail {
  background: #f3f6f9;
  .info {
    background-color: #fff;
    padding: 0 32px;
    .title {
      line-height: 116px;
      background: #fff;
      font-size: 38px;
      font-family: PingFangSC-Semibold, PingFang SC;
      font-weight: 600;
      color: #333;
    }
    .item-flex {
      padding: 34px 0;
      border-bottom: 1px solid #ddd;
      display: flex;
      justify-content: space-between;
      line-height: 44px;
      font-size: 32px;
      font-family: PingFangSC-Regular, PingFang SC;
      .label {
        width: 206px;
        color: #999;
      }
      .value {
        width: calc(100% - 206px);
        word-break: break-all;
        color: #333;
        text-align: right;
        .phone-icon {
          width: 40px;
          height: 40px;
          vertical-align: middle;
          margin-right: 8px;
        }
      }
    }
    .checkPhotos {
      border-bottom: none !important;
    }
    .error-list {
      background-color: #fff !important;
      padding-bottom: 24px;
      margin-top: 10px;
      border-bottom: 1px solid #ddd;
      .records {
        background: #f4f7fe;
        border-radius: 8px;
        padding: 24px 24px 18px 24px;
        box-sizing: border-box;
        margin-bottom: 16px;

        p {
          font-size: 28px;
          font-family: PingFangSC-Regular, PingFang SC;
          color: #343d65;
          line-height: 40px;
          word-break: break-all;
          margin-bottom: 12px;
        }
        div {
          font-size: 24px;
          font-family: PingFangSC-Regular, PingFang SC;
          color: #666;
          line-height: 34px;
          span:last-child {
            display: inline-block;
            margin-left: 32px;
          }
        }
      }
    }
    .item-flexs {
      display: flex;
      justify-content: space-between;
      padding: 34px 0;
      border-bottom: 1px solid #ddd;
      font-size: 32px;
      .label {
        width: 32%;
        color: #999;
      }
      .healths {
        width: 68%;
        word-break: break-all;
      }
    }
    .img-list {
      padding-bottom: 48px;
      img {
        width: 320px;
        height: 320px;
      }
    }
    .item-flex:nth-last-of-type(1) {
      border-bottom: 0;
    }
  }

  .line-bg {
    width: 100%;
    height: 24px;
    background-color: #f3f6f9;
  }
  .footer {
    width: 100%;
    height: 112px;
    line-height: 112px;
    background: #1365dd;
    box-shadow: inset 0px 1px 0px 0px #eeeeee;
    font-size: 32px;
    font-family: PingFangSC-Medium, PingFang SC;
    font-weight: 500;
    color: #fff;
    text-align: center;
  }
}
</style>
