<template>
  <div class="AddReport">
    <div class="tips">请确保以下信息全部由本人填写，本人对所填写内容的真实性和完整性负责</div>
    <div class="title">基本信息</div>
    <div class="form-item__group">
      <div class="form-item">
        <div class="form-item__wrapper">
          <div class="form-item__title">
            <i>*</i>
            <h2>姓名</h2>
          </div>
          <div class="form-item__right">
            <input placeholder="请输入" v-model="form.name" disabled :maxlength="20"/>
          </div>
        </div>
      </div>
      <div class="form-item">
        <div class="form-item__wrapper">
          <div class="form-item__title">
            <i>*</i>
            <h2>身份证号</h2>
          </div>
          <div class="form-item__right">
            <input placeholder="请输入" v-model="form.idNumber" disabled :maxlength="20"/>
          </div>
        </div>
      </div>
    </div>

    <div class="title">健康状况</div>
    <div class="form-item__group">
      <div class="form-item">
        <div class="form-item__wrapper">
          <div class="form-item__title">
            <i>*</i>
            <h2>当前体温</h2>
          </div>
          <div class="form-item__right">
            <input placeholder="请输入" v-model="form.temperature" :maxlength="20"/>
            <i>℃</i>
          </div>
        </div>
      </div>
      <div class="form-item form-item__imgs">
        <div class="form-item__wrapper">
          <div class="form-item__title">
            <i>*</i>
            <h2>14天内是否接触新冠确诊或疑似患者？</h2>
          </div>
          <div class="form-item__right">
            <AiRadio style="width: 100%;" v-model="form.contactPatients" 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">
            <AiCheckbox style="width: 100%;" v-model="form.healthList" dict="EP_healthType"></AiCheckbox>
          </div>
        </div>
      </div>
    </div>

    <div class="title">核酸检测</div>
    <div class="form-item__group">
      <div class="form-item">
        <div class="form-item__wrapper">
          <div class="form-item__title">
            <i>*</i>
            <h2>核酸检测日期</h2>
          </div>
          <div class="form-item__right">
            <div class="ai-area" @click="isShowDate = true">
              <div class="ai-area__wrapper">
                <span class="label" v-if="form.nucleicAcidDate">{{ form.nucleicAcidDate }}</span>
                <i v-else>请选择</i>
                <u-icon name="arrow-right" color="#ddd"/>
              </div>
            </div>
          </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.nucleicAcidResult" dict="EP_nucleicAcidResult"></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.jkmType" dict="EP_jkmType"></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.vaccinationCount" dict="EP_vaccinationCount"></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>
            <!-- <span style="color: #999; font-size:14px;font-weight:normal;">(最多9张)</span> -->
          </div>
          <div class="form-item__right" style="padding-left: 5px">
            <AiUploader valueIsUrl v-model="form.jkmUrlArr" :limit="1"></AiUploader>
          </div>
        </div>
      </div>
      <div class="form-item form-item__imgs">
        <div class="form-item__wrapper">
          <div class="form-item__title">
            <i>*</i>
            <h2>本人核酸检测结果截图</h2>
            <!-- <span style="color: #999; font-size:14px;font-weight:normal;">(最多9张)</span> -->
          </div>
          <div class="form-item__right" style="padding-left: 5px">
            <AiUploader valueIsUrl v-model="form.nucleicAcidUrlArr" :limit="1"></AiUploader>
          </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: {
        reportUserId: '',
        name: '',
        idNumber: '',
        temperature: '',
        contactPatients: '',
        health: '',
        healthList: [],
        nucleicAcidDate: '',
        nucleicAcidResult: '',
        jkmType: '',
        vaccinationCount: '',
        jkmUrl: '',
        jkmUrlArr: [],
        nucleicAcidUrl: '',
        nucleicAcidUrlArr: [],
      }
    }
  },


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

  onLoad(query) {
    this.$dict.load(['epidemicTouchInFourteen','EP_healthType','EP_nucleicAcidResult','EP_jkmType','EP_vaccinationCount']).then(()=> {
      this.form.reportUserId = query.id
      this.form.name = query.name
      this.form.idNumber = query.idNumber
    })
  },

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

    submit() {

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

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

      if (!this.form.healthList.length) {
        return this.$toast('请选择当前健康状况')
      } else {
        this.form.health = this.form.healthList.toString()
      }

      if(!this.form.nucleicAcidDate) {
        return this.$toast('请选择核酸检测日期')
      }

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

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

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

      if (!this.form.jkmUrlArr.length) {
        return this.$toast('请上传健康码截图')
      }

      if (!this.form.nucleicAcidUrlArr.length) {
        return this.$toast('请上核酸检测结果截图')
      }


      this.$loading()
      this.$instance.post(`/app/appepidemicpreventionhealthreportinfo/addReportInfo`, {
        ...this.form,
        jkmUrl: this.form.jkmUrlArr[0].url,
        nucleicAcidUrl: this.form.nucleicAcidUrlArr[0].url,
        nucleicAcidDate: this.form.nucleicAcidDate + ' 00:00:00'
      }).then(res => {
        if (res.code == 0) {
          uni.$emit('update')
          this.$toast('提交成功')
          setTimeout(() => {
            uni.navigateBack()
          }, 400)
        }
        this.$hideLoading()
      })
    }
  }
}
</script>

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

  .title {
    padding: 16px 32px 0 32px;
    box-sizing: border-box;
    background: #fff;
    font-size: 36px;
    font-weight: 600;
  }

  .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: right;
        color: #333;
        padding-right: 10px;
      }

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

        span {
          max-width: 400px;
          margin-right: 8px;
          color: #333333;
          overflow: hidden;
          white-space: nowrap;
          text-overflow: ellipsis;
        }

        i {
          margin-right: 8px;
          color: #999999;
        }
      }
    }

    &: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: 400;
        font-size: 32px;
        color: #333333;
      }
    }


    &.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>
