<template>
  <div class="global-variable">
    <div class="condition">
      <el-form :inline="true" :model="formInline" class="demo-form-inline">
        <el-form-item label="测风塔名称:">
          <el-input
            v-model="formInline.user"
            placeholder="请输入批次编号"
            size="small"
          ></el-input>
        </el-form-item>
        <el-form-item label="选择日期:" size="small">
          <el-date-picker
            v-model="formInline.timeQuantum"
            type="daterange"
            range-separator="至"
            start-placeholder="开始日期"
            end-placeholder="结束日期"
          >
          </el-date-picker>
        </el-form-item>
        <el-form-item>
          <el-button type="primary" @click="onSubmit" size="small"
            >查询</el-button
          >
          <el-button @click="reset" size="small">重置</el-button>
        </el-form-item>
      </el-form>
    </div>
    <div class="list-page">
      <div class="newly">
        <el-button type="primary" @click="newnuedialog" size="small"
          >新增</el-button
        >
      </div>

      <el-table
        class="center-align-table"
        :data="tableData"
        border
        :cell-style="rowStyle"
      >
        <el-table-column align="center" fixed prop="" label="测风塔名称">
          <template slot-scope="scope">
            <el-button @click="particulars(scope.row)" type="text" size="small"
              >泗洪风场</el-button
            >
          </template>
        </el-table-column>

        <el-table-column align="center" label="测风塔编号"> </el-table-column>

        <el-table-column prop="" align="center" label="机型类型">
        </el-table-column>
        <el-table-column prop="" align="center" label="经度" width="100">
        </el-table-column>

        <el-table-column prop="" align="center" label="纬度" width="100">
        </el-table-column>
        <el-table-column prop="" align="center" label="状态" width="100">
        </el-table-column>
        <el-table-column prop="" align="center" label="创建时间">
        </el-table-column>
        <el-table-column
          prop="transition"
          align="center"
          fixed="right"
          label="操作"
          width="200"
        >
          <template slot-scope="scope">
            <el-button @click="compile(scope.row)" type="text" size="small"
              >编辑</el-button
            >

            <el-button
              v-if="scope.row.transition == 1"
              @click="start(scope.row)"
              type="text"
              size="small"
              >启用</el-button
            >
            <el-button
              v-else
              style="color: #666"
              @click="stop(scope.row)"
              type="text"
              size="small"
              >停用</el-button
            >
            <el-button
              style="color: #f00"
              @click="deleted(scope.row)"
              type="text"
              size="small"
              >删除</el-button
            >
          </template>
        </el-table-column>
      </el-table>
      <div class="pagination-container">
        <el-pagination
          :page-size="10"
          :pager-count="11"
          layout="total, prev, pager, next"
          :total="35"
        >
        </el-pagination>
      </div>
    </div>

    <!-- 弹出层 -->

    <!-- 新增 -->
    <el-dialog :title="title" :visible.sync="nuedialog" width="800px">
      <div class="addition">
        <span @click="addition">
          <SvgIcon
            name="jia"
            class="jia"
            width="20px"
            height="22px"
            color="#222"
          ></SvgIcon>
        </span>
        <span @click="subtraction">
          <SvgIcon
            name="jian"
            class="jian"
            width="20px"
            height="22px"
            color="#222"
          ></SvgIcon>
        </span>
      </div>
      <div class="general">
        <div class="condition">
          <p>测风塔名称:</p>
          <el-input v-model="windsiteName"></el-input>
        </div>
        <div class="condition">
          <p>经度:</p>
          <el-input v-model="airdensity"></el-input>
        </div>

        <div class="condition">
          <p>纬度:</p>
          <el-input v-model="altitude"></el-input>
        </div>

        <div
          v-for="(input, index) in heightInputs"
          :key="index"
          class="condition"
        >
          <p>测风塔高度:</p>
          <el-input
            v-model="input.value"
            placeholder="请输入测风塔高度"
          ></el-input>
        </div>
      </div>

      <span slot="footer" class="dialog-footer">
        <el-button @click="nuedialog = false" size="small">取 消</el-button>
        <el-button type="primary" @click="newly" size="small">确 定</el-button>
      </span>
    </el-dialog>

    <!-- 风场详情 -->
    <el-dialog title="详情" :visible.sync="unusualdialog" width="800px">
    </el-dialog>
  </div>
