<template>
  <div class="add">
    <div class="form-group">
      <div class="form-item">
        <div class="form-item__wrapper">
          <div class="left">
            <i>*</i>
            <span>监测对象类型</span>
          </div>
          <div class="right">
            <AiSelect dict="fpType" v-model="form.type"></AiSelect>
          </div>
        </div>
      </div>
      <div class="form-item">
        <div class="form-item__wrapper">
          <div class="left">
            <i>*</i>
            <span>户主姓名</span>
          </div>
          <div class="right">
            <input placeholder="请输入" type="text" v-model="form.phone" :maxlength="8"
                   placeholder-style="color: #999; font-size: 30rpx;"/>
          </div>
        </div>
      </div>
      <div class="form-item">
        <div class="form-item__wrapper">
          <div class="left">
            <i>*</i>
            <span>身份证号</span>
          </div>
          <div class="right">
            <input placeholder="请输入" type="idcard" v-model="form.phone" :maxlength="18"
                   placeholder-style="color: #999; font-size: 30rpx;"/>
          </div>
        </div>
      </div>
      <div class="form-item">
        <div class="form-item__wrapper">
          <div class="left">
            <i>*</i>
            <span>性别</span>
          </div>
          <div class="right">
            <input placeholder="自动识别" type="idcard" v-model="form.phone" disabled
                   placeholder-style="color: #999; font-size: 30rpx;"/>
          </div>
        </div>
      </div>
    </div>
    <div class="form-group">
      <div class="form-item">
        <div class="form-item__wrapper">
          <div class="left">
            <i>*</i>
            <span>联系方式</span>
          </div>
          <div class="right">
            <input placeholder="请输入" type="number" v-model="form.phone" :maxlength="11"
                   placeholder-style="color: #999; font-size: 30rpx;"/>
          </div>
        </div>
      </div>
      <div class="form-item">
        <div class="form-item__wrapper">
          <div class="left">
            <i>*</i>
            <span>现住址</span>
          </div>
          <div class="right">
            <AiAreaPicker ref="address" class="aiArea" :fullName.sync="form.addressArea" :value="form.addressAreaId" :areaId="$areaId" mode="custom" all @select="onAreaChange">
                <div class="aiArea">
                  <span class="label" v-if="form.addressArea">{{ form.addressArea }}</span>
                  <i v-else>请选择</i>
                  <u-icon name="arrow-right" color="#ddd"/>
                </div>
            </AiAreaPicker>
          </div>
        </div>
      </div>
    </div>
    <div class="form-group">
      <div class="form-item">
        <div class="form-item__wrapper">
          <div class="left">
            <i style="opacity: 0;">*</i>
            <span>民族</span>
          </div>
          <div class="right">
            <AiSelect dict="fpType" v-model="form.type"></AiSelect>
          </div>
        </div>
      </div>
      <div class="form-item">
        <div class="form-item__wrapper">
          <div class="left">
            <i style="opacity: 0;">*</i>
            <span>政治面貌</span>
          </div>
          <div class="right">
            <AiSelect dict="fpType" v-model="form.type"></AiSelect>
          </div>
        </div>
      </div>
      <div class="form-item">
        <div class="form-item__wrapper">
          <div class="left">
            <i style="opacity: 0;">*</i>
            <span>文化程度</span>
          </div>
          <div class="right">
            <AiSelect dict="fpType" v-model="form.type"></AiSelect>
          </div>
        </div>
      </div>
      <div class="form-item">
        <div class="form-item__wrapper">
          <div class="left">
            <i style="opacity: 0;">*</i>
            <span>详细地址</span>
          </div>
          <div class="right">
            <input placeholder="请输入" v-model="form.address" placeholder-style="color: #999; font-size: 30rpx;"/>
          </div>
        </div>
      </div>
    </div>
    <div class="form-group">
      <div class="form-item">
        <div class="form-item__wrapper border-b0">
          <div class="left">
            <i style="opacity: 0;">*</i>
            <span>个人照片</span>
          </div>
        </div>
      </div>
      <div class="upload">
        <AiUploader :def.sync="form.files" multiple placeholder="上传图片" :limit="9" action="/admin/file/add2"></AiUploader>
      </div>
    </div>

    <div class="form-group">
      <div class="form-item">
        <div class="form-item__wrapper">
          <div class="left">
            <i style="opacity: 0;">*</i>
            <span>在校情况</span>
          </div>
          <div class="right">
            <AiSelect dict="fpType" v-model="form.type"></AiSelect>
          </div>
        </div>
      </div>
      <div class="form-item">
        <div class="form-item__wrapper">
          <div class="left">
            <i style="opacity: 0;">*</i>
            <span>劳动技能</span>
          </div>
          <div class="right">
            <AiSelect dict="fpType" v-model="form.type"></AiSelect>
          </div>
        </div>
      </div>
      <div class="form-item">
        <div class="form-item__wrapper">
          <div class="left">
            <i style="opacity: 0;">*</i>
            <span>务工区域</span>
          </div>
          <div class="right">
            <input placeholder="请输入" v-model="form.address" placeholder-style="color: #999; font-size: 30rpx;"/>
          </div>
        </div>
      </div>
      <div class="form-item">
        <div class="form-item__wrapper">
          <div class="left">
            <i style="opacity: 0;">*</i>
            <span>务工时间/月</span>
          </div>
          <div class="right">
            <input placeholder="请输入" v-model="form.address" type="number" placeholder-style="color: #999; font-size: 30rpx;" maxlength="2"/>
          </div>
        </div>
      </div>
    </div>
    <div class="form-group">
      <div class="form-item">
        <div class="form-item__wrapper">
          <div class="left">
            <i>*</i>
            <span>是否参加医保</span>
          </div>
          <div class="right">
            <div class="check-item" :class="form.medicalInsurance == 1 ? 'check-active' : '' " @click="form.medicalInsurance=1">是<img src="./components/img/check-icon.png" alt=""></div>
            <div class="check-item" :class="form.medicalInsurance != 1 ? 'check-active' : '' " @click="form.medicalInsurance=0">否<img src="./components/img/check-icon.png" alt=""></div>
          </div>
        </div>
      </div>
      <div class="form-item">
        <div class="form-item__wrapper">
          <div class="left">
            <i>*</i>
            <span>是否参加大病保险</span>
          </div>
          <div class="right">
            <div class="check-item" :class="form.sicknessInsurance == 1 ? 'check-active' : '' " @click="form.sicknessInsurance=1">是<img src="./components/img/check-icon.png" alt=""></div>
            <div class="check-item" :class="form.sicknessInsurance != 1 ? 'check-active' : '' " @click="form.sicknessInsurance=0">否<img src="./components/img/check-icon.png" alt=""></div>
          </div>
        </div>
      </div>
      <div class="form-item">
        <div class="form-item__wrapper">
          <div class="left">
            <i>*</i>
            <span>是否参加养老保险</span>
          </div>
          <div class="right">
            <div class="check-item" :class="form.endowmentInsurance == 1 ? 'check-active' : '' " @click="form.endowmentInsurance=1">是<img src="./components/img/check-icon.png" alt=""></div>
            <div class="check-item" :class="form.endowmentInsurance != 1 ? 'check-active' : '' " @click="form.endowmentInsurance=0">否<img src="./components/img/check-icon.png" alt=""></div>
          </div>
        </div>
      </div>
      <div class="form-item">
        <div class="form-item__wrapper">
          <div class="left">
            <i>*</i>
            <span>是否享受最低生活保障</span>
          </div>
          <div class="right">
            <div class="check-item" :class="form.subsistenceAllowance == 1 ? 'check-active' : '' " @click="form.subsistenceAllowance=1">享受<img src="./components/img/check-icon.png" alt=""></div>
            <div class="check-item" :class="form.subsistenceAllowance != 1 ? 'check-active' : '' " @click="form.subsistenceAllowance=0">未享受<img src="./components/img/check-icon.png" alt=""></div>
          </div>
        </div>
      </div>
      <div class="form-item">
        <div class="form-item__wrapper">
          <div class="left">
            <i>*</i>
            <span>是否特困供养</span>
          </div>
          <div class="right">
            <div class="check-item" :class="form.destitute == 1 ? 'check-active' : '' " @click="form.destitute=1">是<img src="./components/img/check-icon.png" alt=""></div>
            <div class="check-item" :class="form.destitute != 1 ? 'check-active' : '' " @click="form.destitute=0">否<img src="./components/img/check-icon.png" alt=""></div>
          </div>
        </div>
      </div>
    </div>

   
    <div class="btn" hover-class="text" @click="submit"> {{ isEdit ? '保存' : '申请纳入监测' }}</div>
  </div>
