<template>
	<view class="app">
		<view id="app-top">
			<view class="app-body">
				<!--关键词搜索-->
				<view class="sreach fx-r fx-bc fx-ac">
					<image class="icon" src="/static/img/tb-seach.png"></image>
					<input type="text" v-model="keyword"  placeholder="请输入用户昵称/用户ID" placeholder-style="color: #B3B3B3;" />
					<view class="fx-g1"></view>
					<view class="search-btn"  @tap="tapSerach">搜索</view>
				</view>
			</view>
			<view class="app-inner">
				<view class="pannel">
					<view class="status fx-r">
						<view class="people fx-r fx-bc fx-ac" @tap="isShowTime = true"	>
							<image src="/static/img/gz_yy.png"></image>
							<view class="label">检索日期:</view>
							<view class="value">
								<uni-datetime-picker
												:border="false"
												type="daterange"
												start="2023-01-01"
												:end="endTime"
												rangeSeparator="至"
												@change="tapDateTime"
												v-model="datetime"
												>
												{{ utils.date('m月d日',utils.strtotime(datetime[0])) }}/
												{{ utils.date('m月d日',utils.strtotime(datetime[1])) }}
												</uni-datetime-picker>
							</view>
						</view>
						
						<view class="fx-g1"></view>
						<view class="search-tm fx-r fx-bc fx-ac" @tap="tapCg">
							<view class="text">{{ gzItem.id == 0 ? '全部场馆' : gzItem.nickname }}</view>
							<u-icon name="arrow-down" class="icon"></u-icon>
						</view>
					</view>
					
					<view class="panel-info fx-r">
						<view class="item">
							<view class="count">{{ total.count || 0 }}</view>
							<view class="label">拆分单数</view>
						</view>
						<view class="line"></view>
						<view class="item">
							<view class="count">{{ total.price || 0 }}</view>
							<view class="label">拆分金额</view>
						</view>
					</view>
					
				</view>
			</view>
		</view>
		
		<scroll-view scroll-y class="scroll" :style="'height: calc(100vh - ' + hFoot + 'px - ' + barheight + 'px);'"  @scrolltolower="loadMoreData">
			<view class="sc-body">
				<view class="item" v-for="item in listAr">
					<view class="info fx-r">
						<view class="nickname">{{ item.nickname }}({{ item.auction_name }})</view>
						<view class="fx-r  fx-bc" @tap="tapCall(item.mobile)">
							<view class="mobile">{{ item.mobile }}</view>
							<image src="/static/img/call-tel.png" style="width: 15px;height: 15px;margin-left: 5px;"></image>
						</view>
					</view>
					
					<view class="info fx-r">
						<view class="id">ID号：{{ item.uid }}</view>
						<view class="fx-g1"></view>
						<view class="changci">订单编号：{{ item.order_id }}</view>
					</view>
					
					<view class="info fx-r">
						<view class="id">拆分时间：{{ item.time }}</view>
					</view>
					
					<view class="info-list" v-for="item2 in item.orderIds">
						<view class="fx-r">
							<view class="iivi">子订单:{{ item2 }}</view>
							<view class="fx-g1"></view>
							<view class="iivi">价格:<text style="color: red;font-weight: bold;">￥{{ item.price / 2 }}</text></view>
						</view>
					</view>
					
					<view class="infos fx-r">
						<view class="time">订单价格:<text style="color: red;">{{ item.price }}</text></view>
					</view>
					
				</view>
				
				<view v-if="listAr.length > 0">
					<view class="loading fx-r fx-ac fx-bc" v-if="page.isFrite && !page.isFoot">
						<image src="/static/img/xloading.png"></image>
						<text>正在载入更多...</text>
					</view>
					<view class="loading complete" :hidden="!page.isFoot">已加载全部</view>
				</view>
				
				<view v-if="listAr.length == 0 && isFirst">
					<u-empty
								mode="data"
								icon="/static/img/no-empty.png"
							></u-empty>		
				</view>
				
			</view>
		</scroll-view>
		
		<u-popup :show="isPop" @close="isPop = false">
			<scroll-view style="height: 40vh;background: #fff;">
				<view class="pop-info">
					<view class="item ihover" @tap="tapGzItem(item)" v-for="item in gzData">{{ item.nickname }}</view>
				</view>
			</scroll-view>
			
			
		</u-popup>
		
	</view>
