<template>
  <div class="app-container app-edit">
     <el-form class="small-space" :model="form"  ref="form" label-position="right" label-width="120px" style="width: 700px;">
      <!--  -->
      <el-form-item label="欢迎页图片" prop="value" :required="true">
        <el-upload
          class="avatar-uploader"
          accept="image/*"
          action="/api/upload/uploadImg"
          :show-file-list="false"
          :on-success="handleSuccess"
          :before-upload="handleBefore">
          <img v-if="form.value " :src="form.value" class="avatar">
          <i v-else class="el-icon-plus avatar-uploader-icon"></i>
        </el-upload>
        <el-input v-model="form.value" placeholder="请输入" type="hidden"></el-input>
      </el-form-item>  

      <el-form-item>
        <el-button type="primary"  @click="handleSave">保存</el-button>
      </el-form-item>
    </el-form>
  </div>
</template>
<script>
import { find, update } from '@/api//config'

export default {
  data() {
    return {
      form: {
        id: undefined,
        value: ''
      }
    }
  },
  created() {
    find().then(response => {
      this.form.id = response.config.id
      this.form.value = response.config.value
    })
  },
  methods: {
    handleBefore() {

    },
    handleSuccess(res) {
      this.form.value = res.err_msg
    },
    handleSave() {
      update(this.form).then(response => {

      })
    }
  }
}
</script>
<style>
  .avatar-uploader .el-upload {
    border: 1px dashed #d9d9d9;
    border-radius: 6px;
    cursor: pointer;
    position: relative;
    overflow: hidden;
  }
  .avatar-uploader .el-upload:hover {
    border-color: #20a0ff;
  }
  .avatar-uploader-icon {
    font-size: 28px;
    color: #8c939d;
    width: 178px;
    height: 178px;
    line-height: 178px;
    text-align: center;
  }
  .avatar {
    width: 178px;
    height: 178px;
    display: block;
  }
</style>