<template>
  <el-dialog
    class="addtowerDialogline"
    title="新增杆塔"
    :visible.sync="isShow"
    :close-on-click-modal="false"
    width="420px"
    @close="handleclose"
  >
    <el-form
      label-position="left"
      label-width="92px"
      ref="formLineInfo"
      :rules="rules"
      :model="formdata"
    >
      <el-form-item label="线路名称：" prop="lineId">
        <el-input
          v-model="formdata.lineId"
          autocomplete="off"
          :disabled="true"
        ></el-input>
      </el-form-item>
      <el-form-item label="杆塔名称：" prop="towerName">
        <el-input v-model="formdata.towerName" autocomplete="off"></el-input>
      </el-form-item>
      <el-form-item label="杆塔地址：" prop="address">
        <el-input v-model="formdata.address" autocomplete="off"></el-input>
      </el-form-item>
    </el-form>

    <div slot="footer" class="dialog-footer">
      <el-button @click="isShow = false">取 消</el-button>
      <el-button type="primary" @click="submitForm()">确 定</el-button>
    </div>
  </el-dialog>
</template>
<script>
import { addTowerApi } from "@/utils/api/index";

export default {
  props: {
    lineDialogTitle: String,
  },

  data() {
    return {
      isShow: false,
      formdata: {},
      dyOptions: "",
      rules: {
        towerName: [
          {
            required: true,
            message: "请输入杆塔名称",
            trigger: "blur",
          },
        ],
        // address: [
        //   { required: true, message: "请输入杆塔地址", trigger: "blur" },
        // ],
      },
    };
  },
  methods: {
    //判断
    getdataform(val) {
      //this.formdata = val;
      this.formdata = JSON.parse(JSON.stringify(val));
      this.formdata.lineId = val.name;
    },
    // 保存确定操作
    submitForm() {
      this.$refs.formLineInfo.validate((valid) => {
        if (valid) {
          // 走保存请求

          addTowerApi({
            list: [
              {
                lineId: this.formdata.id,
                name: this.formdata.towerName,
                address: this.formdata.address,
              },
            ],
          })
            .then((res) => {
              if (res.code == 200) {
                this.$message({
                  duration: 1500,
                  showClose: true,
                  message: "新增杆塔成功",
                  type: "success",
                });
                this.$parent.lineList();
                this.isShow = false;
              } else {
                this.$message.error(res.msg);
              }
            })
            .catch((err) => {
              this.$message({
                duration: 1500,
                showClose: true,
                message: "添加失败",
                type: "error",
              });
            });
        } else {
          console.log("error submit!!");
          return false;
        }
      });
    },
    display() {
      this.isShow = true;
    },
    hide() {
      this.isShow = false;
    },
    handleclose() {
      this.$parent.lineList();
    },
  },

  created() {},
};
</script>
<style lang="less">
.addtowerDialogline {
  .el-select {
    width: 100%;
  }
}
</style>
