<template>
  <el-card shadow="never" class="aui-card--fill">
    <div class="mod-custom__evaluaterole}">
      <el-form :inline="true" :model="dataForm" ref="dataForm">
        <!-- <el-form-item>
          <el-input v-model="dataForm.id" placeholder="id" clearable></el-input>
        </el-form-item> -->
        <el-form-item label="是否开启“干部评价”功能" prop="available">
          <el-switch v-model="dataForm.available" active-color="#13ce66" inactive-color="#ff4949" active-value="1" inactive-value="0" @change="availableHandle()"></el-switch>
        </el-form-item>
      </el-form>
    </div>
  </el-card>
</template>

<script>
import mixinViewModule from '@/mixins/view-module'
export default {
  mixins: [mixinViewModule],
  data () {
    return {
      dataForm: {
        id: ''
      }
    }
  },
  created () {
    this.getInfo()
  },
  methods: {
    // 获取信息
    getInfo () {
      this.$http.get(`/custom/evaluaterole/getAvailable`).then(({ data: res }) => {
        if (res.code !== 0) {
          return this.$message.error(res.msg)
        }
        this.dataForm = {
          ...this.dataForm,
          ...res.data
        }
      }).catch(() => {})
    },
    availableHandle () {
      let postData = {
        available: this.dataForm.available
      }
      this.$http['post'](
        '/custom/evaluaterole/updateRoleInfo',
        postData
      )
        .then(({ data: res }) => {
          if (res.code !== 0) {
            return this.$message.error(res.msg)
          }
          this.$message({
            message: this.$t('prompt.success'),
            type: 'success',
            duration: 500,
            onClose: () => {
              this.visible = false
              this.$emit('refreshDataList')
            }
          })
        })
        .catch(() => {})
    }
  }
}
</script>
