<template>
	<view class="page">
		<!-- 图表 -->
		<!-- <qiun-title-bar title="柱状图+渐变色" /> -->
		<view class="charts-box" v-if="userId === '360267753694692613'">
			<view class="example-body">
				<uni-datetime-picker v-model="range" type="daterange"  @change="change" />
			</view>
			<view class="biao-item">
				<view class="biao">
					固投、利润、销售收入和总产值
				</view>
				<view class="charts">
					<qiun-data-charts type="column" :opts="opts1" :chartData="chartsDataColumn1" />
				</view>
			</view>
			<view class="biao-item">
				<view class="biao">
					数量和税收
				</view>
				<view class="charts">
					<qiun-data-charts type="column" :opts="opts1" :chartData="chartsDataColumn2" />
				</view>
			</view>
			<view class="biao-item">
				<view class="biao">
					进口总额和出口总额
				</view>
				<view class="charts">
					<qiun-data-charts type="column" :opts="opts1" :chartData="chartsDataColumn3" />
				</view>
			</view>
			<view class="biao-item">
				<view class="biao">
					填报企业规模大览
				</view>
				<view class="charts">
					<qiun-data-charts type="pie" :opts="opts2" :chartData="chartData2" />
				</view>
			</view>
			<view class="biao-item">
				<view class="biao">
					填报企业行业分类大览
				</view>
				<view class="charts">
					<qiun-data-charts type="pie" :opts="opts2" :chartData="chartData3" />
				</view>
			</view>
			<view class="biao-item">
				<view class="biao">
					填报企业从业人数大览
				</view>
				<view class="charts">
					<qiun-data-charts type="pie" :opts="opts2" :chartData="chartData4"/>
				</view>
			</view>
		</view>
		
		
		<view class="listBox" v-else>
			<view class="content">
				<view class="user-list" v-show="!isAdmin">
					<view class="list" @click="toData" style="background-color:#D32D25;">
						<view class="title" style="color:white">
							<text>表单设计</text>
						</view>
						<view class="more-content">
							<view class="more-content-img">
								<image src="../../static/right2.png"></image>
							</view>
						</view>
					</view>
				</view>
				<view class="user-list">
					<view class="list" @click="toPostCom()">
						<view class="title">
							<text>企业信息采集</text>
						</view>
						<view class="more-content">
							<view class="more-content-img">
								<image src="../../static/right2.png"></image>
							</view>
						</view>
					</view>
				</view>
				<view class="user-list" style="padding-top: 0;padding-bottom: 0;" v-for="(item,index) in formList">
					<view class="list" @click="toForm(it)" v-for="(it,index) in item.children">
						<view class="title">
							<text>{{it.fullName}}</text>
						</view>
						<view class="more-content">
							<view class="buttons">
								<button size="mini">已选择<span>0</span>家企业</button>
							</view>
							<view class="buttons">
								<button size="mini" type="warn">通知</button>
							</view>
							<view class="more-content-img">
								<image src="../../static/right2.png"></image>
							</view>
						</view>
					</view>
				</view>
			</view>
		</view>

		
	</view>
</template>

