<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="iconClass">
              <j-search-select-tag v-model="model.iconClass" dict="common_icon_image,title,id"  />
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="图片" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="image">
              <j-image-upload isMultiple  v-model="model.image" ></j-image-upload>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="标题" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="title">
              <a-input v-model="model.title" placeholder="请输入标题"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="分类标识" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="classId">
              <j-search-select-tag v-model="model.classId" dict="common_class,title,id"  />
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="标签" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="iconTitle">
              <a-input v-model="model.iconTitle" placeholder="请输入标签"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="价格" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="price">
              <a-input-number v-model="model.price" placeholder="请输入价格" style="width: 100%" />
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <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="24">
            <a-form-model-item label="地址" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="address">
              <a-input v-model="model.address" placeholder="请输入地址"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="浏览量" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="num">
              <a-input-number v-model="model.num" placeholder="请输入浏览量" style="width: 100%" />
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="年限" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="timeGo">
              <a-input-number v-model="model.timeGo" placeholder="请输入年限" style="width: 100%" />
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="热点名称" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="iconName">
              <a-input v-model="model.iconName" placeholder="请输入热点名称"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="视频" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="homeMp4">
              <j-upload v-model="model.homeMp4"   ></j-upload>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="户型" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="homeType">
              <a-input v-model="model.homeType" placeholder="请输入户型"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="面积" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="homeMi">
              <a-input v-model="model.homeMi" placeholder="请输入面积"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="房屋结构" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="homeJg">
              <a-input v-model="model.homeJg" placeholder="请输入房屋结构"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="房屋编号" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="homeNo">
              <a-input v-model="model.homeNo" placeholder="请输入房屋编号"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="房屋周边" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="homeBian">
              <a-input v-model="model.homeBian" placeholder="请输入房屋周边"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="房间数量" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="homeNum">
              <a-input v-model="model.homeNum" placeholder="请输入房间数量"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="菜地" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="homeCai">
              <a-input v-model="model.homeCai" placeholder="请输入菜地"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="距离场镇距离" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="homeJl">
              <a-input v-model="model.homeJl" placeholder="请输入距离场镇距离"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="距离成都西三环" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="homeShjl">
              <a-input v-model="model.homeShjl" placeholder="请输入距离成都西三环"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="房屋主体是否改造" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="homeGz">
              <a-input v-model="model.homeGz" placeholder="请输入房屋主体是否改造"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="房屋面积" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="homeMj">
              <a-input v-model="model.homeMj" placeholder="请输入房屋面积"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="院子总面积" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="homeYzmj">
              <a-input v-model="model.homeYzmj" placeholder="请输入院子总面积"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="房屋朝向及海拔" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="homeHb">
              <a-input v-model="model.homeHb" placeholder="请输入房屋朝向及海拔"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="是否经过安置" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="homeAz">
              <a-input v-model="model.homeAz" placeholder="请输入是否经过安置"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="交通" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="homeJt">
              <a-input v-model="model.homeJt" placeholder="请输入交通"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="坟包及电塔 工厂噪音" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="homeZy">
              <a-input v-model="model.homeZy" placeholder="请输入坟包及电塔 工厂噪音"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="水电气网" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="homeSd">
              <a-input v-model="model.homeSd" placeholder="请输入水电气网"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="停车" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="homeCat">
              <a-input v-model="model.homeCat" placeholder="请输入停车"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="付款方式及押金" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="homePay">
              <a-input v-model="model.homePay" placeholder="请输入付款方式及押金"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="租期" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="homeTime">
              <a-input v-model="model.homeTime" placeholder="请输入租期"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="非正常死亡" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="homeSw">
              <a-input v-model="model.homeSw" placeholder="请输入非正常死亡"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="邻居对房东评价" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="homePj">
              <a-input v-model="model.homePj" placeholder="请输入邻居对房东评价"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="佣金" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="homeMoney">
              <a-input-number v-model="model.homeMoney" placeholder="请输入佣金" style="width: 100%" />
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="钥匙" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="homeYs">
              <a-input-number v-model="model.homeYs" placeholder="请输入钥匙" style="width: 100%" />
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="户主家庭职业" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="homeJtzy">
              <a-input v-model="model.homeJtzy" placeholder="请输入户主家庭职业"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="报建手续" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="homeBjsx">
              <a-input v-model="model.homeBjsx" placeholder="请输入报建手续"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="府市民云房屋信息档案查询" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="homeTf">
              <j-image-upload isMultiple  v-model="model.homeTf" ></j-image-upload>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="审核状态" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="status">
              <j-dict-select-tag type="list" v-model="model.status" dictCode="home_status" placeholder="请选择审核状态" />
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="户主年龄" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="homeAge">
              <a-input v-model="model.homeAge" placeholder="请输入户主年龄"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="产权证照片" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="homeImage">
              <j-image-upload isMultiple  v-model="model.homeImage" ></j-image-upload>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="备注" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="homeBz">
              <a-input v-model="model.homeBz" placeholder="请输入备注"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="用户" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="userId">
              <j-search-select-tag v-model="model.userId" dict="han_hai_member,nick_name,id"  />
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="经度" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="longitude">
              <a-input v-model="model.longitude" placeholder="请输入经度"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="纬度" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="latitude">
              <a-input v-model="model.latitude" placeholder="请输入纬度"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="地区标识" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="areaId">
              <j-search-select-tag v-model="model.areaId" dict="comm_city,title,id"  />
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="视频" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="mpVio">
              <j-upload v-model="model.mpVio"   ></j-upload>
            </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: 'CommonHomeForm',
    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: {
           status: [
              { required: true, message: '请输入审核状态!'},
           ],
        },
        url: {
          add: "/commonHome/commonHome/add",
          edit: "/commonHome/commonHome/edit",
          queryById: "/commonHome/commonHome/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>