<template>
  <el-dialog :visible.sync="visible" :title="!dataForm.id ? $t('add') : $t('查看')" :close-on-click-modal="false" :close-on-press-escape="false">
    <el-form :disabled="true" :model="dataForm" :rules="dataRule" ref="dataForm" @keyup.enter.native="dataFormSubmitHandle()" :label-width="$i18n.locale === 'en-US' ? '120px' : '80px'">
      <el-form-item label="公民身份证号" prop="idCard">
          <el-input v-model="dataForm.idCard" placeholder="公民身份证号"></el-input>
      </el-form-item>
      <el-form-item label="证件类型" prop="idType">
          <el-input v-model="dataForm.idType" placeholder="证件类型"></el-input>
      </el-form-item>
          <el-form-item label="姓名" prop="rotatorsName">
          <el-input v-model="dataForm.rotatorsName" placeholder="姓名"></el-input>
      </el-form-item>
      <el-form-item label="曾用名" prop="formerName">
          <el-input v-model="dataForm.formerName" placeholder="曾用名"></el-input>
      </el-form-item>
      <el-form-item label="性别" prop="sex">
          <el-input v-model="dataForm.sex" placeholder="性别"></el-input>
      </el-form-item>
      <el-form-item label="出生日期" prop="birthday">
          <el-input v-model="dataForm.birthday" placeholder="出生日期"></el-input>
      </el-form-item>
      <el-form-item label="民族" prop="nation">
          <el-input v-model="dataForm.nation" placeholder="民族"></el-input>
      </el-form-item>
      <el-form-item label="婚姻状况" prop="marriageStatus">
          <el-input v-model="dataForm.marriageStatus" placeholder="婚姻状况"></el-input>
      </el-form-item>
      <el-form-item label="政治面貌" prop="party">
          <el-input v-model="dataForm.party" placeholder="政治面貌"></el-input>
      </el-form-item>
      <el-form-item label="学历" prop="education">
          <el-input v-model="dataForm.education" placeholder="学历"></el-input>
      </el-form-item>
      <el-form-item label="宗教信仰" prop="religious">
          <el-input v-model="dataForm.religious" placeholder="宗教信仰"></el-input>
      </el-form-item>
      <el-form-item label="职业类别" prop="occupationType">
          <el-input v-model="dataForm.occupationType" placeholder="职业类别"></el-input>
      </el-form-item>
      <el-form-item label="职业" prop="occupation">
          <el-input v-model="dataForm.occupation" placeholder="职业"></el-input>
      </el-form-item>
      <el-form-item label="联系方式" prop="telephone">
          <el-input v-model="dataForm.telephone" placeholder="联系方式"></el-input>
      </el-form-item>
      <el-form-item label="户籍门(楼)详址" prop="householdAddressDetail">
          <el-input v-model="dataForm.householdAddressDetail" placeholder="户籍门(楼)详址"></el-input>
      </el-form-item>
      <el-form-item label="现住地社区/村" prop="curliveAddressVillage">
          <el-input v-model="dataForm.curliveAddressVillage" placeholder="现住地社区/村"></el-input>
      </el-form-item>
      <el-form-item label="现住门(楼)详址" prop="curliveAddressDetail">
          <el-input v-model="dataForm.curliveAddressDetail" placeholder="现住门(楼)详址"></el-input>
      </el-form-item>
      <el-form-item label="是否重点关注人员" prop="isFocusPerson">
          <el-input v-model="dataForm.isFocusPerson" 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: {
        rotatorsId: '',
        idCard: '',
        idType: '',
        rotatorsName: '',
        formerName: '',
        sex: '',
        birthday: '',
        nation: '',
        nativeAddressProv: '',
        nativeAddressCity: '',
        nativeAddressCountry: '',
        marriageStatus: '',
        party: '',
        education: '',
        religious: '',
        occupationType: '',
        occupation: '',
        serviceAddress: '',
        telephone: '',
        householdAddressProv: '',
        householdAddressCity: '',
        householdAddressCountry: '',
        householdAddressTown: '',
        householdAddressVillage: '',
        householdAddressDetail: '',
        curliveAddressProv: '',
        curliveAddressCity: '',
        curliveAddressCountry: '',
        curliveAddressTown: '',
        curliveAddressVillage: '',
        curliveAddressDetail: '',
        inflowReason: '',
        certificateType: '',
        certificateNumber: '',
        signDate: '',
        endDate: '',
        residenceType: '',
        isFocusPerson: '',
        createBy: '',
        createDate: '',
        updateBy: '',
        updateDate: '',
        deleteFlag: '',
        platcode: '',
        gridId: '',
        versions: ''
      }
    }
  },
  computed: {
    dataRule () {
      return {
        idCard: [
          { required: true, message: this.$t('validate.required'), trigger: 'blur' }
        ],
        idType: [
          { required: true, message: this.$t('validate.required'), trigger: 'blur' }
        ],
        rotatorsName: [
          { required: true, message: this.$t('validate.required'), trigger: 'blur' }
        ],
        formerName: [
          { required: true, message: this.$t('validate.required'), trigger: 'blur' }
        ],
        sex: [
          { required: true, message: this.$t('validate.required'), trigger: 'blur' }
        ],
        birthday: [
          { required: true, message: this.$t('validate.required'), trigger: 'blur' }
        ],
        nation: [
          { required: true, message: this.$t('validate.required'), trigger: 'blur' }
        ],
        nativeAddressProv: [
          { required: true, message: this.$t('validate.required'), trigger: 'blur' }
        ],
        nativeAddressCity: [
          { required: true, message: this.$t('validate.required'), trigger: 'blur' }
        ],
        nativeAddressCountry: [
          { required: true, message: this.$t('validate.required'), trigger: 'blur' }
        ],
        marriageStatus: [
          { required: true, message: this.$t('validate.required'), trigger: 'blur' }
        ],
        party: [
          { required: true, message: this.$t('validate.required'), trigger: 'blur' }
        ],
        education: [
          { required: true, message: this.$t('validate.required'), trigger: 'blur' }
        ],
        religious: [
          { required: true, message: this.$t('validate.required'), trigger: 'blur' }
        ],
        occupationType: [
          { required: true, message: this.$t('validate.required'), trigger: 'blur' }
        ],
        occupation: [
          { required: true, message: this.$t('validate.required'), trigger: 'blur' }
        ],
        serviceAddress: [
          { required: true, message: this.$t('validate.required'), trigger: 'blur' }
        ],
        telephone: [
          { required: true, message: this.$t('validate.required'), trigger: 'blur' }
        ],
        householdAddressProv: [
          { required: true, message: this.$t('validate.required'), trigger: 'blur' }
        ],
        householdAddressCity: [
          { required: true, message: this.$t('validate.required'), trigger: 'blur' }
        ],
        householdAddressCountry: [
          { required: true, message: this.$t('validate.required'), trigger: 'blur' }
        ],
        householdAddressTown: [
          { required: true, message: this.$t('validate.required'), trigger: 'blur' }
        ],
        householdAddressVillage: [
          { required: true, message: this.$t('validate.required'), trigger: 'blur' }
        ],
        householdAddressDetail: [
          { required: true, message: this.$t('validate.required'), trigger: 'blur' }
        ],
        curliveAddressProv: [
          { required: true, message: this.$t('validate.required'), trigger: 'blur' }
        ],
        curliveAddressCity: [
          { required: true, message: this.$t('validate.required'), trigger: 'blur' }
        ],
        curliveAddressCountry: [
          { required: true, message: this.$t('validate.required'), trigger: 'blur' }
        ],
        curliveAddressTown: [
          { required: true, message: this.$t('validate.required'), trigger: 'blur' }
        ],
        curliveAddressVillage: [
          { required: true, message: this.$t('validate.required'), trigger: 'blur' }
        ],
        curliveAddressDetail: [
          { required: true, message: this.$t('validate.required'), trigger: 'blur' }
        ],
        inflowReason: [
          { required: true, message: this.$t('validate.required'), trigger: 'blur' }
        ],
        certificateType: [
          { required: true, message: this.$t('validate.required'), trigger: 'blur' }
        ],
        certificateNumber: [
          { required: true, message: this.$t('validate.required'), trigger: 'blur' }
        ],
        signDate: [
          { required: true, message: this.$t('validate.required'), trigger: 'blur' }
        ],
        endDate: [
          { required: true, message: this.$t('validate.required'), trigger: 'blur' }
        ],
        residenceType: [
          { required: true, message: this.$t('validate.required'), trigger: 'blur' }
        ],
        isFocusPerson: [
          { required: true, message: this.$t('validate.required'), trigger: 'blur' }
        ],
        createBy: [
          { required: true, message: this.$t('validate.required'), trigger: 'blur' }
        ],
        createDate: [
          { required: true, message: this.$t('validate.required'), trigger: 'blur' }
        ],
        updateBy: [
          { required: true, message: this.$t('validate.required'), trigger: 'blur' }
        ],
        updateDate: [
          { required: true, message: this.$t('validate.required'), trigger: 'blur' }
        ],
        deleteFlag: [
          { required: true, message: this.$t('validate.required'), trigger: 'blur' }
        ],
        platcode: [
          { required: true, message: this.$t('validate.required'), trigger: 'blur' }
        ],
        gridId: [
          { required: true, message: this.$t('validate.required'), trigger: 'blur' }
        ],
        versions: [
          { 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.post(`/opendata/caRotators/getRotatorsDetails`, { idCard: 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.rotatorsId ? 'post' : 'put']('/axis/caRotators/', 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>
