<template>
  <div>
    <back :title="titlename"></back>
    <div class="content">
      <van-field
        v-model="suggestScene"
        name="建议场景"
        label="建议场景"
        placeholder="请输入建议场景"
        :rules="[{ required: false }]"
      />
      <textarea
        v-model="feedbackContent"
        cols="30"
        rows="10"
        placeholder="请输入意见建议"
      ></textarea>
      <van-button color="#0c2469" @click="tj">提交</van-button>
    </div>
  </div>
</template>

<script>
import { Toast, Dialog } from "vant";
export default {
  data() {
    return {
      titlename: "意见建议",
      feedbackContent: "", //意见建议内容
      userId: "",
      mailRoomId: "", //收发室Id
      feedbackPerson: "", //反馈人
      expressNo: "1", //关联快递单号-选填
      suggestScene: "" //建议场景：寄件、收件
    };
  },
  created: function() {
    this.isLogin();
    this.userId = localStorage.getItem("userId");
    this.mailRoomId = localStorage.getItem("roomId");
  },
  methods: {
    //提交
    tj() {
      if (this.suggestScene == "" || this.suggestScene == undefined) {
        Toast("请输入建议场景");
        return;
      }
      if (this.feedbackContent == "" || this.feedbackContent == undefined) {
        Toast("请输入意见建议");
        return;
      }
      this.$http
        .post(
          this.$store.state.host + "/personal/userSubmitSuggest.do",
          {
            userId: this.userId,
            mailRoomId: this.mailRoomId,
            expressNo: this.expressNo,
            suggestScene: this.suggestScene,
            feedbackContent: this.feedbackContent
          },
          {
            emulateJSON: true
          }
        )
        .then(
          res => {
            //发送成功
            if (res.body.msg == "success") {
              Toast("提交成功");
              let that = this;
              setTimeout(function() {
                that.$router.push({
                  path: "/My"
                });
              }, 1000);
            } else {
              Toast("提交失败");
              Toast.clear();
            }
          },
          res => {
            //发送失败
            Toast("网络错误");
          }
        );
      Toast.clear();
    }
  }
};
</script>

<style scoped lang="less">
.content {
  padding: 0.33rem;
  font-size: 0.36rem;

  .title {
    font-weight: bold;
    text-align: center;
    margin-bottom: 0.2rem;
  }

  textarea {
    width: 96%;
    padding: 2%;
    border-color: #dedede;
    font-size: 0.3rem;
    margin-top: 0.3rem;
  }

  button {
    width: 100%;
    margin-top: 0.3rem;
  }
}
</style>
