<template>
	<view>
		<view class="top-fixed">
			<!-- tab切换 -->
			<view class="pub-tab-box">
				<u-tabs :current="current" :list="listStatus" :scrollable="false" @change="listStatusChange"></u-tabs>
			</view>
			<view class="search-cont">
				<view class="inner">
					<image class="icon-search" src="https://bjyjb-1362704775.cos.ap-chongqing.myqcloud.com/shop/image/icon_search.png" mode=""></image>
					<input type="text" value="" placeholder="输入商品" confirm-type="搜索" @confirm="goSearch"   placeholder-style="font-size:28rpx;color:#BBBBBB;font-family: PingFang SC;" />
				</view>
			</view>
		</view>
		<mescroll-body top="100px" ref="mescrollRef" @init="mescrollInit" @down="downCallback" @up="upCallback" :down="downOption" :up="upOption">
			<view class="order-list">
				<view  v-for="(item,index) in dataList" :key="index" class="item" >
					<view class="ordersn-box" @click="showDetail(item)">
						<view class="num">创建时间：{{item.createTime}}</view>
						<view class="status-box">
							<text class="text success" v-show="item.auditStatus==1">
								审核中
							</text>
							<text class="text info" v-show="item.auditStatus==0">
								待审核
							</text>
							<text class="text success" v-show="item.auditStatus==2">
								已通过
							</text>
							<text class="text black" v-show="item.auditStatus==-1">
								驳回
							</text>
						</view>
					</view>
					<view class="name-box">{{item.matchedProducts}}</view>
					<view class="amount-paid mt16" v-if="item.auditRemark&&item.auditStatus==-1">
						<text class="label">驳回原因：</text>
						<text style="font-size: 28rpx;">{{item.auditRemark||''}}</text>
					</view>
					<view class="amount-paid mt16">
						<text class="label">物流代收自定义金额：</text>
						<view class="price-box">
							<view class="unit">¥</view>
							<view class="num" >{{item.payAmount.toFixed(2)}}</view>
						</view>
					</view>
					<view class="bottom-box">
						<view class="amount-paid">
							<text class="label">支付金额：</text>
							<view class="price-box">
								<view class="unit">¥</view>
								<view class="num" >{{item.money.toFixed(2)}}</view>
							</view>
						</view>
						<view class="btn-box">
							<view class="btn pay" v-if="item.auditStatus==2" @click="handleDetail(item)">查看详情</view>
							<view class="btn cancel" v-if="item.auditStatus==0||item.auditStatus==-1" @click="handleDel(item)">删除</view>
						</view>
					</view>
				</view>
			</view>
		</mescroll-body>
	</view>
</template>

<script>
	import MescrollMixin from "@/uni_modules/mescroll-uni/components/mescroll-uni/mescroll-mixins.js";
	import { changeList,delList } from '../api/companyOrder.js'
	export default {
		mixins: [MescrollMixin], 
		data() {
			return {
				listStatus: [
					{name:"审核中",value:"1"},
					{name:"待审核",value:"0"},
					{name:"已通过",value:"2"},
					{name:"驳回",value:"-1"}
				],
				status: 1,
				current: 0,
				mescroll:null,
				downOption: {
					//下拉刷新
					use: true,
					auto: false // 不自动加载 (mixin已处理第一个tab触发downCallback)
				},
				// 上拉加载的配置
				upOption: {
					onScroll:true,
					use: true, // 是否启用上拉加载; 默认true
					page: {
						num: 0, // 当前页码,默认0,回调之前会加1,即callback(page)会从1开始
						size: 10 // 每页数据的数量,默认10
					},
					noMoreSize: 10, // 配置列表的总数量要大于等于5条才显示'-- END --'的提示
					empty: {
						icon:'https://bjyjb-1362704775.cos.ap-chongqing.myqcloud.com/app/newImages/empty_icon.png',
						tip: '暂无数据'
					}
				},
				// 列表数据
				dataList: [],
				searchKey: ''
			}
		},
		methods: {
			listStatusChange(e) {
				this.current = e.index
				this.status = e.value
				this.mescroll.resetUpScroll()
			},
			goSearch() {
				this.searchKey=e.detail.value;
				this.mescroll.resetUpScroll()
			},
			mescrollInit(mescroll) {
				this.mescroll = mescroll;
			},
			/*下拉刷新的回调 */
			downCallback(mescroll) {
				mescroll.resetUpScroll()
			},
			upCallback(page) {
				//联网加载数据
				var that = this;
				var data = {
					matchedProducts:this.searchKey,
					auditStatus:this.status,
					page: page.num,
					pageSize: page.size,
					token:uni.getStorageSync('CompanyUserToken')
				};
				changeList(data).then(res => {
					if(res.code==200){
						//设置列表数据
						if (page.num == 1) {
							that.dataList = res.data.list; 
							
						} else {
							that.dataList = that.dataList.concat(res.data.list);
							 
						}
						that.mescroll.endBySize(res.data.list.length, res.data.total);
						
					}else{
						uni.showToast({
							icon:'none',
							title: "请求失败",
						});
						that.dataList = null;
						that.mescroll.endErr();
					}
				});
			},
			handleDetail(item) {
				uni.navigateTo({
					url: '/pages_company/order/confirmCompanyOrder?source=audit&auditId='+item.id
				})
			},
			handleDel(item) {
				let that = this
				uni.showModal({
					title: '提示',
					content: '确定删除该申请吗？',
					success: function (res) {
						if (res.confirm) {
							delList(item.id).then(res=>{
								if(res.code == 200) {
									uni.showToast({
										icon:'none',
										title: '删除成功',
									});
									that.mescroll.resetUpScroll();
								} else {
									uni.showToast({
										icon:'none',
										title: res.msg,
									});
								}
							})
						} else if (res.cancel) {
							console.log('用户点击取消');
						}
					}
				});
			},
		}
	}
