<template>
	<view class="detail">
		<view class="top">
			<image :src="proInfo.img" mode=""></image>
			<view class="title clamp">{{ proInfo.title }}</view>
			<view class="tip">
				<view class=""></view>
				基本信息
			</view>
			<view class="base-info">
				<view class="item">
					<text>捐赠进度</text>
					<text class="status">{{ proInfo.project_progress*100 }}%</text>
				</view>
				<view class="item">
					<text>创立时间</text>
					{{ proInfo.add_time | time }}
				</view>
				<view class="item">
					<text>开始时间</text>
					{{ proInfo.start_time | time }}
				</view>
				<view class="item">
					<text>结束时间</text>
					{{ proInfo.end_time | time }}
				</view>
			</view>
			<view class="dynamic flex" v-if="newItem">
				<view class="left">实时动态</view>
				<view class="right flex">
					<view>捐赠时间：{{ newItem.add_time | time }}</view>
					<view>
						捐赠人：
						<text>{{ newItem.name | name }}</text>
					</view>
					<view class="clamp" style="width: 500rpx;">捐赠数量：{{ newItem.item | item(typeList) }}</view>
				</view>
			</view>
		</view>
		<view class="content">
			<view class="content-nav flex">
				<view class="nav-item" v-for="(item, index) in navList" :key="index" :class="{ active: currentIndex === index }" @click="navClick(index)">{{ item }}</view>
			</view>
		</view>

		<view v-if="currentIndex === 0">
			<view class="item-detail" ref="swiperItemOne">
				<view class="tip">
					<view class=""></view>
					捐赠介绍
				</view>
				<view class="item-content" v-html="proInfo.info"></view>
				<view class="tip">
					<view class=""></view>
					项目需求
				</view>
				<view class="item-needs">
					<view class="need-item" v-for="item in proInfo.project_donation_info">
						<view class="">
							{{ item.project_donation_id | type(typeList) }}：
							<text>{{ item.project_donation_num }}</text>
						</view>
						<view class="">
							最低需求捐赠数：
							<text>{{ item.project_donation_num }}</text>
						</view>
						<!-- <view class="">
							物资捐赠要求：
							<text>全新</text>
						</view> -->
					</view>
					<!-- <view class="need-item">
						<view class="">
							帐篷类（帐篷）：
							<text>500</text>
							顶
						</view>
						<view class="">
							最低需求捐赠数：
							<text>500</text>
							顶
						</view>
						<view class="">
							物资捐赠要求：
							<text>全新</text>
						</view>
					</view> -->
				</view>
			</view>
		</view>
		<view v-else class="feedback">
			<view class="feedback-nav">
				<view class="nav-item" :class="{ action: navCurrentIndex === 0 }" @click="lookmore(0)">全部</view>
				<view class="nav-item" :class="{ action: navCurrentIndex === 1 }" @click="lookmore(1)">已成功</view>
				<view class="nav-item nav-item-err" :class="{ action: navCurrentIndex === 2 }" @click="lookmore(2)">已失败</view>
			</view>
			<view class="feedback-content">
				<view class="overall" v-if="navCurrentIndex === 0 && proInfo.status === 2">
					<view class="title">项目整体反馈</view>
					<view class="content">{{ proInfo.feedback }}</view>
				</view>
				<view class="without" v-if="backList.length === 0">
					暂无捐赠
				</view>
				<template v-if="navCurrentIndex === 0">
					<view class="feedback-item" :key="item.id" v-for="item in backList">
						<view class="item-top">
							<image src="../../static/img/002.png" mode=""></image>
							<view class="item-name-time">
								<view class="item-name">神农架林区捐赠</view>
								<view class="item-time">{{ item.time | time }}</view>
							</view>
						</view>
						<view class="item-content">
							<text>{{ item.name }}</text>
							{{ item.time | time }}, {{ item.message }}
						</view>
					</view>
				</template>
				<template v-if="navCurrentIndex === 1">
					<view class="feedback-item" :key="item.id" v-for="item in backList" v-if="item.order_status !== -1">
						<view class="item-top">
							<image src="../../static/img/002.png" mode=""></image>
							<view class="item-name-time">
								<view class="item-name">神农架林区捐赠</view>
								<view class="item-time">{{ item.time | time }}</view>
							</view>
						</view>
						<view class="item-content">
							<text>{{ item.name }}</text>
							{{ item.time | time }}, {{ item.message }}
						</view>
					</view>
				</template>
				<template v-if="navCurrentIndex === 2">
					<view class="feedback-item" :key="item.id" v-for="item in backList" v-if="item.order_status === -1">
						<view class="item-top">
							<image src="../../static/img/002.png" mode=""></image>
							<view class="item-name-time">
								<view class="item-name">荆州捐赠</view>
								<view class="item-time">{{ item.time | time }}</view>
							</view>
						</view>
						<view class="item-content">
							<text>{{ item.name }}</text>
							{{ item.message }}
						</view>
					</view>
				</template>
			</view>
		</view>
		<view class="jg" style="height: 99rpx;"></view>
		<view class="btn-wrapper flex">
			<view class="btn1 btn" @click="navTo('/pages/donate/progress?id=' + proInfo.id)">实时进展</view>
			<view class="btn2 btn" @click="proInfo.status === 1 ? want() : cant()">我要捐款</view>
		</view>
		<uni-popup ref="popup" type="center">
			<view class="type-box">
				<image src="../../static/img/sele.png" mode="" class="bg"></image>

				<view class="box-title">捐款类型</view>
				<view class="box-tip">请选择您的捐赠身份类型</view>
				<view class="box-btn" @click="chooseType(0)">
					<image src="../../static/icon/jz1.png" mode=""></image>
					<view class="btn-title">个人捐赠</view>
					<view class="qq" :class="{ action: jxType === 0 }"><view class="yx"></view></view>
				</view>
				<view class="box-btn" @click="chooseType(1)">
					<image src="../../static/icon/jz2.png" mode=""></image>
					<view class="">企业(团队)捐赠</view>
					<view class="qq" :class="{ action: jxType === 1 }"><view class="yx"></view></view>
				</view>
				<view class="qr" @click="qr()">确认</view>
			</view>
		</uni-popup>
	</view>
