<template>
  <section class="askForm">
    <template v-if="showDetail&&!isManager">
      <form-detail/>
    </template>
    <template v-else-if="isManager">
      <form-list ref="FormList"/>
    </template>
    <ai-loading v-else :tips="errMsg"/>
  </section>
</template>

<script>
import AiLoading from "../../components/AiLoading";
import {mapState} from "vuex";
import FormDetail from "./formDetail";
import FormList from "./formList";

export default {
  name: "askForm",
  components: {FormList, FormDetail, AiLoading},
  computed: {
    ...mapState(['openUser', 'user']),
    showDetail() {
      return !!this.$route.query?.id
    },
    isManager() {
      let {hash, query: {preview}} = this.$route
      if (preview) return false
      else if (hash == "#dev") return true
      else return hash != '#form' && !!this.user.id
    }
  },
  data() {
    return {
      errMsg: "加载表单中..."
    }
  },
  onReachBottom() {
    this.$refs?.FormList?.reachBottom()
  }
}
</script>

<style lang="scss" scoped>
.askForm {
  position: absolute;
  width: 100%;
  height: 100%;
  background: #fff;
}
</style>
