<template>
  <div class="Detail">
    <div class="header">
      <h2 class="name">{{info.name}}
        <span @click="callPhone(info.phone)">{{info.phone}}</span><img :src="$cdn + 'common/phone.png'" alt="" @click="callPhone(info.phone)" class="phone-icon" />
      </h2>
      <p><img src="./components/img/idnumber-icon.png" alt=""><span class="start-name">{{info.idNumber}}</span></p>
      <p><img src="./components/img/address-icon.png" alt=""><span class="start-name">{{info.startAreaName}}</span></p>
    </div>
    <div class="info">
      <div class="title">上报记录<span class="day-text"><span>7</span>/14</span></div>
      <p class="mini-title">个人连续无异常上报7天后自动解除风险</p>
      <div class="error-list">
        <div class="item" v-for="(item, index) in 10" :key="index">
          <p class="time">2022-05-16(自主上报）<span>有异常</span></p>
          <div class="text">
            <span class="label">健康状况</span>
            <span class="value">发烧、乏力、咳嗽</span>
          </div>
          <div class="text">
            <span class="label">当前情况</span>
            <span class="value">发烧、乏力、咳嗽</span>
          </div>
        </div>
      </div>
    </div>
    <div class="bg-line"></div>
    <div class="footer">
      <div class="add" @click="toContent">新增记录</div>
      <div class="confirm" @click="cancel()">解除风险</div>
    </div>
  </div>
</template>

<script>
import { mapState } from 'vuex'

export default {
  data() {
    return {
      show: false,
      value: '',
      id: '',
      list: [],
      info: {}
    }
  },
  computed: {
    ...mapState(['user']),
  },
  onShow() {
    document.title = '异常情况处理'
  },
  onLoad(option) {
    // this.id = option.id
    this.id = '5173745c3c00452a9346d1c559266982'
    this.$dict.load('epidemicRecentHealth').then(() => {
      this.getDetail()
    })
    this.getList()
  },
  methods: {
    getList() {
      this.$http.post(`/app/appepidemicunusuallog/list?recordId=${this.id}`).then((res) => {
        if (res.code == 0) {
          this.list = res.data.records
        }
      })
    },
    getDetail() {
      this.$http.post(`/app/appepidemicbackhomerecord/queryDetailById?id=${this.id}`).then((res) => {
        if (res.code == 0) {
          res.data.idNumber = res.data.idNumber.replace(/(.{6}).*(.{4})/,"$1********$2")
          this.info = res.data
          this.info.health = this.info.health.split(',')
        }
      })
    },
    cancel() {
      this.$confirm(`是否解除该条异常信息？`).then(() => {
        this.$http.post("/app/appepidemicbackhomerecord/release", {id: this.id}).then(res => {
          if (res.code == 0) {
            this.$u.toast("解除成功!")
            uni.$emit('updateDetail')
            uni.$emit('updateList')
            setTimeout(() => {
              uni.navigateBack()
            }, 600);
          }
        })
      })
    },
    confirm() {
      if(!this.value) {
        return this.$u.toast('请输入异常情况')
      }

      var params = {
        "content": this.value,
        "createUserId": this.user.id,
        "createUserName": this.user.name,
        "recordId": this.id
      }
      this.$http.post("/app/appepidemicunusuallog/addOrUpdate", params).then(res => {
        if (res.code == 0) {
          this.$u.toast("新增成功!")
          this.show = false
          this.value = ''
          this.getList()
        }
      })
    },
    callPhone(phone) {
      uni.makePhoneCall({phoneNumber: phone})
    },
    toContent() {
      uni.navigateTo({url: './Content'})
    }
  },
}
</script>

<style scoped lang="scss">
.Detail {
  height: 100%;
  background-color: #f3f6f9;
  .header {
    padding: 32px 64px 24px;
    background-color: #fff;
    .name{
      font-size: 36px;
      font-family: PingFangSC-Medium, PingFang SC;
      font-weight: 500;
      color: #333;
      line-height: 50px;
      margin-bottom: 36px;
      span {
        font-size: 32px;
        font-family: PingFangSC-Medium, PingFang SC;
        font-weight: 500;
        color: #4181ff;
        line-height: 44px;
        margin: 0 20px 0 32px;
      }
      img {
        width: 32px;
        height: 32px;
        vertical-align: middle;
      }
    }
    p{
      font-size: 28px;
      font-family: PingFangSC-Regular, PingFang SC;
      color: #333;
      line-height: 40px;
      margin-bottom: 8px;
      img{
        width: 32px;
        height: 32px;
        margin-right: 18px;
        vertical-align: top;
      }
    }
    .color-999{
      margin-bottom: 24px;
      color: #999;
    }
    .start-name{
      display: inline-block;
      width: calc(100% - 50px);
    }
  }
  .info {
    padding: 32px;
    background-color: #fff;
    margin-top: 24px;
    .title {
      font-size: 38px;
      font-family: PingFangSC-Semibold, PingFang SC;
      font-weight: 600;
      color: #333;
      line-height: 52px;
      overflow: hidden;
      .day-text{
        float: right;
        font-size: 32px;
        font-family: PingFangSC-Medium, PingFang SC;
        font-weight: 500;
        span{
          color: #5AAD6A;
        }
      }
    }
    .mini-title{
      font-size: 30px;
      font-family: PingFangSC-Regular, PingFang SC;
      color: #999;
      line-height: 42px;
      margin: 18px 0 24px 0;
    }
    .error-list {
      .item {
        width: 100%;
        background: #f4f7fe;
        border-radius: 8px;
        padding: 32px 32px 24px;
        box-sizing: border-box;
        margin-bottom: 16px;
        .time{
          font-size: 32px;
          font-family: PingFangSC-Medium, PingFang SC;
          font-weight: 500;
          color: #333;
          line-height: 44px;
          overflow: hidden;
          margin-bottom: 24px;
          span{
            float: right;
            font-size: 28px;
            font-family: PingFangSC-Regular, PingFang SC;
          }
          .color-f46{
            color: #f46;
          }
          .color-2EA222{
            color: #2EA222;
          }
        }
        .text{
          font-size: 26px;
          font-family: PingFangSC-Regular, PingFang SC;
          line-height: 36px;
          margin-bottom: 8px;
          .label{
            display: inline-block;
            width: 136px;
            color: #999;
          }
          .value{
            width: calc(100% - 136px);
            color: #333;
          }
        }
      }
    }
  }
  .footer {
    position: fixed;
    bottom: 0;
    left: 0;
    width: 100%;
    height: 112px;
    line-height: 112px;
    background: #fff;
    display: flex;
    font-size: 36px;
    font-family: PingFangSC-Regular, PingFang SC;
    .add {
      flex: 1;
      color: #333;
    }
    .confirm {
      flex: 2;
      color: #fff;
      background: #1365dd;
    }
    div {
      text-align: center;
    }
  }
  .bg-line {
    width: 100%;
    height: 130px;
  }
  .textarea {
    margin: 32px 32px 24px;
    width: calc(100% - 64px);
    padding: 16px;
    box-sizing: border-box;
    background: #f7f7f7;
    border-radius: 8px;
    p {
      font-size: 26px;
      font-family: PingFangSC-Regular, PingFang SC;
      color: #999;
      line-height: 36px;
      text-align: right;
    }
  }
  .btn {
    padding: 0 32px 24px;
    height: 64px;
    display: flex;
    justify-content: space-between;
    span {
      display: inline-block;
      line-height: 64px;
      font-size: 26px;
      font-family: PingFangSC-Regular, PingFang SC;
      color: #666;
    }
    .confirm {
      width: 144px;
      text-align: center;
      background: #1365dd;
      border-radius: 32px;
      font-size: 28px;
      font-family: PingFangSC-Regular, PingFang SC;
      color: #fff;
    }
  }
}
</style>
