<template>
  <!-- 新增表号-功能号 -->
  <div id="addTabFunNum">
    <el-form :model='form' label-width="150px" ref="ruleForm" :rules="rules" style="height:500px;overflow:auto;">
      <el-form-item label="表号-功能号" prop="Id">
        <el-input v-model="form.Id"></el-input>
      </el-form-item>
      <el-form-item label="设定采集间隔时间" prop="intervalTime">
        <el-input v-model="form.intervalTime" placeholder="设定时间不能小于10s"></el-input>
      </el-form-item>
      <el-form-item label="值单位" prop="unit">
        <el-select v-model="form.unit" placeholder="请选择">
          <el-option v-for="item in options" :key="item.value" :label="item.label" :value="item.value"></el-option>
        </el-select>
      </el-form-item>
      <el-form-item label="取直公式" prop="formula">
        <el-input type="textarea" placeholder="请输入取值公式" v-model="form.formula"></el-input>
      </el-form-item>
      <el-form-item label="">
        <el-button type="primary" @click="add()">新增</el-button>
        <el-button @click="$emit('closeDrawer')">取消</el-button>
      </el-form-item>
    </el-form>
  </div>
</template>

<script>
import { mapGetters, mapActions } from 'vuex'
import {
  addTabFunNum
} from '@/api/point/request'
export default {
  data() {
    return {
      form: {
        Id: 'xx-xxx',//表号-功能号
        intervalTime: '',//采集间隔时间
        formula: 'xxxxxxxxxx',//取值公式
        unit: '',//值单位
      },
      //下拉框选项
      options: [
        {
          value: '选项1',
          label: '选项1'
        }, {
          value: '选项2',
          label: '选项2'
        },
      ],
      //验证规则
      rules: {
        Id: [
          { required: true, message: '请输入表号-功能号', trigger: 'blur' }
        ],
        intervalTime: [
          { required: true, message: '请输入采集间隔时间', trigger: 'blur' }
        ],
        formula: [
          { required: true, message: '请选择值单位', trigger: 'change' }
        ],
        unit: [
          { required: true, message: '请填写取直公式', trigger: 'blur' }
        ]
      }
    }
  },
  computed: {
    ...mapGetters('layout', ['projectId', 'userId'])
  },
  methods: {
    //添加
    add() {
      this.$refs.ruleForm.validate((valid) => {
        if (valid) {
          addTabFunNum(this.form, res => {

          });
        } else {
          console.log('error submit!!');
          return false;
        }
      });
    }
  }
}
</script>

<style lang="less" scoped>
</style>