<template>
  <div class="Add">
    <p class="title">已采样<span class="num">{{info.nucleicAcidSamplingCount}}</span>次</p>
    <div class="item mar-b16">
      <div class="label">
        <span class="tips">*</span>管理区域
      </div>
      <div class="value color-999">{{info.areaName}}</div>
    </div>
    <div class="info mar-b16">
      <div class="item solid">
        <div class="label">
          <span class="tips">*</span>管理对象
        </div>
        <div class="value color-999">{{info.name}}</div>
      </div>
      <div class="item solid">
        <div class="label">
          <span class="tips">*</span>身份证号
        </div>
        <div class="value color-999">{{info.idNumber}}</div>
      </div>
      <div class="item solid">
        <div class="label">
          <span class="tips">*</span>手机号码
        </div>
        <div class="value color-999">{{info.phone}}</div>
      </div>
      <div class="item solid">
        <div class="label">
          <span class="tips">*</span>居家状态
        </div>
        <div class="value color-999">{{ $dict.getLabel('EP_homeStatus2', info.homeStatus)}}</div>
      </div>
      <div class="item solid">
        <div class="label">
          <span class="tips">*</span>隔离时间
        </div>
        <div class="value color-999" v-if="info.quarantineBeginTime">{{info.quarantineBeginTime.substring(0, 10)}}至{{info.quarantineEndTime.substring(0, 10)}}</div>
      </div>
      <div class="item">
        <div class="label">
          <span class="tips">*</span>隔离策略
        </div>
        <div class="value color-999">{{ $dict.getLabel('EP_quarantineStrategy', info.quarantineStrategy)}}</div>
      </div>
    </div>
    <div class="info mar-b16">
      <div class="item solid">
        <div class="label">
          <span class="tips">*</span>采样人员
        </div>
        <div class="value">
          <u-input placeholder="请输入" input-align="right" height="32" maxlength="6" v-model="form.createUserName" :custom-style="{'font-size': '17px'}" />
        </div>
      </div>
      <div class="item solid">
        <div class="label">
          <span class="tips">*</span>联系方式
        </div>
        <div class="value">
          <u-input placeholder="请输入" type="number" input-align="right" height="32" maxlength="11" v-model="form.createUserPhone" :custom-style="{'font-size': '17px'}" />
        </div>
      </div>
      <div class="item">
        <div class="label">
          <span class="tips">*</span>采样时间
        </div>
        <div class="value" @click="selectTime(form.createTime)">
          <span :class="form.createTime === '' ? 'color-999' : ''">{{form.createTime || '请选择'}}</span>
          <u-icon name="arrow-right" color="#cccccc" size="24"/>
        </div>
      </div>
    </div>
    <div class="btn-height"></div>
    <div class="footer">
      <div class="confirm" @click="submit">保存</div>
    </div>
    <u-picker mode="time" v-model="dateShow" :params="deteParams" start-year="2020" @confirm="dateConfirm"></u-picker>
  </div>
</template>

<script>
import { mapState } from 'vuex'

export default {
   data() {
    return {
      id: '',
      info: {},
      form: {
        createUserName: '',
        createUserPhone: '',
        createTime: ''
      },
      dateShow: false,
      deteParams: {year: true, month: true, day: true, hour: true, minute: true, second: true},
    }
  },
  computed: {
    ...mapState(['user']),
  },
  onLoad(option) {
    this.id = option.id
    this.$dict.load('EP_homeStatus2', 'EP_quarantineStrategy').then(() => {
      this.id = option.id
      this.getDetail()
    })

    this.form.createUserName = this.user.name
    this.form.createUserPhone = this.user.phone

    var myDate = new Date();
    this.form.createTime = `${myDate.getFullYear()}-${this.isNum(myDate.getMonth()+1)}-${this.isNum(myDate.getDate())} ${this.isNum(myDate.getHours())}:${this.isNum(myDate.getMinutes())}:${this.isNum(myDate.getSeconds())}`
  },
  onShow() {
    document.title = '核酸采样'
  },
  methods: {
    submit() {
      if(!this.form.createUserName) {
        return this.$u.toast('请输入采样人员')
      }
      if(!this.form.createUserPhone) {
        return this.$u.toast('请输入联系方式')
      }
      if(this.form.createUserPhone &&  !/^1[0-9]{10,10}$/.test(this.form.createUserPhone)) {
        return this.$u.toast("请输入正确的手机号码");
      }
      if(!this.form.createTime) {
        return this.$u.toast('请输入采样时间')
      }
      this.form.cmId = this.id
      this.form.registerId = this.info.registerId
      this.$http.post(`/app/appepidemicpreventioncommunitymanagement/nucleicAcidSamplin`, this.form).then((res) => {
        if (res.code == 0) {
          this.$u.toast('提交成功')
          uni.$emit('updateDetail')
          uni.$emit('updateList')
          uni.navigateBack()
        }
      })
      
    },
    selectTime() {
      this.dateShow = true
    },
    dateConfirm(e) {
      this.form.createTime = `${e.year}-${e.month}-${e.day} ${e.hour}:${e.minute}:${e.second}`
    },
    getDetail() {
      this.$http.post(`/app/appepidemicpreventioncommunitymanagement/queryDetailById?id=${this.id}`).then((res) => {
        if (res.code == 0) {
          this.info = res.data
        }
      })
    },
    isNum(num) {
      if(num < 10) {
        num = '0'+`${num}`
      }
      return num
    },
  },
}
</script>

<style scoped lang="scss">
.Add {
  background-color: #F3F6F9;
  .title {
    line-height: 96px;
    padding-left: 32px;
    font-size: 30px;
    color: #666;
    .num {
      font-size: 32px;
      font-weight: 700;
      color: #f46;
    }
  }
  .item {
    background-color: #fff;
    display: flex;
    padding: 40px 0 40px 32px;
    .label {
      width: 200px;
      line-height: 48px;
      font-family: PingFangSC-Medium;
      font-weight: 500;
      font-size: 34px;
      color: #666;
      .tips {
        display: inline-block;
        font-family: PingFangSC-Medium;
        font-weight: 700;
        font-size: 34px;
        color: #F46;
        margin-right: 8px;
        vertical-align: text-top;
      }
    }
    .value {
      width: calc(100% - 200px);
      padding-right: 32px;
      text-align: right;
      font-family: PingFangSC-Regular;
      font-size: 34px;
      color: #333;
      
    }
    .color-999 {
      color: #999;
    }
    .item-textarea {
      width: calc(100% - 32px);
    }
  }
  ::v-deep uni-textarea{
    width: calc(100% - 32px);
  }
  .info {
    padding-left: 32px;
    background-color: #fff;
    .item {
      padding-left: 0;
    }
    .solid {
      border-bottom: 1px solid #ddd;
      box-sizing: border-box;
    }
  }
  .mar-b16 {
    margin-bottom: 16px;
  }
  .btn-height{
    height: 130px;
  }
  .footer {
    width: 100%;
    height: 112px;
    position: fixed;
    bottom: 0;
    .confirm {
      width: 100%;
      height: 112px;
      line-height: 112px;
      text-align: center;
      font-family: PingFangSC-Regular;
      font-size: 32px;
      background-color: #1365DD;
      color: #fff;
    }
  }
}
</style>
