

const checkMagnification = (rule, value, callback) => {
  var reg = /^(-?\d+)(\.\d+)?$/
  if (!reg.test(value)) {
    // 如果校验失败，则返回
    callback(new Error('请填写浮点数'))
  }
}
const checkMaxDuration = (rule, value, callback) => {
  var reg = /^[1-9]\d*$/
  if (!reg.test(value)) {
    // 如果校验失败，则返回
    callback(new Error('请填写正整数'))
  }
}
export const tableOption = {
  "border": true,
  "index": true,
  "indexLabel": "序号",
  "stripe": true,
  "menuAlign": "center",
  "align": "center",
  "searchMenuSpan": 6,
  "column": [

    {
      "type": "select",
      "label": "场站编码",
      "prop": "stationCode",
      filterable: true,
      dicUrl: '/electricfield/all',
      cascader: ['equipmentId','equipmentAttributeId'],
      rules:[{ required: true, message: '请选择场站' }]
    }
    , {
      "type": "select",
      "label": "设备类型",
      "prop": "eqType",
      "dicData": [{value: 'POWERSTATION', label: '发电站'},
        {value: 'WEATHERSTATION', label: '气象站'},
        {value: 'INVERTER', label: '逆变器'},
        {value: 'WINDTOWER', label: '测风塔'},
        {value: 'WINDTURBINE', label: '风机'},
        {value: 'BOOSTERSTATION', label: '升压站'},
        {value: 'AGC_AVC', label: 'AGC_AVC'}],
      cascader: ['equipmentId','equipmentAttributeId'],
      rules:[{ required: true, message: '请选择设备类型' }]
    }
    , {
      "type": "select",
      "label": "设备名",
      "prop": "equipmentId",
      rules:[{ required: true, message: '请选择设备名'}]
      // dicUrl: `da/getEquipmentByType/{{stationCode}}/{{eqType}}`,
    }
    , {
      "type": "select",
      "label": "设备数据属性",
      "prop": "equipmentAttributeId",
      "labelWidth": '120',
      rules:[{ required: true, message: '请选择数据属性'}]
      // dicUrl: `da/getEquipmentAttributeByType/{{stationCode}}/{{eqType}}`,
    }
    , {
      "type": "input",
      "label": "倍率",
      "prop": "magnification",
      rules:[{ required: true, trigger: "blur",message: '请输入倍率', validator: checkMagnification }]
    }
    , {
      "type": "select",
      "label": "点位采集规则",
      "prop": "dataSource",
      "labelWidth": '120',
      value: 'GATHER',
      "dicData": [
        {value: 'GATHER', label: '外部接入'},
        {value: 'GENERATE', label: '公式生成'}],
      rules:[{ required: true, message: '请选择点位采集规则'}],
      change: (val) => {
        if (val.value != '') {
          if (val.value === 'GATHER') {
            tableOption.column[6].display = tableOption.column[7].display = true
            tableOption.column[6].rules[0].required = tableOption.column[7].rules[0].required = true
            tableOption.column[8].display = false
            tableOption.column[8].rules[0].required = false
          } else {
            tableOption.column[6].display = tableOption.column[7].display = false
            tableOption.column[6].rules[0].required = tableOption.column[7].rules[0].required = false
            tableOption.column[8].display = true
            tableOption.column[8].rules[0].required = true
          }
        }
      }
    }
    /***点位采集规则为外部接入显示以下列***/
    , {
      "type": "select",
      "label": "通道号",
      "prop": "tunnelId",
      rules:[{ required: true, message: '请选择通道号'}],
    }
    , {
      "type": "input",
      "label": "点位顺序",
      "prop": "tunnelPointNo",
      rules:[{ required: true, message: '请输入点位顺序',trigger: "blur"}],
    }
    /******/
    /***点位采集规则为公式生成接入显示以下列***/
    , {
      "type": "input",
      "label": "生成规则",
      "prop": "generationregulation",
      "labelWidth": '120',
      "span": 24,
      display: false
    }
    /******/
    , {
      "type": "select",
      "label": "数据类型",
      "prop": "tunnelDataType",
      rules:[{ required: true, message: '请选择数据类型'}],
    }
    , {
      "type": "select",
      "label": "是否在首页展示",
      "prop": "showOnHomePage",
      "labelWidth": '150',
      rules:[{ required: true, message: '请选择是否在首页展示'}],
    }
    , {
      "type": "select",
      "label": "是否需要数据合理性考核",
      "prop": "needAudit",
      "labelWidth": '180',
      "dicData": [
        {value: true, label: '是'},
        {value: false, label: '否'}],
      value: false,
      rules:[{ required: true, message: '请选择是否需要数据合理性考核'}],
      change: (val) => {
        if (val.value) {
          tableOption.column[12].display =  tableOption.column[13].display =  tableOption.column[14].display =  tableOption.column[15].display = true
          tableOption.column[12].rules[0].required = tableOption.column[13].rules[0].required =tableOption.column[14].rules[0].required =tableOption.column[15].rules[0].required = true
        } else {
          tableOption.column[12].display =  tableOption.column[13].display =  tableOption.column[14].display =  tableOption.column[15].display = false
          tableOption.column[12].rules[0].required = tableOption.column[13].rules[0].required =tableOption.column[14].rules[0].required =tableOption.column[15].rules[0].required = false
        }
      }
    }
    /***是否考核为是展示以下四列***/
    , {
      "type": "input",
      "label": "允许的最大变化值",
      "prop": "maxChangeValue",
      "labelWidth": '150',
      rules:[{ required: true, trigger: "blur",message: '请输入允许的最大变化值', validator: checkMagnification }],
      display: false
    }
    , {
      "type": "input",
      "label": "允许的最大值",
      "prop": "maxValue",
      "labelWidth": '120',
      rules:[{ required: true, trigger: "blur",message: '请输入允许的最大值', validator: checkMagnification }],
      display: false
    }
    , {
      "type": "input",
      "label": "允许的最小值",
      "prop": "minValue",
      "labelWidth": '120',
      rules:[{ required: true, trigger: "blur",message: '请输入允许的最小值', validator: checkMagnification }],
      display: false
    }
    , {
      "type": "input",
      "label": "允许数值不发生变化的最长时长(min) ",
      "placeholder": "当值为空时 说明不限制时长",
      "prop": "maxDuration",
      "labelWidth": '250',
      rules:[{ required: true, trigger: "blur",message: '请输入允许的最小值', validator: checkMaxDuration }],
      display: false
    }
  ],
}

