<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="传感器ID" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="sensorId">
              <a-input v-model="model.sensorId" placeholder="请输入传感器ID"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="状态 (0正常 1预警 2报警)" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="status">
              <a-input-number v-model="model.status" placeholder="请输入状态 (0正常 1预警 2报警)" style="width: 100%" />
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="报警字段名" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="statusname">
              <a-input v-model="model.statusname" placeholder="请输入报警字段名 逗号分隔"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="协议版本" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="data01">
              <a-input v-model="model.data01" placeholder="请输入协议版本"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="备注符号" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="data02">
              <a-input v-model="model.data02" placeholder="请输入备注符号"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="ANSII/binär" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="data03">
              <a-input v-model="model.data03" placeholder="请输入ANSII/binär"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="数据隔离符号" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="data05">
              <a-input v-model="model.data05" placeholder="请输入数据隔离符号"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="部件数据隔离符号" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="data06">
              <a-input v-model="model.data06" placeholder="请输入部件数据隔离符号"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="机床类型" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="data12">
              <a-input v-model="model.data12" placeholder="请输入机床类型"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="机床号码" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="data13">
              <a-input v-model="model.data13" placeholder="请输入机床号码"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="当前日期" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="data19">
              <a-input v-model="model.data19" placeholder="请输入当前日期"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="当前时间" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="data110">
              <a-input v-model="model.data110" placeholder="请输入当前时间"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="用户名称" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="data21">
              <a-input v-model="model.data21" placeholder="请输入用户名称"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="操作者姓名" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="data24">
              <a-input v-model="model.data24" placeholder="请输入操作者姓名"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="当前轮对识别号" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="data311">
              <a-input v-model="model.data311" placeholder="请输入当前轮对识别号"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="车辆编码" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="data313">
              <a-input v-model="model.data313" placeholder="请输入车辆编码"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="加工原因" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="data314n">
              <a-input v-model="model.data314n" placeholder="请输入加工原因"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="车辆方向" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="data34">
              <a-input v-model="model.data34" placeholder="请输入车辆方向"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="当前车辆车轴配置" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="data35">
              <a-input v-model="model.data35" placeholder="请输入当前车辆车轴配置"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="车辆号码" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="data38">
              <a-input v-model="model.data38" placeholder="请输入车辆号码"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="当前轮对号" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="data39">
              <a-input v-model="model.data39" placeholder="请输入当前轮对号"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="轮廓号码" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="data43sn">
              <a-input v-model="model.data43sn" placeholder="请输入轮廓号码"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="轮廓变量" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="data44sn">
              <a-input v-model="model.data44sn" placeholder="请输入轮廓变量"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="公里数" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="data55">
              <a-input v-model="model.data55" placeholder="请输入公里数"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="内侧距" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="data58n">
              <a-input v-model="model.data58n" placeholder="请输入内侧距"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="预测量左侧径向跳动" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="data611sn">
              <a-input v-model="model.data611sn" placeholder="请输入预测量左侧径向跳动"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="预测量右侧径向跳动" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="data612sn">
              <a-input v-model="model.data612sn" placeholder="请输入预测量右侧径向跳动"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="data661" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="data661">
              <a-input v-model="model.data661" placeholder="请输入data661"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="data662" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="data662">
              <a-input v-model="model.data662" placeholder="请输入data662"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="data68" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="data68">
              <a-input v-model="model.data68" placeholder="请输入data68"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="后测量左侧径向跳动" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="data6111sn">
              <a-input v-model="model.data6111sn" placeholder="请输入后测量左侧径向跳动"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="后测量右侧径向跳动" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="data6112sn">
              <a-input v-model="model.data6112sn" placeholder="请输入后测量右侧径向跳动"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="后测量左侧轴向跳动" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="data6121sn">
              <a-input v-model="model.data6121sn" placeholder="请输入后测量左侧轴向跳动"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="后测量右侧轴向跳动" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="data6122sn">
              <a-input v-model="model.data6122sn" placeholder="请输入后测量右侧轴向跳动"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="后测量左侧直径" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="data6131sn">
              <a-input v-model="model.data6131sn" placeholder="请输入后测量左侧直径"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="后测量右侧直径" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="data6132sn">
              <a-input v-model="model.data6132sn" placeholder="请输入后测量右侧直径"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="预测量左侧轴向跳动" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="data621sn">
              <a-input v-model="model.data621sn" placeholder="请输入预测量左侧轴向跳动"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="预测量右侧轴向跳动" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="data622sn">
              <a-input v-model="model.data622sn" placeholder="请输入预测量右侧轴向跳动"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="data731" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="data731">
              <a-input v-model="model.data731" placeholder="请输入data731"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="data732" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="data732">
              <a-input v-model="model.data732" placeholder="请输入data732"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="data741" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="data741">
              <a-input v-model="model.data741" placeholder="请输入data741"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="data742" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="data742">
              <a-input v-model="model.data742" placeholder="请输入data742"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="后测量左侧轮缘厚度" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="data7121sn">
              <a-input v-model="model.data7121sn" placeholder="请输入后测量左侧轮缘厚度"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="后测量右侧轮缘厚度" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="data7122sn">
              <a-input v-model="model.data7122sn" placeholder="请输入后测量右侧轮缘厚度"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="后测量左侧轮缘高度" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="data7131sn">
              <a-input v-model="model.data7131sn" placeholder="请输入后测量左侧轮缘高度"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="后测量右侧轮缘高度" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="data7132sn">
              <a-input v-model="model.data7132sn" placeholder="请输入后测量右侧轮缘高度"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="左侧名义轮缘厚度" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="data7211sn">
              <a-input v-model="model.data7211sn" placeholder="请输入左侧名义轮缘厚度"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="右侧名义轮缘厚度" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="data7212sn">
              <a-input v-model="model.data7212sn" placeholder="请输入右侧名义轮缘厚度"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="左侧轮廓测量点坐标" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="data7221sn">
              <a-input v-model="model.data7221sn" placeholder="请输入左侧轮廓测量点坐标"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="右侧轮廓测量点坐标" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="data7222sn">
              <a-input v-model="model.data7222sn" 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: 'BuZyExpDataOnlineForm',
    components: {
    },
    props: {
      //表单禁用
      disabled: {
        type: Boolean,
        default: false,
        required: false
      },
      queryType: {
        type: String,
        default: 'online'
      },
      queryMonth: {
        type: String,
        default: undefined
      }
    },
    data () {
      return {
        model:{
         },
        labelCol: {
          xs: { span: 24 },
          sm: { span: 5 },
        },
        wrapperCol: {
          xs: { span: 24 },
          sm: { span: 16 },
        },
        confirmLoading: false,
        validatorRules: {
        },
        url: {
          add: "/ZyExpDataOnline/buZyExpDataOnline/add",
          edit: "/ZyExpDataOnline/buZyExpDataOnline/edit",
          queryById: "/ZyExpDataOnline/buZyExpDataOnline/queryById"
        }
      }
    },
    computed: {
      formDisabled(){
        return this.disabled
      },
    },
    created () {
       //备份model原始值
      this.modelDefault = JSON.parse(JSON.stringify(this.model));
    },
    methods: {
      add () {
        this.edit(this.modelDefault);
      },
      edit (record, queryType, queryMonth) {
        this.model = Object.assign({}, record);
        this.visible = true;
        // Store the query type and month for use during submission
        this.currentQueryType = queryType;
        this.currentQueryMonth = queryMonth;
      },
      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';

              // If editing historical data, add query parameters
              if (this.currentQueryType === 'history' && this.currentQueryMonth) {
                httpurl += '?dataType=history&month=' + this.currentQueryMonth;
              }
            }

            console.log('准备提交编辑请求:', {url: httpurl, data: this.model, method: method});

            httpAction(httpurl,this.model,method).then((res)=>{
              console.log('收到编辑响应:', res);
              if(res.success){
                that.$message.success(res.message);
                that.$emit('ok');
              }else{
                that.$message.warning(res.message);
                console.error('编辑失败:', res);
              }
            }).catch((error) => {
              console.error('编辑请求异常:', error);
              that.$message.error('编辑请求异常: ' + (error.message || '网络错误'));
            }).finally(() => {
              that.confirmLoading = false;
            })
          }

        })
      },
    }
  }
</script>