<template>
	<view class="container">
		<view class="search-user flex-y-center ">
			<view class="search-content flex-y-center">
				<icon type="search" size="18" />
				<input confirm-type="search" v-model="seTval" @confirm="confirm" @input="getSearch" class="flex-grow-1"
					type="text" placeholder-style="font-size:26rpx" placeholder="请输入订单编号" />
				<view class="flex-center" style="margin-left: 10rpx;" @click.stop="onDel" v-if="seTval">
					<icon type="clear" size="18" />
				</view>
			</view>
			<view class="search-btn" @click="search">
				搜索
			</view>
		</view>
		<view class="box-pack-between headerScreen flex-y-center ">
			<view class="flex-y-center flex-grow-1 ft26 header-text">
				<view style="width: 50%;" class="flex-grow-1 flex-center " data-text="1" :class="act_index==1?'act':''"
					@click="onTopBtnTap(1)">
					<view class="text-1" style="width: auto; max-width: 300rpx;">
						{{level_text}}
					</view>
					<view class="d3"></view>
				</view>
				<view style="width: 50%;" class="flex-grow-1 flex-center text-1" data-text="2"
					:class="act_index==2?'act':''" @click="onTopBtnTap(2)">
					<view class="text-1" style="width: auto; max-width: 300rpx;">
						{{type_text}}
					</view>
					<view class="d3"></view>
				</view>

				<view style="width: 50%;" class="flex-grow-1 flex-center text-1" data-text="2"
					:class="act_index==3?'act':''" @click="onTopBtnTap(3)">
					<view class="text-1" style="width: auto; max-width: 300rpx;">
						{{store_text}}
					</view>
					<view class="d3"></view>
				</view>
				
				<view style="width: 50%;" class="flex-grow-1 flex-center text-1" data-text="2"
					:class="act_index==4?'act':''" @click="onTopBtnTap(4)">
					<view class="text-1" style="width: auto; max-width: 300rpx;">
						{{time_text}}
					</view>
					<view class="d3"></view>
				</view>
				
			</view>
		</view>

		<view class="header-hg200"></view>

		<view class="flex table-header ft28">
			<view class="flex-grow-1" @click="bindTab(1)" :class="tab_index==1?'act':''">
				数据统计
			</view>
			<view class="flex-grow-1" @click="bindTab(2)" :class="tab_index==2?'act':''">
				数据列表
			</view>
		</view>

		<uni-popup-top ref="popup" type="top" :top="top" :maskClass="maskClass">
			<view class="showpay">
				<block v-if='act_index==1'>
					<view class="box-li" :class="index_id==0?'active':''" @click="Onlevel(0,'全部')" data-text='全部'>全部
					</view>
					<scroll-view scroll-y="true" style="height: 400rpx;">
						<view class="box-li" v-for="(item,index) of tableTypeList" :key='index'
							:class="item.type==index_id?'active':''" @click="Onlevel(item.type,item.title)">
							{{item.title}}
						</view>
					</scroll-view>
				</block>

				<block v-if='act_index==2'>
					<view class="box-li" :class="status==0?'active':''" @click="onStatus(0,'全部')" data-text='全部'>全部
					</view>
					<view class="box-li" :class="status==1?'active':''" @click="onStatus(1,'微信')" data-text='微信'>微信
					</view>
					<view class="box-li" :class="status==2?'active':''" @click="onStatus(2,'支付宝')" data-text='支付宝'>支付宝
					</view>
				</block>

				<block v-if='act_index==3'>
					<view class="box-li" v-if="type==1" :class="storeIndex==0?'active':''" @click="bindStore(0,'全部')"
						data-text='全部'>全部
					</view>
					<scroll-view scroll-y="true" style="height: 400rpx;">
						<view class="box-li" v-for="(item,index) of storeArr" :key='index'
							:class="item.id==storeIndex?'active':''" @click="bindStore(item.id,item.title)">
							{{item.title}}
						</view>
					</scroll-view>
				</block>
				<block v-if='act_index==4'>
				       <view class="model">
				        <view class="flex-center  model-date box-pack-between">
				
				            <view class="model-item" :class="time_index==1?'act':''">
				                <picker mode='date' :value="start"
				                    @change="bindDateChange1" data-index="1">
				                    <view class="flex-center">
				                        <text>{{start}}</text>
				                    </view>
				                </picker>
				            </view>
				
				            <view class="model-item" :class="time_index==2?'act':''">
				                <picker mode='date' :value="end" 
				                    @change="bindDateChange2" data-index="1">
				                    <view class="flex-center">
				                        <text>{{end}}</text>
				                    </view>
				                </picker>
				            </view>
				
				        </view>
				        <view class="flex">
				            <view class="model-btn-close  model-btn flex-center" @click="clear">
				                清空
				            </view>
				            <view class="model-btn-success flex-center model-btn" @click="sure">
				                确定
				            </view>
				        </view>
				    </view>
				</block>
				
			</view>
		</uni-popup-top>

		<block v-if="tab_index==1">
			<view class="list">
				<view class="flex table-total ft30">
					<view class="flex-grow-1">
						<text>{{obj.jr_zon_shoukuan}}</text>
						<view class="list-title">
							今日总的金额
						</view>
					</view>
					<view class="flex-grow-1">
						<text>{{obj.jr_zon_tuikuan}}</text>
						<view class="list-title">
							今日总的退款
						</view>
					</view>
					<view class="flex-grow-1">
						<text>{{obj.jr_wx}}</text>
						<view class="list-title">
							今日总的微信
						</view>
					</view>
				</view>
				<view class="flex table-total ft28">
					<view class="flex-grow-1">
						<text>{{obj.jr_yhk}}</text>
						<view class="list-title">
							今日总的银行卡
						</view>
					</view>
					<view class="flex-grow-1">
						<text>{{obj.jr_zfb}}</text>
						<view class="list-title">
							今日总的支付宝
						</view>
					</view>
					<view class="flex-grow-1">
						<text>{{obj.jr_xz}}</text>
						<view class="list-title">
							今日总的现金
						</view>
					</view>
				</view>
				<view class="flex table-total ft28">
					<view class="flex-grow-1">
						<text>{{obj.zon_shoukuan}}</text>
						<view class="list-title">
							总的金额
						</view>
					</view>
					<view class="flex-grow-1">
						<text>{{obj.zon_tuikuan}}</text>
						<view class="list-title">
							总的退款
						</view>
					</view>
					<view class="flex-grow-1">
						<text>{{obj.zon_wx}}</text>
						<view class="list-title">
							总的微信
						</view>
					</view>
				</view>
				<view class="flex table-total ft28">
					<view class="flex-grow-1">
						<text>{{obj.zon_yhk}}</text>
						<view class="list-title">
							总的银行卡
						</view>
					</view>
					<view class="flex-grow-1">
						<text>{{obj.zon_zfb}}</text>
						<view class="list-title">
							总的支付宝
						</view>
					</view>
					<view class="flex-grow-1">
						<text>{{obj.zon_xj}}</text>
						<view class="list-title">
							总的现金
						</view>
					</view>
				</view>
			</view>
		</block>

		<block v-if="tab_index==2">
			<no-none v-if='list.length<=0'></no-none>
			<view class="list" v-else>
				<view class="item" style="border: none;" v-for="(item,index) in list" :key="index">
					<view class="box-pack-between">
						<view class="name box-pack-between flex-grow-1">
							<text>{{item.out_trade_no}}</text>
							<view class="flex-center ft28" style="padding-right: 20rpx;color: #247EFF;">
								{{item.status==1?'已支付':item.status==0?'待支付':item.status==2?'已退款':item.status==3?'部分退款':
							'其他'}}
							</view>
						</view>
					</view>

					<view class="content">
						<view class="flex flex-y-center">
							<view class="cell flex flex-y-center">
								<view class="title">支付金额：</view>
								<view class="desc">{{item.pay_price}}</view>
							</view>
						</view>

						<view class="flex flex-y-center" style="margin-top: 16rpx;">
							<view class="cell flex flex-y-center " style="width:100%">
								<view class="title">退款金额：</view>
								<view class="desc">{{item.refund_price}}</view>
							</view>
						</view>

						<view class="flex flex-y-center" style="margin-top: 16rpx;">
							<view class="cell flex flex-y-center " style="width:100%">
								<view class="title">支付方式：</view>
								<view class="desc">{{item.pay_type==1?'微信':item.pay_type==2?'支付宝':'其他'}}</view>
							</view>
						</view>

						<view class="flex flex-y-center" style="margin-top: 16rpx;">
							<view class="cell flex flex-y-center " style="width:100%">
								<view class="title">订单类型：</view>
								<view class="desc">
									{{
						item.order_type==1?'聚合码-H5':
						item.order_type==2?'聚合码-小程序':
						item.order_type==3?'微收银':
						item.order_type==4?'如意':
						item.order_type==5?'POS':
						item.order_type==6?'商米D2':
						item.order_type==7?'IOT-蜻蜓':
						item.order_type==8?'IOT-青蛙':'其他'
						}}
								</view>
							</view>
						</view>

						<view class="flex flex-y-center" style="margin-top: 16rpx;">
							<view class="cell flex flex-y-center " style="width:100%">
								<view class="title">所属门店：</view>
								<view class="desc">{{item.title}}</view>
							</view>
						</view>

						<view class="flex flex-y-center" style="margin-top: 16rpx;">
							<view class="cell flex flex-y-center " style="width:100%">
								<view class="title"> 下单时间：</view>
								<view class="desc">{{item.pay_time}}</view>
							</view>
						</view>
					</view>
				</view>
			</view>
		</block>
	

	
	</view>
