<template>
  <div>
    <el-form
      :inline="true"
      ref="fromPlt"
      class="demo-form-inline"
      label-width="170px"
      :model="formData"
    >
      <el-row>
        <el-col :span="12" v-for="item in pltList" :key="item.key">
          <el-form-item :label="item.name" :prop="item.key">
            <el-input
              size="small"
              v-model="formData[item.key]"
              :placeholder="item.name"
            ></el-input>
          </el-form-item>
        </el-col>
      </el-row>
    </el-form>
  </div>
</template>

<script>
import list from "./windCodeForPlt";
import axios from "axios";
export default {
  data() {
    return {
      pltList: [],
      formData: {}, // 表单数据对象
    };
  },
  created() {
    this.pltList = [...list];
    this.initializeFormData();
  },
  methods: {
    initializeFormData() {
      // 初始化 formData 对象
      this.pltList.forEach((item) => {
        this.$set(this.formData, item.key, item.value);
      });
    },
    reset(from) {
      this.$refs[from].resetFields();
    },
    //编辑回显
    reSetByWindCodeAndTypeForPlt(obj) {
      const token = JSON.parse(sessionStorage.getItem("vuex"))?.auth?.userInfo
        ?.token;
      axios
        .post(
          "/transDataWeb/transConf/getByWindCodeAndTypeForPlt",
          {
            ...obj,
          },
          {
            headers: {
              token,
            },
          }
        )
        .then((res) => {
          if (res.data.code === 200) {
            this.formData = { ...res.data.datas };
          }
        })
        .catch((error) => {});
    },
  },
};
</script>
