<template>
  <a-row :gutter="[24, 24]">
    <a-col :span="24">
      <a-form :inline="true" :model="formData" :rules="rules" ref="formRef" :label-col="{span: 4}"
        :wrapper-col="{span:18}">
        <div class="drawing-board">
          <a-col :span="12">
            <a-form-item label="表名称" name="tableName" :labelCol="{'span':4}" :wrapperCol="{'span':18}">
              <a-input :maxlength="20" placeholder="请输入仓库名称" show-word-limit v-model:value="formData.tableName">
              </a-input>
            </a-form-item>
          </a-col>
          <a-col :span="12">
            <a-form-item label="表描述" name="tableComment" :labelCol="{'span':4}" :wrapperCol="{'span':18}">
              <a-input :maxlength="20" placeholder="请输入" show-word-limit v-model:value="formData.tableComment">
              </a-input>
            </a-form-item>
          </a-col>
          <a-col :span="12">
            <a-form-item label="实体类名称" name="className" :labelCol="{'span':4}" :wrapperCol="{'span':18}">
              <a-input :maxlength="20" placeholder="请输入" show-word-limit v-model:value="formData.className">
              </a-input>
            </a-form-item>
          </a-col>
          <a-col :span="12">
            <a-form-item label="作者" name="functionAuthor" :labelCol="{'span':4}" :wrapperCol="{'span':18}">
              <a-input placeholder="请输入" v-model:value="formData.functionAuthor"></a-input>
            </a-form-item>
          </a-col>
          <a-col :span="24">
            <a-form-item label="备注" name="remark" :labelCol="{'span':2}" :wrapperCol="{'span':18}">
              <a-textarea :maxlength="100" placeholder="请输入" show-word-limit v-model:value="formData.remark">
              </a-textarea>
            </a-form-item>
          </a-col>
        </div>
      </a-form>
    </a-col>
  </a-row>
  <div class="submit t-c">
    <a-button type="primary" @click="submitForm()">保存基础信息</a-button>
  </div>
</template>
<script>
import { reactive, inject, toRefs, watch, onMounted, getCurrentInstance } from 'vue'
import { util } from '../../../entery'
export default {
  name: "BasicInfoForm",
  props: {
    tableInfo: {
      type: Object,
      default: null
    }
  },
  emits: ["reload"],
  setup (props, context) {
    let { proxy } = getCurrentInstance()
    let http = inject('http')
    let _data = reactive({
      formData: {},
      formRef: null,
      rolePermiss: null,
      rules: {
        tableName: [
          { required: true, message: '请输入表名称', trigger: 'blur' },
        ],
        tableComment: [
          { required: true, message: "请输入表描述", trigger: "blur" }
        ],
        className: [
          { required: true, message: "请输入实体类名称", trigger: "blur" }
        ],
        functionAuthor: [
          { required: true, message: "请输入作者", trigger: "blur" }
        ]
      },
    })
    let _methods = {
      submitForm () {
        _data.formRef.validate().then(() => {
          let param = util.util.cloneObj(_data.formData)
          http.updateBase(param).then((res) => {
            context.emit('reload')
            proxy.$message.success('基础信息保存成功')
          })
        })
      }
    }
    onMounted(() => {
      _data.formData = util.util.cloneObj(props.tableInfo)
    })
    return {
      ...toRefs(_data),
      ..._methods
    }
  },

};
</script>