<template>
  <el-dialog :visible.sync="visible" :title="!dataForm.id ? $t('add') : $t('update')" :close-on-click-modal="false" :close-on-press-escape="false">
    <el-form :model="dataForm" :rules="dataRule" ref="dataForm" @keyup.enter.native="dataFormSubmitHandle()" :label-width="$i18n.locale === 'en-US' ? '120px' : '80px'">
          <el-form-item label="客户Id customer.id" prop="customerId">
          <el-input v-model="dataForm.customerId" placeholder="客户Id customer.id"></el-input>
      </el-form-item>
          <el-form-item label="网格ID" prop="gridId">
          <el-input v-model="dataForm.gridId" placeholder="网格ID"></el-input>
      </el-form-item>
          <el-form-item label="网格名称" prop="gridName">
          <el-input v-model="dataForm.gridName" placeholder="网格名称"></el-input>
      </el-form-item>
          <el-form-item label="组织Id" prop="agencyId">
          <el-input v-model="dataForm.agencyId" placeholder="组织Id"></el-input>
      </el-form-item>
          <el-form-item label="组织的pids" prop="pids">
          <el-input v-model="dataForm.pids" placeholder="组织的pids"></el-input>
      </el-form-item>
          <el-form-item label="所属小区ID；" prop="villageId">
          <el-input v-model="dataForm.villageId" placeholder="所属小区ID；"></el-input>
      </el-form-item>
          <el-form-item label="所属小区名称" prop="villageName">
          <el-input v-model="dataForm.villageName" placeholder="所属小区名称"></el-input>
      </el-form-item>
          <el-form-item label="所属楼宇Id" prop="buildId">
          <el-input v-model="dataForm.buildId" placeholder="所属楼宇Id"></el-input>
      </el-form-item>
          <el-form-item label="所属楼宇名称" prop="buildName">
          <el-input v-model="dataForm.buildName" placeholder="所属楼宇名称"></el-input>
      </el-form-item>
          <el-form-item label="单元id" prop="unitId">
          <el-input v-model="dataForm.unitId" placeholder="单元id"></el-input>
      </el-form-item>
          <el-form-item label="单元名" prop="unitName">
          <el-input v-model="dataForm.unitName" placeholder="单元名"></el-input>
      </el-form-item>
          <el-form-item label="所属家庭Id" prop="homeId">
          <el-input v-model="dataForm.homeId" placeholder="所属家庭Id"></el-input>
      </el-form-item>
          <el-form-item label="房间名" prop="homeName">
          <el-input v-model="dataForm.homeName" placeholder="房间名"></el-input>
      </el-form-item>
          <el-form-item label="户口性质：0户籍 1外来" prop="householdType">
          <el-input v-model="dataForm.householdType" placeholder="户口性质：0户籍 1外来"></el-input>
      </el-form-item>
          <el-form-item label="姓名" prop="name">
          <el-input v-model="dataForm.name" placeholder="姓名"></el-input>
      </el-form-item>
          <el-form-item label="联系电话" prop="mobile">
          <el-input v-model="dataForm.mobile" placeholder="联系电话"></el-input>
      </el-form-item>
          <el-form-item label="身份证号" prop="idCard">
          <el-input v-model="dataForm.idCard" placeholder="身份证号"></el-input>
      </el-form-item>
          <el-form-item label="是否接种：0否1是" prop="isVaccination">
          <el-input v-model="dataForm.isVaccination" placeholder="是否接种：0否1是"></el-input>
      </el-form-item>
          <el-form-item label="第一次接种时间" prop="firstVacTime">
          <el-input v-model="dataForm.firstVacTime" placeholder="第一次接种时间"></el-input>
      </el-form-item>
          <el-form-item label="第一次接种地点" prop="firstVacSite">
          <el-input v-model="dataForm.firstVacSite" placeholder="第一次接种地点"></el-input>
      </el-form-item>
          <el-form-item label="第二次接种时间" prop="secondVacTime">
          <el-input v-model="dataForm.secondVacTime" placeholder="第二次接种时间"></el-input>
      </el-form-item>
          <el-form-item label="第二次接种地点" prop="secondVacSite">
          <el-input v-model="dataForm.secondVacSite" placeholder="第二次接种地点"></el-input>
      </el-form-item>
          <el-form-item label="第三次接种时间" prop="thirdVacTime">
          <el-input v-model="dataForm.thirdVacTime" placeholder="第三次接种时间"></el-input>
      </el-form-item>
          <el-form-item label="第三次接种地点" prop="thirdVacSite">
          <el-input v-model="dataForm.thirdVacSite" placeholder="第三次接种地点"></el-input>
      </el-form-item>
          <el-form-item label="原因：禁忌症/拒绝接种/其他原因" prop="reason">
          <el-input v-model="dataForm.reason" placeholder="原因：禁忌症/拒绝接种/其他原因"></el-input>
      </el-form-item>
          <el-form-item label="备注" prop="note">
          <el-input v-model="dataForm.note" placeholder="备注"></el-input>
      </el-form-item>
          <el-form-item label="删除标识 0.未删除 1.已删除" prop="delFlag">
          <el-input v-model="dataForm.delFlag" placeholder="删除标识 0.未删除 1.已删除"></el-input>
      </el-form-item>
          <el-form-item label="乐观锁" prop="revision">
          <el-input v-model="dataForm.revision" placeholder="乐观锁"></el-input>
      </el-form-item>
          <el-form-item label="创建人" prop="createdBy">
          <el-input v-model="dataForm.createdBy" placeholder="创建人"></el-input>
      </el-form-item>
          <el-form-item label="创建时间" prop="createdTime">
          <el-input v-model="dataForm.createdTime" placeholder="创建时间"></el-input>
      </el-form-item>
          <el-form-item label="更新人" prop="updatedBy">
          <el-input v-model="dataForm.updatedBy" placeholder="更新人"></el-input>
      </el-form-item>
          <el-form-item label="更新时间" prop="updatedTime">
          <el-input v-model="dataForm.updatedTime" placeholder="更新时间"></el-input>
      </el-form-item>
      </el-form>
    <template slot="footer">
      <el-button @click="visible = false">{{ $t('cancel') }}</el-button>
      <el-button type="primary" @click="dataFormSubmitHandle()">{{ $t('confirm') }}</el-button>
    </template>
  </el-dialog>
