<template>
	<view>
		<view class="timetabct">
			<view class="timetabctview">
				<view :class="{ activecllasscet: activeTotal == 0 }" @click="tabtimetap(0)">7天</view>
			</view>
			<view class="timetabctview">
				<view :class="{ activecllasscet: activeTotal == 1 }" @click="tabtimetap(1)">15天</view>
			</view>
			<view class="timetabctview">
				<view :class="{ activecllasscet: activeTotal == 2 }" @click="tabtimetap(2)">30天</view>
			</view>
		</view>

		<view class="timepick">
			<view class="timepicktime">
				<view @click="tabtimetap(3)">{{sheartime1}}</view>
				<view>
					<image class="Underimg" src="../../../static/images/Underimg.png" mode=""></image>
				</view>
			</view>
			<view class="timepickpick">
				<view @click="checkboxChange()" style="width: 40rpx;height:40rpx;border: 1rpx solid #E0E0E0;">
					<image v-if="timepickpickisshow" style="width: 40rpx;height: 40rpx;"
						src="../../../static/images/xuanzhong.png" mode=""></image>
				</view>
				<view style="font-size:26rpx;text-indent: 12rpx;">对比</view>
			</view>
			<view class="timepicktime" v-if="timepickpickisshow">
				<view @click="tabtimetap(4)">{{sheartime2}}</view>
				<view>
					<image class="Underimg" src="../../../static/images/Underimg.png" mode=""></image>
				</view>
			</view>
		</view>

		<view class="timeduibi">
			<view class="timeshow">数据起始时间：<text style="color: #333333;">{{kanbanlist.kaishitime}}</text></view>
			<view class="timeshow" v-if="kanbanlist.duibitime.length!=0">
				数据对比时间：
				<text style="color: #333333;">{{kanbanlist.duibitime}}</text>
			</view>
		</view>
		<view style="width: 100%;height: 20rpx;background: #FAFAFA;"></view>
		<view class="boxzonglan" style="min-height: 100rpx;">
			<view class="zonglantit">简报</view>
			<view class="zonglanbox">
				<view class="grid" v-for="(item,index) in numlist" :key="index"
					style="height: auto;padding-bottom: 20rpx;">
					<view class="audonum" v-if="item.name=='接待时长'">{{item.name}}/分</view>
					<view class="audonum" v-else>{{item.name}}</view>
					<view class="num">
						<view class="" style="width: 35%;">
							{{index==1?item.num+'%':item.num}}
						</view>
						<view class="comparesize" v-if="compareFlag&&timepickpickisshow">
							<text style="margin-right: 10rpx;">对比：{{index==1?item.num1+'%':item.num1}} </text>
							<template v-if="item.num2*1 != 0">
								<text
									:style="{color:item.num2*1>0?'red':'green'}">{{item.num2+'%'}}{{item.num2*1 > 0 ? '↑':'↓'}}</text>
							</template>
							<template>
								<text
									:style="{color:item.num2*1>0?'red':'green'}">{{item.num2+'%'}}</text>
							</template>
						</view>
					</view>
				</view>
			</view>
		</view>
		<view style="width: 100%;height: 20rpx;background: #FAFAFA;"></view>
		<view class="boxtittab" style="border: none;height: 82rpx;">
			<view class="tabbox">
				<view :class="{ activecllasscet2: newactiveTotal == 0 }" @click="tabxuanxiangtap(0)">项目</view>
			</view>
			<view class="tabbox">
				<view :class="{ activecllasscet2: newactiveTotal == 1 }" @click="tabxuanxiangtap(1)">顾问</view>
			</view>
			<view class="tabbox">
				<view :class="{ activecllasscet2: newactiveTotal == 2 }" @click="tabxuanxiangtap(2)">团队</view>
			</view>
			<view class="tabbox">
				<view :class="{ activecllasscet2: newactiveTotal == 3 }" @click="tabxuanxiangtap(3)">销讲一级</view>
			</view>
			<view class="tabbox">
				<view :class="{ activecllasscet2: newactiveTotal == 4 }" @click="tabxuanxiangtap(4)">销讲二级</view>
			</view>
		</view>


		<view class="chart">
			<view
				style="display: flex;justify-content:center;padding-left: 30rpx;padding-right: 30rpx;margin-top: 16rpx;"
				v-if="guwenshow&&lopanobj.name" @click="oninputtap()">
				<view class="title2-che" style="width: 220rpx;">{{lopanobj.name}}
					<image class="righttochoose" src="../../../static/images/righttochoose.png" mode=""></image>
				</view>
			</view>

			<view style="padding: 30rpx;padding-bottom: 20rpx;align-items: center;" v-if="Selectlevel">
				<view style="display: flex;align-items: center;border-bottom: 1px solid #C9C9C9;height: 80rpx;">
					<view>选择一级：</view>
					<view style="width:75%;">
						<input @click="oninputtap2()" v-model="Selectlevelobj.name" type="text" disabled="true"
							:border="border" placeholder="请选择" />
					</view>
					<view>
						<image src="https://qufang.oss-cn-beijing.aliyuncs.com/upload/icon/xcx/jjycrm/qf/more.png"
							style="width:12rpx;height:23rpx;margin-left: 16rpx;">
					</view>
					<!-- <view style="display: flex;justify-content:center;padding-left: 30rpx;padding-right: 30rpx;margin-top: 16rpx;"
						v-if="Selectlevelobj.name" @click="oninputtap2()">
						<view class="title2-che" style="width: 220rpx;">{{Selectlevelobj.name}}
							<image class="righttochoose" src="../../../static/images/righttochoose.png" mode=""></image>
						</view>
					</view> -->
				</view>


				<view style="display: flex;align-items: center;border-bottom: 1px solid #C9C9C9;height: 80rpx;">
					<view>选择二级：</view>
					<view style="width:75%;">
						<input @click="oninputtap3()" v-model="erSelectlevelobj.name" type="text" disabled="true"
							:border="border" placeholder="请选择" />
					</view>
					<view>
						<image src="https://qufang.oss-cn-beijing.aliyuncs.com/upload/icon/xcx/jjycrm/qf/more.png"
							style="width:12rpx;height:23rpx;margin-left: 16rpx;">
					</view>
					<!-- <view style="display: flex;justify-content:center;padding-left: 30rpx;padding-right: 30rpx;margin-top: 16rpx;"
						v-if="erSelectlevelobj.name" @click="oninputtap3()">
						<view class="title2-che" style="width: 220rpx;">{{erSelectlevelobj.name}}
							<image class="righttochoose" src="../../../static/images/righttochoose.png" mode=""></image>
						</view>
					</view> -->
				</view>
			</view>

			<view style="display: flex;align-items: center;height: 80rpx;justify-content: center;"
				v-if="Selecttuandui&&Selecttuanduiobj.name" @click="oninputtap4()">
				<view class="title2-che" style="width: 220rpx;">{{Selecttuanduiobj.name}}
					<image class="righttochoose" src="../../../static/images/righttochoose.png" mode=""></image>
				</view>
			</view>


			<view class="single">
				<!-- <view class="danwei" style="margin-top: 10rpx;">销讲词执行率</view> -->
				<view class="uchaserbox" :class="{ uchaserboxs : newactiveTotal  == 1 || newactiveTotal == 3 }"
					v-if="lineOptsect.series.length!=0">

					<qiun-data-charts :style="!showCanvas?'display:none':''" :type="linetype" :chartData="lineOptsect"
						background="none" :ontouch="true" canvasId="wangxiaohuaerlingeryilingwuyibao" :opts="opts"
						:canvas2d="true" />
				</view>
				<view v-else style="width: 100%;">
					<view style="width: 100%;text-align: center;">
						<image style="width: 200rpx;height: 200rpx;"
							src="https://static.quhouse.com/zhikong_xcx_img/nodatalist.png" mode=""></image>
					</view>
					<view style="text-align: center;width: 100%;margin-top: 20rpx;color: #999999;">暂无数据</view>
				</view>
			</view>

		</view>

		<view style="width: 100%;height: 20rpx;background: #FAFAFA;"></view>
		<view class="single" v-if="timepickpickisshow">
			<view class="title">
				<view class="title1">对比报表</view>
			</view>
			<view class="table" v-if="!guwenFlag">
				<view v-for="(item,index) in tableDate" :key="index">
					<view class="tr">
						<view v-for="(item1,index1) in item" :key="index" style="width: 100%;">
							<view v-if="index1<item.length-1||index==0" class="td"
								style="border-right:1px solid #E0E0E0;">{{item1}}</view>
							<view v-if="index>0 && index1==item.length-1" class="td"
								style="border-right:1px solid #E0E0E0;" :style="{color:item1*1>0?'red':'green'}">
								{{item1==0?'--':item1+'%'}}{{item1*1>0?'↑':item1*1<0?'↓':''}}
							</view>
						</view>
					</view>
				</view>
			</view>
			<view class="table" v-if="guwenFlag" style="width: 100%;">
				<scroll-view scroll-x="true" style="white-space: nowrap;">
					<view v-for="(item,index) in tableDate" :key="index"
						:style="{display:index==0?'inline-block':'block'}">
						<view class="tr" style="display: inline-block;">
							<view v-for="(item1,index1) in item" :key="index1" class="trd"
								style="display: inline-block;">
								<view v-if="index==1&&index1>0" class="td" :style="{color:item1*1>0?'red':'green'}"
									style="border-right:1px solid #E0E0E0;">
									{{item1==0?'--':item1+'%'}}{{item1*1>0?'↑':item1*1<0?'↓':''}}
								</view>
								<view v-else-if="index>1&&index1>0" class="td" style="border-right:1px solid #E0E0E0;">
									{{item1+'%'}}
								</view>
								<view v-else class="td" style="border-right:1px solid #E0E0E0;">{{item1}}</view>
							</view>
						</view>
					</view>
				</scroll-view>
			</view>

		</view>
		<view style="width: 100%;height: 60rpx;"></view>
		<u-select v-model="Showhiddenunits" mode="single-column" :list="selectlist" @confirm="confirm"
			:default-value="selindexList">
		</u-select>
		<u-select v-model="Showhiddenunits2" mode="single-column" :list="selectlist2" @confirm="confirm2"
			:default-value="selindex">
		</u-select>
		<u-select v-model="Showhiddenunits3" mode="single-column" :list="selectlist3" @confirm="confirm3"
			:default-value="selindex">
		</u-select>
		<u-select v-model="Showhiddenunits4" mode="single-column" :list="selectlist4" @confirm="confirm4"
			:default-value="selindexList4">
		</u-select>
		<u-calendar v-model="totalTimeShow" mode="range" @change="totalTimeChange"></u-calendar>
		<newcalendar v-model="totalTimeShow2" :planNum='intervaltime' mode="date" @change="totalTimeChange2">
		</newcalendar>
	</view>

