<template>
  <div></div>
</template>
<script>
import { seeDoctor } from "@/api/patients.js";
import { getPatiiensMsg } from "@/api/diagnosis.js";
import { mapState, mapGetters, mapActions, mapMutations } from "vuex";
import { getDataByKey } from "@/api/system.js";
import { setSessionModalId } from '@/utils/url';
export default {
  data() {
    return {
      routePath: "/index/diagnosis" // 配置跳转值
    };
  },
  created() {
    sessionStorage.removeItem("activeID");
    sessionStorage.removeItem("active");
    this.setUserInfo({});
    this.$nextTick(() => {
      let pid = this.$route.query.token;
      let token = this.$route.query.Authorization;

      setSessionModalId();

      if (token) {
        localStorage.setItem("token", token);
        if (this.getuserinfo) this.getDataByKey();
      }
      if (!token) return;
      if (pid) {
        this.getPatiiensMsg(pid);
      }
    });
  },
  methods: {
    // 通过就诊id 获取病人信息
    async getPatiiensMsg(id) {
      let res = await getPatiiensMsg(id);
      if (res.ResultCode == 0) {
        this.setPatients(res.Data);
        this.seeDoctor(res.Data.pid);
      }
    },
    async seeDoctor(pid) {
      let params = {
        recordsId: pid
      };
      const loading = this.$loading({
        lock: true,
        text: "正在处理",
        spinner: "el-icon-loading",
        background: "rgba(0, 0, 0, 0.7)"
      });
      let res = await seeDoctor(params).catch(err => {
        loading.close();
      });
      if (res.ResultCode == 0) {
        loading.close();
        let preNo = this.$route.query.preNo;
        let path = preNo
          ? `/index/prescribing?recipeID=${preNo}&recipeType=edit&from=his`
          : "/index/prescribing?from=his";
        this.setIsSee(true);
        this.setPreNo(preNo || '');
        await this.$router.push({
          path: path
          // path: this.routePath
        });
      }
    },
    // 获取页面跳转配置
    async getDataByKey() {
      let res = await getDataByKey({
        key: "diagnosisHomePage",
        organizationid: this.getuserinfo.organizationid
      });
      if (res.ResultCode == 0) {
        if (res.ResultInfo == "0") {
          this.routePath = "/index/emr";
        } else if (res.ResultInfo == "1") {
          this.routePath = "/index/dialectical";
        } else if (res.ResultInfo == "2") {
          this.routePath = "/index/prescribing";
        } else if (res.ResultInfo == "3") {
          this.routePath = "/index/doctorcaseBefore";
        }
      }
    },
    ...mapMutations({
      setUserInfo: "user/setUserinfo",
      setPatients: "user/setPatiensInfo",
      setPreNo: "user/setPreNo",
      setIsSee: "user/setIsSee"
    })
  }
};
</script>
    