<template>
	<view style="background-color: #f2f2f6;padding-bottom: 0.01rpx;">
		<view style="background-color: #fff;position: fixed;top: 0;width: 100%;z-index: 8;"><u-tabs :list="list"
				:current="current" lineColor="#FD4B09" @click="sectionChange"></u-tabs>
			<view
				style="background-color: #fff;padding: 8rpx 0rpx;display: flex;justify-content: space-between;align-items: center;">
				<u-search placeholder="请输入商品名" v-model="cname" @custom="custom" @search="custom"></u-search>
			</view>
		</view>
		<view class="content" style="margin-top: 95px;">
			<view class="contentBox" v-for="(item,index) in dataList" :key="index" @click="choice(item,index)">
				<view style="width: 100%;margin: 0 auto;">
					<u-cell-group :border="false">
						<u-cell :border="false" center :title="`${item.salesCompanyName || ''}`" arrow-direction="down">
							<view slot="icon" style="width: 10rpx;height: 35rpx;background-color: #fd4b09;"></view>
							<view slot="value">
								<view
									style="padding: 0rpx 20rpx;border:1rpx solid #FD4B09;border-radius: 100rpx;color: #FD4B09;">
									{{item.xcxStatus || ''}}
								</view>
							</view>
						</u-cell>
					</u-cell-group>
					<view class="textBox">
						<view
							style="overflow:hidden;white-space: nowrap;text-overflow: ellipsis;-o-text-overflow:ellipsis;">
							{{item.goodsNameJoin || ''}}
						</view>
					</view>
					<view class="textBox">
						<view>订单数量:</view>
						<view>{{~~item.goodsTotalNum || ''}}</view>
					</view>
					<view class="textBox">
						<view>订单金额:</view>
						<view>￥{{item.totalMoney || ''}}</view>
					</view>
					<view class="textBox">
						<view>订单日期:</view>
						<view>{{item.createTime || ''}}</view>
					</view>
				</view>
			</view>
		</view>
		<u-empty v-if="page.total == 0" style="position: absolute;top: 45%;left: 50%;transform:translate(-50%,-50%)"
			mode="data" icon="http://cdn.uviewui.com/uview/empty/data.png" />
		<u-loadmore v-if="page.total !== 0 && dataList.length != 0" :status="status" />
	</view>
</template>

<script>
	import {
		appStatusList
	} from '@/api/views/salesSlip/index.js'
	export default {
		data() {
			return {
				current: 0,
				cname:"",
				list: [{
					name: '全部',
					status: '',
					badge: {
						value: 0
					}
				}
				// , {
				// 	name: '未付款',
				//  status: '未付款',
				// 	badge: {
				// 		value: 0
				// 	}
				// }
				, {
					name: '待发货',
					status: '待发货',
					badge: {
						value: 0
					}
				}, {
					name: '待收货',
					status: '待收货',
					badge: {
						value: 0
					}
				}, {
					name: '已收货',
					status: '已收货',
					badge: {
						value: 0
					}
				}, {
					name: '退款售后',
					status: '退款请核,退款中,已取消',
					badge: {
						value: 0
					}
				}],
				dataList: [],
				search: {},
				page: {
					total: 0,
					size: 10,
					current: 1
				},
				status: 'loadmore',
			}
		},
		onLoad(onLoad) {
			for (let i in this.list) {
				if (onLoad.text == this.list[i].name) {
					this.current = i
				}
			}
			this.page = {
				total: 0,
				size: 10,
				current: 1
			}
			this.search = {
				xcxStatus: this.list[this.current].status
			}
			this.dataList = []
			this.onSearch()
		},
		onReachBottom() {
			this.status = 'loading'
			if (this.dataList.length < this.page.total) {
				this.page.current++
				this.onSearch()
			} else {
				this.status = 'nomore'
			}
		},
		methods: {
			sectionChange(item) {
				this.current = item.index;
				this.search = {
					xcxStatus: this.list[item.index].name == "全部" ? "" : this.list[item.index].status
				}
				this.page = {
					total: 0,
					size: 10,
					current: 1
				}
				this.dataList = []
				this.onSearch()
			},
			onSearch() {
				uni.showLoading({
					title: '加载中',
					mask: true
				});
				appStatusList({
					size: this.page.size,
					current: this.page.current,
					...this.search
				}).then(res => {
					this.dataList = this.dataList.concat(res.data.records)
					this.page.total = res.data.total
					if (this.dataList.length == res.data.total) {
						this.status = 'nomore'
					}
					uni.hideLoading();
				}).catch(err => {
					uni.hideLoading();
				})
			},
			//搜索
			custom(){
				this.page = {
					total: 0,
					size: 10,
					current: 1
				}
				this.search = {
					retrieval:this.cname
				}
				this.onSearch()
			},
			choice(item, index) {
				uni.$u.route('/pages/views/salesSlip/orderDetails', {
					id: item.id
				});
			}
		}
	}
</script>

<style lang="scss" scoped>
	.contentBox {
		width: 96%;
		margin: 20rpx auto;
		background-color: #FFFFFF;
		border-radius: 20rpx;
		/* box-shadow: 0 5rpx 14rpx 0 rgba(101, 176, 249, 0.42); */
		padding-top: 15rpx;
		padding-bottom: 10rpx;
	}

	.textBox {
		padding: 0 15px;
		display: flex;
		justify-content: space-between;
		font-size: 24rpx;
		margin-bottom: 10rpx;
		align-items: flex-end;
	}
</style>