<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="执行器主键ID" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="jobGroup">
              <a-input-number v-model="model.jobGroup" placeholder="请输入执行器主键ID" style="width: 100%" />
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="任务，主键ID" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="jobId">
              <a-input-number v-model="model.jobId" placeholder="请输入任务，主键ID" style="width: 100%" />
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="jobDesc" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="jobDesc">
              <a-input v-model="model.jobDesc" placeholder="请输入jobDesc"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="执行器地址，本次执行的地址" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="executorAddress">
              <a-input v-model="model.executorAddress" placeholder="请输入执行器地址，本次执行的地址"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="执行器任务handler" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="executorHandler">
              <a-input v-model="model.executorHandler" placeholder="请输入执行器任务handler"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="执行器任务参数" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="executorParam">
              <a-input v-model="model.executorParam" placeholder="请输入执行器任务参数"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="执行器任务分片参数，格式如 1/2" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="executorShardingParam">
              <a-input v-model="model.executorShardingParam" placeholder="请输入执行器任务分片参数，格式如 1/2"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="失败重试次数" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="executorFailRetryCount">
              <a-input-number v-model="model.executorFailRetryCount" placeholder="请输入失败重试次数" style="width: 100%" />
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="调度-时间" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="triggerTime">
              <j-date placeholder="请选择调度-时间" v-model="model.triggerTime"  style="width: 100%" />
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="调度-结果" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="triggerCode">
              <a-input-number v-model="model.triggerCode" placeholder="请输入调度-结果" style="width: 100%" />
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="调度-日志" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="triggerMsg">
              <a-textarea v-model="model.triggerMsg" rows="4" placeholder="请输入调度-日志" />
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="执行-时间" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="handleTime">
              <j-date placeholder="请选择执行-时间" v-model="model.handleTime"  style="width: 100%" />
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="执行-状态" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="handleCode">
              <a-input-number v-model="model.handleCode" placeholder="请输入执行-状态" style="width: 100%" />
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="执行-日志" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="handleMsg">
              <a-textarea v-model="model.handleMsg" rows="4" placeholder="请输入执行-日志" />
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="告警状态：0-默认、1-无需告警、2-告警成功、3-告警失败" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="alarmStatus">
              <a-input-number v-model="model.alarmStatus" placeholder="请输入告警状态：0-默认、1-无需告警、2-告警成功、3-告警失败" style="width: 100%" />
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="datax进程Id" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="processId">
              <a-input v-model="model.processId" placeholder="请输入datax进程Id"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="增量表max id" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="maxId">
              <a-input-number v-model="model.maxId" placeholder="请输入增量表max id" 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: 'LogDataXJobForm',
    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: {
           jobGroup: [
              { required: true, message: '请输入执行器主键ID!'},
           ],
           jobId: [
              { required: true, message: '请输入任务，主键ID!'},
           ],
           triggerCode: [
              { required: true, message: '请输入调度-结果!'},
           ],
           handleCode: [
              { required: true, message: '请输入执行-状态!'},
           ],
           alarmStatus: [
              { required: true, message: '请输入告警状态：0-默认、1-无需告警、2-告警成功、3-告警失败!'},
           ],
        },
        url: {
          add: "/logDataXJob/logDataXJob/add",
          edit: "/logDataXJob/logDataXJob/edit",
          queryById: "/logDataXJob/logDataXJob/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>