</script>

<style scoped lang="scss">
	.top-fixed{
		width: 100%;
		position: fixed;
		top: 0;
		left: 0;
		z-index: 10;
	}
	.pub-tab-box{
		box-sizing: border-box;
		width: 100%;
		padding: 0 40upx;
		background-color: #FFFFFF;
	}
	.search-cont{
		padding: 16upx 30upx;
		background-color: #FFFFFF;
		.inner{
			box-sizing: border-box;
			width: 100%;
			height: 72upx;
			background: #F7F7F7;
			border-radius: 36upx;
			display: flex;
			align-items: center;
			padding: 0 30upx;
			.icon-search{
				width: 28upx;
				height: 28upx;
				margin-right: 20upx;
			}
			input{
				height: 60upx;
				line-height: 60upx;
				flex: 1;
			}
		}
	}
	.order-list{
		padding: 20upx;
		.item{
			background: #FFFFFF;
			border-radius: 16upx;
			padding: 0 30upx;
			margin-bottom: 20upx;
			.ordersn-box{
				display: flex;
				align-items: center;
				justify-content: space-between;
				padding: 34upx 0 20upx;
				.num{
					font-size: 26upx;
					font-family: PingFang SC;
					font-weight: 500;
					color: #999999;
					line-height: 1;
				}
				.status-box{
					display: flex;
					align-items: center;
					.text{
						font-size: 28upx;
						font-family: PingFang SC;
						font-weight: 500;
						line-height: 1;
						&.success{
							color: #2583EB;
						}
						&.black{
							color: #111111;
						}
						&.info{
							color: #999999;
						}
					}
				}
			}
		}
	}
	.name-box {
		font-size: 32upx;
		font-family: PingFang SC;
		font-weight: 500;
		color: #111111;
		line-height: 40upx;
	}
	.amount-paid{
		display: flex;
		align-items: center;
		.label{
			font-size: 24upx;
			font-family: PingFang SC;
			font-weight: 500;
			color: #999999;
			line-height: 1;
		}
		.price-box{
			display: flex;
			align-items: flex-end;
			.unit{
				font-size: 24upx;
				font-family: PingFang SC;
				font-weight: 500;
				color: #FF6633;
				line-height: 1.2;
				margin-right: 4upx;
			}
			.num{
				font-size: 32upx;
				font-family: PingFang SC;
				font-weight: bold;
				color: #FF6633;
				line-height: 1;
			}
		}
	}
	.bottom-box{
		height: 110upx;
		display: flex;
		align-items: center;
		justify-content: space-between;
		.btn-box{
			box-sizing: border-box;
			display: flex;
			align-items: center;
			.btn{
				width: 155upx;
				height: 64upx;
				line-height: 64upx;
				font-size: 26upx;
				font-family: PingFang SC;
				font-weight: 500;
				text-align: center;
				border-radius: 32upx;
				margin-left: 15upx;
				&:first-child{
					margin-left: 0;
				}
				&.cancel{
					border: 1px solid #DDDDDD;
					color: #666666;
				}
				&.pay{
					background: #2583EB;
					color: #FFFFFF;
				}
			}
		}
	}
</style>