</template>
<script>
	import uniPopupTop from '@/components/zx-uni-popup/uni-popup-top.vue'
	export default {
		components: {
			uniPopupTop
		},
		data() {
			return {
				act_index: 1,
				type_text: '支付方式',
				level_text: '订单类型',
				store_text: "门店",
				time_text:'日期筛选',
				store_id: "",
				admin_id: '',
				list: [],
				page: 1,
				is_bottom: false,
				keywords: "",
				status: 0,
				type: 2,
				tableTypeList: [{
						title: "聚合码-H5",
						type: 1,
					},
					{
						title: "聚合码-小程序",
						type: 2,
					},
					{
						title: "微收银",
						type: 3,
					},
					{
						title: "如意",
						type: 4,
					},
					{
						title: "POS",
						type: 5,
					},
					{
						title: "商米D2",
						type: 6,
					},
					{
						title: "IOT-蜻蜓",
						type: 7,
					}, {
						title: "IOT-青蛙",
						type: 8,
					},
				],
				top: "200rpx",
				maskClass: {
					'position': 'fixed',
					'bottom': 0,
					'top': "100rpx",
					'left': 0,
					'right': 0,
					'backgroundColor': 'rgba(0, 0, 0, 0.4)'
				},
				index_id: null,
				storeArr: [],
				storeIndex: 0,
				tab_index: 1,
				obj:{},
				start: "开始时间",
				end: "结束时间",
				time_index: 0,
				time_index2: 0,
			}
		},

		onLoad(e) {
			this.type = e.type || 2;
			this.store_id = e.type == 1 ? '' : uni.getStorageSync("store_id");
			this.admin_id = uni.getStorageSync("admin_id");
			this.shop_store_index();
		},

		onShow() {
			this.getData(1)
		},

		onReachBottom() {
			if (!this.is_bottom) {
				this.getData(this.page + 1)
			}
		},

		methods: {
			
			bindDateChange1(e) {
			    this.time_index = e.currentTarget.dataset.index;
			    this.start = e.target.value;
			},
			
			bindDateChange2(e) {
			    this.time_index2 = e.currentTarget.dataset.index;
			    this.end = e.target.value;
			},
			
			sure(e) {
			    this.getData(1);
			    this.$refs.popup.close();
			    this.start_text = this.end;
			},
			
			clear() {
			    this.start = '开始时间';
			    this.start_text = '日期查找';
			    this.end = '结束时间';
			    this.getData(1);
			    this.$refs.popup.close();
			},
			
			
			bindTab(index) {
				this.tab_index = index;
			},
			
			shop_store_index() {
				let storeinfo = uni.getStorageSync("storeinfo");
				this.request({
					url: 'Smdcshop/shop_store_index',
					data: {
						admin_id: this.admin_id,
					}
				}).then(res => {
					if (res.code == 200) {
						if (res.data.length > 0) {
							this.storeArr = res.data;
						} else {
							this.storeArr = [{
								title: storeinfo.title,
								id: storeinfo.id,
							}];
							this.store_text = storeinfo.title;
						}
					}

				})
			},

			onStatus(e, text) {
				this.status = e;
				this.type_text = text;
				this.list = [];
				this.getData(1);
				this.$refs.popup.close();
			},


			Onlevel(e, text) {
				this.index_id = e;
				this.level_text = text;
				this.list = [];
				this.getData(1);
				this.$refs.popup.close();
			},
			bindStore(e, text) {
				this.storeIndex = e;
				this.store_id = e;
				this.store_text = text;
				this.list = [];
				this.getData(1);
				this.$refs.popup.close();
			},

			getSearch(e) {
				if (!e.detail.value) {
					this.page = 1;
					this.list = [];
					this.keywords = "";
					this.getData(1);
				}
				this.keywords = e.detail.value;
			},

			onDel() {
				this.seTval = '';
				this.page = 1;
				this.list = [];
				this.keywords = "";
				this.getData(1);
			},

			confirm(e) {
				this.page = 1;
				this.list = [];
				this.keywords = e.detail.value;
				this.getData(1);
			},

			search(e) {
				this.page = 1;
				this.list = [];
				this.getData(1);
			},

			onTopBtnTap(e) {
				this.act_index = e;
				this.$refs.popup.open();
			},

			getData(page) {
				if (page == 1) {
					this.list = []
					this.page = 1
					this.is_bottom = false
				}
				this.request({
					url: 'Smdcshop/getOrderList',
					data: {
						page,
						limit: 10,
						pay_type: this.status,
						keywords: this.keywords,
						admin_id: this.admin_id,
						order_type: this.index_id,
						store_id: this.store_id,
						start: this.start == '开始时间' ? '' : this.start,
						end: this.end == '结束时间' ? '' : this.end,
					}
				}).then(res => {
					this.obj=res.data;
					if (res.code == 200 && res.data.list.length) {
						this.list = this.list.concat(res.data.list);
						this.page = page;	
					} else {
						this.is_bottom = true
					}
					
				})
			}
		}
	}