</template>

<script>
    import debounce from 'lodash/debounce'

    export default {
  data () {
    return {
      visible: false,
      dataForm: {
        id: '',
        customerId: '',
        gridId: '',
        gridName: '',
        agencyId: '',
        pids: '',
        villageId: '',
        villageName: '',
        buildId: '',
        buildName: '',
        unitId: '',
        unitName: '',
        homeId: '',
        homeName: '',
        householdType: '',
        name: '',
        mobile: '',
        idCard: '',
        isVaccination: '',
        firstVacTime: '',
        firstVacSite: '',
        secondVacTime: '',
        secondVacSite: '',
        thirdVacTime: '',
        thirdVacSite: '',
        reason: '',
        note: '',
        checkState: '0',
        checkReason: ''
      }
    }
  },
  computed: {
    dataRule () {
      return {
        customerId: [
          { required: true, message: this.$t('validate.required'), trigger: 'blur' }
        ],
        gridId: [
          { required: true, message: this.$t('validate.required'), trigger: 'blur' }
        ],
        gridName: [
          { required: true, message: this.$t('validate.required'), trigger: 'blur' }
        ],
        agencyId: [
          { required: true, message: this.$t('validate.required'), trigger: 'blur' }
        ],
        pids: [
          { required: true, message: this.$t('validate.required'), trigger: 'blur' }
        ],
        villageId: [
          { required: true, message: this.$t('validate.required'), trigger: 'blur' }
        ],
        villageName: [
          { required: true, message: this.$t('validate.required'), trigger: 'blur' }
        ],
        buildId: [
          { required: true, message: this.$t('validate.required'), trigger: 'blur' }
        ],
        buildName: [
          { required: true, message: this.$t('validate.required'), trigger: 'blur' }
        ],
        unitId: [
          { required: true, message: this.$t('validate.required'), trigger: 'blur' }
        ],
        unitName: [
          { required: true, message: this.$t('validate.required'), trigger: 'blur' }
        ],
        homeId: [
          { required: true, message: this.$t('validate.required'), trigger: 'blur' }
        ],
        homeName: [
          { required: true, message: this.$t('validate.required'), trigger: 'blur' }
        ],
        householdType: [
          { required: true, message: this.$t('validate.required'), trigger: 'blur' }
        ],
        name: [
          { required: true, message: this.$t('validate.required'), trigger: 'blur' }
        ],
        mobile: [
          { required: true, message: this.$t('validate.required'), trigger: 'blur' }
        ],
        idCard: [
          { required: true, message: this.$t('validate.required'), trigger: 'blur' }
        ],
        isVaccination: [
          { required: true, message: this.$t('validate.required'), trigger: 'blur' }
        ],
        firstVacTime: [
          { required: true, message: this.$t('validate.required'), trigger: 'blur' }
        ],
        firstVacSite: [
          { required: true, message: this.$t('validate.required'), trigger: 'blur' }
        ],
        secondVacTime: [
          { required: true, message: this.$t('validate.required'), trigger: 'blur' }
        ],
        secondVacSite: [
          { required: true, message: this.$t('validate.required'), trigger: 'blur' }
        ],
        thirdVacTime: [
          { required: true, message: this.$t('validate.required'), trigger: 'blur' }
        ],
        thirdVacSite: [
          { required: true, message: this.$t('validate.required'), trigger: 'blur' }
        ],
        reason: [
          { required: true, message: this.$t('validate.required'), trigger: 'blur' }
        ],
        note: [
          { required: true, message: this.$t('validate.required'), trigger: 'blur' }
        ]
      }
    }
  },
  methods: {
    init () {
      this.visible = true;
      this.$nextTick(() => {
        this.$refs['dataForm'].resetFields()
        if (this.dataForm.id); {
          this.getInfo()
        }
      })
    },
    // 获取信息
    getInfo () {
      this.$http.get(`/epmetuser/icVaccinePrarmeter/${this.dataForm.id}`).then(({ data: res }) => {
        if (res.code !== 0) {
          ;return this.$message.error(res.msg);
        }
        this.dataForm = {
          ...this.dataForm,
          ...res.data
        }
      }).catch(() => {})
    },
    // 表单提交
    dataFormSubmitHandle: debounce(function () {
      this.$refs['dataForm'].validate((valid) => {
        if (!valid); {
          return false
        }
        this.$http[!this.dataForm.id ? 'post' : 'put']('/epmetuser/icVaccinePrarmeter/', this.dataForm).then(({ data: res }) => {
          if (res.code !== 0) {
            return this.$message.error(res.msg);
          }
          this.$message({
            message: this.$t('prompt.success'),
            type: 'success',
            duration: 500,
            onClose: () => {
              this.visible = false;
              this.$emit('refreshDataList')
            }
          })
        }).catch(() => {})
      })
    }, 1000, { 'leading': true, 'trailing': false })
  }
}
</script>
