<template>
	<view style="background-color: #f2f2f6;padding-bottom: 0.01rpx;">
		<view style="background-color: #fff;position: fixed;top: 0;width: 100%;z-index: 8;">
			<view
				style="background-color:#E75F37;padding: 24rpx 32rpx;display: flex;justify-content: space-between;align-items: center;">
				<u-search placeholder="请输入商品名" v-model="cname" @custom="custom" @search="custom" :showAction="false"
					bgColor="#fff"></u-search>
			</view>

			<u-tabs :list="list" :current="current" lineColor="#E75F37" @click="sectionChange"></u-tabs>
		</view>
		<view style="margin-top: 180rpx;">
			<view class="card" v-for="(item,index) in dataList" :key="index" @click="choice(item,index)">
				<view>
					<view
						style="font-size: 26rpx;color: #717171;margin-bottom: 28rpx;display: flex;justify-content: space-between;">
						<view class="">
							{{item.salesCompanyName}}
						</view>
						<view style="color: #E75F37;">
							{{item.xcxStatus=='录入'?'待付款':item.xcxStatus || ''}}
						</view>
					</view>
					<view>
						<view style="display: flex;" v-for="(ite,inde) in item.orderItemsList" :key="inde">
							<view style="display: flex;width: 100%;align-items: center;margin-bottom: 20rpx;">
								<image :src="ite.url" mode="scaleToFill"
									style="width:120rpx;height: 120rpx;border-radius: 10rpx;border: 2rpx solid #EEEEEE;margin-right: 27rpx;">
								</image>
								<view style="width:477rpx;">
									<view
										style="display: flex;justify-content: space-between;align-items: center;font-size: 26rpx;color: #4E4E4E;font-weight: 500;">
										<u--text color="#4E4E4E" size="26rpx" :lines="1"
											:text="ite.goodsName"></u--text>
										<view>
											￥{{ite.price}}
										</view>
									</view>
									<view style="display: flex;justify-content:flex-end;margin-top: 20rpx;">
										<view style="font-size: 26rpx;color: #4D4D4D;">
											x{{ite.goodsNum}}
										</view>
									</view>
								</view>
							</view>

						</view>

					</view>
					<!-- <view style="display: flex;justify-content: flex-end;">
						<view style="width: 136rpx;margin-right: 17rpx;">
							<u-button type="primary" text="取消订单" color="#E75F37" shape='circle' plain
								@click="deleteGoods(item.id)"></u-button>
						</view>
						<view style="width: 136rpx;">
							<u-button type="primary" text="去支付" color="#E75F37" shape='circle'
								@click="paySubmit(item,index,ind)"></u-button>
						</view>
					</view> -->
					<view style="width: 623rpx;height: 2rpx;background: #F1F1F1;margin: 48rpx 0 40rpx 0;">
					</view>
					<view style="font-size: 26rpx;color: #717171;">
						<view style="margin-bottom: 20rx;">
							订单编号：<text style="color: #C4C4C4;">{{item.ordNo}}</text>
						</view>
						<view style="margin-bottom: 20rx;">
							支付方式：<text
								style="color: #C4C4C4;">{{item.payType && item.payType.indexOf('01') != -1?'扫码支付':'微信支付'}}</text>
						</view>
						<view>
							下单时间：<text style="color: #C4C4C4;">{{item.createTime}}</text>
						</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,
		appStatusShareList
	} 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
				});
				if (uni.getStorageSync('whether_openShare') == 1) {
					appStatusShareList({
						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();
					})
				} else {
					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.dataList = []
				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;
	}

	.card {
		padding: 54rpx 63rpx;
		background-color: #fff;
		margin-bottom: 20rpx;

		::v-deep .u-button {
			height: 60rpx;
		}
	}
</style>