<template>
  <view class="p-l-r-30 p-b-t-40 k-parse height-100 width-100" style="box-sizing: border-box;">
    <u-button @click="show = true">{{feedbackTitle?feedbackTitle:'请选择反馈类型'}}</u-button>
    <u-picker :show="show" :columns="columns" @confirm="confirm"></u-picker>
    <textarea class="feedback-content" v-model="feedback" auto-focus maxlength="500"
      placeholder="请输入您需要反馈的内容"></textarea>
    <view class="submit-btn" @click="submit">提交反馈</view>
  </view>
</template>

<script>
  export default {
    mixins: [],
    data() {
      return {
        show: false,
        columns: [
          ['资讯', '专业风采', '名店', '名点', '名菜']
        ],
        feedbackTitle: '',
        feedbackType: '',
        feedback: '',
        submitting: false,
      }
    },
    computed: {},
    methods: {
      confirm(e) {
        // INFORMATION("information", "资讯"),
        // PROFESSIONAL_STYLE("professional_style", "风采"),
        // DISH("dish", "名菜"),
        // SNACKS("snacks", "名点"),
        // RESTAURANT("restaurant", "名店");
        switch (e.indexs[0]) {
          case 0:
            this.feedbackType = 'information';
            break;
          case 1:
            this.feedbackType = 'professional_style';
            break;
          case 2:
            this.feedbackType = 'famous_restaurant';
            break;
          case 3:
            this.feedbackType = 'famous_dish';
            break;
          case 4:
            this.feedbackType = 'famous_snacks';
            break;
          case 0:
            this.feedbackType = e.indexs[0];
            break;
        }

        //
        this.feedbackTitle = '反馈类型：' + e.value[0]
        this.show = false
      },
      submit() {
        if (!this.feedbackType || !this.feedback) {
          uni.showToast({
            icon: "none",
            title: "请完善反馈内容后再试"
          })
          return;
        }
        if (this.submitting) {
          return;
        }
        this.submitting = true;
        wx.showLoading();

        this.$u.api.submitFeedback(this.feedbackType, this.feedback).then(res => {
          uni.showToast({
            icon: "none",
            title: "反馈成功"
          })
          uni.navigateBack({
            delta: -1
          })
        }).catch(e=> {
          wx.hideLoading();
          this.submitting = false;
        })
      }
    },
  }
</script>

<style scoped>
  .feedback-content {
    border: 1px solid #999999;
    padding: 10px;
    width: 100%;
    height: calc(100% - 100px);
    box-sizing: border-box;
  }

  .submit-btn {
    text-align: center;
    width: 80%;
    line-height: 40px;
    color: white;
    background-color: #65371b;
    margin: 10px auto auto auto;
  }
</style>