<template>
  <div class="layout-no-cols">
    <el-toolbar>
      <el-button @click="$router.back()" type="primary" size="medium" round class="shadow-primary">
        <i class="fa fa-chevron-left"></i> 返回上页
      </el-button>
      <span class="button-separator"></span>
      <el-button :loading="btnLoading" @click="saveStopWord" :priv="ID === 'new' ? 'Search.DicManager.AddStopWord' : 'Search.DicManager.EditStopWord'">
        <i class="fa fa-save"></i>保 存
      </el-button>
    </el-toolbar>
    <div class="detail-panel form-panel">
      <el-form :model="tmpStopWord" status-icon ref="form" label-width="128px">
        <el-form-item label="停用词：" :verify="['NotNull']" prop="rootWord">
          <el-input v-model="tmpStopWord.rootWord"></el-input>
        </el-form-item>
      </el-form>
    </div>
  </div>
</template>
<script>

import util from '@src/common/util.js'
export default {
  props: {
    ID: {
      type: [String, Number],
      default: 0
    }
  },
  data() {
    return {
      tmpStopWord: {},
      btnLoading: false
    }
  },
  created() {
    this.loadData()
  },
  methods: {
    async loadData() {
      if (this.ID && this.ID !== 'new') {
        let res = await axios.get(`/ui/generalword/${this.ID}`)
        if (res.data.status === 1) {
          this.tmpStopWord = res.data.data
        } else {
          this.tmpStopWord = {}
        }
      } else {
        this.tmpStopWord = {}
      }
    },
    /* 提交停用词添加或编辑请求 */
    async saveStopWord() {
      this.btnLoading = true
      try {
        await util.validateForm(this.$refs['form'])
        let res = this.ID && this.ID !== 'new'
          ? await axios.put(`/ui/stopword/${this.ID}`, this.tmpStopWord)
          : await axios.post('/ui/stopword', this.tmpStopWord)
        this.btnLoading = false
        util.showResponseMessage(res.data)
      } catch (e) {
        this.btnLoading = false
        util.showErrorMessageBox(e)
      }
    }
  }
}
</script>
<style scoped>
</style>