</template>
<script>
	import newcalendar from '@/components/newcalendar/newcalendar.vue';
	export default {
		data() {
			return {
				selindexList: [0], // 默认选中第一项
				selindexList4: [0], // 默认选中第一项
				compareFlag: false,
				numlist: [{
						name: '接待量',
						num: '10',
						num1: '0',
						num2: '0'
					},
					{
						name: '平均执行率',
						num: '10',
						num1: '0',
						num2: '0'
					},
					{
						name: '接待时长',
						num: '10',
						num1: '0',
						num2: '0'
					},
				],
				activeTotal: 0, //时间下标
				newactiveTotal: 0, //tab下标
				totalTimeShow: false,
				totalTimeShow2: false,
				totalTimeShow3: false,
				cWidth: uni.upx2px(690),
				cHeight: uni.upx2px(453),
				AcHeight: uni.upx2px(500),
				kanbanlist: { //录音和测评的数据
					kaishitime: '',
					duibitime: '',
					audonum: '',
					audotime: "",
					avgDuration: '',
					fraction: ''
				},
				pamect: { //接口参数
					houseId: '',
					timeType: "4",
					firstStartDate: '', //第一次开始时间
					firstEndDate: '', //第一次结束时间
					lastStartDate: '',
					lastEndDate: '',
					accountId: '', //顾问ids
					marketingId: '', //二级销讲id
					deptId: "", //部门id
					showStatus: 0
				},
				linetype: "line",
				lineOptsect: {}, //图表数据
				Showhiddenunits: false,
				selectlist: [],
				guwenshow: false,
				lopanobj: {
					id: '',
					name: ''
				},
				//二级相关
				Selectlevel: false,
				Selectlevelobj: {
					id: '',
					name: ''
				},
				erSelectlevelobj: {
					id: '',
					name: ''
				},
				Showhiddenunits2: false,
				Showhiddenunits3: false,
				selectlist2: [],
				selectlist3: [],
				//团队相关
				Selecttuandui: false,
				selectlist4: [],
				Selecttuanduiobj: {
					id: '',
					name: ''
				},
				Showhiddenunits4: false,
				showCanvas: true,

				timepickpickisshow: false,
				sheartime1: "",
				sheartime2: "",
				intervaltime: 0,
				tableDate: [],
				guwenFlag: false,
				opts: {}, // 配置项为空
			};

		},
		components: {
			newcalendar
		},
		onLoad: function(options) {
			this.pamect.houseId = uni.getStorageSync('buildingID').id;
			this.init()
		},
		onPullDownRefresh() {
			this.init()
			setTimeout(function() {
				uni.stopPullDownRefresh();
			}, 1000);
		},
		watch: {
			Showhiddenunits(newValue, oldValue) {
				this.showCanvas = !newValue
			},
			Showhiddenunits2(newValue, oldValue) {
				this.showCanvas = !newValue
			},
			Showhiddenunits3(newValue, oldValue) {
				this.showCanvas = !newValue
			},
			Showhiddenunits4(newValue, oldValue) {
				this.showCanvas = !newValue
			},

			totalTimeShow(newValue, oldValue) {
				this.showCanvas = !newValue
			},
			totalTimeShow2(newValue, oldValue) {
				this.showCanvas = !newValue
			},
			totalTimeShow3(newValue, oldValue) {
				this.showCanvas = !newValue
			},
		},
		methods: {
			//是否对比
			checkboxChange() {
				if (this.newactiveTotal == 3) {
					uni.showToast({
						title: '销讲一级无对比',
						duration: 2000
					});
					return
				}
				if (this.newactiveTotal == 2) {
					if (this.Selecttuanduiobj.id == '') {
						uni.showToast({
							title: '全部团队无对比',
							duration: 2000
						});
						return
					}
				}

				if (this.timepickpickisshow == true) {
					this.timepickpickisshow = false;
					this.pamect.showStatus = 0;
					this.init()
				} else {
					this.timepickpickisshow = true;
					this.pamect.showStatus = 1;
				}
				this.activeTotal = 8;
			},

			init() {
				this.$u.post("/cusLvStatistics/lyAndcp", this.pamect).then(data => {
					this.pamect.lastStartDate = data.lastStartDate;
					this.pamect.lastEndDate = data.lastEndDate;
					this.numlist[0].num = data.startSumCustomer
					this.numlist[1].num = data.startFraction;

					this.numlist[2].num = Math.floor(data.startSumDuration / 60) || 0;
					if (data.endSumDuration != null) {
						this.compareFlag = true
						// return
						this.numlist[0].num1 = data.endSumCustomer
						this.numlist[1].num1 = data.endFraction;
						this.numlist[2].num1 = Math.floor(data.endSumDuration / 60) || 0;
						this.numlist[0].num2 = data.contrastSumCustomer
						this.numlist[1].num2 = data.contrastFraction;
						this.numlist[2].num2 = data.contrastSumDuration || 0;
					} else {
						this.compareFlag = false
					}
					this.sheartime1 = data.lastStartDate.substring(5, 10) + "--" + data.lastEndDate.substring(5,
						10);
					this.sheartime2 = '请选择';
					this.kanbanlist.duibitime = '';
					var kaishi = this.DateDiff(data.lastStartDate, data.lastEndDate);
					this.kanbanlist.kaishitime = data.lastStartDate + "至" + data.lastEndDate + "(" + kaishi + "天)";
					if (this.pamect.showStatus == 1) {
						this.sheartime2 = data.firstStartDate.substring(5, 10) + "--" + data.firstEndDate
							.substring(5, 10);
						var jeishu = this.DateDiff(data.firstStartDate, data.firstEndDate);
						this.kanbanlist.duibitime = data.firstStartDate + "至" + data.firstEndDate + "(" + jeishu +
							"天)";
					}
					this.kanbanlist.audonum = data.sumCustomer;
					this.kanbanlist.audotime = data.avgDuration;
					this.kanbanlist.avgDuration = data.fraction;
					this.kanbanlist.fraction = data.fraction;

					if (this.newactiveTotal == 0) {
						this.ProjectDimension()
					} else if (this.newactiveTotal == 1) {
						if (this.pamect.accountId == "") {
							this.getguwenlist()
						} else {
							this.ConsultantDimension()
						}
					} else if (this.newactiveTotal == 2) {
						if (this.pamect.deptId == "") {
							this.getuanduilist()
						} else {
							this.TeamCompared()
						}
					} else if (this.newactiveTotal == 3) {
						this.speakingLevel()
					} else {
						if (this.pamect.marketingId == '') {
							this.getonsyiji()
						} else {
							this.aboutEecondary()
						}
					}
				});
			},
			//起始时间
			totalTimeChange(e) {
				this.pamect.lastStartDate = e.startDate;
				this.pamect.lastEndDate = e.endDate;
				var kaishi = this.DateDiff(this.pamect.lastStartDate, this.pamect.lastEndDate)
				this.kanbanlist.kaishitime = this.pamect.lastStartDate + "至" + this.pamect.lastEndDate + "(" + kaishi +
					"天)";

				if (this.pamect.showStatus == 0) {
					this.init()
					this.totalTimeShow = false;
				} else {
					if (this.pamect.firstStartDate.length == 0) {
						uni.showToast({
							title: '请选择对比时间',
							duration: 2000
						});
					} else {
						var jshu = this.DateDiff(this.pamect.firstStartDate, this.pamect.firstEndDate)
						if (kaishi == jshu) {
							this.init()
						} else {
							uni.showToast({
								title: '请选择相同天数',
								duration: 2000
							});
						}
					}
					this.totalTimeShow = false;
				}
			},
			//对比时间
			totalTimeChange2(e) {
				var d = new Date(e.result);
				d.setDate(d.getDate() + this.intervaltime);
				var year = d.getFullYear();
				var month = d.getMonth() + 1;
				if (month < 10) month = '0' + month;
				var day = d.getDate();
				if (day < 10) day = '0' + day;
				this.pamect.firstStartDate = e.result;
				this.pamect.firstEndDate = year + '-' + month + '-' + day;
				console.log(this.pamect.firstStartDate)
				var kaishi = this.DateDiff(this.pamect.lastStartDate, this.pamect.lastEndDate)
				var jeishu = this.DateDiff(this.pamect.firstStartDate, this.pamect.firstEndDate)
				this.kanbanlist.duibitime = this.pamect.firstStartDate + "至" + this.pamect.firstEndDate + "(" + jeishu +
					"天)";

				console.log(this.pamect.lastStartDate, this.pamect.lastEndDate, kaishi, jeishu)
				if (kaishi == jeishu) {
					this.init()
				} else {
					uni.showToast({
						title: '请选择相同天数',
						duration: 2000
					});
				}
				this.totalTimeShow2 = false;
			},
			//自定义时间
			totalTimeChange3(e) {
				this.pamect.firstStartDate = "";
				this.pamect.firstEndDate = "";
				this.pamect.lastStartDate = e.startDate;
				this.pamect.lastEndDate = e.endDate;
				this.init()
				this.totalTimeShow3 = false;
			},


			//时间切换
			tabtimetap(index) {
				if (index == 0) {
					this.pamect.timeType = "4";
					this.pamect.firstStartDate = '';
					this.pamect.firstEndDate = '';
					this.pamect.lastStartDate = '';
					this.pamect.lastEndDate = '';
					this.init()
				} else if (index == 1) {
					this.pamect.timeType = "5";
					this.pamect.firstStartDate = '';
					this.pamect.firstEndDate = '';
					this.pamect.lastStartDate = '';
					this.pamect.lastEndDate = '';
					this.init()
				} else if (index == 2) {
					this.pamect.timeType = "6";
					this.pamect.firstStartDate = '';
					this.pamect.firstEndDate = '';
					this.pamect.lastStartDate = '';
					this.pamect.lastEndDate = '';
					this.init()
				} else if (index == 3) {
					this.pamect.timeType = "";
					this.totalTimeShow = true;
				} else if (index == 4) {
					this.pamect.timeType = "";
					var kaishi = this.DateDiff(this.pamect.lastStartDate, this.pamect.lastEndDate)
					console.log(kaishi)
					this.intervaltime = kaishi - 1;
					this.totalTimeShow2 = true;
				} else {
					this.pamect.timeType = "";
					this.totalTimeShow3 = true;
				}
				this.activeTotal = index;
			},
			//tab切换
			tabxuanxiangtap(index) {
				this.newactiveTotal = index;
				this.guwenshow = false;
				this.Selectlevel = false;
				this.Selecttuandui = false;
				this.tableDate = []
				this.pamect.showStatus = 0;
				this.pamect.timeType = "4";
				this.pamect.firstStartDate = '';
				this.pamect.firstEndDate = '';
				this.pamect.lastStartDate = '';
				this.pamect.lastEndDate = '';
				this.pamect.accountId = '';
				this.pamect.marketingId = '';
				this.pamect.deptId = ""
				this.activeTotal = 0;
				this.timepickpickisshow = false;
				this.init()

				if (index == 1) {
					this.guwenshow = true;
				}
			},
			//项目维度
			ProjectDimension() {
				const that = this;
				that.lineOptsect = {
					categories: [],
					series: []
				};
				this.linetype = "line";
				this.$u.post("/cusLvStatistics/teamOrOneValueShow", this.pamect).then(data => {
					if (this.pamect.showStatus == 0) {
						that.lineOptsect = {
							categories: [],
							series: [{
								name: '起始时间',
								data: [],
								color: '#7ED3F4'
							}]
						}
						data.lastValue.forEach((child, zxc) => {
							that.lineOptsect.categories.push(child.statDate.substring(5, 10))
						})
						that.lineOptsect.series[0].data = data.lastValue.map(item => item.fraction);
					} else {
						that.lineOptsect = {
							categories: [],
							series: [{
									name: '起始时间',
									data: [],
									color: '#7ED3F4'
								},
								{
									name: '对比时间',
									data: [],
									color: '#FF7070'
								},
							]
						}
						data.firstValue.forEach((item, sdf) => {
							data.lastValue.forEach((child, zxc) => {
								if (sdf == zxc) {
									that.lineOptsect.categories.push(
										child.statDate.substring(5, 10) + 'vs' + item.statDate
										.substring(5, 10)
									)
								}
							})
						})
						that.lineOptsect.series[1].data = data.firstValue.map(item => item.fraction);
						that.lineOptsect.series[0].data = data.lastValue.map(item => item.fraction)
						that.guwenFlag = false
						// // 处理表格数据
						let arr = [
							['时间', '时段一', '时段二', '变化']
							// {
							// 	time:'时间',
							// 	time1:'时段一',
							// 	time2:'时段二',
							// 	compare:'变化'
							// },
						]
						that.lineOptsect.categories.map((item, index) => {
							let newarr = [item, data.lastValue[index].fraction, data.firstValue[index]
								.fraction, data.contrast[index].data
							]
							// obj.time=item
							// obj.time1=data.firstValue[index].fraction
							// obj.time2=data.lastValue[index].fraction
							// obj.compare=data.contrast[index].data
							// arr.push(obj)
							arr.push(newarr)
						})
						// console.log(arr)
						that.tableDate = arr
					}
				});
			},
			//顾问维度
			ConsultantDimension() {
				const that = this;
				that.lineOptsect = {
					categories: [],
					series: []
				};
				this.linetype = "radar";
				this.$u.post("/cusLvStatistics/accFirstLevelContrast", this.pamect).then(data => {
					// return
					let max = data.firstList[0].total
					for (let i = 0; i < data.firstList.length; i++) {
						if (max < data.firstList[i]) max = data.firstList[i];
					}
					this.opts = {
						fontSize: 10,
						extra: {
							radar: {
								max: max + 25
							}
						}
					}
					if (this.pamect.showStatus == 0) {
						that.lineOptsect = {
							categories: [],
							series: [{
								name: '时段一',
								data: [],
								color: '#7ED3F4'
							}]
						}
						data.firstList.forEach((item, sdf) => {
							that.lineOptsect.categories.push(item.name)
							that.lineOptsect.series[0].data.push(data.firstList[sdf].total)
						})
						console.log(this.lineOptsect, 'console.log(this.lineOptsect)')
						// that.lineOptsect.series[0].data = data.lastValue.map(item => item.fraction);
					} else {
						// 当有对比的时候
						that.lineOptsect = {
							categories: [],
							series: [{
									name: '时段一',
									data: [],
									color: '#7ED3F4'
								},
								{
									name: '时段二',
									data: [],
									color: '#FF7070'
								},
							]
						}
						data.headerList.forEach((item, sdf) => {
							that.lineOptsect.categories.push(item.name)
							that.lineOptsect.series[0].data.push(data.firstList[sdf].total)
							that.lineOptsect.series[1].data.push(data.secondList[sdf].total)
						})
						// return
						// // 处理表格数据
						that.guwenFlag = true
						let arr = []
						arr[0] = ['时间', ...that.lineOptsect.categories]
						arr[1] = ['变化']
						arr[2] = ['时段一']
						arr[3] = ['时段二']
						// console.log(arr)
						data.firstList.map((item, index) => {
							arr[2].push(item.total)
							arr[3].push(data.secondList[index].total)
							arr[1].push(data.thirdList[index].total)
						})
						that.tableDate = arr

						console.log(this.lineOptsect, 'console.log(this.lineOptsect)')
					}

				});
			},
			// 顾问纬度选择顾问
			oninputtap() {
				this.Showhiddenunits = true;
			},
			// 顾问选择确认
			confirm(e) {
				this.lopanobj.id = e[0].value;
				this.lopanobj.name = e[0].label;
				this.pamect.accountId = this.lopanobj.id;
				this.ConsultantDimension()
				this.Showhiddenunits = false;
				for (let i = 0; i < this.selectlist.length; i++) {
					if (e[0].value == this.selectlist[i].value) {
						this.selindexList[0] = i
					}
				}
			},
			//获取顾问
			getguwenlist() {
				this.$u.post("/cusLvStatistics/selectAllAccountIdByHouseId", {
					houseId: this.pamect.houseId
				}).then(data => {
					this.selectlist = [];
					if (data.length == 0) {
						this.lineOptsect = {
							categories: [],
							series: []
						};
						this.guwenshow = false;
						return
					} else {
						this.guwenshow = true;
						data.forEach(item => {
							this.selectlist.push({
								value: item.accountId,
								label: item.name
							})
						})
						this.lopanobj.id = data[0].accountId;
						this.lopanobj.name = data[0].name;
						this.pamect.accountId = this.lopanobj.id;
						this.ConsultantDimension()
					}
				})
			},
			//销讲一级
			speakingLevel() {
				this.linetype = "radar";
				this.lineOptsect = {
					categories: [],
					series: []
				};
				this.$u.post("/cusLvStatistics/firstLevelContrast", this.pamect).then(data => {
					if (data.length == 0) {
						return
					} else {
						let max = data[0].avgExecutionRate
						let list = data.map(item => {
							return item.name
						});
						let list1 = data.map(item => {
							if (item.avgExecutionRate == null) {
								item.avgExecutionRate = 0
							} else {
								item.avgExecutionRate = item.avgExecutionRate
							}
							if (max < item.avgExecutionRate) max = item.avgExecutionRate;
							return item.avgExecutionRate
						});
						this.opts = {
							fontSize: 10,
							extra: {
								radar: {
									max: max + 25
								}
							}
						}
						this.lineOptsect = {
							"categories": list,
							"series": [{
								"name": "销讲一级",
								"data": list1
							}]
						}
					}
				})
			},
			//销讲二级
			aboutEecondary() {
				this.lineOptsect = {};
				this.linetype = "line";
				this.$u.post("/cusLvStatistics/level2Contrast", this.pamect).then(data => {
					if (this.pamect.showStatus == 0) {
						this.lineOptsect = {
							categories: [],
							series: [{
								name: '起始时间',
								data: [],
								color: '#7ED3F4'
							}]
						}
						data.lastList.forEach((item, sdf) => {
							this.lineOptsect.categories.push(item.statDate.substring(5, 10))
						})
						this.lineOptsect.series[0].data = data.lastList.map(item => item.avgExecutionRate);
					} else {
						this.lineOptsect = {
							categories: [],
							series: [{
									name: '起始时间',
									data: [],
									color: '#7ED3F4'
								},
								{
									name: '对比时间',
									data: [],
									color: '#FF7070'
								},
							]
						}
						data.firstList.forEach((item, sdf) => {
							data.lastList.forEach((child, zxc) => {
								if (sdf == zxc) {
									this.lineOptsect.categories.push(
										child.statDate.substring(5, 10) + 'vs' + item.statDate
										.substring(5, 10)
									)
								}
							})
						})
						this.lineOptsect.series[1].data = data.firstList.map(item => item.avgExecutionRate);
						this.lineOptsect.series[0].data = data.lastList.map(item => item.avgExecutionRate)
						let that = this
						this.guwenFlag = false
						// // 处理表格数据
						let arr = [
							['时间', '时段一', '时段二', '变化']
						]
						that.lineOptsect.categories.map((item, index) => {
							let newarr = [item, data.lastList[
									index].avgExecutionRate, data.firstList[index].avgExecutionRate,
								data.contrast[index].data
							]
							arr.push(newarr)
						})
						// console.log(arr)
						that.tableDate = arr
					}
				})
			},
			//销讲二级:获取一级
			getonsyiji() {
				this.$u.post("/cusLvStatistics/findAllFirstLevel", {
					houseId: this.pamect.houseId
				}).then(data => {
					this.selectlist2 = [];
					if (data.length == 0) {
						this.Selectlevel = false;
						this.lineOptsect = {
							categories: [],
							series: []
						};
						return
					} else {
						this.Selectlevel = true;
						data.forEach(item => {
							this.selectlist2.push({
								value: item.marketingId,
								label: item.name
							})
						})
						this.Selectlevelobj.id = data[0].marketingId;
						this.Selectlevelobj.name = data[0].name;
						this.getonserji(this.Selectlevelobj.id)
					}
				})
			},
			//销讲二级:通过一级获取二级
			getonserji(ccd) {
				this.$u.post("/cusLvStatistics/findLevel2ByFirstLevel", {
					houseId: this.pamect.houseId,
					marketingId: ccd
				}).then(data => {
					this.selectlist3 = [];
					data.forEach(item => {
						this.selectlist3.push({
							value: item.marketingId,
							label: item.name
						})
					})
					this.erSelectlevelobj.id = data[0].marketingId;
					this.erSelectlevelobj.name = data[0].name;
					this.pamect.marketingId = this.erSelectlevelobj.id;
					this.aboutEecondary()
				})
			},
			//销讲二级:一级选择
			oninputtap2() {
				this.Showhiddenunits2 = true;
			},
			//销讲二级:二级选择
			oninputtap3() {
				if (this.Selectlevelobj.id == "") {
					uni.showToast({
						title: '请先选择一级',
						duration: 2000
					});
				} else {
					this.Showhiddenunits3 = true;
				}
			},
			//销讲二级:一级选择确认
			confirm2(e) {
				this.Selectlevelobj.id = e[0].value;
				this.Selectlevelobj.name = e[0].label;
				this.getonserji(this.Selectlevelobj.id)
			},
			//销讲二级:二级选择确认
			confirm3(e) {
				this.erSelectlevelobj.id = e[0].value;
				this.erSelectlevelobj.name = e[0].label;
				this.pamect.marketingId = this.erSelectlevelobj.id;
				this.aboutEecondary()
			},





			//团队请选择
			oninputtap4() {
				this.Showhiddenunits4 = true;
			},
			//团队选择确认
			confirm4(e) {
				this.Selecttuanduiobj.id = e[0].value;
				this.Selecttuanduiobj.name = e[0].label;
				this.pamect.deptId = this.Selecttuanduiobj.id;

				this.pamect.showStatus = 0;
				this.pamect.timeType = "4";
				this.pamect.firstStartDate = '';
				this.pamect.firstEndDate = '';
				this.pamect.lastStartDate = '';
				this.pamect.lastEndDate = '';
				this.activeTotal = 0;
				this.timepickpickisshow = false;
				this.init()
				this.TeamCompared()

				for (let i = 0; i < this.selectlist4.length; i++) {
					if (e[0].value == this.selectlist4[i].value) {
						this.selindexList4[0] = i
					}
				}
			},
			//获取团队列表
			getuanduilist() {
				this.$u.post("/cusLvStatistics/findAllDeptIdByHouseId ", {
					houseId: this.pamect.houseId
				}).then(data => {
					this.selectlist4 = [{
						value: "",
						label: "全部"
					}];
					if (data.length == 0) {
						this.Selecttuandui = false;
						this.lineOptsect = {
							categories: [],
							series: []
						};
						return
					} else {
						this.Selecttuandui = true;
						data.forEach(item => {
							this.selectlist4.push({
								value: item.deptId,
								label: item.deptName
							})
						})
						this.Selecttuanduiobj.id = "";
						this.Selecttuanduiobj.name = "全部";
						this.pamect.deptId = this.Selecttuanduiobj.id;
						this.TeamCompared()
					}
				})
			},
			//团队对比
			TeamCompared() {
				const that = this;
				that.lineOptsect = {};
				this.linetype = "line";
				this.$u.post("/cusLvStatistics/teamOrOneValueShowByDept", this.pamect).then(data => {
					if (this.Selecttuanduiobj.id == "") {
						var newlist = [];
						for (var i in data) {
							var ect = data[i].receptionStatList.map(item => {
								if (item.fraction == null) {
									item.fraction = 0
								} else {
									item.fraction = item.fraction
								}
								return item.fraction
							});
							newlist.push({
								name: data[i].deptName,
								data: ect
							})
						}
						var timelist = [];
						for (var i in data) {
							var ect = data[i].receptionStatList.map(item => {
								return item.statDate
							});
							timelist.push({
								name: data[i].deptName,
								data: ect
							})
						}
						var xAxisdata = [];
						timelist[0].data.forEach((item, sdf) => {
							xAxisdata.push(item.substring(5, 10))
						})
						that.lineOptsect = {
							categories: xAxisdata,
							series: newlist
						}
					} else {
						if (this.pamect.showStatus == 0) {
							that.lineOptsect = {
								categories: [],
								series: [{
									name: '起始时间',
									data: [],
									color: '#7ED3F4'
								}]
							}
							data.lastValue.receptionStatList.forEach((item, sdf) => {
								that.lineOptsect.categories.push(item.statDate.substring(5, 10))
							})
							that.lineOptsect.series[0].data = data.lastValue.receptionStatList.map(item => item
								.fraction);
						} else {
							that.lineOptsect = {
								categories: [],
								series: [{
										name: '起始时间',
										data: [],
										color: '#7ED3F4'
									},
									{
										name: '对比时间',
										data: [],
										color: '#FF7070'
									},
								]
							}
							data.firstValue.receptionStatList.forEach((item, sdf) => {
								data.lastValue.receptionStatList.forEach((child, zxc) => {
									if (sdf == zxc) {
										that.lineOptsect.categories.push(
											child.statDate.substring(5, 10) + 'vs' + item
											.statDate.substring(5, 10)
										)
									}
								})
							})
							that.lineOptsect.series[1].data = data.firstValue.receptionStatList.map(item => item
								.fraction);
							that.lineOptsect.series[0].data = data.lastValue.receptionStatList.map(item => item
								.fraction)
							that.guwenFlag = false
							// 团队处理数据
							// // 处理表格数据
							let arr = [
								['时间', '时段一', '时段二', '变化']
								// {
								// 	time:'时间',
								// 	time1:'时段一',
								// 	time2:'时段二',
								// 	compare:'变化'
								// },
							]
							that.lineOptsect.categories.map((item, index) => {
								let newarr = [item, data
									.lastValue.receptionStatList[index].fraction, data.firstValue
									.receptionStatList[index].fraction, data.contrast
									.receptionStatList[index].data
								]
								// obj.time=item
								// obj.time1=data.firstValue[index].fraction
								// obj.time2=data.lastValue[index].fraction
								// obj.compare=data.contrast[index].data
								// arr.push(obj)
								arr.push(newarr)
							})
							// console.log(arr)
							that.tableDate = arr
						}
					}
				});
			},

			//算相隔天数
			DateDiff(sDate1, sDate2) {
				var aDate, oDate1, oDate2, iDays;
				aDate = sDate1.split("-");
				oDate1 = new Date(aDate[1] + '-' + aDate[2] + '-' + aDate[0]); //转换为yyyy-MM-dd格式
				aDate = sDate2.split("-");
				oDate2 = new Date(aDate[1] + '-' + aDate[2] + '-' + aDate[0]);
				iDays = parseInt(Math.abs(oDate1 - oDate2) / 1000 / 60 / 60 / 24); //把相差的毫秒数转换为天数
				return iDays + 1; //返回相差天数
			},
		},
	}
