<template>
  <div class="app-container">
    <div class="tinymce-title"><span class="title-tip">*</span>关于我们：</div>
    <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 => {
        this.introduction = response.data.introduction
        this.from.contactNumber = response.data.contactNumber
      })
    },
    onSubmite() {
      this.$refs['dataForm'].validate((valid) => {
        if (valid) {
          if (this.introduction === '') {
            this.$message({ message: '内容不能为空', type: 'warning', center: true })
            return
          }
          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()
            }, 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>