</template>

<script>
	import dayjs from 'dayjs';
import {mapState,mapMutations } from 'vuex';
	export default {
		computed: mapState(['user']),
		data() {
		    return {
				isFirst:false,
				listAr:[],
				keyword : "",
				id : 0,
				hFoot : 0,
				barheight : 0,
				datetime:["",""],
				total : {},	
				isShowTime : false,
				endTime : "",
				
				page:{
					isFirst:false,
					isLoad:false,
					isFoot:false,
					page:1
				},
				isPop : false,
				
				gzData : [],
				gzItem : {
					name :"",
					id : 0
				},
		    }
		}, 
		onLoad(options) {
			this.id = options.id || 0;
			//基本配置
			this.endTime = dayjs().format("YYYY-MM-DD");
			this
				.request
				.get("gzAuction")
				.then(res => {
					if(res.code == 200){
						this.gzData = res.data;
					}
				});
			//基本配置
			this.datetime = [
				dayjs().format("YYYY-MM-01"),
				dayjs().format("YYYY-MM-DD")
			];
			this.initView();
			
			// #ifdef H5
				this.hFoot = 60;
			// #endif
		},
			 
		methods: {
			...mapMutations(['checkUserLogin']),
			/**
			 * 加载基础配置
			 */
			initView:function(){
				
				this.$nextTick(() => {
					uni.createSelectorQuery().select("#app-top").boundingClientRect(res=>{
						this.barheight = res.height + 20;
					}).exec();
				});
				this.initData();
				this.getData(true);
				
			},	
			initData:function(){

				this.request.post("auctionDisassembleInit",{
					str_time : this.datetime[0],
					end_time : this.datetime[1],
					auActionId : this.gzItem.id
				}).then(res => {
					if(res.code == 200) {
						this.total = res.data;
					}
				});
			},
			/**
			 * 获取数据
			 */
			getData:function(isPull = false){
				if(this.page.isLoad) return;
				this.page.isLoad = true;
				if(isPull) {
					this.page.page = 1;
					this.page.isLoad = false;
					this.page.isFoot = false;
				}
				uni.showLoading({ title: '获取数据中..' });
				var post = {};
				post.page = this.page.page;
			
				this
					.request
					.post("auctionDisassembleLog",{
						keyword : this.keyword,
						page : this.page.page,
						str_time : this.datetime[0],
						end_time : this.datetime[1],
						auActionId : this.gzItem.id
					})	
					.then(res => {
						uni.hideLoading();
						this.page.isFirst = true;
						this.page.isLoad = false;
						this.isFirst = true;
						if(isPull) {
							this.listAr = res.data.list;
						} else {
							this.listAr = this.listAr.concat(res.data.list);
						}
						//是否到底
						if(res.data.list.length != res.data.pageSize) {
							this.page.isFoot = true;
						} 
					})
					.catch((res)=>{
						console.log(res);
						uni.hideLoading();
						uni.showModal({title: '系统提示',content: '加载失败，返回在尝试',showCancel: false});
					});
			},
			//选择场馆
			tapCg:function(){
				this.isPop = true;
			},
			
			
			tapGzItem:function(item){
				this.isPop = false;
				this.gzItem = item;
				this.initData();
				this.getData(true);
			},
			tapSerach:function(){
				this.getData(true);
				this.initData();
			},
			tapDateTime:function(ev){
				this.initData();
				this.getData(true);
			},
			loadMoreData:function() {
				if(this.page.isFoot || this.page.isLoad) {
					return;
				}
				this.page.page ++;
				this.getData();			
			},
			
			tapCall:function(tel){
				if(tel == null) {
					this.utils.showAlert({
						title:"系统提示",
						content:"暂无联系方式"
					});
					return;
				}
				const info =  uni.getSystemInfoSync();
				if(info.platform == 'android'){
					uni.showModal({
						content: "确认拨打" + tel,
						confirmText: "确定",
						cancelText: "取消",
					  		success:function(res){
					  			if(res.confirm){
									
									this.$store.dispatch('permission/requestPermissions', 'CALL_PHONE').then(res => {
										if(res !== 1) return;
										uni.makePhoneCall({
										   phoneNumber: tel,
										});
									});   
					  			}
					  		}
					});
				} else {
					uni.makePhoneCall({
					   phoneNumber: tel
					});
				}
			}
	},
}
</script>	


