<template>
  <div class="HealthDetail">
    <div class="top">
      <div class="templates">
        <img :src="userList.avatar" alt="" v-if="userList.avatar" />
        <img src="./components/img/user-img.png" alt="" />

        <div class="rightCont">
          <div class="rightContLeft">
            <div class="nameLeft">
              <div class="nameTop">
                <div class="names">{{ userList.name }}</div>
                <div class="types" v-if="userList.status == '0'">异常</div>
              </div>

              <div class="nameBottom">
                <span>上报第</span>
                <span class="num">{{ userList.diffNum }}</span>
                <span>天</span>
              </div>
            </div>
          </div>

          <div class="rightContRight" @click.stop="callPhone(userList.phone)">
            <img src="./components/img/phone2@.png" alt="" />
            <span class="call">拨打电话</span>
          </div>
        </div>
      </div>
    </div>

    <div class="middle">
      <div class="record">异常情况记录</div>

      <template v-if="data.length">
        <div class="templatess" v-for="(item, i) in data" :key="i" @click="toUserDetail(item)">
          <div class="left">
            <div class="recordType recordType1" v-if="item.status == 1">正常</div>
            <div class="recordType recordType2" v-if="item.status == 0">异常</div>
          </div>

          <div class="right">
            <div class="times">{{ item.checkTime }}</div>
            <u-icon name="arrow-right" color="#CCCCCC"></u-icon>
          </div>
        </div>
      </template>

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

    <!-- v-if="userList.status == '0'" -->
    <div class="fixedBtn" @click="toErr">异常情况处理</div>
  </div>
</template>

<script>
import { mapState } from 'vuex'

export default {
  name: 'HealthDetail',
  components: {},
  props: {},
  data() {
    return {
      data: [],
      id: '',
      name: '',
      userList: [],
    }
  },
  computed: {
    ...mapState(['user']),
  },
  watch: {},
  onLoad(o) {
    console.log(o)
    if (o.id) {
      this.name = o.name
      this.id = o.id
      this.phone = o.phone
      this.getUser()
    }
    this.getRecord()

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

    getRecord() {
      this.$loading()
      this.$http
        .post(`/app/appepidemichealthreport/list?memberId=${this.id}`)
        .then((res) => {
          if (res?.code == 0) {
            this.data = this.current > 1 ? [...this.data, ...res.data.records] : res.data.records
            this.$hideLoading()
          } else {
            this.$hideLoading()
          }
        })
        .catch(() => {
          this.$hideLoading()
        })
    },

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

    toUserDetail(item) {
      uni.navigateTo({
        url: `./UserDetail?id=${item.id}&temperature=${item.temperature}&touchInFourteen=${item.touchInFourteen}&health=${item.health}&checkTime=${item.checkTime}&checkResult=${item.checkResult}&checkPhoto=${item.checkPhoto}&status=${item.status}&memberId=${this.id}`,
      })
    },

    toErr() {
      uni.navigateTo({
        url: `./ErrorDetail?id=${this.id}`,
      })
    },
  },
}
</script>

<style scoped lang="scss">
.HealthDetail {
  height: 100%;
  padding-bottom: 120px;
  background: #f3f6f9;
  .top {
    .templates {
      display: flex;
      align-items: center;
      padding: 32px;
      box-shadow: inset 0px -1px 0px 0px #dddddd;
      background: #fff;
      img {
        width: 128px;
        height: 128px;
        // border-radius: 50%;
        // border: 1px solid #cccccc;
      }
      .rightCont {
        display: flex;
        justify-content: space-between;
        margin-left: 32px;
        width: 100%;
        .rightContLeft {
          // display: flex;
          // justify-content: space-between;
          // align-items: center;
          // width: 100%;
          .nameLeft {
            .nameTop {
              display: flex;
              .names {
                font-size: 32px;
                font-weight: 500;
                color: #333333;
              }
              .types {
                margin-left: 16px;
                padding: 4px 16px 8px 16px;
                background: #faeceb;
                border-radius: 20px;
                font-size: 24px;
                color: #cd413a;
              }
            }
            .nameBottom {
              margin-top: 12px;
              font-size: 28px;
              color: #999999;
              .num {
                color: #135ab8;
              }
            }
          }
        }

        .rightContRight {
          display: flex;
          flex-direction: column;
          align-items: center;
          width: 25%;
          img {
            width: 64px;
            height: 64px;
          }
          .call {
            font-size: 24px;
            color: #3d94fb;
          }
        }
      }
    }
  }

  .middle {
    margin-top: 16px;
    background: #fff;
    .record {
      padding: 26px 0 26px 32px;
      box-shadow: inset 0px -1px 0px 0px #dddddd;
    }
    .templatess {
      display: flex;
      justify-content: space-between;
      padding: 28px 32px;
      box-shadow: inset 0px -1px 0px 0px #dddddd;
      .left,
      .right {
        display: flex;
        .recordType {
          font-size: 28px;
          font-weight: 500;
        }
        .recordType1 {
          color: #5aad6a;
        }
        .recordType2 {
          color: #cd413a;
        }
      }
    }
    .emptyWrap {
      background: #f5f5f5;
      margin-top: 0 !important;
    }
  }

  .fixedBtn {
    position: fixed;
    bottom: 0;
    width: 100%;
    padding: 34px 0;
    text-align: center;
    background: #1365dd;
    box-sizing: border-box;
    font-size: 32px;
    font-weight: 500;
    color: #ffffff;
  }
}
</style>
