<template>
  <div class="app-container">
    <div class="tinymce-title"><span class="title-tip">*</span>购物须知：</div>
    <tinymce v-model="shoppingNotes" :height="300" />
    <div slot="footer" class="dialog-footer" style="float: right;padding:80px 0 80px 0;">
      <el-button type="primary" style="width:100px;" :loading="loadingbut" @click="onSubmite()">{{ loadingbuttext }}</el-button>
    </div>
  </div>
</template>

<script>
import Tinymce from '@/components/Tinymce'
import { getOrganizeInfo, updateOrganizeInfo } from '@/api/other'
export default {
  components: {
    Tinymce
  },
  data() {
    return {
      isContent: false,
      shoppingNotes: '',
      loadingbut: false,
      loadingbuttext: '提交'
    }
  },
  computed: {
    organizeId() {
      return this.$store.getters.organizeId
    }
  },
  created() {
    this.initData()
  },
  methods: {
    initData() {
      getOrganizeInfo({ id: this.organizeId }).then(response => {
        console.log(response)
        this.shoppingNotes = response.data.shoppingNotes
      })
    },
    onSubmite() {
      if (this.shoppingNotes === '') {
        this.$message({ message: '内容不能为空', type: 'warning', center: true })
        return
      }
      this.loadingbut = true
      this.loadingbuttext = '提交中'
      updateOrganizeInfo({ id: this.organizeId, shoppingNotes: this.shoppingNotes }).then(response => {
        this.$message({ message: response.msg, type: 'success', center: true })
        this.loadingbut = false
        this.loadingbuttext = '提交'
        setTimeout(() => {
          this.initData()
        }, 1000)
      }).catch(() => {
        this.loadingbut = false
        this.loadingbuttext = '提交'
      })
    }
  }
}
</script>

<style lang="scss" scoped>
  .tinymce-title{
    font-size: 14px;
    line-height: 20px;
    padding: 10px 0;
    text-align: left;
    font-weight: bold;
  }
  .title-tip{
    color: red;
  }
</style>
