<template>
	<view>

		<view class="headsearch width94 mart15 paddtop5 paddbotm10 fotct">

			<view class="mart10 width90 alijusstart">
				<view class="fcorfff font14 margleri10 width60 fotlt">开始时间 :</view>
				<picker mode="date" :value="startdate" :start="startDate" :end="endDate" @change="bindDateChange">
					<view class="datetim fcorfff">{{startdate}}<i class="down"></i></view>
				</picker>
			</view>
			<view class="mart10 width90 alijusstart">
				<view class="fcorfff font14 margleri10 width60 fotlt">结束时间 :</view>
				<picker mode="date" :value="enddate" :start="startDate" :end="endDate" @change="bindDateChange1">
					<view class="datetim fcorfff">{{enddate}}<i class="down"></i></view>
				</picker>
			</view>
			<view class="input-box">
				<view class="icon search"></view>
				<input placeholder="请输入订单编号" v-model="orderNo" placeholder-style="color:#c0c0c0;" @input="toSearch()" />
			</view>
		</view>


		<view class="width100 height90 backcorfff marb5 mart15" style="border-radius: 22px 0 22px 0;">
			<view class="width100 fotct height40p alijus font20 fcor333">
				<view class="width50">
					{{totalPrice}} 元
				</view>
				<view class="width50 ">
					{{totalNum}} 笔
				</view>
				<!-- <view style="width: 1px;" class="height80 backcor6"></view> -->
			</view>
			<view class="width100 fotct height40p alijus font14 fcor333">
				<view class="width50 ">
					交易金额
				</view>
				<view class="width50">
					交易笔数
				</view>
			</view>
		</view>
		<view v-if="notesList == ''" class="mart60 fotct font14 fcor666">
			<image mode="widthFix" style="width: 70vw;" src="../../../static/img/noorder.png"></image>
		</view>
		<view class="width100 backcorfff" v-for="(item,index) in notesList" :key="index" @click="jumpOderlist()">
			<view class="width94 height70 alijusstart bor-botm1">
				<view class="width15">
					<image src="../../../static/img/wechat.png" mode="widthFix" class="iconw40"
						v-if="item.payMode == 'WECHAT'"></image>
					<image src="../../../static/img/alipay.png" mode="widthFix" class="iconw40"
						v-if="item.payMode == 'ALIPAY'"></image>
				</view>
				<view class="width85">
					<view class="alijusstart font15 fcor333">
						<view class="width50 font15 fcor333">扫一扫</view>
						<view class="width50 fotrt">¥ {{item.tradeAmount}}</view>
					</view>
					<view class="alijusstart font15 paddtop5 fcor999">
						<view class="width70">{{item.createTime | timeFormat('yyyy-mm-dd hh:mm:ss')}}
						</view>
						<view class="width30 fotrt">{{statusList[item.status]}}</view>
					</view>
				</view>
			</view>

		</view>
	</view>
</template>

