<template>
	<view class="box">
		<view class="topt">
			<view class="search_con flexC">
				<view class="search_inp flexB">
					<view class="flex">
						<image src="../../static/return/search.png"></image>
						<input type="text" v-model="params.apply_number" :placeholder="tid == 0 ? '输入退货单号' : '输入调货单号'" placeholder-class="textS" style="width: 370rpx;" />
					</view>
					<view class="search" @click="cearBox">查询</view>
				</view>
			</view>
			<view class="topt_title flexB">
				<view :style="{color: tid == 0 ? '#FB231F' : '#333'}" class="topt_item flexCC" @click="tid = 0, cearBox()">
					<text>退货订单（{{ return_count }}）</text>
					<view :class="tid == 0 ? 'checked_l' : 'nochecked_l'" />
				</view>
				<view class="topt_line" />
				<view :style="{color: tid == 1 ? '#FB231F' : '#333'}" class="topt_item flexCC" @click="tid = 1, cearBox()">
					<text>调货订单</text>
					<view :class="tid == 1 ? 'checked_l' : 'nochecked_l'" />
				</view>
			</view>
		</view>
		<view class="boxList">
			<view v-show="tid == 0" class="boxList_item" v-for="(item, i) in list" :key="i" @click="getDetail(item)">
				<image :src="item.apply_status == 5 ? statusList[1] : statusList[0]" class="itemtipImg"></image>
				<view class="number">
					退货单号:{{ item.apply_number }}
				</view>
				<view v-for="(v, ind) in item.applydetail" :key="ind" class="flexB" style="padding-top: 24rpx">
					<image :src="v.goods_img" mode="" class="boxList_goodImage"></image>
					<view class="">
						<view class="goodName">大卫博士健康内裤（{{ v.good_name + v.good_size }}）</view>
						<view class="goodNumD flexB">
							<view class="goodNumD_left">{{ `${v.total + (v.unit ? v.unit : '条' )}` }}</view>
							<view class="goodNumD_right">
								<text>￥{{ v.return_price }}</text>
							</view>
						</view>
					</view>
				</view>
				<view class="boxList_bottom">
					<view class="bottom1">
						共
						<text v-show="item.count">{{ item.count }}套</text>
						<text v-show="item.total">{{ item.total }}条</text>
						，
					</view>
					<text class="bottom2">合计；</text>
					<text class="bottom3">￥</text>
					<text class="bottom4">{{ item.return_price }}</text>
				</view>
			</view>
			<view v-show="tid == 1" class="boxList_tip">
				该功能暂未开通
			</view>
		</view>
	</view>
</template>

<script>
	import { getCustomerReturnList, GetApplyList, getTabNum } from '@/api/index.js'
	export default {
		data() {
			return {
				tid: 0,
				totalPage: 0,
				total: 0,
				list: [],
				return_count: 0,
				apply_count:0,
				params: {
					page_index: 1,
					page_size: 5,
					apply_number: ''
				},
				statusList: [
					require('../../static/return/audit.png'),
					require('../../static/return/succe.png'),
					// require('../../static/return/error.png')
				]
			}
		},
		onLoad() {
			this.getList()
			this.getTab()
		},
		onReachBottom: function() {
			this.getMore()
		},
		methods: {
			getTab() {
				getTabNum().then(res => {
					if (res.code == 200) {
						this.return_count = res.data.return_count
						this.apply_count = res.data.apply_count
					}
				})
			},
			cearBox() {
				this.params.page_index = 1
				this.getList()
			},
			/*获取列表*/
			getList(isMore) {
				let _this = this
				let params = this.params
				if (this.tid == 0) { // 退货列表
				uni.showLoading({ title: '加载中', mask: true })
				getCustomerReturnList(params).then(res => {
					uni.hideLoading()
					if (res.code == 200) {
						_this.list = res.data.list
						_this.total = res.data.total
						_this.return_count = res.data.total
						_this.totalPage = Math.ceil(res.data.total / _this.params.page_size)
					} else {
						uni.showModal({
							content: res.data || '获取数据失败',
							showCancel: false
						});
					}
				}).catch(err => {uni.hideLoading()})
				} else { // 调货列表
					_this.list = []
				}
			},
			/*获取更多的列表*/
			getMore() {
				if (this.params.page_index >= this.totalPage) {
					uni.showToast({
						title: '没有更多啦~',
						icon: 'none'
					});
					return false
				}
				this.params.page_index++
				this.getList(true)
			},
			getDetail(goodItem) {
				const URL = encodeURIComponent(JSON.stringify(goodItem))
				uni.navigateTo({
					url: './returnDetail?item=' + URL
				})
			}
		}
	}
