const _Http = getApp().globalData.http,
	{
		formatTime
	} = require("../../utils/getTime");
let obj = {};
Page({
	data: {

	},
	onLoad(options) {
		this.getDetail()
		let date = formatTime().split(" ")[0].split("/");
		obj = {
			year: date[0],
			month: date[1],
			day: date[2],
			quarter: Math.ceil(date[1] / 3)
		};
		console.log(obj)
	},
	getDetail() {
		_Http.basic({
			"id": "20230110151902",
			"version": 1,
			"content": {
				"where": {
					"year": obj.year
				}
			}
		}).then(res => {
			console.log("业绩目标", res)
			if (res.msg != '成功') return wx.showToast({
				title: res.msg,
				icon: "none"
			})
			if (res.data.length == 0) {
				wx.showToast({
					title: '未查询到内容',
					icon: "none",
					mask: true
				});
				setTimeout(() => {
					wx.navigateBack()
				}, 1000)
			};
			//l基本 h挑战 a实际 pl基础目标实际完成率 ph挑战目标实际完成率
			let data = res.data[0];
			let ar = [{
					fulfill: data.m1a + data.m2a + data.m3a,
					target: data.m3l + data.m3l + data.m3l,
				}, {
					fulfill: data.m4a + data.m5a + data.m6a,
					target: data.m4l + data.m5l + data.m6l,
				}, {
					fulfill: data.m7a + data.m8a + data.m9a,
					target: data.m7l + data.m8l + data.m9l,
				}, {
					fulfill: data.m10a + data.m11a + data.m12a,
					target: data.m10l + data.m11l + data.m12l,
				}].map(v => {
					v.achievingRate = (v.fulfill / v.target) * 100 + '%'
					return v
				}),
				table = [{
					label: "年",
					fulfill: data.y1a,
					target: data.y1l,
					achievingRate: data.y1pl + '%'
				}, {
					label: "第一季度",
					...ar[0]
				}, {
					label: "1月",
					fulfill: data.m1a,
					target: data.m1l,
					achievingRate: data.m1pl + '%'
				}, {
					label: "2月",
					fulfill: data.m2a,
					target: data.m2l,
					achievingRate: data.m2pl + '%'
				}, {
					label: "3月",
					fulfill: data.m3a,
					target: data.m3l,
					achievingRate: data.m3pl + '%'
				}, {
					label: "第二季度",
					...ar[1]
				}, {
					label: "4月",
					fulfill: data.m4a,
					target: data.m4l,
					achievingRate: data.m4pl + '%'
				}, {
					label: "5月",
					fulfill: data.m5a,
					target: data.m5l,
					achievingRate: data.m5pl + '%'
				}, {
					label: "6月",
					fulfill: data.m6a,
					target: data.m6l,
					achievingRate: data.m6pl + '%'
				}, {
					label: "第三季度",
					...ar[2]
				}, {
					label: "7月",
					fulfill: data.m7a,
					target: data.m7l,
					achievingRate: data.m7pl + '%'
				}, {
					label: "8月",
					fulfill: data.m8a,
					target: data.m8l,
					achievingRate: data.m8pl + '%'
				}, {
					label: "9月",
					fulfill: data.m9a,
					target: data.m9l,
					achievingRate: data.m9pl + '%'
				}, {
					label: "第四季度",
					...ar[3]
				}, {
					label: "10月",
					fulfill: data.m10a,
					target: data.m10l,
					achievingRate: data.m10pl + '%'
				}, {
					label: "11月",
					fulfill: data.m11a,
					target: data.m11l,
					achievingRate: data.m11pl + '%'
				}, {
					label: "12月",
					fulfill: data.m12a,
					target: data.m12l,
					achievingRate: data.m12pl + '%'
				}],
				statistics = [{
					label: "月度",
					fulfill: data[`m${obj.month}a`],
					target: data[`m${obj.month}l`],
					distance: Math.abs(data[`m${obj.month}a`] - data[`m${obj.month}l`]), //差额
					achievingRate: data[`m${obj.month}pl`] + "%", //达成
					color: "#FF9900"
				}, {
					label: "季度",
					...ar[obj.quarter - 1],
					distance: Math.abs(ar[obj.quarter - 1].fulfill - ar[obj.quarter - 1].target), //差额
					color: "#2AB4A3"
				}, {
					...table[0],
					label: "年度",
					distance: Math.abs(data.y1a - data.y1l), //差额
					color: "#FF001F"
				}].map(v => {
					v.achievingRate = v.achievingRate.split("%")[0] - 0
					return v
				})
			this.setData({
				table,
				statistics
			})
			console.log(statistics)
		})
	}
})