<template>
  <div class="ErrorInfo">
    <div class="header">
      <div 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" /></div>
      <p>身份证号：</p>
      <p class="mar-b8" style="color: #333">{{info.idNumber}}</p>
      <p>异常情况：</p>
      <p style="color: #ff4466">
        <span>{{info.unusual}}</span>
      </p>
    </div>
    <div class="info" v-if="list.length">
      <div class="title">异常情况记录</div>
      <div class="error-list">
        <div class="item" v-for="(item, index) in list" :key="index">
          <p>{{item.content}}</p>
          <div>{{item.createTime}}
            <span>{{item.createUserName}}</span>
          </div>
        </div>
      </div>
    </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: '',
      id: '',
      list: [],
      info: {}
    }
  },
  computed: {
    ...mapState(['user']),
  },
  onShow() {
    document.title = '异常情况处理'
  },
  onLoad(option) {
    this.id = option.id
    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})
    },
  },
}
</script>

<style scoped lang="scss">
.ErrorInfo {
  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: 0 32px 32px;
    background-color: #fff;
    .title {
      font-size: 38px;
      font-family: PingFangSC-Semibold, PingFang SC;
      font-weight: 600;
      color: #333;
      line-height: 116px;
    }
    .error-list {
      .item {
        width: 100%;
        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 {
            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>