</template>

<script>
import { getProjectInfo, createProject, getDonationInfo, getAllOrder, getMyorder ,getBill,getOrderInfo,getUserList} from '../../api/money.js';
let that;
export default {
	data() {
		return {
			navList: ['捐赠详情', '捐赠反馈'],
			currentIndex: 0,
			swiperHeight: 0,
			navCurrentIndex: 0,
			jxType: 0,
			pid: 0,
			proInfo: {},
			typeList: [], //物资分类列表
			newItem: null, //最新动态,
			isBottom: false,
			backList: [], //反馈lis
			pushBoolen:false,
			endTime: null,
			timer: null,
			newtime: 0
		};
	},
	onReachBottom() {
		// this.isBottom = true;
		// let a = Math.floor( ((new Date()).getTime() - num*1000)/1000)
		// let c = setInterval((e) => {
		// 	a--
		// 	if(a == 0){
		// 		pushBoolen
		// 		clearInterval(c)
		// 	}
		// },1000)
		
	},
	onHide() {
		console.log('页面隐藏')
		clearInterval(this.timer)
	},
	filters: {
		time(val) {
			let str = '';
			// console.log(val)
			if (val) {
				let date = new Date(val * 1000);
				let Y = date.getFullYear();
				let M = date.getMonth() + 1 > 9 ? (date.getMonth()+1) : '0' + (date.getMonth()+1);
				let D = date.getDate() > 9 ? date.getDate() : '0' + date.getDate();
				str = Y + '年' + M + '月' + D + '日';
			}
			return str;
		},
		type(val, typeList) {
			let str = '';
			let arr = typeList;
			let len = arr.length;
			for (let i = 0; i < len; i++) {
				if (arr[i].id === val) {
					return (str = arr[i].name);
				}
			}
		},
		name(val, typeList) {
			let str = '';
			if (val) {
				str = val.substr(0, 1);
			}

			return str + '**';
		},
		item(val, typeList) {
			let str = '';
			if (val) {
				let arr = val.map(item => {
					for (let i = 0; i < typeList.length; i++) {
						if (item.project_donation_id == typeList[i].id) {
							str = str + typeList[i].name + ' ' + item.project_donation_num + ' ' + ' ';
						}
					}
				});
			}

			return str;
		}
	},
	onLoad(opt) {
		console.log('onLoadonLoadonLoadonLoadonLoadonLoadonLoadonLoad');
		that = this;
		this.pid = opt.id;
		console.log(this.pid, '5555555555555555555555');
		this.getNewOrder();

		this.loadDate(this.pid);
		this.getDonationInfo();
		// this.getBill()
		// this.getOrderInfo()
		clearInterval(this.timer)
	},
	methods: {
		loadDate(id) {
			getProjectInfo({
				id: id
			}).then(res => {
				console.log(res,'00000000000000000000000000000')
				let data = res.data;
				console.log(data, 'loaddata++++++++++');
				data.info = data.info.replace(/<img /g, '<img style="width:100%"');
				this.setTime(data.end_time)
				// this.endTime = data.end_time
				// this.newtime = Math.floor((new Date().getTime() - this.endTime*1000)/1000)
				// console.log(this.endTime,this.newtime,'--------------------------')
				// this.timer = setInterval( () => {
				// 	this.newtime--
				// 	if(this.newtime==0){
				// 		this.pushBoolen = true
				// 		clearInterval(this.timer)
				// 	}
				// },1000)
				this.proInfo = data;
				console.log(this.proInfo, 'this.proInfo++++++++++++++++');
				let arr = this.proInfo.project_donation_info;
				let len = arr.length;
				let map = {},
					dest = [];
				for (var i = 0; i < len; i++) {
					var ai = arr[i];
					if (!map[ai.project_donation_id]) {
						dest.push(ai);
						map[ai.project_donation_id] = ai;
					} else {
						for (var j = 0; j < dest.length; j++) {
							var dj = dest[j];
							if (dj.project_donation_id == ai.project_donation_id) {
								dj.project_donation_num = dj.project_donation_num + ai.project_donation_num;
								dj.received = dj.received + ai.received;
								dj.send_num = dj.send_num + ai.send_num;
								dj.transport = dj.transport + ai.transport;
								break;
							}
						}
					}
				}
				this.proInfo.project_donation_info = dest;
				console.log(this.proInfo.project_donation_info, 'proInfo.item++++++++++++++++++++++++++');
			});
		},
		navTo(url) {
			uni.navigateTo({
				url: url
			});
		},
		navClick(index) {
			this.currentIndex = index;
		},
		lookmore(index) {
			this.navCurrentIndex = index;
		},
		want() {
			if(this.pushBoolen){
				return this.$api.msg('捐赠活动已结束');
			}
			this.$refs.popup.open();
		},
		chooseType(index) {
			this.jxType = index;
		},
		qr() {
			this.$refs.popup.close();
			let wzList = [];
			let list = this.proInfo.project_donation_info;
			list.map(item => {
				for (let i = 0; i < this.typeList.length; i++) {
					if (item.project_donation_id === this.typeList[i].id) {
						wzList.push(this.typeList[i]);
					}
				}
			});
			console.log(wzList, '**************************************');

			this.navTo('/pages/donate/idonate?type=' + this.jxType + '&id=' + this.proInfo.id + '&wzlist=' + JSON.stringify(wzList));
		},
		//获取物资分类列表
		getDonationInfo() {
			getDonationInfo().then(({ data }) => {
				this.typeList = data;
				console.log(this.typeList, '获取所有物资');
			});
		},
		getNewOrder() {
			getAllOrder({
				project_id: this.pid,
				page: 1,
				limit: 10000
			}).then(({ data }) => {
				if (data.count !== 0) {
					console.log(data, '999999999999999999999999');
					// this.newItem = data.list[0];
					if (!this.newItem) {
						this.$set(this, 'newItem', data.list[0]);
					}
					this.backList = data.list.map(item => {
						switch (item.order_status) {
							case 6:
								item.time = item.feedback_time;
								item.message = item.feedback || '您捐赠的物资已送至受捐者，感谢您的爱心！';
								break;
							case 4:
								item.time = item.out_delivery_time;
								item.message = item.out_delivery_remark || '捐赠物资已出库';
								break;
							case 3:
								item.time = item.receiving_time;
								item.message = item.receiving_remark || '捐赠物资已入库';
								break;
							// case: '已发货'
							case 1:
								item.time = item.verify_time;
								item.message = item.verify_remark || '捐赠审核已通过';
								break;
							case -1:
								item.time = item.verify_time;
								item.message = item.verify_remark || '您的申请未通过，您可重新提交申请，感谢您的爱心！';
								break;
							case 0:
								item.time = item.add_time;
								item.message = item.verify_remark || '感谢您的爱心！';
								break;
							default:
								item.time = item.add_time;
								item.message = '感谢您的爱心！';
						}
						console.log(item, '捐赠反馈444444444444444444444444');
						return item;
					});
					console.log(this.newItem, '88888888888888888');
					console.log(this.backList, 'this.backList+++++++++++++++++++++++');
				}
			});
		},
		getItem(item) {
			// this.getDonationInfo()
			let str = '';
			console.log(item);
			if (item) {
				item.forEach(item => {
					for (let i = 0; i < this.typeList.length; i++) {
						if (item.project_donation_id === this.typeList[i].project_donation_id) {
							str = str + this.typeList[i].project_donation_name + item.project_donation_num + '';
						}
					}
				});
			}
			console.log(str, '222222222222222222');
			return str;
		},
		cant() {
			console.log(this.pushBoolen)
			if(this.pushBoolen){
				return this.$api.msg('捐赠活动已结束');
			}
			if(this.proInfo.status === -1){
				this.$api.msg('捐赠活动无效');
			}
			if(this.proInfo.status === 0){
				this.$api.msg('捐赠活动未开始');
			}
			if(this.proInfo.status === 2){
				this.$api.msg('捐赠活动已结束');
			}
		},
		getBill() {
			getBill({
				project_id: this.pid,
				page:1,
				limit:1,
				type: 0
			}).then(res => {
				console.log(res,'getBill++++++++++++')
			})
		},
		getOrderInfo() {
			getOrderInfo({
				id: 44
			}).then( res => {
				console.log(res,'getOrderInfo+++++++++++++++')
			})
		},
		setTime(endTime) {
			this.endTime = endTime
			this.newtime = Math.floor((new Date().getTime() - this.endTime*1000)/1000  )
			if(this.newtime<0){
				// this.pushBoolen = true
				console.log(this.newtime,'newtime+++++++++++++++')
				this.timer = setInterval(()=> {
					this.newtime++
					console.log(this.newtime)
					if(this.newtime==0){
						this.pushBoolen = true
						clearInterval(this.timer)
					}
				},1000)
			}else {
				this.pushBoolen = true
			}
			
		}
	}
};
</script>

