<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="serverName">-->
<!--              <a-input v-model="model.serverName" placeholder="请输入上传服务名"  ></a-input>-->
<!--            </a-form-model-item>-->
<!--          </a-col>-->
<!--          <a-col :span="24">-->
<!--            <a-form-model-item label="编号" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="code">-->
<!--              <a-input-number v-model="model.code" placeholder="请输入编号" style="width: 100%" />-->
<!--            </a-form-model-item>-->
<!--          </a-col>-->
<!--          <a-col :span="24">-->
<!--            <a-form-model-item label="PM2.5" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="pm25">-->
<!--              <a-input-number v-model="model.pm25" placeholder="请输入PM2.5" style="width: 100%" />-->
<!--            </a-form-model-item>-->
<!--          </a-col>-->
<!--          <a-col :span="24">-->
<!--            <a-form-model-item label="PM10" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="pm10">-->
<!--              <a-input-number v-model="model.pm10" placeholder="请输入PM10" style="width: 100%" />-->
<!--            </a-form-model-item>-->
<!--          </a-col>-->
<!--          <a-col :span="24">-->
<!--            <a-form-model-item label="温度" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="humidity">-->
<!--              <a-input-number v-model="model.humidity" placeholder="请输入温度" style="width: 100%" />-->
<!--            </a-form-model-item>-->
<!--          </a-col>-->
<!--          <a-col :span="24">-->
<!--            <a-form-model-item label="湿度" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="temperature">-->
<!--              <a-input-number v-model="model.temperature" placeholder="请输入湿度" style="width: 100%" />-->
<!--            </a-form-model-item>-->
<!--          </a-col>-->
<!--          <a-col :span="24">-->
<!--            <a-form-model-item label="大气压力" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="pressure">-->
<!--              <a-input-number v-model="model.pressure" placeholder="请输入大气压力" style="width: 100%" />-->
<!--            </a-form-model-item>-->
<!--          </a-col>-->
<!--          <a-col :span="24">-->
<!--            <a-form-model-item label="光照度" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="illuminance">-->
<!--              <a-input-number v-model="model.illuminance" placeholder="请输入光照度" style="width: 100%" />-->
<!--            </a-form-model-item>-->
<!--          </a-col>-->
<!--          <a-col :span="24">-->
<!--            <a-form-model-item label="UV线电压" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="tvoc">-->
<!--              <a-input-number v-model="model.tvoc" placeholder="请输入UV线电压" style="width: 100%" />-->
<!--            </a-form-model-item>-->
<!--          </a-col>-->
<!--          <a-col :span="24">-->
<!--            <a-form-model-item label="二氧化碳" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="co2">-->
<!--              <a-input-number v-model="model.co2" placeholder="请输入二氧化碳" style="width: 100%" />-->
<!--            </a-form-model-item>-->
<!--          </a-col>-->
<!--          <a-col :span="24">-->
<!--            <a-form-model-item label="甲醛" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="hcho">-->
<!--              <a-input-number v-model="model.hcho" placeholder="请输入甲醛" style="width: 100%" />-->
<!--            </a-form-model-item>-->
<!--          </a-col>-->
<!--          <a-col :span="24">-->
<!--            <a-form-model-item label="臭氧" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="o3">-->
<!--              <a-input-number v-model="model.o3" placeholder="请输入臭氧" style="width: 100%" />-->
<!--            </a-form-model-item>-->
<!--          </a-col>-->
          <a-col :span="24">
            <a-form-model-item label="氧气" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="o2">
              <a-input-number v-model="model.o2" placeholder="请输入氧气" style="width: 100%" />
            </a-form-model-item>
          </a-col>
<!--          <a-col :span="24">-->
<!--            <a-form-model-item label="硫化氢" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="h2s">-->
<!--              <a-input-number v-model="model.h2s" placeholder="请输入硫化氢" style="width: 100%" />-->
<!--            </a-form-model-item>-->
<!--          </a-col>-->
          <a-col :span="24">
            <a-form-model-item label="可燃气体" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="ch4">
              <a-input-number v-model="model.ch4" placeholder="请输入可燃气体" style="width: 100%" />
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="一氧化碳" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="co">
              <a-input-number v-model="model.co" placeholder="请输入一氧化碳" style="width: 100%" />
            </a-form-model-item>
          </a-col>
<!--          <a-col :span="24">-->
<!--            <a-form-model-item label="二氧化碳" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="no2">-->
<!--              <a-input-number v-model="model.no2" placeholder="请输入二氧化碳" style="width: 100%" />-->
<!--            </a-form-model-item>-->
<!--          </a-col>-->
<!--          <a-col :span="24">-->
<!--            <a-form-model-item label="二氧化硫" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="so2">-->
<!--              <a-input-number v-model="model.so2" placeholder="请输入二氧化硫" style="width: 100%" />-->
<!--            </a-form-model-item>-->
<!--          </a-col>-->
<!--          <a-col :span="24">-->
<!--            <a-form-model-item label="氢气" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="h2">-->
<!--              <a-input-number v-model="model.h2" placeholder="请输入氢气" style="width: 100%" />-->
<!--            </a-form-model-item>-->
<!--          </a-col>-->
<!--          <a-col :span="24">-->
<!--            <a-form-model-item label="氨气" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="nh3">-->
<!--              <a-input-number v-model="model.nh3" placeholder="请输入氨气" style="width: 100%" />-->
<!--            </a-form-model-item>-->
<!--          </a-col>-->
<!--          <a-col :span="24">-->
<!--            <a-form-model-item label="噪声" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="noise">-->
<!--              <a-input-number v-model="model.noise" placeholder="请输入噪声" style="width: 100%" />-->
<!--            </a-form-model-item>-->
<!--          </a-col>-->
<!--          <a-col :span="24">-->
<!--            <a-form-model-item label="异味" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="odor">-->
<!--              <a-input-number v-model="model.odor" placeholder="请输入异味" style="width: 100%" />-->
<!--            </a-form-model-item>-->
<!--          </a-col>-->
<!--          <a-col :span="24">-->
<!--            <a-form-model-item label="TSP总悬浮微粒" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="tsp">-->
<!--              <a-input-number v-model="model.tsp" placeholder="请输入TSP总悬浮微粒" style="width: 100%" />-->
<!--            </a-form-model-item>-->
<!--          </a-col>-->
<!--          <a-col :span="24">-->
<!--            <a-form-model-item label="烟雾" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="smoke">-->
<!--              <a-input-number v-model="model.smoke" placeholder="请输入烟雾" style="width: 100%" />-->
<!--            </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: 'BuAirQualityForm',
    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: "/energy/buAirQuality/add",
          edit: "/energy/buAirQuality/edit",
          queryById: "/energy/buAirQuality/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>