<template>
	<view class="corderStyle" :style="{'height':contentHeight}">
		<view style="width: 100%;height: 100%;">
			<u-tabs :list="list" :is-scroll="false" :current="msg.DistrbutionOrderSelectStatus" @change="change" :active-color='mainColor'></u-tabs>
			<u-empty v-if="g.length==0" text="暂无数据" mode="data"></u-empty>
			<template v-if="g.length > 0">
				<view style="height: calc(100vh - 50px);width: calc(100vw);overflow: hidden;padding: 10px 0;">
					<scroll-view :scroll-y="true" :enable-back-to-top="true" :enable-flex="true" @scrolltolower="lower" :style="{ height: '100%' }">
						<view style="display: flex;flex-direction: column;align-items: center;">
							<view v-for="(item, index) in g" :key="index" class="listbox">
								<view class="box_top" @click="redirectToDetail(item)">
									<Text style='font-size: 14px;'>订单号：{{item.OrderNo}}</Text>
									<Text :style="{'font-size':'14px','color':mainColor}">{{item.StatusName}}</Text>
								</view>
								<view class="box_center" @click="isdetail(index)">
									<view class="center_l">
										<u-avatar :src="item.Photo" mode="square" size="70" @click.native.stop='gopeopleinfo(item.UserId)'></u-avatar>
										<view class="box_ltext">
											<Text class='l_name'>{{item.UserName}}</Text>
										</view>
										<!-- <Text v-if='item.Grade==0'>自购返佣</Text>
										<Text v-if='item.Grade==1'>一级分销</Text>
										<Text v-if='item.Grade==2'>二级分销</Text> -->
										<text style="margin-left: 15px;">{{item.GradeDescription}}</text>
									</view>
									<view class="center_l">
										<Text>{{item.CommissionState==1? '待返佣':'已返佣'}}：<Text :style="{color:pricecolor}">{{item.Commission}}</Text>元
										</Text>
										<u-icon name="arrow" v-if='item.showdetail==false'></u-icon>
										<u-icon name="arrow-down" v-if='item.showdetail==true'></u-icon>
									</view>
								</view>
								<view style="display: flex;flex-direction: column;align-items: center;padding-bottom: 15px;width: 100%;" v-if='item.showdetail==true'>
									<view class="box_bottom" v-for="(c, i) in item.DetailList" :key="i">
										<image :src="c.CoverImagePath" style="width: 55px;height: 55px" mode='aspectFit'></image>
										<view class="b_r">
											<Text class='l_name'>{{c.GoodsName}}</Text>
											<view style='display: flex;flex-direction: row;align-items: center;'>
												<Text v-for="(q, w) in c.SpecificationList" :key="w">{{q}}</Text>
											</view>
											<view style="display: flex;flex-direction: row;align-items: center;justify-content: space-between;">
												<Text style='margin-left: 5px;'>x{{c.Number}}</Text>
												<Text :style="{color:pricecolor}">￥{{c.Final_Price}}</Text>
											</view>
										</view>
									</view>
								</view>
							</view>
						</view>
						<u-loadmore :status="status" :load-text="loadText" :font-size="24" :margin-top="20" :margin-bottom="20" bg-color="#f3f4f6" />
					</scroll-view>
				</view>
			</template>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				pageTitle: "分销订单",
				contentHeight: 0,
				mainColor: '',
				secondary: '',
				pricecolor: '',
				g: [],
				list: [{
						name: '全部'
					},
					{
						name: '待付款'
					},
					{
						name: '已付款'
					},
					{
						name: '已完成'
					},
				],
				msg: {
					pageIndex: 1,
					pageSize: 10,
					DistrbutionOrderSelectStatus: 0
				},
				page_count: 1,
				status: "loadmore",
				loadText: {
					loadmore: "轻轻上拉，加载更多",
					loading: "努力加载中",
					nomore: "没有更多了",
				},
			}
		},
		created() {
			this.contentHeight = this.$utils.calcContentHeight(-40) + 'px';
			this.mainColor = this.$uiConfig.mainColor;
			this.secondary = this.$uiConfig.secondary;
			this.pricecolor = this.$uiConfig.pricecolor;
			this.init()
		},
		mounted() {
			let currentPages = getCurrentPages();
			let u = "/" + currentPages[currentPages.length - 1].route;
			let pages = wx.getStorageSync("basedata") ?
				wx.getStorageSync("basedata").bar_title :
				[];
			pages.forEach((x) => {
				if (x.value == u) {
					this.pageTitle = x.new_name ? x.new_name : x.name;
				}
			});
			uni.setNavigationBarTitle({
				title: this.pageTitle,
			});
		},
		methods: {
			init() {
				uni.showLoading({
					title: '加载中'
				});
				this.request2({
						url: '/api/AppletOrder/GetUserDistributionOrdersPageList',
						data: this.msg
					},
					(res) => {
						uni.hideLoading();
						let list = res.data.pageData;
						list.forEach((x) => {
							x.showdetail = false
						})
						this.g = this.g.concat(list);
						this.page_count = res.data.pageCount;
						if (this.page_count == 1) {
							this.status = "nomore";
						}
					}
				);
			},
			change(index) {
				this.msg.DistrbutionOrderSelectStatus = index;
				this.msg.pageIndex = 1;
				this.g = []
				this.init()
			},
			isdetail(index) {
				this.g[index].showdetail = !this.g[index].showdetail
			},
			gopeopleinfo(UserId) {
				uni.navigateTo({
					url: '/pages/share-team/share-detail?UserId=' + UserId
				});
			},
			lower(e) {
				if (this.msg.pageIndex < this.page_count) {
					this.msg.pageIndex++;
					this.status = "loading";
					this.init();
				} else {
					this.status = "nomore";
				}
			},
			redirectToDetail(item) {
				// OrderClassify  0商品   1司导   2网课
				if (item.OrderClassify == 0) {
					uni.navigateTo({
						url: "/pages/order/order-detail?id=" + item.OrderId + '&NewUserId=' + item.UserId,
					});
				} else if (item.OrderClassify == 1) {
					uni.navigateTo({
						url: "/pages/guidecar/orderDetail?OrderId=" + item.OrderId + '&NewUserId=' + item.UserId,
					});
				} else if (item.OrderClassify == 2) {
					uni.navigateTo({
						url: "/pages/school/personal/orderDetail?OrderId=" + item.OrderId + '&NewUserId=' + item.UserId,
					});
				}
			},
		}
	}
