<template>
  <div class="app-container">
    <el-form ref="form" :model="form" :rules="rules" label-width="100px">
      <el-form-item label="标题" prop="title"><el-input v-model="form.title" placeholder="请输入标题" /></el-form-item>
      <el-form-item label="求助电话" prop="helpPhone"><el-input v-model="form.helpPhone" placeholder="请输入求助电话" /></el-form-item>
      <el-form-item label="背景图片"><imageUpload v-model="form.showPictures" :limit="2"/></el-form-item>
      <el-form-item label="背景图片1"><imageUpload v-model="form.bgImg1" :limit="1" /></el-form-item>
      <el-form-item label="背景图片2"><imageUpload v-model="form.bgImg2" :limit="1"/></el-form-item>
      <el-form-item label="背景图片3"><imageUpload v-model="form.bgImg3" :limit="1"/></el-form-item>
      <el-form-item label="背景图片4"><imageUpload v-model="form.bgImg4" :limit="1"/></el-form-item>
    </el-form>
    <div slot="footer" class="dialog-footer"><el-button type="primary" @click="submitForm">确 定</el-button></div>
  </div>
</template>

<script>
import { getAboutUs, addAboutUs, updateAboutUs } from '@/api/management/aboutUs';
export default {
  name: 'AboutUs',
  data() {
    return {
      // 表单参数
      form: {},
      // 表单校验
      rules: {
        title: [{ required: true, message: '标题不能为空' }],
        helpPhone: [{ required: true, message: '请输入求助电话' }],
        browseNum: [{ required: true, message: '点击量不能为空' }],
        content: [{ required: true, message: '详情不能为空' }]
      }
    };
  },
  methods: {
    init(aboutUsId) {
      getAboutUs(aboutUsId).then(response => {
        if (response.code == 200) {
          if (response.data != null) {
            this.form = response.data;
          } else {
            this.reset();
          }
        } else {
          this.msgError('获取信息出错！');
        }
      });
    },
    // 表单重置
    reset() {
      this.form = {
        aboutUsId: null,
        title: null,
        helpPhone: null,
        showPictures: null,
        briefText1: null,
        briefText2: null,
        briefText3: null,
        briefText4: null,
        content: null,
        bgImg1: null,
        bgImg2: null,
        bgImg3: null,
        bgImg4: null,
        createTime: null
      };
      this.resetForm('form');
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs['form'].validate(valid => {
        if (valid) {
          if (this.form.aboutUsId != null) {
            updateAboutUs(this.form).then(response => {
              this.msgSuccess('修改成功');
              this.open = false;
              this.getList();
            });
          } else {
            addAboutUs(this.form).then(response => {
              this.msgSuccess('新增成功');
              this.open = false;
              this.getList();
            });
          }
        }
      });
    }
  },
  created() {
    this.init(1);
  }
};
</script>

<style></style>
