<template>
  <view class="container ask-container">
    <view class="advice-ipt-cont">
      <u-input v-model="advice_content" type="textarea" maxlength="100" :clearable="false" :placeholder="titlePlaceholder" height="300" class="ipt" />
      <text class="num-tag">{{ advice_content.length }}/100</text>
    </view>
    <view class="btn-cont" @click="submitHandle"> 提交 </view>
    <freeCharge class="free-charge" :isShowFreeBtn="isShowFree" />
  </view>
</template>

<script>
import { activity, Report, Home } from "@/config/api.js";
import freeCharge from "@/components/freeCharge";
export default {
  data() {
    return {
      advice_content: "",
      id: "",
      type: "",
      roadshowTitle: "", // 微路演标题
      roadshow: null, // 判断微路演的类型
    };
  },
  components: {
    freeCharge,
  },
  computed: {
    titlePlaceholder() {
      return this.type == "文章" ? "可以留下您对报告内容的看法或者疑问" : "请描述您的问题，分析师会代您向专家提问。";
    },
  },
  methods: {
    async submitHandle() {
      if (!this.advice_content)
        return uni.showToast({
          title: "内容不能为空",
          icon: "none",
          duration: 2000,
        });
      const res =
        this.roadshow && this.type == "文章"
          ? await Home.microRoadshowAdd({
              Id: Number(this.id),
              Content: this.advice_content,
              SourceType: Number(this.roadshow),
              Title: this.roadshowTitle,
              PageRouter: this.$store.state.pageRouterReport,
            })
          : this.type == "文章"
          ? await Report.articleAskAdd({
              ArticleId: Number(this.id),
              Content: this.advice_content,
              PageRouter: this.$store.state.pageRouterReport,
            })
          : await activity.activityAskAdd({
              ActivityId: Number(this.id),
              Content: this.advice_content,
              PageRouter: this.$store.state.pageRouterReport,
            });
      if (res.Ret === 200) {
        this.$util.toast("提交成功");
        this.advice_content = "";
        setTimeout(() => {
          uni.navigateBack();
        }, 500);
      }
    },
  },
  onLoad(option) {
    this.id = option.id;
    this.type = option.type || "";
    this.roadshow = option.roadshow || null;
    this.roadshowTitle = option.roadshowTitle || "";
    uni.setNavigationBarTitle({
      title: this.type == "文章" ? "留言" : this.type == "提问" ? "实时提问" : "帮我带问",
    });
  },
};
</script>

<style scoped lang="scss">
.ask-container {
  background-color: #fff;
  padding: 30rpx 34rpx;
  .advice-ipt-cont {
    height: 420rpx;
    border: 1rpx solid #d0cfd5;
    border-radius: 8rpx;
    padding: 30rpx;
    position: relative;
    font-size: 28rpx;
    color: #d0cfd5;
    .num-tag {
      position: absolute;
      bottom: 30rpx;
      right: 30rpx;
    }
  }
  .btn-cont {
    margin: 80rpx auto;
    width: 368rpx;
    height: 80rpx;
    font-size: 34rpx;
    line-height: 80rpx;
    text-align: center;
    color: #ffffff;
    background: linear-gradient(268deg, #2ddbff 0%, #1599ff 49%, #005eff 100%);
    opacity: 1;
    border-radius: 4rpx;
  }
}
</style>
