<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="createBy">
              <a-input v-model="model.createBy" placeholder="请输入创建人"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="创建时间" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="createTime">
              <j-date placeholder="请选择创建时间" v-model="model.createTime"  style="width: 100%" />
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="电站名称" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="stationName">
              <a-input v-model="model.stationName" placeholder="请输入电站名称"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="电站id" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="stationId">
              <j-dict-select-tag type="list" v-model="model.stationId" dictCode="station_code" placeholder="请选择电站id" />
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="城市" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="city">
              <a-input v-model="model.city" placeholder="请输入城市"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="一月" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="sunshineTimeJanuary">
              <a-input v-model="model.sunshineTimeJanuary" placeholder="请输入一月"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="二月" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="sunshineTimeFebruary">
              <a-input v-model="model.sunshineTimeFebruary" placeholder="请输入二月"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="三月" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="sunshineTimeMarch">
              <a-input v-model="model.sunshineTimeMarch" placeholder="请输入三月"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="四月" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="sunshineTimeApril">
              <a-input v-model="model.sunshineTimeApril" placeholder="请输入四月"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="五月" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="sunshineTimeMay">
              <a-input v-model="model.sunshineTimeMay" placeholder="请输入五月"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="六月" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="sunshineTimeJune">
              <a-input v-model="model.sunshineTimeJune" placeholder="请输入六月"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="七月" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="sunshineTimeJuly">
              <a-input v-model="model.sunshineTimeJuly" placeholder="请输入七月"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="八月" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="sunshineTimeAugust">
              <a-input v-model="model.sunshineTimeAugust" placeholder="请输入八月"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="九月" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="sunshineTimeSeptember">
              <a-input v-model="model.sunshineTimeSeptember" placeholder="请输入九月"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="十月" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="sunshineTimeOctober">
              <a-input v-model="model.sunshineTimeOctober" placeholder="请输入十月"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="十一月" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="sunshineTimeNovember">
              <a-input v-model="model.sunshineTimeNovember" placeholder="请输入十一月"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="十二月" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="sunshineTimeDecember">
              <a-input v-model="model.sunshineTimeDecember" placeholder="请输入十二月"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="备注" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="remark">
              <a-input v-model="model.remark" 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: 'StationSunshineTimeSettingForm',
    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: {
           createBy: [
              { required: true, message: '请输入创建人!'},
           ],
           createTime: [
              { required: true, message: '请输入创建时间!'},
           ],
           stationName: [
              { required: true, message: '请输入电站名称!'},
           ],
           stationId: [
              { required: true, message: '请输入电站id!'},
           ],
           city: [
              { required: true, message: '请输入城市!'},
           ],
           sunshineTimeJanuary: [
              { required: true, message: '请输入一月!'},
           ],
           sunshineTimeFebruary: [
              { required: true, message: '请输入二月!'},
           ],
           sunshineTimeMarch: [
              { required: true, message: '请输入三月!'},
           ],
           sunshineTimeApril: [
              { required: true, message: '请输入四月!'},
           ],
           sunshineTimeMay: [
              { required: true, message: '请输入五月!'},
           ],
           sunshineTimeJune: [
              { required: true, message: '请输入六月!'},
           ],
           sunshineTimeJuly: [
              { required: true, message: '请输入七月!'},
           ],
           sunshineTimeAugust: [
              { required: true, message: '请输入八月!'},
           ],
           sunshineTimeSeptember: [
              { required: true, message: '请输入九月!'},
           ],
           sunshineTimeOctober: [
              { required: true, message: '请输入十月!'},
           ],
           sunshineTimeNovember: [
              { required: true, message: '请输入十一月!'},
           ],
           sunshineTimeDecember: [
              { required: true, message: '请输入十二月!'},
           ],
        },
        url: {
          add: "/station/stationSunshineTimeSetting/add",
          edit: "/station/stationSunshineTimeSetting/edit",
          queryById: "/station/stationSunshineTimeSetting/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>