<template>
  <a-spin :spinning="confirmLoading">
    <j-form-container :disabled="formDisabled">
      <a-form-model ref="form" :model="model" :rules="validatorRules" slot="detail">
        <a-row>
          <a-col :span="12">
            <a-form-model-item label="表英文名" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="tablename">
              <a-input v-model="model.tablename" placeholder="请输入表英文名"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="12">
            <a-form-model-item label="表中文名" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="tablealias">
              <a-input v-model="model.tablealias" placeholder="请输入表中文名"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="12">
            <a-form-model-item label="查询字段名称" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="qfldname">
              <a-input v-model="model.qfldname" placeholder="请输入查询字段名称"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="12">
            <a-form-model-item label="关联表名称" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="reltablename">
              <a-input v-model="model.reltablename" placeholder="请输入关联表名称"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="12">
            <a-form-model-item label="空间分析关联表名称" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="analysistablename">
              <a-input v-model="model.analysistablename" placeholder="请输入空间分析关联表名称"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="12">
            <a-form-model-item label="来源表关联字段名称" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="fromfldname">
              <a-input v-model="model.fromfldname" placeholder="请输入来源表关联字段名称"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="12">
            <a-form-model-item label="关联表字段名称" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="tofldname">
              <a-input v-model="model.tofldname" placeholder="请输入关联表字段名称"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="12">
            <a-form-model-item label="字段展示顺序" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="showorder">
              <a-input-number v-model="model.showorder" placeholder="请输入字段展示顺序" style="width: 100%" ></a-input-number>
            </a-form-model-item>
          </a-col>
          <a-col :span="12">
            <a-form-model-item label="字段英文名" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="fldname">
              <a-input v-model="model.fldname" placeholder="请输入字段英文名"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="12">
            <a-form-model-item label="字段中文名" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="fldalias">
              <a-input v-model="model.fldalias" placeholder="请输入字段中文名"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="12">
            <a-form-model-item label="单位" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="unit">
              <a-input v-model="model.unit" placeholder="请输入单位"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="12">
            <a-form-model-item label="精度" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="pre">
              <a-input-number v-model="model.pre" placeholder="请输入精度" style="width: 100%" />
            </a-form-model-item>
          </a-col>
          <a-col :span="12">
            <a-form-model-item label="字段类型" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="type">
              <a-input v-model="model.type" placeholder="请输入字段类型"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="12">
            <a-form-model-item label="数据字典名称" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="dictname">
              <a-input v-model="model.dictname" placeholder="请输入数据字典名称"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="12">
            <a-form-model-item label="其他信息字段" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="otherfield">
              <a-input v-model="model.otherfield" placeholder="请输入返回的其他信息字段"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="12">
            <a-form-model-item label="返回图形面积" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="returnarea">
              <j-dict-select-tag type="list" v-model="model.returnarea" dictCode="whether" placeholder="请选择是否返回图形面积"/>
            </a-form-model-item>
          </a-col>

        </a-row>
      </a-form-model>
    </j-form-container>
  </a-spin>
</template>

<script>

  import { httpAction, getAction } from '@/api/manage'
  import { validateDuplicateValue } from '@/utils/util'

  export default {
    name: 'CommonQueryConfigForm',
    components: {
    },
    props: {
      //表单禁用
      disabled: {
        type: Boolean,
        default: false,
        required: false
      }
    },
    data () {
      return {
        model:{
         },
        labelCol: {
          xs: { span: 24 },
          sm: { span: 5 },
        },
        wrapperCol: {
          xs: { span: 24 },
          sm: { span: 16 },
        },
        confirmLoading: false,
        validatorRules: {
        },
        url: {
          add: "/commonQueryConfig/commonQueryConfig/add",
          edit: "/commonQueryConfig/commonQueryConfig/edit",
          queryById: "/commonQueryConfig/commonQueryConfig/queryById"
        }
      }
    },
    computed: {
      formDisabled(){
        return this.disabled
      },
    },
    created () {
       //备份model原始值
      this.modelDefault = JSON.parse(JSON.stringify(this.model));
    },
    methods: {
      add () {
        this.edit(this.modelDefault);
      },
      edit (record) {
        this.model = Object.assign({}, record);
        this.visible = true;
      },
      submitForm () {
        const that = this;
        // 触发表单验证
        this.$refs.form.validate(valid => {
          if (valid) {
            that.confirmLoading = true;
            let httpurl = '';
            let method = '';
            if(!this.model.id){
              httpurl+=this.url.add;
              method = 'post';
            }else{
              httpurl+=this.url.edit;
               method = 'put';
            }
            httpAction(httpurl,this.model,method).then((res)=>{
              if(res.success){
                that.$message.success(res.message);
                that.$emit('ok');
              }else{
                that.$message.warning(res.message);
              }
            }).finally(() => {
              that.confirmLoading = false;
            })
          }

        })
      },
    }
  }
</script>
