import { VueLikePage } from '../../utils/page'
import Api from '../../apis/index'
import exhibitionApi from '../../apis/exhibition'
import Router from '../../utils/routes'
VueLikePage([], {
  data: {
    active: 0,
    tabs: []
  },
  methods: {
    async onLoad () {
      let tabs = await this.getCompanyHalls()
      tabs.unshift({name: '全部', id: ''})
      this.selectHall = tabs[0].name === '全部' ? '' : tabs[0].name
      let companyList = await this.getCompanyByHall()
      tabs[0].list = companyList.data.list
      this.setData({
        tabs
      })
    },
    getCompanyHalls () {
      return exhibitionApi.getTradeList().then(res => {
        console.log(res)
        return res.data.map(item => {
          return { name: item.name, id: item.id, list: [] }
        })
      })
    },
    getCompanyByHall () {
      return Api.getCompanyList({tradeName: this.selectHall}).then(res => {
        return res
      })
    },
    search (value) {
      console.log('click')
      Router.push('search')
    },
    async onChange (e) {
      this.selectHall =e.detail.title === '全部' ? '' : e.detail.title
      let res = await this.getCompanyByHall()
      let tabs = this.data.tabs
      tabs[e.detail.index].list = res.data.list
      this.setData({
        tabs
      })
    },
    toScene (e) {
      const { vr_link } = e.currentTarget.dataset
      Router.push({
        url: 'scene',
        query: {
          vr_link
        }
      })
    }
  }
})