<template>
  <div class="ErrorDetail">
    <div class="header">
      <div class="name">
        {{ userList.name }}<span>{{ userList.phone }}</span
        ><img :src="$cdn + 'common/phone.png'" alt="" @click="callPhone(userList.phone)" class="phone-icon" />
      </div>
      <p>身份证号：</p>
      <p class="mar-b8" style="color: #333">{{ userList.idNumber && userList.idNumber.replace(/^(\w{6})\w{8}(.*)$/, '$1********$2') }}</p>
      <p>异常情况：</p>
      <div v-if="datas.length">
        <div v-for="(item, index) in datas" :key="index" style="color: #ff4466">
          <span style="color: #666" v-if="item.status == 0">{{ item.checkTime && item.checkTime.substring(0, 10) }}:</span>

          <div v-if="item.temperature * 1 >= 37.3">
            <span>当前体温</span>

            <span style="margin-left: 10px">{{ item.temperature }}℃</span>
          </div>

          <div v-if="item.touchInFourteen * 1 !== 0">
            <span>14天内是否接触新冠确诊或疑似患者</span>

            <span style="margin-left: 10px">
              {{ $dict.getLabel('epidemicTouchInFourteen', item.touchInFourteen) }}
            </span>
          </div>

          <div v-if="item.health !== '0'">
            <span>当前健康状况</span>

            <div class="healths">
              <span v-for="(items, index) in item.health && item.health.split(',')" :key="index">
                <span v-if="index > 0"> ; </span>
                <span>
                  {{ $dict.getLabel('epidemicRecentHealth', items) }}
                </span>
              </span>
            </div>
          </div>

          <div v-if="item.checkResult != 0">
            <span>核酸检测结果</span>

            <span style="margin-left: 10px">
              {{ $dict.getLabel('epidemicRecentTestResult', item.checkResult) }}
            </span>
          </div>

          <div v-if="item.healthCode == 2 || item.healthCode == 3 || item.healthCode == 4">
            <span>健康码</span>

            <span style="margin-left: 10px">
              {{ $dict.getLabel('epidemicHealthCode', item.healthCode) }}
            </span>
          </div>
        </div>
      </div>

      <p style="color: #333" v-else>暂无异常情况</p>
    </div>

    <div class="info" v-if="data.length">
      <div class="title">异常情况记录</div>
      <div class="error-list" v-if="data.length">
        <div class="itemes" v-for="(item, i) in data" :key="i">
          <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="bg-line"></div> -->

    <div class="footer">
      <div class="add" @click="show = true">新增记录</div>
      <div class="confirm" @click="cancel">解除异常</div>
    </div>

    <u-popup v-model="show" mode="bottom">
      <div class="textarea">
        <u-input v-model="value" type="textarea" :height="120" :auto-height="true" placeholder="异常情况记录" :clearable="false" maxlength="1000" />
        <p>字数{{ value.length }}/1000</p>
      </div>
      <div class="btn">
        <span @click="value = ''">清空内容</span>
        <span class="confirm" @click="confirm">保存</span>
      </div>
    </u-popup>
  </div>
</template>

<script>
import { mapState } from 'vuex'

export default {
  components: {},
  props: {},
  data() {
    return {
      show: false,
      value: '',
      userList: [],
      data: [],
      datas: [],
      size: 10,
      current: 1,
    }
  },
  computed: {
    ...mapState(['user']),
  },
  onLoad(o) {
    console.log(o)
    this.$dict.load('epidemicMemberType', 'epidemicRecentTravel', 'epidemicTouchInFourteen', 'epidemicRecentTestResult', 'epidemicRecentHealth', 'epidemicHealthCode').then(() => {
      if (o) {
        this.id = o.id
        this.getUser()
        this.getRecord()
        this.getErrThing()
      }
    })
  },
  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()
        })
    },

    // 异常情况
    getErrThing() {
      this.$loading()
      this.$http
        .post(`/app/appepidemichealthreport/list?memberId=${this.id}`)
        .then((res) => {
          if (res.code == 0) {
            this.datas = res.data.records
            this.$hideLoading()
          } else {
            this.$hideLoading()
          }
        })
        .catch(() => {
          this.$hideLoading()
        })
    },

    // 异常情况记录
    getRecord() {
      this.$loading()
      this.$http
        .post(`/app/appepidemicunusuallog/list`, null, {
          params: {
            recordId: this.id,
            size: this.size,
            current: this.current,
          },
        })
        .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()
        })
    },

    // 新增记录
    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.getUser()
          this.getRecord()
        }
      })
    },

    cancel() {
      this.$confirm(`是否解除该条异常信息？`).then(() => {
        this.$http.post('/app/appepidemicreportmember/release', { id: this.id }).then((res) => {
          if (res.code == 0) {
            this.$u.toast('解除成功!')
            uni.$emit('updateDetails')
            uni.$emit('updateLists')
            setTimeout(() => {
              uni.navigateBack()
            }, 600)
          }
        })
      })
    },

    callPhone(phone) {
      uni.makePhoneCall({ phoneNumber: phone })
    },
  },
  onReachBottom() {
    this.current++
    this.getRecord()
  },
}
</script>

<style scoped lang="scss">
.ErrorDetail {
  height: 100%;
  .header {
    padding: 32px 48px;
    box-sizing: border-box;
    background-color: #fff;
    margin-bottom: 24px;
    .name {
      font-size: 36px;
      font-family: PingFangSC-Medium, PingFang SC;
      font-weight: 500;
      color: #333;
      line-height: 50px;
      margin-bottom: 16px;
      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: 30px;
      font-family: PingFangSC-Regular, PingFang SC;
      color: #999;
      line-height: 42px;
      color: #999;
    }
    .mar-b8 {
      margin-bottom: 8px;
    }
  }
  .info {
    padding-bottom: 112px;
    .title {
      padding: 0 32px;
      font-size: 38px;
      font-family: PingFangSC-Semibold, PingFang SC;
      font-weight: 600;
      color: #333;
      line-height: 116px;
      background-color: #fff;
    }
    .error-list {
      background-color: #fff !important;
      padding-bottom: 24px;
      .itemes {
        margin: 0 32px;
        background: #f4f7fe;
        border-radius: 8px;
        padding: 24px 24px 18px 24px;
        box-sizing: border-box;
        margin-bottom: 16px;

        span {
          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;
          }
        }
      }
    }
  }
  .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>
