<template>
  <div>
    <div class="item"
      style="margin-bottom: 25px;">
      <span class="item_title">FTP 服务:</span>
      <el-switch class="item_content"
        v-model="config.conf.ftptype"
        active-color="#13ce66"
        inactive-color="#ff4949"
        active-value="on"
        inactive-value="off">
      </el-switch>
    </div>

    <el-row>
      <el-col :span="12">
        <div class="item">
          <span class="item_title">FTP 地址:</span>
          <el-input placeholder="请输入 NTRSer 地址"
            v-model="config.conf.ftpserverip"
            clearable
            class="item_content">
          </el-input>
          <span v-if="!isValidIP"
            style="color: red;"
            class="warn_text">FTP 地址格式不正确</span>
        </div>
      </el-col>
      <el-col :span="12">
        <div class="item">
          <span class="item_title">FTP 端口号:</span>
          <el-input placeholder="请输入端口号"
            v-model="config.conf.ftpserverport"
            clearable
            class="item_content">
          </el-input>
        </div>
      </el-col>
    </el-row>

    <el-row>
      <el-col :span="12">
        <div class="item">
          <span class="item_title">用户名:</span>
          <el-input placeholder="请输入用户名"
            v-model="config.conf.ftpuser"
            clearable
            class="item_content">
          </el-input>
        </div>
      </el-col>
      <el-col :span="12">
        <div class="item">
          <span class="item_title">密码:</span>
          <el-input placeholder="请输入密码"
            v-model="config.conf.ftppasswd"
            clearable
            class="item_content">
          </el-input>
        </div>
      </el-col>
    </el-row>

    <div class="item">
      <span class="item_title">上传间隔(min):</span>
      <el-input placeholder="请输入密码"
        v-model="config.conf.ftptint"
        clearable
        class="item_content">
      </el-input>
    </div>
  </div>
</template>
<script>
export default {
  props: {
    config: []
  },
  computed: {
    // 计算属性来检查 IP 地址格式是否正确
    isValidIP() {
      const ip = this.config.conf.ftpserverip;
      if (!ip) {
        return true
      }

      const ipPattern = /^((25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3}(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)$/;
      return ipPattern.test(ip);
    },
  }
}
</script>
<style scoped>
.item {
  margin-bottom: 10px;
  display: flex;
  align-items: center;
}

.item_title {
  width: 120px;
  text-align: right;
}

.item_content {
  margin-left: 15px;
  width: 200px;
}

.warn_text {
  color: red;
  font-size: 15px;
  margin-left: 15px;
}
</style>
