<template>
	<view>
		<mescroll-body :sticky="true" ref="mescrollRef" @init="mescrollInit" @down="downCallback" @up="upCallback">
			<!-- sticky吸顶悬浮的菜单, 父元素必须是 mescroll -->
			<view class="sticky-tabs">
				<me-tabs v-model="tabIndex" :tabs="tabs" @change="tabChange"></me-tabs>
			</view>
			
			<!-- 搜索  -->
			<view class="cu-bar bg-white search">
				<view class="search-form round">
					<input type="text" @confirm="keywordSearch" v-model="codeOrName" placeholder="请输入客户名称/业务编号" confirm-type="search"></input>
					<text class="cuIcon-search"></text>
				</view>
			</view>					
			
			<view class="add-customer mat15">
				<text>共{{totals}}人</text>
			</view>
			
			<view>
				<view v-for="(item,index) in progressListData" :key="index">
					<view class="good-list">
						<view class="charge" :id="'index-' + item.name" :data-index="item.name">
							<view class="charge-title flex-between">
								<text>{{item.name}}</text>
							</view>
							<view class="charge-text">
								<view>
									<text class="label-text">业务编号：</text>
									<text class="mgl30">{{item.businessCode}}</text>
								</view>
								<view>
									<text class="label-text">联系电话：</text>
									<text class="mgl30">{{item.phone}}</text>
								</view>
								<view>
									<text class="label-text">产品类型：</text>
									<text class="mgl30">{{item.businessType}}</text>
								</view>
								<view>
									<text class="label-text">申请额度(万元)：</text>
									<text class="mgl30">{{item.applyAmount}}</text>
								</view>
								<view>
									<text class="label-text">申请期限：</text>
									<text class="mgl30">{{item.applyTime}}</text>
								</view>
								<view>
									<text class="label-text">申请日期：</text>
									<text class="mgl30">{{item.createTime}}</text>
								</view>
								<view>
									<text class="label-text">任务完成节点：</text>
									<text class="mgl30">{{item.processId}}</text>
								</view>
								<view>
									<text class="label-text">任务完成时间：</text>
									<text class="mgl30">{{item.operationTime}}</text>
								</view>
								<view>
									<text class="label-text">提单人：</text>
									<text class="mgl30">{{item.employeeName}}</text>
								</view>
								<view>
									<text class="label-text">所属部门：</text>
									<text class="mgl30">{{item.department}}</text>
								</view>
							</view>
						</view>
					</view>
				</view>
			</view>
		</mescroll-body>
	</view>
</template>

<script>
	import MescrollMixin from "@/components/mescroll-uni/mescroll-mixins.js";
	import {apiSearch} from "@/api/mock.js"
	export default {
		mixins: [MescrollMixin], // 使用mixin
		data() {
			return {
				tabs:[
					{name:'全部', value: ''},
					{name:'融资担保', value: 0},
					{name:'担保', value: 1},
					{name:'借贷', value: 1},
					{name:'小额贷', value: 1},
					{name:'企业大贷', value: 1}
					],
				tabIndex: 0, // 当前菜单下标
				progressListData: [],
				totals: 0,
				page: {
					num: 1,
					size: 10,
				},
				type: '',
				codeOrName: ''//搜索关键词-
			};
		},
		methods: {
			keywordSearch(e){
				this.codeOrName = e.detail.value
				this.upCallback(this.page)
			},
			/*下拉刷新的回调 */
			downCallback() {
				this.mescroll.resetUpScroll()
			},
			/*上拉加载的回调: 其中page.num:当前页 从1开始, page.size:每页数据条数,默认10 */
			upCallback(page) {
				let type = this.tabs[this.tabIndex]
				this.$http.get('/api-guarantee/guarantee/statistics/list',{
					page: page.num,
					size: page.size,
					type: this.type,
					codeOrName: this.codeOrName
				}).then(res => {
					if(page.num == 1) this.progressListData = []; //如果是第一页需手动制空列表
					res.data.list.map((e) => {
						e.processId = this.core.processNode(e.processId)
						if (e.departments) {
							e.departments = e.departments.join(',');
						}
					});
					this.progressListData = this.progressListData.concat(res.data.list); //追加新数据
					this.mescroll.endSuccess(res.data.list); // 隐藏加载状态栏
					this.totals = res.data.totalCount;
				}).catch(()=>{
					//联网失败, 结束加载
					this.mescroll.endErr();
				})
			
			},
			// 切换菜单
			tabChange () {
				this.codeOrName = '';
				this.progressListData = []; // 置空列表,显示加载进度条
				this.mescroll.resetUpScroll()
			},
		}
	}
</script>

<style lang="scss" scoped>
.cu-bar .search-form{
	border: 2rpx solid #00B9FF;
	border-radius: 20rpx;
	background-color: #fff;
	margin: 0 50rpx;
	height: 72rpx;
	line-height: 72rpx;
	margin-top: 20rpx;
	input{
		height: 72rpx;
		line-height: 72rpx;
		padding: 0 40rpx;
	}
	.cuIcon-search{
		margin: 0 20rpx;
	}
}
.add-customer{
	padding: 0 50rpx;
	button{
		background-color: #00B9FF;
		border-radius: 30rpx;
		.mar-icon{
			margin-right: 10rpx;
		}
	}
}
</style>