<style lang="scss">
	.app-body{
		padding: 0px 20rpx;
	}
	.sreach{
		background: #fff;
		margin:20rpx 0;
		border-radius: 32rpx;
		padding: 16rpx 32rpx;
		.icon{
			width: 46rpx;
			height: 46rpx;
		}
		input{
			width: calc(100% - 46rpx - 16rpx - 50px);
			font-size: 16px;
		}
		.search-btn{
			font-size: 14px;
			color: #FF4C4C;
		}
	}
	
	.sc-body{
		padding: 20rpx;
		.item{
			background: #FFFFFF;
			border-radius: 16rpx;
			padding: 26rpx 44rpx;
			margin-bottom: 10px;
			.info{
				margin-bottom: 10rpx;
				.nickname{
					font-weight: bold;
					font-size: 32rpx;
					color: #303133;
				}
				.mobile{
					font-weight: 500;
					font-size: 30rpx;
					color: #999999;
					margin-left: 10px;
				}
				.id{
					font-weight: 500;
					font-size: 26rpx;
					color: #666666;
				}
				.changci{
					font-weight: 500;
					font-size: 26rpx;
					color: #666666;
					text{
						color: #333333;
					}
				}
				
			}
			.infos{
				margin-top: 10px;
				border-top: 1px solid #f1f1f1;
				padding-top: 6px;
				.time{
					font-size: 14px;
					color: #666;
				}
			}
		}
	}
	
	.info-list{
		padding: 10px 0;
		font-size: 12px;
		border-top: 1px solid #f1f1f1;
	}
	.app-inner{
		padding: 0px 10px;
	}
	.pannel{
		background: #FFFFFF;
		border-radius: 20px;
		padding: 15px;
		margin-top: 10px;
		.panel-info{
			.line{
			    width: 1px;
			    height: 50px;
			    background: #999999;
			    opacity: 0.38;
				margin-top: 10px;
			}
			.item{
				width: calc(50% - 1px);
				display: flex;
				flex-direction: column;
				justify-content: center;
				align-items: center;
				padding-top: 20px;
				.label{
				    font-weight: 500;
				    font-size: 12px;
				    color: #787878;
				    margin-top: 5px;
				}
				.count{
				    font-weight: bold;
				    font-size: 19px;
				    color: #333333;
				}
			}
			
		}
		.status{
			padding: 10px 0;
			border-bottom: 1px solid #f1f1f1;
			.people{
				image{width: 24rpx;height: 22rpx;margin-right: 10rpx;}
				.label{color: #666666;font-size: 13px;}
				.value{font-size: 13px;color: #000;margin-left: 4px;}
			}
			
		}
		
	}
	
	
	.search-tm{
		height: 40px;
		color: #787878;
		font-size: 14px;
		.icon{
			width: 10px;
			height: 10px;
			margin-left: 5px;
		}
	}
	
	.pop-info{
		.item{
			padding: 20rpx 0;
			text-align: center;
			border-bottom: 1px solid #f1f1f1;
		}
	}
	
	
</style>