<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);
      }
    },
  },

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

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

    async getHospitalId() {
      try {
        const res = await getHId(1);
        const { code, msg, data } = res.data;
        if (code === 200) {
          this.setHospitalId(data.id);
        } else {
          this.$message.error('医院查询失败');
        }
      } catch (error) {
        this.$message.error(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>
