<!--
 * @Author: wally
 * @email: 18603454788@163.com
 * @Date: 2021-02-22 09:20:03
 * @LastEditors: wally
 * @LastEditTime: 2021-04-20 10:11:13
-->

<template>
  <a-config-provider :locale="zh_CN">
    <div class="d-flex flex-row flex-nowrap" id="app">
      <btn-con />
      <router-view class="flex-1 bg pa-3"></router-view>
    </div>
  </a-config-provider>
</template>

<script>
import { mapState, mapActions, mapMutations } from 'vuex';
import zh_CN from 'ant-design-vue/lib/locale-provider/zh_CN';
import BtnCon from 'components/BtnCom/BtnCon.vue';
import { getHId } from 'config/api';

export default {
  name: 'App',
  components: { BtnCon },
  data() {
    return { zh_CN };
  },

  computed: mapState('home', ['anyringToken', 'ptProps']),

  watch: {
    ptProps(val) {
      if (val.userId) {
        const params = { userId: val.userId };
        this.getUserId(params);
        this.getHospitalId(val.projectId);
        console.log('val.userId:' + val.userId);
      }
    },
  },
  async created() {
    const userId = '1218763410024566784';
    const params = { userId };
    await this.getUserId(params);
    await this.getToken();
    if (localStorage.getItem('patientId')) {
      this.setPatientId(localStorage.getItem('patientId'));
    }
    if (localStorage.getItem('hospitalization')) {
      this.setHospitalization(localStorage.getItem('hospitalization'));
    }
    const that = this;
    window.plugin = window.TallPlugin.init();
    // 调用created方法 向主窗体发送created消息，以便来接受、存储主窗体传递来的参数
    // created接受一个回调函数 created成功后调用 可选参数
    // 接受PT传过来的 插件id，项目id，角色id，任务id，userId
    window.plugin.created(function(props) {
      console.log('props: ', props);
      that.setPtProps(props);
    });
  },

  methods: {
    ...mapActions('home', ['getUserId']),
    ...mapMutations('home', ['setPtProps', 'setHospitalId', 'setPatientId', 'getToken', 'setHospitalization']),

    async getHospitalId(Id) {
      try {
        const res = await getHId(Id);
        const { code, msg, data } = res.data;
        if (code === 200) {
          this.setHospitalId(data.id);
        }
      } catch (error) {}
    },
  },
};
</script>

<style>
html,
body,
#app {
  min-height: 100%;
}

#app {
  background: transparent;
}
body::-webkit-scrollbar {
  width: 0;
}
</style>

<style lang="stylus">
@import './common/portrait.styl';
</style>