</script>

<style lang="scss" scoped>
	.topt {
		width: 100%;
		padding: 30rpx 24rpx 24rpx 24rpx;
		box-sizing: border-box;
		background-color: #fff;
		position: fixed;
		left: 0;
		top: 0;
		z-index: 10000;
	
		.search_con {
			width: 700rpx;
		}
	
		.search_inp {
			height: 80rpx;
			width: 100%;
			padding: 0 10rpx 0 30rpx;
			border-radius: 44rpx;
			background: #F9F9FB;
			image {
				width: 48rpx;
				height: 48rpx;
				margin-right: 10rpx;
			}
			.textS {
				font-size: 28rpx;
				font-family: PingFang SC-Regular, PingFang SC;
				font-weight: 400;
				color: #999999;
			}
			.flex {
				display: flex;
			}
		}
	
		.search {
			width: 132rpx;
			height: 64rpx;
			line-height: 64rpx;
			font-size: 28rpx;
			color: #FFFFFF;
			text-align: center;
			background: linear-gradient(92deg, #F30000 0%, #FE4815 100%);
			border-radius: 32rpx;
		}
		&_title {
			padding: 0 48rpx;
			margin-top: 24rpx;
			.checked_l {
				width: 32rpx;
				height: 4rpx;
				background: linear-gradient(180deg, #FF232C 0%, #FF571B 100%);
				border-radius: 4rpx 4rpx 4rpx 4rpx;
			}
			.nochecked_l {
				width: 32rpx;
				height: 4rpx;
				border-radius: 4rpx 4rpx 4rpx 4rpx;
			}
		}
		&_line {
			height: 40rpx;
			border: 2rpx solid #F5F5F5;
		}
		&_item {
			margin-bottom: 5rpx;
			text {
				font-size: 32rpx;
				font-family: PingFang SC-Bold, PingFang SC;
				font-weight: bold;
			}
		}
	}
	.boxList {
		padding: 210rpx 24rpx 24rpx 24rpx;
		&_tip {
			text-align: center;
			margin-top: 200rpx;
		}
		&_item {
			background: #FFFFFF;
			padding: 24rpx;
			border-radius: 16rpx 16rpx 16rpx 16rpx;
			margin-top: 24rpx;
			position: relative;
			.itemtipImg {
				width: 110rpx;
				height: 110rpx;
				position: absolute;
				top: 24rpx;
				right: 24rpx;
			}
			.number {
				font-size: 28rpx;
				font-family: PingFang SC-Regular, PingFang SC;
				font-weight: 400;
				color: #333333;
				border-bottom: 2rpx solid #E9E9E9;
				padding-bottom: 24rpx;
			}
			.goodName {
				font-size: 30rpx;
				font-family: PingFang SC-Bold, PingFang SC;
				font-weight: bold;
				color: #333333;
			}
			.goodNumD {
				margin-top: 24rpx;
				width: 474rpx;
				&_left {
					font-size: 28rpx;
					font-family: PingFang SC-Regular, PingFang SC;
					font-weight: 400;
					color: #999999;
					padding: 4rpx 12rpx;
					background: #F5F5F5;
					border-radius: 8rpx 8rpx 8rpx 8rpx;
				}
				&_right {
					// text:nth-child(1) {
					// 	font-size: 28rpx;
					// 	font-family: PingFang SC-Regular, PingFang SC;
					// 	font-weight: 400;
					// 	color: #999999;
					// 	margin-right: 48rpx;
					// }
					text {
						font-size: 28rpx;
						font-family: PingFang SC-Bold, PingFang SC;
						font-weight: bold;
						color: #333333;
					}
				}
			}
		}
		&_goodImage {
			width: 160rpx;
			height: 130rpx;
			border-radius: 16rpx 16rpx 16rpx 16rpx;
		}
		&_bottom {
			text-align: end;
			margin-top: 42rpx;
			display: flex;
			justify-content: flex-end;
			align-items: flex-end;
			text {
				font-size: 28rpx;
				font-family: PingFang SC-Bold, PingFang SC;
				font-weight: bold;
			}
			.bottom1 {
				color: #999999;
			}
			.bottom2 {
				color: #333333;
			}
			.bottom3 {
				color: #FB231F;
				font-weight: 400 !important;
			}
			.bottom4 {
				font-size: 44rpx !important;
				font-family: HarmonyOS Sans SC-Medium, HarmonyOS Sans SC !important;
				color: #FB231F !important;
			}
		}
	}
</style>