<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="24">
            <a-form-model-item label="企业名称" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="qymc">
              <a-input v-model="model.qymc" placeholder="请输入企业名称"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="联系人" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="lxr">
              <a-input v-model="model.lxr" placeholder="请输入联系人"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="手机号" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="sjh">
              <a-input v-model="model.sjh" placeholder="请输入手机号"  ></a-input>
            </a-form-model-item>
          </a-col>
         <!-- <a-col :span="24">
            <a-form-model-item label="问题类型" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="wtlx">
              <j-dict-select-tag type="list" v-model="model.wtlx" dictCode="" placeholder="请选择问题类型" />
            </a-form-model-item>
          </a-col>-->
          <a-col :span="24">
            <a-form-model-item label="问题类型" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="wtlx">
              <j-dict-select-tag type="list" v-model="model.wtlx" dictCode="wtlx" placeholder="请选择问题类型" />
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="问题描述" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="wtms">
              <a-textarea v-model="model.wtms" rows="4" placeholder="请输入问题描述" />
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="审批文件" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="spwj">
              <j-upload v-model='model.spwj' :disabled="formDisabled"></j-upload>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="是否通过审核" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="sftgsh">
              <j-dict-select-tag type="list" v-model="model.sftgsh" dictCode="shzt" placeholder="请选择是否通过审核" />
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="审核意见" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="shyj">
              <a-textarea v-model="model.shyj" rows="4" placeholder="请输入审核意见" />
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="审核人" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="shren">
              <a-input v-model="model.shren" placeholder="请输入审核人"  ></a-input>
            </a-form-model-item>
          </a-col>
<!--          <a-col :span="24">
            <a-form-model-item label="问题状态" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="wtzt">
              <a-input v-model="model.wtzt" placeholder="请输入问题状态"  ></a-input>
            </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: 'QcQywtfkForm',
    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: {
              qymc: [
                  { required: true, message: '请输入企业名称!'},
              ],
              lxr: [
                  { required: true, message: '请输入联系人!'},
              ],
              sjh: [
                  { required: true, message: '请输入手机号!'},
              ],
              wtlx: [
                  { required: true, message: '请输入问题类型!'},
              ],
              wtms: [
                  { required: true, message: '请输入问题描述!'},
              ],
          },
        url: {
          add: "/qcsb.qywtfk/qcQywtfk/add",
          edit: "/qcsb.qywtfk/qcQywtfk/edit",
          queryById: "/qcsb.qywtfk/qcQywtfk/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>