<template>
  <div class="album">
    <div class="tips">请确保以下信息全部由本人填写，本人对所填写内容的真实性和完整性负责</div>

    <div class="form-item__group">
      <div class="form-item form-item__imgs">
        <div class="form-item__wrapper">
          <div class="form-item__title">
            <i>*</i>
            <h2>个人健康状况（可多选）</h2>
          </div>
          <div class="form-item__right">
            <AiRadio style="width: 100%;" v-model="form.touchInFourteen" dict="epidemicTouchInFourteen"></AiRadio>
          </div>
        </div>
      </div>
      <div class="form-item form-item__imgs">
        <div class="form-item__wrapper">
          <div class="form-item__title">
            <i>*</i>
            <h2>当前状况</h2>
          </div>
          <div class="form-item__right">
            <AiRadio style="width: 100%;" v-model="form.healthCode" dict="epidemicHealthCode"></AiRadio>
          </div>
        </div>
      </div>
      <div class="form-item form-item__imgs">
        <div class="form-item__wrapper">
          <div class="form-item__title">
            <i>*</i>
            <h2>备注说明</h2>
          </div>
          <div class="form-item__right">
            <textarea  placeholder="请补充说明健康监测情况" v-model="form.temperature"/>
          </div>
        </div>
      </div>
    </div>

    <!-- <u-picker mode="time" :params="dataParams" v-model="isShowDate" @confirm="onDateChange"></u-picker> -->
    <div class="btn-wrapper">
      <div class="btn" hover-class="text-hover" @click="submit">提交</div>
    </div>
  </div>
</template>

<script>
import {mapState} from 'vuex'

export default {
  appName:"上报今日状态",
  data() {
    return {
      isShowDate: false,
      dataParams: {
        year: true,
        month: true,
        day: true
      },
      form: {
        name: '',
        idNumber: '',
        checkPhoto: [],
        checkResult: '',
        health: '',
        healthCode: '',
        temperature: '',
        vaccine: '',
        checkTime: '',
        memberId: ''
      }
    }
  },


  computed: {
    ...mapState(['user'])
  },

  onLoad(query) {
    this.form.memberId = query.id
    this.getInfo(query.id)
  },

  methods: {
    getInfo(id) {
      this.$instance.post(`/app/appepidemicreportmember/queryDetailById?id=${id}`).then(res => {
        if (res.code === 0) {
          this.form.name = res.data.name
          this.form.idNumber = res.data.idNumber

          this.form.checkTime = res.data.checkTime ? res.data.checkTime.split(' ')[0] : ''
          this.form.checkResult = res.data.checkResult || ''
          this.form.healthCode = res.data.healthCode || ''
          this.form.vaccine = res.data.vaccine || ''
        }

        this.$hideLoading()
      }).catch(() => {
        this.$hideLoading()
      })
    },

    onDateChange(e) {
      this.form.checkTime = `${e.year}-${e.month}-${e.day}`
    },

    submit() {
      if (!this.form.temperature) {
        return this.$toast('请输入当前体温')
      }

      if (!this.form.touchInFourteen) {
        return this.$toast('请选择14天内是否接触新冠确诊或疑似患者')
      }

      if (!this.form.health.length) {
        return this.$toast('请选择当前健康状况')
      }
      if (!this.form.checkTime) {
        return this.$toast('请选择核酸检测日期')
      }

      if (!this.form.checkResult) {
        return this.$toast('请选择核酸检测结果')
      }

      if (!this.form.healthCode) {
        return this.$toast('请选择健康码类型')
      }

      if (!this.form.vaccine) {
        return this.$toast('请选择已接种疫苗次数')
      }

      this.$instance.post(`/app/appepidemichealthreport/addOrUpdate`, {
        ...this.form,
        openid: this.user.openid,
        health: this.form.health.join(','),
        checkPhoto: JSON.stringify(this.form.checkPhoto),
        checkTime: this.form.checkTime + ' 00:00:00'
      }).then(res => {
        if (res.code == 0) {
          uni.$emit('update')
          this.$toast('提交成功')
          setTimeout(() => {
            uni.navigateBack()
          }, 400)
        }
      })
    }
  }
}
</script>

<style lang="scss">
.album {
  padding-bottom: 140px;

  .tips {
    line-height: 1.3;
    padding: 32px 32px;
    color: #FF883C;
    font-size: 30px;
    text-align: justify;
    background: #FFF8F3;
  }

  .form-item__group {
    margin-bottom: 24px;
    background: #fff;
  }

  .form-item {
    padding-left: 32px;

    .form-item__checkbox {
      width: 100%;

      div {
        width: 100%;
        height: 80px;
        line-height: 80px;
        margin-bottom: 24px;
        text-align: center;
        background: #FFFFFF;
        border-radius: 16px;
        color: #333333;
        font-size: 28px;
        border: 1px solid #CCCCCC;

        &.active {
          background: #4181FF;
          color: #fff;
          border-color: #4181FF;
        }
      }
    }

    .form-item__radio {
      display: flex;
      align-items: center;
      flex-wrap: wrap;

      div {
        width: 212px;
        height: 80px;
        line-height: 80px;
        margin-right: 16px;
        margin-bottom: 8px;
        text-align: center;
        background: #FFFFFF;
        border-radius: 16px;
        color: #333333;
        font-size: 28px;
        border: 1px solid #CCCCCC;

        &:nth-of-type(3n) {
          margin-right: 0;
        }

        &.active {
          background: #4181FF;
          color: #fff;
          border-color: #4181FF;
        }
      }
    }

    .ai-area__wrapper {
      display: flex;
      align-items: center;
      padding-left: 100px;

      span {
        color: #333;
        font-size: 30px;
      }

      i {
        color: #999;
        font-size: 30px;
      }

      image {
        width: 16px;
        height: 8px;
      }
    }

    .form-item__wrapper {
      display: flex;
      align-items: center;
      justify-content: space-between;
      height: 128px;
      padding-right: 28px;
      border-bottom: 1px solid #DDDDDD;

      input {
        flex: 1;
        height: 100%;
        text-align: left;
        color: #333;
        padding-right: 10px;
      }

      .form-item__right {
        display: flex;
        align-items: center;
        font-size: 32px;

        // .u-input {
        //   display: block;
        //   width: 100%;
        // }

      }
    }



    .form-item__wrapper_input {
      display: block;

    }

    &:last-child {
      .form-item__wrapper {
        border-bottom: none;
      }
    }

    .form-item__title {
      display: flex;
      align-items: center;

      i {
        font-size: 32px;
        color: #FF4466;
      }

      span {
        font-size: 28px;
        color: #999999;
      }

      h2 {
        padding: 0 4px;
        font-weight: 600;
        font-size: 32px;
        color: #666666;
      }
    }

    &.form-item__imgs, &.form-item__textarea {
      .form-item__wrapper {
        display: block;
        height: auto;
        padding-bottom: 32px;
      }

      textarea {
        width: 100%;
        height: 90px;

      }

      .form-item__title {
        padding: 32px 0;
      }

      .form-item__right {
        padding-left: 18px;
      }
    }
  }
}
</style>