<style lang="scss" scoped>
page {
	width: 100%;
}
.top {
	// height: 863rpx;
	background-color: #fff;
	border-top: 1rpx solid #f6f6f6;
	padding-top: 33rpx;
	margin-bottom: 20rpx;
	image {
		display: block;
		width: 680rpx;
		height: 375rpx;
		border-radius: 20rpx;
		margin: 0 auto;
		// background-color: red;
	}
	.title {
		width: 580rpx;
		font-size: 32rpx;
		font-family: PingFang SC;
		font-weight: bold;
		color: #333333;
		line-height: 1;
		padding-top: 28rpx;
		padding-left: 42rpx;
		margin-bottom: 39rpx;
	}
	.base-info {
		font-size: 27rpx;
		font-family: PingFang SC;
		font-weight: 500;
		color: #999999;
		line-height: 1;
		display: flex;
		padding: 0 56rpx;
		flex-wrap: wrap;
		.item {
			width: 50%;
			padding-bottom: 40rpx;
			.status {
				color: red;
				font-weight: bold;
			}
			text {
				font-size: 26rpx;
				font-family: PingFang SC;
				font-weight: 500;
				color: #666666;
				display: inline-block;
				margin-right: 15rpx;
			}
		}
	}
	.dynamic {
		width: 666rpx;
		height: 111rpx;
		background: #efefef;
		border-radius: 10rpx;
		margin: 5rpx auto 0;
		.left {
			width: 115rpx;
			height: 111rpx;
			background: #5c93fc;
			border-radius: 10rpx 0px 0px 10rpx;
			font-size: 28rpx;
			font-family: PingFang SC;
			font-weight: 500;
			color: #ffffff;
			line-height: 34rpx;
			padding: 22rpx 29rpx;
			margin-right: 15rpx;
		}
		.right {
			font-size: 22rpx;
			font-family: PingFang SC;
			font-weight: 400;
			color: #333333;
			line-height: 1;
			padding: 12rpx 0;
			flex-direction: column;
			justify-content: space-between;
			text {
				color: red;
				font-weight: bold;
			}
		}
	}
}
.content {
	.content-nav {
		height: 82rpx;
		background: #ffffff;
		font-size: 30rpx;
		font-family: PingFang SC;
		font-weight: 500;
		color: #999999;
		line-height: 82rpx;
		justify-content: space-around;
		.active {
			border-bottom: 4rpx solid #fa7e67;
			color: #fa7e67;
			font-weight: bold;
		}
	}
}
.tip {
	margin-left: 42rpx;
	font-size: 30rpx;
	font-family: PingFang SC;
	font-weight: bold;
	color: #333333;
	line-height: 1;
	margin-bottom: 34rpx;
	view {
		display: inline-block;
		width: 4rpx;
		height: 30rpx;
		background: #fa7e67;
		border-radius: 2rpx;
		margin-right: 9rpx;
		position: relative;
		bottom: -2rpx;
	}
}
.btn-wrapper {
	position: fixed;
	bottom: 0;
	width: 100%;
	.btn {
		width: 50%;
		text-align: center;
		height: 99rpx;
		line-height: 99rpx;
		font-size: 34rpx;
		font-family: PingFang SC;
		font-weight: 500;
		color: #ffffff;
	}
	.btn1 {
		background-color: #f7c03e;
	}
	.btn2 {
		background-color: #fa7e67;
	}
}
.item-detail {
	height: 100%;
	padding-top: 42rpx;
	.item-content {
		padding: 0 78rpx 0 48rpx;
		font-size: 26rpx;
		font-family: PingFang SC;
		font-weight: 500;
		color: #666666;
		line-height: 44rpx;
		margin-bottom: 32rpx;
	}
	.item-needs {
		.need-item {
			width: 666rpx;
			height: 100rpx;
			background: #f3f3f3;
			border-radius: 10rpx;
			margin: 0 auto;
			font-size: 26rpx;
			font-family: PingFang SC;
			font-weight: 500;
			color: #333333;
			margin-bottom: 10rpx;
			padding-top: 20rpx;
			padding-left: 13rpx;
			line-height: 1;
			view {
				margin-bottom: 15rpx;
				text {
					color: #e80000;
				}
			}
		}
	}
}
.feedback {
	padding: 25rpx 41rpx 36rpx;
	.feedback-nav {
		margin-bottom: 20rpx;
		.nav-item {
			display: inline-block;
			width: 100rpx;
			height: 55rpx;
			background: #fdcbc2;
			box-shadow: 0px 0px 10rpx 0rpx rgba(0, 0, 0, 0.1);
			border-radius: 10rpx;
			margin-right: 20rpx;
			text-align: center;
			line-height: 55rpx;
			font-size: 24rpx;
			font-family: PingFang SC;
			font-weight: 500;
			color: #ffffff;
		}
		.nav-item-err {
			color: #999999;
			background: #f1f1f0;
		}
		.action {
			background: #fa7e67;
			color: #fff;
		}
	}
	.feedback-content {
		.overall {
			.title {
				width: 667rpx;
				height: 75rpx;
				background: #fa7e67;
				box-shadow: 0px 0px 10rpx 0rpx rgba(0, 0, 0, 0.1);
				border-radius: 10rpx 10rpx 0px 0px;
				font-size: 28rpx;
				font-family: PingFang SC;
				font-weight: bold;
				color: #ffffff;
				line-height: 75rpx;
				padding-left: 17rpx;
			}
			.content {
				padding: 33rpx 36rpx 43rpx 30rpx;
				width: 667rpx;
				background-color: #fff;
				box-shadow: 0px 0px 10rpx 0px rgba(0, 0, 0, 0.1);
				border-radius: 0px 0px 10rpx 10rpx;
				font-size: 26rpx;
				font-family: PingFang SC;
				font-weight: 500;
				color: #999999;
				line-height: 42rpx;
			}
		}
		.feedback-item {
			margin: 20rpx auto;
			// display: flex;
			background-color: #fff;
			box-shadow: 0px 0px 10rpx 0px rgba(0, 0, 0, 0.1);
			border-radius: 10rpx 10rpx 10rpx;
			.item-top {
				height: 118rpx;
				border-radius: 10px 10px 0 0;
				border-bottom: 1px solid #ececec;
				padding: 25rpx 0 0 17rpx;
				display: flex;
				image {
					width: 77rpx;
					height: 77rpx;
					border-radius: 50%;
					// background-color: red;
					margin-right: 12rpx;
				}
				.item-name-time {
					.item-name {
						font-size: 28rpx;
						font-family: PingFang SC;
						font-weight: bold;
						color: #333333;
						line-height: 35rpx;
					}
					.item-time {
						font-size: 24rpx;
						font-family: PingFang SC;
						font-weight: 500;
						color: #999999;
						line-height: 50rpx;
					}
				}
			}
			.item-content {
				padding: 25rpx 47rpx 40rpx 30rpx;
				border-radius: 0 0 10rpx 10rpx;
				font-size: 26rpx;
				font-family: PingFang SC;
				font-weight: 500;
				color: #999;
				line-height: 42rpx;
				text {
					color: #e80000;
					font-weight: bold;
				}
			}
		}
	}
}
.type-box {
	width: 542rpx;
	height: 575rpx;
	// background: linear-gradient(0deg, rgba(249, 98, 105, 0.06), rgba(255, 255, 255, 0.06));
	border-radius: 20rpx;
	background-color: #fff;
	position: relative;
	.bg {
		width: 100%;
		height: 138rpx;
		position: absolute;
	}
	.box-title {
		text-align: center;
		font-size: 36rpx;
		font-family: PingFang SC;
		font-weight: bold;
		color: #333333;
		line-height: 1;
		padding-top: 77rpx;
	}
	.box-tip {
		text-align: center;
		font-size: 24rpx;
		font-family: PingFang SC;
		font-weight: 500;
		color: #808080;
		line-height: 1;
		padding-top: 12rpx;
		margin-bottom: 43rpx;
	}
	.box-btn {
		margin: 0 auto;
		width: 460rpx;
		height: 95rpx;
		display: flex;
		align-items: center;
		border-bottom: 1px solid #f3efef;
		position: relative;
		image {
			height: 43rpx;
			width: 43rpx;
			// background-color: red;
			margin-right: 15rpx;
		}
		.qq {
			width: 32rpx;
			height: 32rpx;
			border: 1px solid #808080;
			opacity: 0.5;
			border-radius: 50%;
			position: absolute;
			right: 0;
		}
		.action {
			border-color: #fa7e67;
			// position: relative;
			.yx {
				width: 20rpx;
				height: 20rpx;
				background: #fa7e67;
				// border: 1px solid #FA7E67;
				border-radius: 50%;
				position: absolute;
				top: 0;
				bottom: 0;
				left: 0;
				right: 0;
				margin: auto;
			}
		}
	}
	.qr {
		width: 460rpx;
		height: 71rpx;
		background: #fa7e67;
		box-shadow: 0px 16rpx 16rpx 0px rgba(250, 126, 103, 0.5);
		border-radius: 10rpx;
		font-size: 28rpx;
		font-family: PingFang SC;
		font-weight: 500;
		color: #ffffff;
		text-align: center;
		line-height: 71rpx;
		margin: 62rpx auto 0;
	}
}
.without {
	padding: 40rpx;
	width: 100%;
	height: 100%;
	text-align: center;
}
</style>