</script>

<style lang="scss">
	@import url("../static/css/common.css");

	page {
		background-color: #F4F5F7;
	}

    .model {
        width: 100%;
        z-index: 10;
        background: #FFFFFF;
        padding-bottom: 20rpx;

        .model-date {
            width: 100%;
            padding: 20rpx 80rpx;
            border-bottom: 1rpx solid #F1F1F1;

            .model-item {
                width: 270rpx;
                text-align: center;
                font-size: 28rpx;
                color: #999;
                position: relative;
                padding: 10rpx 0;
                text-align: center;
                border-radius: 8rpx;
                border: 1rpx solid #999;
            }

            .act {
                // color: #FFFFFF;
                // background: #FFBE2C;
                // border: 1rpx solid #FFBE2C;
            }
        }

        .model-btn {
            border-radius: 8rpx;
            box-shadow: 0px 0px 8rpx 0px rgba(51, 135, 255, 0.20);
            margin: 0 auto;
            margin-top: 20rpx;
            text-align: center;
            width: 41%;
            height: 80rpx;
            border-radius: none;
        }

        .model-btn-close {
            border: 1rpx solid #F1F1F1;
            color: #000;
        }

        .model-btn-success {
            color: #FFFFFF;
            background: linear-gradient(315deg, #3387ff 2%, #569bff 99%);

        }
    }
	.table-header {
		padding: 20rpx 0;
		text-align: center;
		position: fixed;
		left: 0;
		background: #fff;
		top: 200rpx;
		width: 100%;
		color: #999999;
	}

	.table-header .act {
		color: #000;
		font-weight: 700;
	}

	.table-total {
		padding: 60rpx 0;
		text-align: center;
		background: #FFFFFF;
		border-bottom: 1rpx solid #F1F1F1;
	}

	.list-title{
		font-size: 26rpx;    
		margin-top: 20rpx;
	}
	
	.list {
		padding: 10rpx 25rpx;
	}

	.list .item {
		border-radius: 8rpx;
		overflow: hidden;
		padding-left: 30rpx;
		border-left: 8rpx solid #247EFF;
		background-color: #fff;
		margin-bottom: 30rpx;
	}

	.list .item .name {
		height: 80rpx;
		border-bottom: 1rpx solid #f5f5f5;
		font-size: 30rpx;
		line-height: 80rpx;
		font-weight: bold;
	}

	.list .item .content {
		padding: 20rpx 0 24rpx;
	}

	.list .item .content .cell {
		/* flex: none; */
		/* width: 50%; */
		box-sizing: border-box;
		padding-right: 30rpx;
		font-size: 26rpx;
		line-height: 37rpx;
		color: #666;
	}

	.list .item .content .cell .title {
		color: #99A0AD;
	}

	.headerScreen {
		height: 100rpx;
		position: fixed;
		top: 100rpx;
		width: 100%;
		z-index: 999;
		background: #fff;
		border-bottom: 1rpx solid #F1F1F1;
	}

	.header-hg200 {
		height: 290rpx;
	}

	.header-text {
		text-align: center;
	}

	.d3 {
		width: 0;
		height: 0;
		border-width: 12rpx;
		border-style: solid;
		border-color: #000 transparent transparent transparent;
		margin-top: 14rpx;
		margin-left: 6rpx;
	}

	.showpay {
		width: 100%;
		z-index: 10;
		background: #FFFFFF;
	}

	.search-user {
		z-index: 999;
		position: fixed;
		left: 0;
		width: 100%;
		height: 100rpx;
		background: #FFFFFF;
		padding-left: 15rpx;
		margin: 0;
	}

	.search-user .search-content {
		width: 83%;
		height: 70rpx;
		background: #F1F1F1;
		border-radius: 100rpx;
		padding: 0 20rpx;
	}

	.search-user .search-content icon {
		margin-right: 10rpx;
	}

	.search-user .search-btn {
		margin-left: 20rpx;
		font-size: 28rpx;
	}

	.box-li {
		background-color: #fff;
		text-align: center;
		border-bottom: 1rpx solid #f1f1f1;
		height: 80rpx;
		line-height: 80rpx;
		font-size: 26rpx;
	}

	page .active {
		color: #007AFF;
	}
</style>
