<template>
  <div class="app-container">
    <el-card class="box-card">
      <template #header>
        <div class="card-header">
          <span>简介管理</span>
        </div>
      </template>
      <el-form ref="form" :model="form" label-width="80px">
        <el-form-item label="标题">
          <el-input v-model="form.title" placeholder="请输入标题" style="width: 60%" />
        </el-form-item>
        <el-form-item label="内容">
          <editor v-model="form.content" :min-height="300" />
        </el-form-item>
        <el-form-item>
          <el-button type="primary" @click="handleSubmit" :loading="loading">保存</el-button>
        </el-form-item>
      </el-form>
    </el-card>
  </div>
</template>

<script>
import { getIntroduction, updateIntroduction } from "@/api/sdgsat1/introduction";

export default {
  name: "Introduction",
  data() {
    return {
      loading: false,
      form: {
        title: "",
        content: ""
      }
    };
  },
  created() {
    this.getIntroductionData();
  },
  methods: {
    getIntroductionData() {
      this.loading = true;
      getIntroduction()
        .then(response => {
          if (response.data) {
            this.form = response.data;
          }
        })
        .finally(() => {
          this.loading = false;
        });
    },
    handleSubmit() {
      this.loading = true;
      updateIntroduction(this.form)
        .then(response => {
          this.$message.success("保存成功");
        })
        .finally(() => {
          this.loading = false;
        });
    }
  }
};
</script>

<style scoped>
.card-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
}
</style>