<template>
  <van-overlay
    :show="value"
    :duration="0.1"
    @click="$emit('change', false)"
    lock-scroll
  >
    <div class="help-modal" @click.stop>
      <div class="title">反馈</div>
      <input
        type="text"
        class="input"
        v-model="feedback.phone"
        placeholder="留下您的手机号码..."
      />
      <textarea
        class="input textarea"
        v-model="feedback.content"
        placeholder="在此留下您宝贵的意见..."
      />
      <div class="btn" @click="postForm">提交</div>
    </div>
  </van-overlay>
</template>
<script>
import { postFeed } from "../api/index";
import filter from "../common/filter";

export default {
  model: { prop: "value", event: "change" },
  props: { value: Boolean },
  data() {
    return {
      feedback: {
        phone: "",
        content: "",
        channelName: "",
        productName: "",
        spid: "",
        userid: "",
      },
    };
  },
  computed: {
    user() {
      return this.$store.state.user;
    },
    pageData() {
      return this.$store.state.pageData;
    },
  },
  methods: {
    postForm() {
      if (filter.checkPhone(this.feedback.phone) < 0) {
        this.$toast("手机号错误");
        return false;
      } else if (this.feedback.content) {
        let strSQl = /select|update|delete|exec|count|'|"|=|;|>|<|%/i;
        let str = /`~!@#$%^&*()_+<>?:/i;
        if (
          strSQl.test(this.feedback.content) ||
          str.test(this.feedback.content)
        ) {
          this.$toast.fail("请勿输入特殊字符");
        } else {
          this.feedback.channelName = this.pageData.channl.channelName;
          this.feedback.productName = this.pageData.mainProduct.productName;
          this.feedback.spid = this.pageData.mainProduct.spid;
          if (this.user.userid) {
            this.feedback.userid = this.user.userid;
          }
          postFeed(this.feedback)
            .then((res) => {
              this.$toast.success({
                message: res.data,
              });
              this.feedback = { phone: "", content: "" };
              this.$emit("change", false);
            })
            .catch((res) => {
              console.log(res);
            });
        }
      } else {
        this.$toast({
          message: "内容不能为空",
        });
      }
    },
  },
};
</script>
<style lang="scss">
.help-modal {
  box-sizing: border-box;
  position: absolute;
  left: 50%;
  transform: translateX(-50%);
  width: 530px;
  background-color: #fff;
  border-radius: 10px;
  top: 366px;
  padding: 40px 65px;
  .title {
    text-align: center;
    font-size: 36px;
    font-weight: bold;
    color: #222222;
    margin-bottom: 28px;
  }
  .input {
    height: 80px;
    width: 400px;
    line-height: 80px;
    display: block;
    font-size: 30px;
    border: 2px solid #fdc51b;
    border-radius: 10px;
    padding: 0 20px;
    box-sizing: border-box;
    -webkit-appearance: none;
    &.textarea {
      padding: 10px 20px;
      margin-top: 20px;
      height: 220px;
      line-height: 50px;
    }
  }
  .btn {
    width: 260px;
    height: 80px;
    line-height: 80px;
    text-align: center;
    background: #fdc51b;
    border-radius: 40px;
    font-size: 34px;
    font-weight: bold;
    color: #0d0d0d;
    margin: 20px auto 0;
  }
}
</style>