</script>
<style lang="scss" scoped>
	.title2-che {
		width: 178rpx;
		height: 48rpx;
		background: #FFFFFF;
		border-radius: 6rpx;
		border: 1px solid #E0E0E0;
		line-height: 48rpx;
		font-size: 28rpx;
		font-weight: 400;
		color: #666666;
		text-indent: 12rpx;
		margin-left: 35rpx;
		position: relative;

		.righttochoose {
			width: 18rpx;
			height: 24rpx;
			position: absolute;
			top: 12rpx;
			right: 12rpx;
		}
	}

	.table {
		border: 0px solid darkgray;

		.tr {
			display: flex;
			// width: 100%;
			justify-content: center;
			height: 64rpx;
			align-items: center;
			border-bottom: 1px solid #E0E0E0;
			flex-wrap: nowrap;

			.td {
				text-align: center;
				font-size: 24rpx;
				font-weight: 400;
				color: #333333;
				height: 64rpx;
				line-height: 64rpx;
				// flex-shrink: 0;
			}

			.trd {
				flex-shrink: 0;
				min-width: 300rpx;
				// border-bottom: 1px solid #ccc;
			}

			.th {
				height: 64rpx;
				text-align: center;
				font-size: 28rpx;
				font-weight: 400;
				color: #666666;
				line-height: 64rpx;
			}
		}
	}

	.uchaserbox {
		width: 100%;
	}

	.uchaserboxs {
		width: 100%;
		height: 70vh;
	}

	.activecllasscet2 {
		color: #2671E2;
		border-bottom: 2px solid #2671E2;
	}

	.timeduibi {
		width: 100%;
		background: #FFFFFF;
		padding-bottom: 10rpx;

		.timeshow {
			color: #666666;
			width: 100%;
			height: 50rpx;
			font-size: 28rpx;
			line-height: 50rpx;
			text-indent: 30rpx;
		}
	}






	// 顶部时间切换
	.timetabct {
		width: 100%;
		height: 98rpx;
		display: flex;
		align-items: center;
		border-bottom: 1px solid #E0E0E0;
	}

	.timetabctview {
		flex: 1;
		height: 100%;
		display: flex;
		justify-content: center;
		align-items: center;
	}

	.timetabct view {
		width: 94rpx;
		text-align: center;
		height: 100%;
		line-height: 98rpx;
		font-size: 28rpx;
		font-family: PingFangSC-Regular, PingFang SC;
		font-weight: 400;
		color: #666666;
	}

	.activecllasscet {
		border-bottom: 2px solid #2671E2;
	}

	// 对比时间切换
	.timepick {
		width: 100%;
		height: 90rpx;
		display: flex;
		align-items: center;
		background: #FFFFFF;
	}

	.timepicktime {
		width: 260rpx;
		height: 50rpx;
		border: 1rpx solid #E0E0E0;
		margin-left: 30rpx;
		display: flex;
		background: #FFFFFF;
	}

	.timepicktime>view:nth-of-type(1) {
		width: 210rpx;
		height: 100%;
		line-height: 50rpx;
		font-size: 26rpx;
		font-weight: 400;
		text-align: center;
	}

	.timepicktime>view:nth-of-type(2) {
		width: 49rpx;
		height: 100%;
		// border-left: 1px solid #E0E0E0;
	}

	.timepickpick {
		width: 110rpx;
		height: 50rpx;
		margin-left: 30rpx;
		display: flex;
		align-items: center;
	}

	.Underimg {
		width: 50rpx;
		height: 50rpx;
		margin-top: -2rpx;
	}




	.timeButton {
		width: 100%;
		height: 60rpx;
		display: flex;
		color: #b1b1b1;
		font-size: 28rpx;

		.item {
			text-align: center;
			line-height: 60rpx;
			padding-left: 12rpx;
			padding-right: 12rpx;
			border-radius: 8rpx;
			border: 1px solid #E0E0E0;
			margin-right: 20rpx;

			&.active {
				color: #FFFFFF;
				background-color: #2671E2;
			}
		}
	}



	.boardbox {
		width: 100%;
		height: 172rpx;
		display: flex;
		align-items: center;
		background: #F4F8FD;
		border-radius: 8rpx;
		margin-top: 28rpx;

		.boardbox-zuo {
			width: 50%;
			height: 120rpx;
			border-right: 1px solid #E0E0E0;
		}

		.boardbox-you {
			width: 50%;
			height: 120rpx;
		}

		.boardbox-text1 {
			width: 100%;
			text-align: center;
			font-size: 28rpx;
			color: #333333;
		}

		.boardbox-text2 {
			width: 100%;
			text-align: center;
			font-size: 26rpx;
			color: #333333;
			margin-top: 10rpx;
		}
	}

	.comparesize {
		flex: 1;
		font-size: 24rpx;
		color: #666666;
		margin-top: 10rpx;
	}

	.grid:nth-child(1) {
		border-right: none;
		border-bottom: none;
	}

	.grid:nth-child(3) {
		width: 50.5%;
	}
</style>
