<!--
 * @Author: lixg lixg@dongwu-inc.com
 * @Date: 2023-01-16 17:26:39
 * @LastEditors: lixg lixg@dongwu-inc.com
 * @LastEditTime: 2023-03-10 15:20:30
 * @FilePath: /stu_h5/src/components/ReturnHead.vue
 * @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
-->
<template>
  <div class="returnHead">
    <div style="width: 46px">
      <img
        style="width: 9px; height: 15px"
        src="../assets/image/return.png"
        @click="returnclick"
      />
    </div>
    <div class="text">{{ text }}</div>
    <div class="publish" v-if="showpublish" @click="publishClick">
      <img
        style="width: 13px; height: 12px"
        src="../assets/image/publish.png"
      />
      <div style="margin-left: 5px; color: #2478ff">发布</div>
    </div>
    <div class="publish" v-else-if="showfile">
      <img
        style="width: 21px; height: 18px; margin-left: 25px; cursor: pointer"
        src="../assets/image/file/file.png"
        @click="goFileStorage"
      />
    </div>
    <div class="publish" v-else-if="ispublish" @click="goPublish">
      <img
        style="width: 14px; height: 14px"
        src="../assets/image/publishDis.png"
      />
      <div style="margin-left: 5px; color: #2478ff">发表</div>
    </div>

    <div class="publish" v-else></div>
  </div>
</template>
<script >
import { useRouter } from "vue-router";
export default {
  name: "ReturnHead",
  props: {
    text: String,
    showpublish: {
      type: Boolean,
      default: false,
    },
    publishWork: {
      type: Function,
      default: null,
    },
    ispublish: {
      type: Boolean,
      default: false,
    },

    showfile: {
      type: Boolean,
      default: false,
    },
    courseId: {
      type: Number,
      default: null,
    },
    type: {
      type: Number,
      default: null,
    },
    discussId: {
      type: Number,
      default: null,
    },
    postAdd: {
      type: Function,
      default: null,
    },
    id: {
      type: Number,
      default: null,
    },
    gohome: {
      type: Boolean,
      default: false,
    },
  },
  setup(props, ctx) {
    const router = useRouter();
    const returnclick = () => {
      console.log("props.gohome", props.gohome, import.meta.env.VITE_BOE_STUDY);
      if (props.gohome) {
        window.open(
          window.location.protocol + import.meta.env.VITE_BOE_STUDY,
          "_top"
        );
      } else {
        if (window.history.length <= 1) {
          window.open(import.meta.env.VITE_BOE_STUDY, "_top");
        } else {
          router.back(-1);
        }
      }
    };
    const publishClick = () => {
      if (props.postAdd) {
        props.postAdd && props.postAdd();
      }
      if (props.publishWork) {
        props.publishWork && props.publishWork();
      }
    };
    const goFileStorage = () => {
      router.push({
        path: "/fileStorag",
        query: {
          courseId: props.courseId,
          type: props.type,
        },
      });
    };
    const goPublish = () => {
      router.push({
        path: "/discussupload",
        query: {
          discussId: props.discussId,
          type: props.type,
          id: props.id,
        },
      });
    };
    return {
      returnclick,
      publishClick,
      goFileStorage,
      goPublish,
    };
  },
};
</script>
<style scoped lang="scss">
.returnHead {
  width: 95%;
  height: 44px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: 14px;
  background-color: #ffffff;
  padding-left: 2.5%;
  padding-right: 2.5%;
  .text {
    font-size: 18px;
    font-weight: 600;
    color: #323233;
    line-height: 12px;
    margin-left: 11px;
  }
  .publish {
    width: 48px;
    display: flex;
    align-items: center;
  }
}
</style>