</template>

<script>

export default {
  data() {
    return {
      form: {
        addressAreaId: '',
        address: '',
        addressArea: '',
        move: '02',
        place: '',
        placeAreaId: '',
        placeArea: '',
        type: '',
        files: []
      },
      $areaId: '',
      isEdit: false,
      id: '',
      areaName: '',
    }
  },

  created() {
    this.areaName = this.$store.state.user.areaFullName
    this.$dict.load(['fpType', 'fpYesOrNo'])
  },

  onLoad(query) {
    if (query.id) {
      this.isEdit = true
      this.id = query.id

      this.getInfo(this.id)
    }
    document.title = query.id ? '编辑监测对象' : '添加监测对象'
  },

  methods: {
    submit() {
      if (!this.form.type) {
        return this.$u.toast('请选择监测类型')
      }

      if (!this.form.phone) {
        return this.$u.toast('请输入联系方式')
      }

      if (!this.form.addressAreaId) {
        return this.$u.toast('请选择住址')
      }

      uni.showLoading()
      this.$http.post('/app/apppreventionreturntopoverty/addOrUpdate', {
        ...this.form,
        id: this.isEdit ? this.id : ''
      }).then(res => {
        if (res.code === 0) {
          this.$u.toast(this.isEdit ? '保存成功' : '提交成功')
          uni.$emit('reload')
          uni.navigateBack({
            delta: 1
          })
        }
        uni.hideLoading()
      })
    },

    onAreaChange(e) {
      this.form.addressAreaId = e
    },

    onChange(e) {
      this.form.placeAreaId = e
    },

    getInfo(id) {
      this.$http.post(`/app/apppreventionreturntopoverty/queryDetailById?id=${id}`).then(res => {
        if (res.code === 0) {
          this.form = {
            ...this.form,
            ...res.data
          }
        }
      })
    }
  }
}
</script>

