<template>
  <el-dialog
    class="patientDialog"
    :visible.sync="visible"
    width="30%"
    title="修改身份证"
    @close="closedDialog"
  >
    <el-form ref="dataForm" :model="dataForm" :rules="dataRule">
      <el-form-item label="身份证号:" label-width="90px" prop="newIdNumber" class="formItemOne">
        <el-input v-model="dataForm.newIdNumber" placeholder="请输入患者身份证号" />
      </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 {
  props: {
    patientTypeList: {
      type: Array,
      default: () => []
    }
  },
  data() {
    return {
      visible: false,
      dataForm: {
        newIdNumber: '',
        oldIdNumber: '',
        drgsName: window.localStorage.getItem('identity')
      }
    }
  },
  computed: {
    dataRule() {
      return {
        newIdNumber: [
          { required: true, message: '请输入身份证号', trigger: 'blur' }
        ]
      }
    }
  },
  methods: {
    init() {
      this.visible = true
      this.$nextTick(() => {
        this.$refs.dataForm.resetFields() // 重置表单
      })
    },
    // 表单提交
    dataFormSubmitHandle: debounce(function() {
      this.$refs.dataForm.validate((valid) => {
        if (!valid) {
          return false
        }
        this.$http.post('/quguang/pat/Manage/updateIdNumber', 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 }),

    // 关闭dialog
    closedDialog() {
      this.$emit('editPatidVisible')
    }
  }
}
</script>
<style lang="scss" scoped>
.patientDialog {
  .cycle-display {
    .el-form-item__content {
      display: flex;
    }
    .el-input-number {
      width: 100px;
      margin-right: 16px;
    }
  }
}

</style>
<style lang="scss">
.patientDialog {
  .el-dialog__header {
    margin-bottom:12px
  }
    .el-dialog__body {
        padding-right: 30px;
    }
    .formItemOne .el-form-item__content {
      display: flex;
    }

}
</style>