</template>

<script>
export default {
  data() {
    return {
      // 新增信息
      windsiteName: "",
      airdensity: "",
      superior: "",
      superiorOptions: [],
      altitude: "",
      sheng: "",
      shengOptions: [],
      shi: "",
      shiOptions: [],
      longitude: "",
      dimensionality: "",
      anemometer: "",
      anemometerOptions: [],

      fileList: [
        {
          name: "food.jpeg",
          url: "https://fuss10.elemecdn.com/3/63/4e7f3a15429bfda99bce42a18cdd1jpeg.jpeg?imageMogr2/thumbnail/360x360/format/webp/quality/100",
        },
      ],
      formInline: {
        user: "",
        region: "",
        timeQuantum: "",
      },
      tableData: [
        {
          id: 1,
          name: "王小虎",
          transition: "1",
        },
        {
          id: 3,
          name: "王小虎",
          abnormal: "1",
          transition: "0",
          children: [
            {
              id: 31,

              name: "王小虎",

              abnormal: "1",
            },
          ],
        },
      ],
      nuedialog: false,
      unusualdialog: false,

      newform: {
        unit: "",
        province: "",
        city: "",
        descr: "",
      },
      title: "",
      heightInputs: [{ value: "" }],
    };
  },
  methods: {
    rowStyle() {
      return "text-align:center";
    },

    // 查询
    onSubmit() {
      console.log("submit!");
    },
    // 重置
    reset() {},

    // 新增
    newly() {
      this.heightInputs.forEach((value, index) => {
        console.log(`测风塔高度 ${index + 1}:`, value);
      });

      this.nuedialog = false;
      this.heightInputs = [{ value: "" }];
    },

    //异常详情
    particulars(row) {
      this.unusualdialog = true;
    },

    // 编辑
    compile(row) {
      this.nuedialog = true;
      this.title = "编辑";
    },

    // 启用
    start(row) {},
    // 停用
    stop(row) {},
    // 删除
    deleted(row) {
      this.$confirm("此操作将永久删除该文件, 是否继续?", "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning",
      })
        .then(() => {
          this.$message({
            type: "success",
            message: "删除成功!",
          });
        })
        .catch(() => {
          this.$message({
            type: "info",
            message: "已取消删除",
          });
        });
    },
    // 删除附件
    deleteRow(row) {
      this.$confirm("此操作将永久删除该文件, 是否继续?", "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning",
      })
        .then(() => {
          this.$message({
            type: "success",
            message: "删除成功!",
          });
        })
        .catch(() => {
          this.$message({
            type: "info",
            message: "已取消删除",
          });
        });
    },
    addition() {
      this.heightInputs.push({ value: "" }); // Add a new object with an empty string property
    },

    // Method to remove the last input for "测风塔高度"
    subtraction() {
      if (this.heightInputs.length > 1) {
        // Ensure at least one input remains
        this.heightInputs.pop();
      }
    },

    // 新增
    newnuedialog() {
      this.nuedialog = true;
      this.title = "新增";
    },
  },
};
</script>

<style lang="scss" scoped>
.general {
  display: flex;
  flex-wrap: wrap;

  .condition {
    width: 50%;
    display: flex;

    p {
      width: 100px;
      text-align: right;
      line-height: 40px;
    }

    span {
      line-height: 40px;

      padding-left: 20px;
    }

    .el-select {
      width: 100%;
      margin-bottom: 20px;
    }

    .el-input {
      margin-bottom: 20px;
    }
  }
}

.attachment {
  display: flex;
  padding-top: 10px;

  p {
    margin-right: 20px;
    color: #409eff;
  }
}

.addition {
  display: flex;
  justify-content: flex-end;
  margin-bottom: 10px;
}
</style>
