<template>
	<view class="content">
		<!-- 自定义导航 -->
		<view class="navbar-box">
			<u-navbar title="申请记录" :safeAreaInsetTop="true" @leftClick="leftClick"></u-navbar>
		</view>
		<u-tabs :list="tabList" :is-scroll="false" height="108" bar-width="100" :current="tabCurrent" @change="tabChange"></u-tabs>
		<mescroll-body ref="mescrollRef" @init="mescrollInit" @down="downCallback" @up="upCallback" :down="downOption" :up="upOption">
			<view class="item u-tips-color" @click="itemClick(item.id)" v-for="item in dataList" :key="item.id">
				<view class="u-flex u-row-between">
					<view class="left">
						<view class="name u-line-1 u-m-b-10">{{item.mateNames}}</view>
						<view class="">申请时间:</view>
						<view class="">{{item.createTime}}</view>
					</view>
					<view class="right u-text-center">
						<view class="u-m-b-10">{{filterPaymentName(item.storeOutType)}}</view>
						<view class="">联系人:{{item.contactPerson}}</view>
					</view>
					<view class=""></view>
				</view>
			</view>
		</mescroll-body>
	</view>
</template>

<script>
	import {otherApiUrl} from '@/common/apiurl.js';
	import MescrollMixin from "@/uni_modules/mescroll-uni/components/mescroll-uni/mescroll-mixins.js";
	export default {
		mixins: [MescrollMixin], // 使用mixin
		components: {
			
		},
		data() {
			return {
				// 下拉刷新的配置(可选, 绝大部分情况无需配置)
				downOption: {
				},
				// 上拉加载的配置(可选, 绝大部分情况无需配置)
				upOption: {
					page: {
						size: 10 // 每页数据的数量,默认10
					},
					noMoreSize: 5, // 配置列表的总数量要大于等于5条才显示'-- END --'的提示
					empty: {
						tip: '暂无相关数据'
					}
				},
				// 列表数据
				dataList: [],
				tabCurrent:0,
				tabList:[
					{name:'申请中',status:'1'},
					{name:'已通过',status:'2'},
					{name:'已驳回',status:'3'},
				],
				paymentList:[],
			}
		},
		onLoad() {
			this.getpaymentList();
		},
		computed:{
			filterPaymentName(){
				return function(value){
					let v = '';
					for (let i = 0; i < this.paymentList.length; i++){
						// console.log('value',value);
						// console.log('value',this.paymentList[i]);
						let item = this.paymentList[i];
						if (value == item.value) {
						  v = item.label;
						  break;
						}
					}
					return v
				}
			}
		},
		methods: {
			/*上拉加载的回调*/
			upCallback(page) {
				let params ={
					pageNum:page.num,
					pageSize:page.size,
					askforStatus:this.askforStatus||'1',
				} 
				this.$u.api.applyList(params).then(curPageData=>{
					// console.log('curPageData',curPageData)
					//联网成功的回调,隐藏下拉刷新和上拉加载的状态;
					// this.mescroll.endSuccess(curPageData.total);
					this.mescroll.endBySize(curPageData.rows.length, curPageData.total);
					//设置列表数据
					if(page.num == 1) this.dataList = []; //如果是第一页需手动制空列表
					this.dataList=this.dataList.concat(curPageData.rows); //追加新数据
				}).catch((err)=>{
					uni.showToast({
						title:'链接失败'
					});
					console.log('err',err)
					//联网失败, 结束加载
					this.mescroll.endErr();
				})
				
			},
			/*若希望重新加载列表,只需调用此方法即可(内部会自动page.num=1,再主动触发up.callback)*/
			reloadList(){
				this.mescroll.resetUpScroll();
			},
			leftClick() {
			   let canNavBack = getCurrentPages();
				 if(canNavBack && canNavBack.length>1) {  
				   uni.navigateBack({  
					 delta: 1  
				   });  
				 } else {  
				   history.back();  
				 }
			},
			// 切换菜单
			tabChange(index) {
				this.tabCurrent = index;
				this.askforStatus = this.tabList[index].status;
				this.reloadList()
			},
			async getpaymentList() {
				let { code, data, msg} = await this.$u.get(otherApiUrl.getDict + 'payment')
				if(code === 200) {
					this.paymentList = data.map(item => {
						return {
							label: item.dictLabel,
							value: item.dictValue
						}
					})
				}
			},
			itemClick(id){
				console.log('itemClick',id);
				this.$u.route({
					url: 'pages/apply/applyItem/applyItem',
					params: {
						id: id,
						askforStatus:this.askforStatus||'1'
					}
				})
			}
		}
	}
</script>

<style lang="scss" scoped>
.item{
	margin: 24rpx;
	padding: 24rpx;
	border: 1px solid #ddd;
	border-radius: 10rpx;
	.name{
		color: #444;
		font-size: 30rpx;
	}
	.left{
		max-width: 240px;
		flex: 1;
	}
	.right{
		
	}
}
</style>