<style lang="scss">
.add {
  padding-bottom: 120px;

  .aiArea {
    display: flex;
    align-items: center;

    .label {
      max-width: 480px;
      height: 112px;
      overflow: hidden;
      text-overflow:ellipsis;
      white-space: nowrap;
      color: #303133 !important;
      font-size: 30px;
    }

    i {
      margin-left: 4px;
      font-style: normal;
      color: #999999;
      font-size: 30px;
    }
  }

  ::v-deep .u-radio {
    &:last-child {
      .u-radio__label {
        margin-right: 0;
      }
    }
  }

  & > div {
    margin-bottom: 16px;
    background: #fff;
  }

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

      .form-item__wrapper {
        display: flex;
        align-items: center;
        justify-content: space-between;
        height: 112px;
        border-bottom: 1px solid #E4E5E6;
      }

      .right {
        height: 112px;
        line-height: 112px;
        padding-right: 32px;

        span {
          font-size: 30px;
          color: #999999;
        }
        .check-item{
          display: inline-block;
          width: 160px;
          height: 64px;
          line-height: 64px;
          text-align: center;
          background: #F5F5F5;
          border-radius: 4px;
          font-size: 30px;
          font-family: PingFangSC-Medium, PingFang SC;
          font-weight: 500;
          color: #333;
          position: relative;
          img{
            display: none;
          }
        }
        .check-item:nth-of-type(1) {
          margin-right: 36px;
        }
        .check-active{
          background: #E7F1FE;
          color: #1174FE;
          img{
            display: block;
            position: absolute;
            bottom: 0;
            right: 0;
            width: 48px;
            height: 48px;
          }
        }
      }

      input {
        height: 100%;
        text-align: right;
      }

      .left {
        display: flex;
        align-items: center;

        span {
          color: #333333;
          font-size: 32px;
        }

        i {
          margin-right: 4px;
          font-style: normal;
          color: #FF4466;
          font-size: 32px;
        }
      }

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

  .form-item__imgs {
    padding: 32px;

    .form-item__title {
      display: flex;
      align-items: center;
      margin-bottom: 34px;

      h2 {
        color: #333333;
        font-weight: normal;
        font-size: 32px;
      }

      i {
        color: #999999;
        font-size: 28px;
        font-style: normal;
      }
    }

    textarea {
      width: 100%;
    }
  }

  .form-type {
    display: flex;
    align-items: center;
    justify-content: space-between;
    height: 112px;
    padding: 0 32px;

    h2 {
      font-weight: normal;
      color: #333333;
      font-size: 32px;
    }

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

  .btn {
    position: fixed;
    left: 0;
    bottom: 0;
    z-index: 11;
    width: 100%;
    height: 112px;
    line-height: 112px;
    margin: 0;
    text-align: center;
    color: #FFFFFF;
    font-size: 32px;
    background: #3192F4;
  }
  .upload {
    width: 100%;
    padding: 10px 32px 32px 32px;
    box-sizing: border-box;
  }
  .border-b0{
    border-bottom: 0!important;
  }
}
</style>
