request-api.js 3.3 KB
import http from "@/utils/http.js";
import utils from "@/utils/utils.js";

const request_api = {
	// 获取关注数据
	async getFollowList() {
		let query_data = `query{
	        info_get_attentions(type_name:"比赛",type_id:1,order:[["created_at","DESC"]]){
	          error success error_type rows 
	        }
	      	getlivedata 
			liveScore(lotId:73,matchState:"进行中",limit:50){
	      	  count
	        	matchs {
	            Sportsdt {
	              SportsdtMatchId
	            }
				YiqiuMatchId
				QcBf
				MatchState
				HostName
				GuestName 
				HostTeam{LogoFullPath} 
				GuestTeam{LogoFullPath}
	          }
	      	}
	      }`

		let result = await http.gql({
			query: query_data
		})

		console.info("-->" + JSON.stringify(result.data));

		var rows = result.data.info_get_attentions.rows;
		var liveData = result.data.getlivedata.LiveData;

		console.info(rows);
		if (rows) {
			for (let attention of rows) {
				console.log(attention)
				if (attention.target_base_data) {
					console.log(attention.target_base_data)
					// if(attention.target_base_data.validGame == 1) {
					if (utils.dateFormat(attention.target_base_data.Date).indexOf(utils.dateFormatYear(Date
						.now())) !== -1) {
						if (liveData[attention.target_code]) {
							if (attention.target_type_name == "足球") {
								attention.target_base_data.Half = liveData[attention.target_code].Half
								attention.target_base_data.RedCard = liveData[attention.target_code].RedCard
								attention.target_base_data.YellowCard = liveData[attention.target_code]
									.YellowCard
								attention.target_base_data.Status = liveData[attention.target_code].Status
								attention.target_base_data.ScoreAll = liveData[attention.target_code].ScoreAll

								var currStateTime = result.data.getlivedata.current_time - liveData[attention
									.target_code].TStartTime

								attention.target_base_data.MatchState = utils.getCurrentState(liveData[attention
									.target_code].Status, currStateTime)
							}
						}
					}
					// }
				}

			}


			var followList = [];
			for (let attention of rows) {
				var data = {}
				data.YiqiuMatchId = attention.target_base_data.yiqiu_id
				data.Sportsdt.SportsdtMatchId = attention.target_code
				data.HostName = attention.target_base_data.HomeTeam.Name
				data.GuestName = attention.target_base_data.AwayTeam.Name
				data.HostTeam.LogoFullPath = attention.target_base_data.HomeTeam.Photo
				data.GuestTeam.LogoFullPath = attention.target_base_data.AwayTeam.Photo
				data.MatchState = attention.target_base_data.Status
				data.MatchTime = attention.target_base_data.Date
				data.BcBf = attention.target_base_data.Half
				data.QcBf = attention.target_base_data.Score[0] + "-" + attention.target_base_data.Score[1]
				data.isFollow = true
				console.log(data)
				followList.push(data)
			}

		}

		return followList;
	},
	async getMatchList() {
		let query_data = `query{
        liveScore(lotId:72,matchState: "未") {
          count
          matchs {
            MatchTime
            MatchState
			IssueName
            GameName
            HostName
            GuestName
            YiqiuMatchId
          }
        } 
      }`

		let result = await http.gql({
			query: query_data
		})
		console.info(result);
		return result.data.liveScore.matchs;
	}

}



export default request_api;