<script>
	import {
		getTradeOrderList
	} from '../../../Utils/Api.js';
	export default {
		data() {
			const currentDate = this.getDate({
				format: true
			})
			return {
				startdate: currentDate,
				enddate: currentDate,
				notesList: [],
				statusList: {
					1: "待支付",
					2: "支付中",
					3: "支付成功",
					4: "支付失败",
					5: "已取消",
					6: "已退款"
				},
				pageNum: 1,
				pageSize: 10,
				isNoMoreData: false, //是否加载中
				orderNo: '', //订单编号
				totalPrice: 0, //总价格
				totalNum: 0, //总笔数
			}
		},
		computed: {
			startDate() {
				return this.getDate('start');
			},
			endDate() {
				return this.getDate('end');
			}
		},
		onLoad() {
			this.getTradeOrderList();
		},
		onReachBottom() {
			this.getTradeOrderList();
		},

		methods: {
			//时间修改
			getDate(type) {
				const date = new Date();
				let year = date.getFullYear();
				let month = date.getMonth() + 1;
				let day = date.getDate();

				if (type === 'start') {
					year = year - 60;
				} else if (type === 'end') {
					year = year + 2;
				}
				month = month > 9 ? month : '0' + month;;
				day = day > 9 ? day : '0' + day;
				return `${year}-${month}-${day}`;
			},
			//选择时间
			bindDateChange(e) {
				this.startdate = e.target.value;
				this.pageNum = 1;
				this.notesList = [];
				this.isNoMoreData = false;
				this.getTradeOrderList();
			},
			bindDateChange1(e) {
				this.enddate = e.target.value;
				this.pageNum = 1;
				this.notesList = [];
				this.isNoMoreData = false;
				this.getTradeOrderList();
			},
			toSearch(){
				this.pageNum = 1;
				this.notesList = [];
				this.isNoMoreData = false;
				this.getTradeOrderList();
			},
			//查询列表
			getTradeOrderList() {
				uni.showLoading({
					title: '加载中...'
				})
				if (this.isNoMoreData) {
					uni.hideLoading()
					return false;
				}
				console.log('1111111111');
				let a = new Date(this.startdate).getTime();
				let b = new Date(this.enddate).getTime();
				let startTime = a - 28800000;
				let endTime = b + 57599000;
				let pagenum = this.pageNum;
				let datas = {
					status: 3,
					payTimeS: startTime,
					payTimeE: endTime,
					outTradeNo: this.orderNo,
					pageNum: pagenum,
					pageSize: this.pageSize
				}
				getTradeOrderList(datas).then(res => {
					uni.hideLoading();
					if (res.return_code == '000000' && res.return_data.pageInfo.list) {
						this.totalPrice = res.return_data.totalPrice;
						this.totalNum = res.return_data.totalNum;
						this.isNoMoreData = res.return_data.pageInfo.list.length == this.pageSize ? false : true;
						this.notesList = this.notesList.concat(res.return_data.pageInfo.list);
						if (res.return_data.pageInfo.total == (this.pageNum * this.pageSize)) {
							this.isNoMoreData = true;
						}
						this.pageNum = res.return_data.pageInfo.list.length == this.pageSize ? ++pagenum : pagenum;
					} else {
						this.notesList = [];
						uni.showToast({
							title: res.return_msg,
							duration: 2000,
							icon: 'none'
						})
					}
				})
			},
			//跳转详情
			jumpOderlist() {
				// uni.navigateTo({
				// 	url: '/pages/index/order-list-details/order-list-details'
				// })
			}
		}
	}
</script>

<style lang="scss">
	page {
		background-color: #f8f9f9;
	}

	.input-box {
		width: 90%;
		margin-left: 5%;
		margin-top: 15px;
		margin-bottom: 15px;
		height: 70rpx;
		background-color: #f5f5f5;
		border-radius: 10rpx;
		position: relative;
		display: flex;
		align-items: center;

		.icon {
			display: flex;
			align-items: center;
			position: absolute;
			top: 2px;
			left: 5px;
			width: 60upx;
			height: 60upx;
			font-size: 34upx;
			color: #c0c0c0;
		}

		input {
			padding-left: 50upx;
			height: 28upx;
			font-size: 28upx;
			width: 100%;
		}
	}

	i {
		border: solid #ffffff;
		border-width: 0 2px 2px 0;
		display: inline-block;
		padding: 4px;
		margin-left: 10px;
		vertical-align: 3px;
	}

	.down {
		-webkit-transform: rotate(45deg);
	}

	.font306adb {
		color: #306adb;
	}

	.stus {
		float: right;
		margin-right: 20px;
	}

	.headsearch {
		border-radius: 8px;
		background-color: #4c7fe6;
	}

	.datetim {
		width: 130px;
		height: 30px;
		line-height: 30px;
		text-align: right;
		border-radius: 15px;
	}
</style>