<template>
  <div class="ManagementContent">
    <div class="info mar-b16">
      <div class="item solid">
        <div class="label">
          <span class="tips">*</span>移交对象
        </div>
        <div class="value" @click="dictSelectClick('EP_handoverObject', 'handoverObject')">
          <span :class="form.handoverObject === '' ? 'color-999' : ''">{{ $dict.getLabel('EP_handoverObject', form.handoverObject) || '请选择'}}</span>
          <u-icon name="arrow-right" color="#999" size="16" style="margin-left: 4px" />
        </div>
      </div>
      <div class="item solid">
        <div class="label">
          <span class="tips">*</span>移交方式
        </div>
        <div class="value" @click="dictSelectClick('EP_handoverMethod', 'handoverMethod')">
          <span :class="form.handoverMethod === '' ? 'color-999' : ''">{{ $dict.getLabel('EP_handoverMethod', form.handoverMethod) || '请选择'}}</span>
          <u-icon name="arrow-right" color="#999" size="16" style="margin-left: 4px" />
        </div>
      </div>
      <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.handoverPersonName" :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.handoverPersonPhone" :custom-style="{'font-size': '17px'}" />
        </div>
      </div>
      <div class="item">
        <div class="label">
          <span class="tips">*</span>交接图片
        </div>
      </div>
      <div style="padding: 0 16px 24px 0;">
        <AiUploader :def.sync="form.fileList" multiple placeholder="上传图片" :limit="9" action="/admin/file/add2"></AiUploader>
      </div>
    </div>
    <div class="footer" @click="submit">提交</div>
    <u-calendar v-model="showDateSelect" mode="range" min-year="2020" max-date="2050-12-31" @change="dateConfirm"></u-calendar>
    <u-select v-model="showDictSelect" :list="$dict.getDict(selectDictName)" label-name="dictName" value-name="dictValue" @confirm="dictConfirm"></u-select>
  </div>
</template>

<script>
import { mapState } from 'vuex'

export default {
  data() {
    return {
      handlerTypeList: [],
      form: {
        registerId: '',
        registerIdNumber: '',
        handleType: '',
        quarantineAddress: '',
        quarantineBeginTime: '',
        quarantineEndTime: '',
        quarantineStrategy: '',
        homeStatus: '',
        controlMethod: '',
        remarks: '',
        handoverObject: '',
        handoverMethod: '',
        handoverPersonName: '',
        handoverPersonPhone: '',
        fileList: []
      },
      showDateSelect: false,
      showDictSelect: false,
      selectDictName: '',
      selectFormName: '',
      haveHomeQuarantineBtn: 1, //0隐藏居家 1不隐藏
      delta: 0, //返回几层 
    }
  },
  computed: {
    ...mapState(['user']),
  },
  onLoad(Option) {
    this.delta = Option.delta
    this.form = uni.getStorageSync('checkPointContent')
    this.$dict.load('EP_handleType', 'EP_quarantineAddress', 'EP_quarantineStrategy', 'EP_homeStatus', 'EP_controlMethod', 'EP_handoverObject', 'EP_handoverMethod')
  },
  onShow() {
    document.title = '移交人员'
  },
  methods: {
    submit() {
      if(this.form.handoverObject === '') {
        return this.$u.toast('请选择移交对象')
      }
      if(this.form.handoverMethod === '') {
        return this.$u.toast('请选择移交方式')
      }
      if(!this.form.handoverPersonName) {
        return this.$u.toast('请输入交接人姓名')
      }
      if(!this.form.fileList.length) {
        return this.$u.toast('请上传交接图片')
      }

      this.form.homeQuarantineOperation = '1'
      if(!this.form.quarantineBeginTime) {
        this.form.quarantineBeginTime = null
        this.form.quarantineEndTime = null
      }

      this.$http.post(`/app/appepidemicpreventionregisterinfo/riskDisposal?homeQuarantineOperation=${this.form.homeQuarantineOperation}`, this.form).then((res) => {
        if (res.code == 0) {
          this.$u.toast('提交成功')
          uni.$emit('updateDetail')
          uni.$emit('updateList')
          setTimeout(() => {
            uni.navigateBack({ delta: parseInt(this.delta) })
          }, 600)
          
        }
      }).catch((err) => {
        this.$u.toast(err)
      })

    },
    handleTypeClick(index) {
      if(index == this.form.handleType) return

      for(var i in this.form) {
        if(i != 'registerId' && i != 'registerIdNumber') {
          this.form[i] = ''
        }
      }
      this.form.handleType = index
      this.form.fileList = []
    },
    dateConfirm(e) {
      this.form.quarantineBeginTime = e.startDate
      this.form.quarantineEndTime = e.endDate
    },
    dictSelectClick(dictName, formName) {
      this.selectDictName = dictName
      this.selectFormName = formName
      this.showDictSelect = true
    },
    dictConfirm(e) {
      this.form[this.selectFormName] = e[0].value
    }
  },
}
</script>

<style scoped lang="scss">
.ManagementContent {
  background-color: #F3F6F9;
  padding-top: 16px;
  .type-select {
    .type-item {
      display: inline-block;
      width: 218px;
      height: 80px;
      line-height: 80px;
      text-align: center;
      background: #FFF;
      border: 1px solid #CCC;
      border-radius: 16px;
      font-family: PingFangSC-Regular;
      font-size: 28px;
      color: #333;
      margin: 0 16px 16px 0;
    }
    .type-item:nth-of-type(3n) {
      margin-right: 0;
    }
    .active {
      background: #4181FF;
      border: none;
      color: #fff;
    }
  }
  .item {
    background-color: #fff;
    display: flex;
    padding: 40px 0 40px 32px;
    .label {
      width: 220px;
      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% - 220px);
      padding-right: 32px;
      text-align: right;
      font-family: PingFangSC-Regular;
      font-size: 34px;
      color: #333;
      .color-999 {
        color: #999;
        font-size: 30px;
      }
    }
    textarea {
      width: 100%;
    }
  }
  ::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;
    line-height: 112px;
    background: #1365DD;
    box-shadow: inset 0px 1px 0px 0px #EEEEEE;
    font-size: 32px;
    font-family: PingFangSC-Medium, PingFang SC;
    font-weight: 500;
    color: #FFF;
    text-align: center;
    position: fixed;
    bottom: 0;
    left: 0;
  }
}
</style>
