<template>
  <div style="margin: 12px 12px 0px">
    <index-chart></index-chart>
    <sys-tip-modal ref="sysTipModal"></sys-tip-modal>
  </div>
</template>

<script>
import IndexChart from './IndexChart'
import SysTipModal from './dialog/SysTipModal.vue'
import { getMaterialWarn } from '@/api/api.js'

let isFirst = true
export default {
  name: 'Analysis',
  components: {
    IndexChart,
    SysTipModal,
  },
  data() {
    return {
      warnData: {}
    }
  },
  created() {
    if(isFirst){
      this.getWarnData()
    }
  },
  methods: {
    getWarnData(){
      isFirst = false
      const hasArrayData = (val) => {
        return Array.isArray(val) && val.length > 0
      }
      getMaterialWarn().then(res => {
        const {expirationReminder = [],inventoryReminder = [],noMovingPinReminder = []} = res.data
        if(hasArrayData(expirationReminder)||hasArrayData(inventoryReminder)||hasArrayData(noMovingPinReminder)){
          this.$nextTick(() => {
            this.$refs.sysTipModal.open(
              {
                expirationReminder,
                inventoryReminder,
                noMovingPinReminder
              }
            )
          })
        }
      })
    },
    openSysTipModal() {
      this.$refs.sysTipModal.open({})
    },
  },
}
</script>
