<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="monitor">
        <el-select
          v-model="leakyCableForm.monitor"
          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="leakyCableCode">
        <el-input
          v-model="leakyCableForm.leakyCableCode"
          placeholder="请输入漏缆编号"
        />
      </el-form-item>
      <el-form-item label="漏缆描述：" prop="leakyCableDescribe">
        <el-input
          v-model="leakyCableForm.leakyCableDescribe"
          placeholder="请输入漏缆描述"
        />
      </el-form-item>

      <el-form-item label="漏缆型号：" prop="leakyCableMode">
        <el-input
          v-model="leakyCableForm.leakyCableMode"
          placeholder="请输入漏缆型号"
        />
      </el-form-item>
      <el-form-item label="漏缆长度：" prop="leakyCableLength">
        <el-input
          v-model="leakyCableForm.leakyCableLength"
          placeholder="请输入漏缆长度"
        />
      </el-form-item>
      <el-form-item label="漏缆百米损耗：" prop="hundredMetersLoss">
        <el-input
          v-model="leakyCableForm.hundredMetersLoss"
          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-item label="天馈线长度：" prop="antennaFeederLength">
        <el-input
          v-model="leakyCableForm.antennaFeederLength"
          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 { leakyCablesave } from "../../api";
import { mapGetters, mapActions } from "vuex";
import { successAlert, warningAlert } from "@/utils/alert";
export default {
  props: [],
  components: {},
  data() {
    return {
      railWaySelect: [],
      stationSelect2: [],
      fsuSelect2: [],
      monitor2: [],
      FSUrailway: [
        {
          key: 6,
          label: "张呼客运专线",
        },
        {
          key: 12,
          label: "南昆客运专线",
        },
      ],
      leakyCableForm: {
        wayId: "",
        siteId: "",
        fsuId: "",
        monitor: "",
        antennaFeederLength: 0,
        hundredMetersLoss: 0,
        inserterLength: 0,
        jumperLength: 0,
        leakyCableCode: "22",
        leakyCableDescribe: "打打",
        leakyCableLength: 0,
        leakyCableMode: "打打",
        parentId: 0,
        reductRatio: 0,
        sendPower: 0,
      },
      rules: {
        parentId: [
          { required: true, message: "请选择铁路线", trigger: "blur" },
        ],

        antennaFeederLength: [
          { required: true, message: "请输入天馈线长度", trigger: "blur" },
        ],
        hundredMetersLoss: [
          { required: true, message: "请输入漏缆百米损耗", trigger: "blur" },
        ],
        inserterLength: [
          { required: true, message: "请输入插入器长度", trigger: "blur" },
        ],
        jumperLength: [
          { required: true, message: "请输入跳线长度", trigger: "blur" },
        ],
        leakyCableCode: [
          { required: true, message: "请输入漏缆编号", trigger: "blur" },
        ],
        leakyCableDescribe: [
          { required: true, message: "请输入漏缆描述", trigger: "blur" },
        ],
        leakyCableLength: [
          { required: true, message: "请输入漏缆长度", trigger: "blur" },
        ],
        leakyCableMode: [
          {
            required: true,
            message: "请输入漏缆型号",
            trigger: "blur",
          },
        ],
        reductRatio: [
          {
            required: true,
            message: "请输入漏缆速度衰减系数",
            trigger: "blur",
          },
        ],
        sendPower: [
          {
            required: true,
            message: "请输入漏缆测试信号发射功率",
            trigger: "blur",
          },
        ],
      },
    };
  },
  computed: {
    ...mapGetters({
      railWaylist: "railWay/list",
      stationlist: "station/list",
      fsulist: "FSU/list",
      monitorEquiplist: "monitor/list",
    }),
  },
  methods: {
    ...mapActions({
      asyncrailWayList: "railWay/asyncList",
      asyncstationList: "station/asyncList",
      asyncfsuList: "FSU/asyncList",
      asyncmonitorList: "monitor/asyncList",
    }),
    changerailWay() {
      this.stationSelect2 = this.stationlist.filter(
        (item) => item.parentId === this.leakyCableForm.wayId
      );
    },
    changesite() {
      this.fsuSelect2 = this.fsulist.filter(
        (item) => item.parentId === this.leakyCableForm.siteId
      );
    },
    changefsu() {
      this.monitor2 = this.monitorEquiplist.filter(
        (item) => item.parentId === this.leakyCableForm.fsuId
      );
    },
    reset() {
      this.$refs.leakyCableForm.resetFields();
    },
    submit() {
      this.$refs.leakyCableForm.validate((valid) => {
        if (valid) {
          leakyCablesave(this.leakyCableForm).then((res) => {
            if (res.code == 200) {
              successAlert("添加成功");
            } else {
              warning("添加失败");
            }
          });
        }
        this.leakyCableForm = {
          parentId: "",
          siteId: "",
          fsuId: "",
          monitor: "",
          antennaFeederLength: 0,
          hundredMetersLoss: 0,
          inserterLength: 0,
          jumperLength: 0,
          leakyCableCode: "22",
          leakyCableDescribe: "打打",
          leakyCableLength: 0,
          leakyCableMode: "打打",
          parentId: 0,
          reductRatio: 0,
          sendPower: 0,
        };
      });
    },
  },
  mounted() {
    this.asyncrailWayList();
    this.asyncstationList();
    this.asyncfsuList();
    this.asyncmonitorList();

    this.railWaySelect = this.railWaylist;
  },
};
</script>
<style lang="scss" scoped>
.form {
  padding: 20px 0;
  width: 600px;
  margin: 0 auto;
}
.btn {
  padding-top: 50px;
  text-align: center;
  button {
    width: 120px;
  }
}
</style>