<template>
  <div class="app-container">
    <div id="container" class="container"></div>
  </div>
</template>

<script>

const isAMRT = () => {
  return new Promise((resolve, reject) => {
    const fun = () => {
      if (typeof AMRT !== "undefined" && AMRT) {
        resolve(true)
      } else {
        setTimeout(fun, 100)
      }
    }
    fun()
  })
}

export default {
  name: "Model",
  data() {
    return {
      viewer: null
    }
  },
  async mounted() {
    await isAMRT()
    console.log(AMRT)
    const param = {
      appkey: 'aveMPyNWzDJm',
      appsecret: 'rXmhoLAiOPNKzbl7g2qxCV8tFwRdYuZM'
    }
    const viewer = new AMRT.Viewer('container', param)
    const callback = () => {
      console.log('click on model')
    }
    const callback1 = () => {
      console.log('click on model123213213')
    }
    let num = 0
    viewer.loadModel('1720250797926780928', {
      background: false,
      onLoad: function (m) {
        num+=1
        if(num === 5){
          alert('加载完成');
        }
        m.on('click', callback)
      }
    })
    viewer.loadModel('1720250751495835648', {
      background: false,
      onLoad: function (m) {
        num+=1
        if(num === 5){
          alert('加载完成');
        }
        m.on('click', callback1)
      }
    })
    viewer.loadModel('1720250742998175744', {
      background: false,
      onLoad: function (m) {
        num+=1
        if(num === 5){
          alert('加载完成');
        }
        m.on('click', callback1)
      }
    })
    viewer.loadModel('1720250716490174464', {
      background: false,
      onLoad: function (m) {
        num+=1
        if(num === 5){
          alert('加载完成');
        }
        m.on('click', callback1)
      }
    })
    viewer.loadModel('1720250709951254528', {
      background: false,
      onLoad: function (m) {
        num+=1
        if(num === 5){
          alert('加载完成');
        }
        m.on('click', callback1)
      }
    })
  },
  methods: {}
};
</script>
<style scoped>
* {
  margin: 0;
  padding: 0
}

.container {
  width: 100vw;
  height: 100vh
}

</style>
