<style lang="less">
.page-meetingroom-list {
  height: 100%;
  width: 100%;
}
.list {
  height: 100%;
  width: 100%;
  padding: 0 48rpx;
  box-sizing: border-box;
}

.list .item {
  width: 100%;
  height: 112rpx;
  line-height: 112rpx;
  font-size: 14px;
  border-bottom: 1px solid rgba(2, 2, 82, 0.03);
}

.list .item .icon {
  width: 48rpx;
  height: 48rpx;
  vertical-align: middle;
}

.list .item .value {
  margin-left: 24rpx;
  color: rgba(13, 13, 61, 0.86);
}
</style>

<template>
  <view class="page-meetingroom-list">
    <view class="list">
      <view class="item" v-for="(item, index) in list" bindtap="toMapPage" data-item="{{item}}">
        <image class="icon" src="{{h5StaticPath+'icon_meetingroom.svg'}}" />
        <label class="value">{{item.value}}</label>
      </view>
    </view>
  </view>
</template>

<script>
import wepy from '@wepy/core';
import { checkHasUserInfo } from '@/service/user';

import {
  setLastSearchedSpace,
  getHistorySearchedSpaceList,
  setHistorySearchedSpaceList
} from '../service/search';
import { getMapInfoHttp } from '@/packagesEnv/api/intelligentControl';

import config from '@/config';
import { getCompanyMapData } from '@/api/home';

let h5StaticPath = config.h5StaticPath + '/page-intelligent-control/';
let pageQuery = {};
let CompanyMapData;
let combinedData = [];
wepy.page({
  data: {
    list: [],
    h5StaticPath,
    companyId: ''
  },
  onLoad(query) {
    pageQuery = query;
    let meetingList = [];
    checkHasUserInfo()
      .then(userInfo => {
        this.companyId = query.companyId || userInfo.companyId;
        return getCompanyMapData(this.companyId);
      }).then(res => {
        CompanyMapData = JSON.parse(res.data);
         return getMapInfoHttp();
      })
      .then(res => {
        const result = JSON.parse(res.data);
        const httpDdata = (result && result.content) || [];
        combinedData = httpDdata.reduce((acc, cur) => {
          const target = acc.find(e => e.id == cur.id);
          if (target) {
            Object.assign(target, { title: cur.localName });
            // console.log('找到了', cur, index);
          } else {
            // console.log('data有没找到', cur.id);
          }
          return acc;
        }, CompanyMapData.mapInfo);

        combinedData.forEach(item => {
          if (item.roomFuncType == 320) {
            meetingList.push({
              key: 'title',
              spaceId: item.id,
              value: item.title,
              roomFuncType: item.roomFuncType
            });
          }
        });
        this.list = meetingList || [];
      });
  },
  methods: {
    toMapPage(e) {
      let item = e.target.dataset.item;
      setLastSearchedSpace(item);
      getHistorySearchedSpaceList().then(historyList => {
        setHistorySearchedSpaceList(historyList, item);
        if (pageQuery.from == 'home') {
          wx.navigateTo({
            url: `/packagesEnv/pages/officehome/index?spaceId=${item.spaceId}&companyId=${this.companyId}`
          });
        } else if (pageQuery.from == 'officehome') {
          wx.navigateBack({
            delta: 2
          });
        } else {
          wx.navigateBack({
            delta: 3
          });
        }
      });
    }
  }
});
</script>

<config>
{
  
    navigationBarTitleText: '所有会议室',
    navigationBarTextStyle: 'black',
    navigationBarBackgroundColor: '#FFFFFF',
    "backgroundColor": "#FFFFFF",
    usingComponents: {
     "user-space-list": "../components/user-space-list/user-space-list"
    }
}
</config>
