<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="propertyName">
              <a-input v-model="model.propertyName" placeholder="请输入物业公司名称"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="统一信用代码" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="creditCode">
              <a-input v-model="model.creditCode" placeholder="请输入统一信用代码"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="法人姓名" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="legalName">
              <a-input v-model="model.legalName" placeholder="请输入法人姓名"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="注册资本" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="registCapital">
              <a-input-number v-model="model.registCapital" placeholder="请输入注册资本" style="width: 100%" />
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="联系人" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="contactName">
              <a-input v-model="model.contactName" placeholder="请输入联系人"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="联系电话" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="contactPhone">
              <a-input v-model="model.contactPhone" placeholder="请输入联系电话"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="注册地址" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="registAdress">
             <j-area-linkage type="cascader" v-model="model.registAdress" placeholder="请输入省市区"  />
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="详细地址" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="adressInfo">
              <a-input v-model="model.adressInfo" placeholder="请输入详细地址"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="集团logo" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="logoUrl">
              <a-input v-model="model.logoUrl" placeholder="请输入集团logo"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="集团介绍" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="groupInfo">
              <a-textarea v-model="model.groupInfo" rows="4" placeholder="请输入集团介绍" />
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="授权开始日期" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="empowerBeginDate">
              <j-date placeholder="请选择授权开始日期" v-model="model.empowerBeginDate"  style="width: 100%" />
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="授权结束日期" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="empowerEndDate">
              <j-date placeholder="请选择授权结束日期" v-model="model.empowerEndDate"  style="width: 100%" />
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="收费标准id" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="chargingStandardId">
              <j-dict-select-tag type="list" v-model="model.chargingStandardId" dictCode="" placeholder="请选择收费标准id" />
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="合同附件" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="contractUrl">
              <j-upload v-model="model.contractUrl"   ></j-upload>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="删除状态(0-正常,1-已删除)" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="delFlag">
              <a-input-number v-model="model.delFlag" placeholder="请输入删除状态(0-正常,1-已删除)" style="width: 100%" />
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="试用小区数量" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="ontrialCommunityNum">
              <a-input-number v-model="model.ontrialCommunityNum" placeholder="请输入试用小区数量" style="width: 100%" />
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="试用开始日期" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="ontrialBeginDate">
              <j-date placeholder="请选择试用开始日期" v-model="model.ontrialBeginDate"  style="width: 100%" />
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="试用结束日期" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="ontrialEndDate">
              <j-date placeholder="请选择试用结束日期" v-model="model.ontrialEndDate"  style="width: 100%" />
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="管理员登录账号" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="adminLoginName">
              <a-input v-model="model.adminLoginName" placeholder="请输入管理员登录账号"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="管理员登录密码" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="adminPassword">
              <a-input-password v-model="model.adminPassword" 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: 'PropertySettledForm',
    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: {
           adminLoginName: [
              { required: false},
              { validator: (rule, value, callback) => validateDuplicateValue('property_settled', 'admin_login_name', value, this.model.id, callback)},
           ],
        },
        url: {
          add: "/property/propertySettled/add",
          edit: "/property/propertySettled/edit",
          queryById: "/property/propertySettled/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>