<template>
  <div class="add">
    <div class="add-tab">
      <el-tabs v-model="activeName" :stretc="true">
        <el-tab-pane
          v-for="item in tabs"
          :key="item.key"
          :label="item.label"
          :name="item.key"
        />
      </el-tabs>
    </div>
    <div class="content">
      <div class="content-title">添加铁路信息</div>
      <el-form
        ref="form"
        :model="formData"
        :rules="rules"
        label-width="200px"
        class="form"
      >
        <el-form-item label="铁路名：" prop="name">
          <el-input v-model="formData.name" placeholder="请输入铁路名" />
        </el-form-item>
        <el-form-item label="铁路线起点站名：" prop="start">
          <el-input
            v-model="formData.start"
            placeholder="请输入铁路线起点站名："
          />
        </el-form-item>
        <el-form-item label="铁路线终点站名：" prop="end">
          <el-input v-model="formData.end" placeholder="请输入铁路线终点站名" />
        </el-form-item>
        <el-form-item label="铁路全长（公里）：" prop="long">
          <el-input
            v-model="formData.long"
            placeholder="请输入铁路全长公里数"
          />
        </el-form-item>
      </el-form>
    </div>
    <div class="btn">
      <el-button type="primary" @click="reset">重置</el-button>
      <el-button type="primary" @click="submit">确认提交</el-button>
    </div>
  </div>
</template>

<script>
export default {
  data() {
    return {
      activeName: '0',
      tabs: [
        {
          label: '铁路线',
          key: '0'
        },
        {
          label: '站点',
          key: '1'
        },
        {
          label: 'FSU',
          key: '2'
        },
        {
          label: '监测设备',
          key: '3'
        },
        {
          label: '漏缆',
          key: '4'
        },
        {
          label: '天馈线',
          key: '5'
        }
      ],
      formData: {
        name: '',
        start: '',
        end: '',
        long: ''
      },
      rules: {
        name: [
          { required: true, message: '请输入铁路名', trigger: 'blur' }
          // { min: 3, max: 5, message: '长度在 3 到 5 个字符', trigger: 'blur' }
        ],
        start: [
          { required: true, message: '请输入铁路线起点站名', trigger: 'blur' }
        ],
        end: [
          { required: true, message: '请输入铁路线终点站名', trigger: 'blur' }
        ],
        long: [
          { required: true, message: '请输入铁路全长公里数', trigger: 'blur' }
        ]
      }
    }
  },
  methods: {
    reset() {
      this.$refs.form.resetFields()
    },
    submit() {
      this.$refs.form.validate((valid) => {
        if (valid) {
          console.log(this.formData)
        }
      })
    }
  }
}
</script>

<style lang="scss" scoped>
::v-deep .el-tabs__nav {
  display: flex;
  width: 100%;
  padding-bottom: 10px;
  .el-tabs__item {
    flex: 1;
    text-align: center;
    font-size: 18px;
    color: #666;
  }
  .el-tabs__item.is-active {
    color: #1e64f6;
  }
  .el-tabs__active-bar {
    background-color: #1e64f6;
  }
}
.add {
  padding: 10px;
  .tab {
    // width: 600px;
    margin: 0 auto;
  }
  .content {
    border: 1px solid #e3e3e3;
    border-radius: 10px;
    .content-title {
      width: 100%;
      height: 60px;
      background: rgba(226, 235, 255, 0.39);
      line-height: 60px;
      font-size: 18px;
      color: #333;
      font-weight: 500;
      text-align: center;
      border-bottom: 1px solid #e3e3e3;
    }
    .form {
      padding: 20px 0;
      width: 600px;
      margin: 0 auto;
    }
  }
  .btn {
    padding-top: 50px;
    text-align: center;
    button {
      width: 120px;
    }
  }
}
</style>