</script>

<style>
	.corderStyle {
		background: #f3f4f6;
	}

	.corderStyle .listbox {
		width: 100%;
		background: #fff;
		padding: 0 15px;
		margin-bottom: 15px;
		display: flex;
		flex-direction: column;
		align-items: center;
	}

	.corderStyle .listbox .box_top {
		width: 100%;
		height: 45px;
		display: flex;
		flex-direction: row;
		align-items: center;
		justify-content: space-between;
		border-bottom: 1px solid #f5f5f5;
	}

	.corderStyle .listbox .box_center {
		width: 100%;
		height: 45px;
		display: flex;
		flex-direction: row;
		align-items: center;
		justify-content: space-between;
		font-size: 13px;
	}

	.corderStyle .center_l {
		display: flex;
		flex-direction: row;
		align-items: center;
	}

	.corderStyle .listbox .box_ltext {
		width: 90px;
		margin-left: 5px;
	}

	.corderStyle .listbox .l_name {
		overflow: hidden;
		text-overflow: ellipsis;
		display: -webkit-box;
		-webkit-line-clamp: 1;
		-webkit-box-orient: vertical;
	}

	.corderStyle .listbox .box_bottom {
		width: 100%;
		display: flex;
		flex-direction: row;
		align-items: center;
		justify-content: space-between;
		padding: 15px 0 0;
		border-top: 1px solid #f5f5f5;
		font-size: 13px;
	}

	.box_bottom .b_r {
		width: calc(100vw - 30px - 50px - 20px);
		display: flex;
		flex-direction: column;
		justify-content: space-between;
	}
</style>