<template>
  <div>
    <el-form
      ref="leakyCableForm"
      :model="leakyCableForm"
      :rules="rules"
      label-width="200px"
      class="form"
    >
      <el-form-item label="所在铁路线：" prop="wayId">
        <el-select
          v-model="leakyCableForm.wayId"
          placeholder="请选择铁路线"
          @change="changerailWay()"
        >
          <el-option
            v-for="item in railWaySelect"
            :key="item.id"
            :label="item.name"
            :value="item.id"
          ></el-option>
        </el-select>
      </el-form-item>
      <el-form-item label="所在站点：" prop="siteId">
        <el-select
          v-model="leakyCableForm.siteId"
          placeholder="请选择站点"
          @change="changesite()"
        >
          <el-option
            v-for="item in stationSelect2"
            :key="item.id"
            :label="item.siteName"
            :value="item.id"
          ></el-option>
        </el-select>
      </el-form-item>
      <el-form-item label="所在FSU：" prop="fsuId">
        <el-select
          v-model="leakyCableForm.fsuId"
          placeholder="请选择FSU"
          @change="changefsu()"
        >
          <el-option
            v-for="item in fsuSelect2"
            :key="item.id"
            :label="item.equipName"
            :value="item.id"
          ></el-option>
        </el-select>
      </el-form-item>
      <el-form-item label="所在监测设备：" prop="equipId">
        <el-select
          v-model="leakyCableForm.equipId"
          placeholder="请选择监测设备"
        >
          <el-option
            v-for="item in monitor2"
            :key="item.id"
            :label="item.equipName"
            :value="item.id"
          ></el-option>
        </el-select>
      </el-form-item>
      <el-form-item label="天馈线编号：" prop="feederCode">
        <el-input
          v-model="leakyCableForm.feederCode"
          placeholder="请输入天馈线编号"
        />
      </el-form-item>
      <el-form-item label="天馈线描述：" prop="feederDescribe">
        <el-input
          v-model="leakyCableForm.feederDescribe"
          placeholder="请输入天馈线描述"
        />
      </el-form-item>

      <el-form-item label="天馈线型号：" prop="feederModel">
        <el-input
          v-model="leakyCableForm.feederModel"
          placeholder="请输入天馈线型号"
        />
      </el-form-item>
      <el-form-item label="天馈线长度：" prop="feederLength">
        <el-input
          v-model="leakyCableForm.feederLength"
          placeholder="请输入天馈线长度"
        />
      </el-form-item>
      <el-form-item label="天馈线百米损耗：" prop="feederLossMeters">
        <el-input
          v-model="leakyCableForm.feederLossMeters"
          placeholder="请输入天馈线百米损耗"
        />
      </el-form-item>
      <el-form-item label="天馈线速度衰减系数：" prop="reductRatio">
        <el-input
          v-model="leakyCableForm.reductRatio"
          placeholder="请输入天馈线速度衰减系数"
        />
      </el-form-item>
      <el-form-item label="天馈线测试信号发射功率：" prop="sendPower">
        <el-input
          v-model="leakyCableForm.sendPower"
          placeholder="请输入天馈线测试信号发射功率"
        />
      </el-form-item>
      <el-form-item label="跳线长度：" prop="jumperLength">
        <el-input
          v-model="leakyCableForm.jumperLength"
          placeholder="请输入跳线长度"
        />
      </el-form-item>
      <el-form-item label="插入器长度：" prop="inserterLength">
        <el-input
          v-model="leakyCableForm.inserterLength"
          placeholder="请输入插入器长度"
        />
      </el-form-item>
    </el-form>
    <div class="btn">
      <el-button type="primary" @click="reset">重置</el-button>
      <el-button type="primary" @click="submit">确认提交</el-button>
    </div>
  </div>
</template>
<script>
import {
  antennaFeederSave,
  selectForSite,
  selectForFsu,
  selectForEquip,
  railWaylist,
} from "../../api";
import { successAlert, warningAlert } from "@/utils/alert";
export default {
  props: [],
  components: {},
  data() {
    return {
      railWaySelect: [],
      stationSelect2: [],
      fsuSelect2: [],
      monitor2: [],
      FSUrailway: [],
      leakyCableForm: formInit(),
      params: {
        current: 1,
        size: 10,
      },
      rules: {
        wayId: [{ required: true, message: "请选择铁路线", trigger: "blur" }],
        siteId: [{ required: true, message: "请选择站点", trigger: "blur" }],
        fsuId: [{ required: true, message: "请选择FSU", trigger: "blur" }],
        equipId: [
          { required: true, message: "请选择监测设备", trigger: "blur" },
        ],
        feederLength: [
          { required: true, message: "请输入天馈线长度", trigger: "blur" },
        ],
        // feederLossMeters: [
        //   { required: true, message: "请输入天馈线百米损耗", trigger: "blur" },
        // ],
        inserterLength: [
          { required: true, message: "请输入插入器长度", trigger: "blur" },
        ],
        jumperLength: [
          { required: true, message: "请输入跳线长度", trigger: "blur" },
        ],
        feederCode: [
          { required: true, message: "请输入天馈线编号", trigger: "blur" },
        ],
        feederDescribe: [
          { required: true, message: "请输入天馈线描述", trigger: "blur" },
        ],
        feederModel: [
          {
            required: true,
            message: "请输入天馈线型号",
            trigger: "blur",
          },
        ],
        reductRatio: [
          {
            required: true,
            message: "请输入天馈线速度衰减系数",
            trigger: "blur",
          },
        ],
        sendPower: [
          {
            required: true,
            message: "请输入天馈线测试信号发射功率",
            trigger: "blur",
          },
        ],
      },
    };
  },
  computed: {},
  methods: {
    changerailWay() {
      selectForSite({ wayId: this.leakyCableForm.wayId }).then((res) => {
        this.stationSelect2 = res;
      });
    },
    changesite() {
      selectForFsu({ siteId: this.leakyCableForm.siteId }).then((res) => {
        this.fsuSelect2 = res;
      });
    },
    changefsu() {
      selectForEquip({ fsuId: this.leakyCableForm.fsuId }).then((res) => {
        this.monitor2 = res;
      });
    },
    reset() {
      this.$refs.leakyCableForm.resetFields();
    },
    submit() {
      this.$refs.leakyCableForm.validate((valid) => {
        if (valid) {
          antennaFeederSave(this.leakyCableForm).then((res) => {
            if (res.code == 200) {
              successAlert("添加成功");
            } else {
              warningAlert("添加失败");
            }
          });
        }
        this.leakyCableForm = formInit();
      });
    },
    getAllWay() {
      railWaylist(this.params).then((res) => {
        this.railWaySelect = res.records;
        if (res.total > this.params.size) {
          this.params.size = res.total;
          this.getAllWay();
        }
      });
    },
  },
  mounted() {
    this.getAllWay();
  },
};
function formInit(data = {}) {
  return {
    parentId: "",
    siteId: "",
    fsuId: "",
    equipId: "",
    feederLossMeters: "",
    inserterLength: 0,
    jumperLength: 0,
    feederCode: "",
    feederDescribe: "",
    feederLength: 0,
    feederModel: "",
    parentId: 0,
    reductRatio: 0,
    sendPower: 0,
    ...data,
  };
}
</script>
<style lang="scss" scoped>
.form {
  padding: 20px 0;
  width: 600px;
  margin: 0 auto;
}
.btn {
  padding: 20px 0 50px 0;
  text-align: center;
}
</style>
