import { defineComponent } from 'vue'
import { Button, Field, Toast } from 'vant'
import request from '/src/helpers/request'
import styles from './content.module.less'

export default defineComponent({
  name: 'suggestionContent',
  props: {
    close: {
      type: Function,
      default: () => {}
    }
  },
  data() {
    return {
      value: '',
      loading: false,
    }
  },
  methods: {
    submit() {
      try {
        if (!this.value) {
          return Toast('请先填写意见反馈')
        }
        this.loading = true
        request.post('/suggestion/add', {
          data: {
            content: this.value,
            type: 'SMART_PRACTICE'
          }
        })
        Toast('意见反馈已提交')
        this.close()
      } catch (error) {}
      this.loading = false
    }
  },
  render() {
    return (
      <div class={styles.content}>
        <div class={styles.title}>意见反馈</div>
        <Field
          class={styles.input}
          modelValue={this.value}
          onChange={evt => this.value = evt.target.value}
          rows="3"
          autosize
          type="textarea"
          placeholder="请输入意见反馈"
        />
        <Button class={styles.btn} size="mini" loading={this.loading} onClick={this.submit} round color="#01C1B5">提交反馈</Button>
      </div>
    )
  }
})
