<template>
  <div class="app-container">
    <tinymce v-model="introduction" :height="300" />
    <el-form ref="dataForm" :rules="rules" :model="from" label-position="left" label-width="80px" style="float: left;margin-top: 20px;">
      <el-form-item label="联系我们" prop="contactNumber">
        <el-input v-model="from.contactNumber" maxlength="11" placeholder="请输入联系方式" />
      </el-form-item>
    </el-form>
    <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,
      introduction: '',
      loadingbut: false,
      loadingbuttext: '提交',
      from: {
        contactNumber: ''
      },
      rules: {
        contactNumber: [{ required: true, message: '联系方式不能为空', trigger: 'blur' }]
      }
    }
  },
  computed: {
    organizeID() {
      return this.$store.getters.organizeID
    }
  },
  created() {
    this.initData()
  },
  methods: {
    initData() {
      getOrganizeInfo({ id: this.organizeID }).then(response => {
        console.log(response)
        this.introduction = response.data.introduction
        this.from.contactNumber = response.data.contactNumber
      })
    },
    onSubmite() {
      this.$refs['dataForm'].validate((valid) => {
        if (valid) {
          const Formobj = { id: this.organizeID, introduction: this.introduction }
          const params = Object.assign(Formobj, this.from)
          this.loadingbut = true
          this.loadingbuttext = '提交中'
          updateOrganizeInfo(params).then(response => {
            this.$message({ message: response.msg, type: 'success', center: true })
            this.loadingbut = false
            this.loadingbuttext = '提交'
            setTimeout(() => {
              this.initData()
            }, 3000)
          })
        }
      })
    }
  }
}
</script>

<style scoped>

</style>
