<template>
  <div class="app-container">
    <el-form :model="form" :rules="rules"  ref="form" label-width="150px">
<!--      <el-row>
        <el-form-item label="站点标题" prop="homeTitle">
          <el-input v-model="form.homeTitle" placeholder="请输入站点标题" />
        </el-form-item>
      </el-row>-->
      <el-row>
        <el-form-item label="banner图" prop="bannerOne">
          <imageUpload v-model="form.bannerOne"/>
        </el-form-item>
      </el-row>
      <el-row>
        <el-form-item label="聊天配置" prop="chatUrl">
          <el-input v-model="form.chatUrl" placeholder="请输入聊天配置" />
        </el-form-item>
      </el-row>
<!--      <el-row>
        <el-form-item label="公章" prop="commonSeal">
          <imageUpload  v-model="form.bannerUrl"/>
        </el-form-item>
      </el-row>-->
      <el-form-item>
        <el-button :loading="buttonLoading" type="primary" size="mini" @click="submitForm">保存</el-button>
      </el-form-item>
    </el-form>
  </div>
</template>

<script>
import {
  getHomeSetting,
  updateHomeSetting
} from '@/api/dk/HomeSetting'
import ImageUpload from '@/components/ImageUpload/index'

export default {
  name: "HomeSetting",
  components: {
    ImageUpload
  },
  data() {
    return {
      //按钮loading
      buttonLoading: false,
      // 表单参数
      form: {
        homeTitle: undefined,
        bannerOne: undefined,
        commonSeal: undefined,
        chatUrl: undefined
      },
      // 表单校验
      rules: {
      },
      formDisable:true,
    };
  },
  created() {
    this.init();
  },
  methods: {
    init(){
      this.refreshData(this.form.appType);
    },
    refreshData(){
      getHomeSetting().then(response => {
        this.form = response.data;
      })
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          this.buttonLoading = true;
          updateHomeSetting({
            id:this.form.id,
            homeTitle: this.form.homeTitle,
            bannerOne:this.form.bannerOne,
            commonSeal:this.form.commonSeal,
            chatUrl: this.form.chatUrl
          }).then(response => {
            this.formDisable = true;
            this.buttonLoading = false;
            this.msgSuccess("修改成功");
          }).catch(() => {
            this.formDisable = true;
            this.buttonLoading = false;
          });
        }
      });
    }
  }
};
</script>