<script>
	import request from "@/utils/request"
	export default {
		data() {
			return {
				formList: [],
				// 判断用户是否是管理员
				isAdmin: false,
				range: ['2024-02-20', '2024-2-26'],
				// 开始日期
				startDate: '2024-02-20',
				// 结束日期
				endDate: '2024-2-26',
				isSystem:false,
				chartsDataColumn1: {
					categories: [],
					series: [{
							name: "固投",
							data: []
						},
						
						{
							name: "利润",
							data: []
						},
						{
							name: "销售收入",
							data: []
						},
						
						
						{
							name: "总产值",
							data: []
						},
					]
				},
				
				chartsDataColumn2: {
					categories: [],
					series: [
						{
							name: "数量",
							data: []
						},
						
						{
							name: "税收",
							data: []
						},
					]
				},
				chartsDataColumn3: {
					categories: [],
					series: [
						{
							name: "进口总额",
							data: []
						},
						{
							name: "出口总额",
							data: []
						},
					]
				},
				opts1: {
					color: ["#1890FF", "#91CB74", "#FAC858", "#EE6666", "#73C0DE", "#3CA272", "#FC8452", "#9A60B4",
						"#ea7ccc"
					],
					padding: [15, 15, 0, 5],
					enableScroll: false,
					legend: {},
					xAxis: {
						disableGrid: true
					},
					yAxis: {
						data: [{
							min: 0
						}]
					},
				},

				chartData2: {
					series: [{
						data: []
					}]
				},
				chartData4: {
					series: [{
						data: [{
								name: '0-20人',
								value: '0'
							},
							{
								name: '20-50人',
								value: '0'
							},
							{
								name: '50-100人',
								value: '0'
							},
							{
								name: '100-200人',
								value: '0'
							},
							{
								name: '200人以上',
								value: '0'
							},
						]
					}]
				},
				chartData3: {
					series: [{
						data: []
					}]
				},
				opts2: {
					color: ["#1890FF", "#91CB74", "#FAC858", "#EE6666", "#73C0DE", "#3CA272", "#FC8452", "#9A60B4",
						"#ea7ccc"
					],
					padding: [5, 5, 5, 5],
					enableScroll: false,
					extra: {
						pie: {
							activeOpacity: 0.5,
							activeRadius: 10,
							offsetAngle: 0,
							labelWidth: 15,
							border: true,
							borderWidth: 3,
							borderColor: "#FFFFFF",
							linearType: "custom"
						}
					}
				}
			}
		},
		onLoad() {
			this.getUser()
			this.getPostQing()
		},
		created() {
			this.getFormList()
		},
		methods: {
			change(e) {
				console.log('change事件:', e);
				this.startDate = e[0];
				this.endDate = e[1]
				console.log(this.startDate,this.endDate)
				this.getPostQing()
			},
			// 获取用户信息
			getUser() {
				// // 获取日期
				// // 获取当前日期
				// var currentDate = new Date();

				// // 获取前七天的日期
				// var previousDates = [];
				// for (var i = 6; i >= 0; i--) {
				// 	var previousDate = new Date(currentDate);
				// 	previousDate.setDate(currentDate.getDate() - i);
				// 	previousDates.push(previousDate);
				// }

				// // 格式化日期
				// var formattedDates = previousDates.map(function(date) {
				// 	var year = date.getFullYear();
				// 	var month = (date.getMonth() + 1).toString().padStart(2, '0');
				// 	var day = date.getDate().toString().padStart(2, '0');
				// 	return year + '-' + month + '-' + day;
				// });

				// console.log('日期', formattedDates); // 输出前七天的日期数组
				// this.startDate = formattedDates[0]
				// this.endDate = formattedDates[6]
				if (uni.getStorageSync('user')) {
					let userCode = uni.getStorageSync('user')
					// console.log("用户的code", this.userCode)
					this.userId = userCode.userInfo.userId
					this.userName = userCode.userInfo.userAccount
					this.userIcon = userCode.userInfo.headIcon
					this.organizeName = userCode.userInfo.organizeName
					this.isAdmin = userCode.userInfo.isCompany
					console.log(userCode)
				} else {
					uni.showToast({
						title: '请登录',
						icon: 'none'
					})
					setTimeout(() => {
						uni.reLaunch({
							url: '/pages/login/index'
						})
					})
				}
			},
			// 获取填报情况
			getPostQing() {
				let that = this
				that.chartsDataColumn1.categories = []
				that.chartsDataColumn2.categories = []
				that.chartsDataColumn3.categories = []
				that.chartsDataColumn3.series[0].data = []
				that.chartsDataColumn3.series[1].data = []
				that.chartsDataColumn2.series[0].data = []
				that.chartsDataColumn2.series[1].data = []
				that.chartsDataColumn1.series[0].data = []
				that.chartsDataColumn1.series[1].data = []
				that.chartsDataColumn1.series[2].data = []
				that.chartsDataColumn1.series[3].data = []
				that.chartData3.series[0].data = []
				that.chartData2.series[0].data = []
				request({
					url: '/api/SubDev/baseenterprisemanager/GetDataNumber',
					method: 'get',
					data: {
						startDate: this.startDate,
						endDate: this.endDate
					}
				}).then(res => {
					if (res.code == 200) {
						console.log(res)
						for (let i = 0; i < res.data.GetCreateDateNumber.length; i++) {
							that.chartsDataColumn1.categories.push(res.data.GetCreateDateNumber[i].Day)
							that.chartsDataColumn2.categories.push(res.data.GetCreateDateNumber[i].Day)
							that.chartsDataColumn3.categories.push(res.data.GetCreateDateNumber[i].Day)
							that.chartsDataColumn3.series[0].data.push(res.data.GetCreateDateNumber[i].Imports)	
							that.chartsDataColumn3.series[1].data.push(res.data.GetCreateDateNumber[i]
								.TotalExportValue)
							that.chartsDataColumn2.series[0].data.push(res.data.GetCreateDateNumber[i].Number)
							that.chartsDataColumn2.series[1].data.push(res.data.GetCreateDateNumber[i].Taxation)
							that.chartsDataColumn1.series[0].data.push(res.data.GetCreateDateNumber[i]
								.FixedInvestment)					
							that.chartsDataColumn1.series[1].data.push(res.data.GetCreateDateNumber[i].Profit)
							that.chartsDataColumn1.series[2].data.push(res.data.GetCreateDateNumber[i]
								.SalesRevenue)
							that.chartsDataColumn1.series[3].data.push(res.data.GetCreateDateNumber[i]
								.TotalOutputValue)
						}
						// 企业行业分布
						for (let i = 0; i < res.data.GetIndustryNumber.length; i++) {
							that.chartData3.series[0].data.push({
								name: res.data.GetIndustryNumber[i].EnterpriseScale,
								value: res.data.GetIndustryNumber[i].Number
							})
						}
						// 企业规模
						for (let i = 0; i < res.data.GetEnterpriseScalNumber.length; i++) {
							that.chartData2.series[0].data.push({
								name: res.data.GetEnterpriseScalNumber[i].EnterpriseScale,
								value: res.data.GetEnterpriseScalNumber[i].Number
							})
						}
						// 企业从业人数规模
						that.chartData4 = {
							series: [{
								data: [{
										name: '0-20人',
										value: res.data.GetEmployees.top20
									},
									{
										name: '20-50人',
										value: res.data.GetEmployees.top50
									},
									{
										name: '50-100人',
										value: res.data.GetEmployees.top100
									},
									{
										name: '100-200人',
										value: res.data.GetEmployees.top200
									},
									{
										name: '200人以上',
										value: res.data.GetEmployees.top200Up
									},
								]
							}]
						}
					}
				})
			},
			// 获取表单列表
			getFormList() {
				let that = this
				request({
					url: '/api/visualdev/Base',
					method: 'get',
					data: {
						type: 2
					},
				}).then(res => {
					console.log(res)
					if (res.code === 600) {
						uni.showToast({
							icon: "exception",
							title: '登录过期，请重新登录'
						})
					}
					this.formList = res.data.list
				})
			},
			toData() {
				uni.navigateTo({
					url: '/pages/data/data'
				})
			},
			// 去企业信息表单采集
			toPostCom() {
				uni.navigateTo({
					url: '/pages/postCompany/postCompany'
				})
			},
			// 去表单填写页面
			toForm(item) {
				// uni.navigateTo({
				// 	url: `/pages/apply/dynamicModel/index?data=${JSON.stringify(it)}`
				// })
				uni.navigateTo({
					url: '/pages/apply/dynamicModel/index?id=' + item.id + '&fullName=' + item.fullName,
					fail: (err) => {
						this.$u.toast("暂无此页面")
					}
				})
			},
		}
	}
</script>

<style scoped lang="scss">
	@import 'datain.scss';
</style>