import HttpApi from "@/api";
import storeUtil from "@/util/store";
import Vue from "vue";

/*----------------------初始化字典信息---------------------*/
let dictionaryData: any = {};
HttpApi.searchDictionary('1').then((res: any) => {
  if (res) {
    dictionaryData.shipCountry = res
  }
});
HttpApi.searchDictionary('2').then((res: any) => {
  if (res) {
    dictionaryData.shipType = res
  }
});
HttpApi.searchDictionary('3').then((res: any) => {
  if (res) {
    dictionaryData.shipStatus = res
  }
})

setTimeout(() => {
  storeUtil.setDictionary(dictionaryData)
}, 1000)
/*----------------------初始化字典信息结束---------------------*/

/* 获取船队数据*/
// HttpApi.getShipRanks({}).then((res: any) => {
//   const TreeData: any[] = []
//   let shipIds = ''
//   const newShipList: any = []
//   for (let i = 0; i < res.length; i++) {
//     const fleet = JSON.parse(JSON.stringify(res[i]))
//     let tempData: any = {}
//     tempData = JSON.parse(JSON.stringify(fleet))
//     tempData.status = true
//     tempData.followShipList = []
//
//     if (fleet.followShipList && fleet.followShipList.length > 0) {
//       for (let j = 0; j < fleet.followShipList.length; j++) {
//         const ship = JSON.parse(JSON.stringify(fleet.followShipList[j]))
//         ship.status = true
//         ship.color = fleet.color
//         ship.name = ship.customName
//         tempData.followShipList.push(ship)
//         shipIds += ship.shipId + ','
//       }
//     }
//
//     TreeData.push(tempData)
//   }
//   Vue.prototype.$fleetList = TreeData
//   const data = {shipId: shipIds}
//
//   HttpApi.getShipMessage(data).then((res: any) => {
//     if (res) {
//       const fleetList = Vue.prototype.$fleetList
//       for (let i = 0; i < fleetList.length; i++) {
//         const followShipList = fleetList[i].followShipList
//         if (followShipList) {
//           for (let j = 0; j < followShipList.length; j++) {
//             for (let m = 0; m < res.length; m++) {
//               if (res[m].shipId === followShipList[j].shipId) {
//                 res[m].color = followShipList[j].color
//                 const element = res[m]
//                 element.isFleet = true
//                 Vue.prototype.$sourceShips.push(element)
//                 newShipList.push({
//                   y: element.shiptype,
//                   m: element.mmsi,
//                   h: element.heading,
//                   g: element.callsign,
//                   c: element.cog,
//                   o: element.imo,
//                   s: element.sog,
//                   v: element.aisNavStatus,
//                   l: element.length,
//                   p: element.destPort,
//                   b: element.breadth,
//                   r: element.eta,
//                   d: element.draught,
//                   t: element.posTime,
//                   i: element.shipId,
//                   n: element.lon,
//                   a: element.lat,
//                   e: element.shipnameEn,
//                   color: element.color,
//                   isFleet: true
//                 })
//               }
//             }
//           }
//         }
//       }
//       Vue.prototype.$originAllShipRankList = JSON.parse(JSON.stringify(newShipList))
//     }
//   })
// })
