<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="woId">
              <a-input v-model="model.woId" placeholder="请输入工单id" :disabled="editdisabled"></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="报告编号" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="jihuaShiyanId">
              <j-search-select-tag v-model="model.jihuaShiyanId" dict="itdm_test_plan,report_no,id"  />
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="实绩设备" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="shijiShebeiId">
              <j-search-select-tag v-model="model.shijiShebeiId" dict="itdm_device,device_name,id"  />
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="实绩试验类型" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="shijiShiiyanType">
<!--              <a-input v-model="model.shijiShiiyanType" placeholder="请输入实绩试验类型"  ></a-input>-->
              <j-multi-select-tag type="list_multi" v-model="model.shijiShiiyanType" dictCode="shiiyan_type" placeholder="请选择实绩试验类型" />
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="任务日期" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="workDate">
              <j-date placeholder="请选择任务日期" v-model="model.workDate"  style="width: 100%" />
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="试验开始时间" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="startTime">
              <a-input v-model="model.startTime" placeholder="请输入试验开始时间"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="试验结束时间" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="endTime">
              <a-input v-model="model.endTime" placeholder="请输入试验结束时间"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="实绩任务日期" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="shijiWorkDate">
              <j-date placeholder="请选择实绩任务日期" v-model="model.shijiWorkDate"  style="width: 100%" />
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="实绩试验开始时间" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="shijiStartTime">
              <a-input v-model="model.shijiStartTime" placeholder="请输入实绩试验开始时间"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="实绩试验结束时间" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="shijiEndTime">
              <a-input v-model="model.shijiEndTime" 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-col :span="24">
            <a-form-model-item label="传感器" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="chuanganqi">
              <j-multi-select-tag type="list_multi" v-model="model.chuanganqi" dictCode="itdm_chuanganqi,xuliehao,id" placeholder="请选择传感器" />
            </a-form-model-item>
          </a-col>
<!--          <a-col :span="24">-->
<!--            <a-form-model-item label="传感器" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="chuanganqi">-->
<!--              <a-input v-model="model.chuanganqi" 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: 'ItdmGongdanDetailForm',
  components: {
  },
  props: {
    //表单禁用
    disabled: {
      type: Boolean,
      default: false,
      required: false
    },
    //禁止编辑
    editdisabled: {
      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: {
        woId: [
          { required: true, message: '请输入工单id!'},
        ],
        workDate: [
          { required: true, message: '请输入任务日期!'},
        ],
        startTime: [
          { required: true, message: '请输入试验开始时间!'},
        ],
        endTime: [
          { required: true, message: '请输入试验结束时间!'},
        ],
      },
      url: {
        add: "/itdmGongdanDetail/itdmGongdanDetail/add",
        edit: "/itdmGongdanDetail/itdmGongdanDetail/edit",
        queryById: "/itdmGongdanDetail/itdmGongdanDetail/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>