<template>
	<view>
		<view class="scoped-list-pdf">
			<view v-if="customerList.length == 0" class="empty-wrap"><u-empty mode="list" text="暂无数据"></u-empty></view>
			<view v-for="(item, index) in customerList" class="slp-item" :key="index">

				<view class="slp-info" @click="pageTo(`/pages/user/contract/edit?id=${item.id}`)">
					<view class="p1">{{ item.contract_name }}</view>
					<view class="p2">合同金额:{{ item.contract_amount }}万元</view>
					<view class="p2">截至日期:{{ item.end_at }}</view>
					<view class="p2">创建时间:{{ item.create_at }}</view>
				</view>
				
				<u-image src="/static/icon_bg_pdf.png" @click="linkWebView(item)" mode="heightFix" height="100rpx" class="img"></u-image>

				<!-- <view @click="delHandle(item)" >删除</view> -->

			</view>
		</view>

		<view class="float-search2" @click="pageTo('/pages/user/contract/edit')"><u-icon name="plus" size="42" color="#fff"></u-icon></view>
		<view class="float-search" @click="searchPopupShow = true"><u-icon name="search" size="42" color="#fff"></u-icon></view>

		<u-popup v-model="searchPopupShow" mode="center" width="80%" height="340rpx" border-radius="20">
			<view class="bwin-popup">
				<view class="popup-header">合同搜索</view>
				<view class="popup-body">
					<u-input v-model="searchFormData.contract_name" border placeholder="请输入合同标题(支持模糊搜索)"></u-input>
					<!-- <u-divider marginTop="10" marginBottom="10">或</u-divider>
					<u-input v-model="searchFormData.phone" border placeholder="请输入手机号(可仅输入一部分)"></u-input> -->
				</view>
				<view class="popup-footer" style="position: absolute;">
					<u-button size="medium" @click="searchPopupShow = false">取消</u-button>
					<u-button size="medium" type="primary" @click="searchHandle()">搜索</u-button>
				</view>
			</view>
		</u-popup>
		
		
		

		<u-loadmore
			v-if="customerList.length > 0"
			marginTop="32"
			:line="true"
			:status="loadmore.status"
			:loading-text="loadmore.loadingText"
			:loadmore-text="loadmore.defaultText"
			:nomore-text="loadmore.nomoreText"
		/>
	</view>
</template>
<script>
var that;
export default {
	data() {
		return {
			searchKeyword: null,
			searchPopupShow: false,
			searchFormData: {
				contract_name: '',
				phone: ''
			}, // 搜索栏数据
			curRoles: '',
			customerList: [],
			loadmore: {
				status: 'loadmore',
				loadingText: '努力加载中',
				defaultText: '轻轻上拉 查看更多',
				nomoreText: '实在没有了',
				currnetPage: 1
			}
		};
	},
	onLoad(params) {
		that = this;
		const userInfo2 = uni.getStorageSync('MD_userInfo2')
		this.curRoles = userInfo2 ? userInfo2.roles : ''
		// 默认筛选项
		if (params.filterStepStatus !== undefined) {
			that.filterStepStatus = parseInt(params.filterStepStatus);
			this.filterDropdownValue = [[],[],[],[that.filterStepStatus],[]]
		}

		this.getDataList()
	},
	onReachBottom() {
		if (that.loadmore.status == 'nomore') return;
		that.loadmore.currnetPage++
		this.getDataList()
	},
	onPullDownRefresh() {
		// 防止频繁刷新
	},
	methods: {

		linkWebView (item) {
			let params = {
				id: item.id,
				url: item.contract_pdf_pub,
				tname: item.contract_name
			}
			uni.setStorageSync('MD_contractObj', params)
			uni.navigateTo({
				url: `/pages/user/contract/dtl?id=${item.id}`
			})
		},

		delHandle (item) {
			uni.$msgConfirm('确定删除吗?', () => {				
				uni.api.base.apicontractdel({
					id: item.id
				}).then(res => {
					uni.$msg('删除成功~')
					this.loadmore.currnetPage = 1
					this.getDataList()
				})
			})
		},
		getDataList (bc) {
			const that = this
			let params = {
				...this.searchFormData
			}
			uni.api.base.apicontractlist({
				page: that.loadmore.currnetPage,
				...params,
			}).then(res => {
				const list = res.list || []
				if (list.length < 10) {
					that.loadmore.status = 'nomore';
				}
				if (res.current_page === 1) {
					if (list.length == 0) {
						uni.$msg('无搜索结果', 'none');
					}
					that.customerList = [...list]
				} else {
					that.customerList = that.customerList.concat(list)
				}
				if (bc) bc()
			})
		},
		customBack() {
			uni.navigateBack();
		},
		// 带监听器跳转
		pageTo(url, data) {
			/// xxxxx
			uni.navigateTo({
				url: url,
				events: {
					// 为指定事件添加一个监听器,获取被打开页面传送到当前页面的数据
					update: function(data) {
						// 当B页面运行 eventChannel.emit('update', { a:1 }); 时,会运行这里的代码逻辑。
					}
				},
				success: function(res) {
					// 通过eventChannel向被打开页面传送数据
					res.eventChannel.emit('data', data);
				}
			});
		},
		searchHandle() {
			that.loadmore.currnetPage = 1
			this.getDataList(() => {
				this.searchPopupShow = false
			})
		},
	}
};
</script>
<style lang="scss">
.search-wrap {
	padding: 20rpx;
}

.filter-wrap {
	position: relative;
}

// 列表
.scoped-list-pdf {
	width: 100%;


}

.float-search {
	opacity: 0.9;
	position: fixed;
	right: 20rpx;
	bottom: 40rpx;
	padding: 20rpx;
	border-radius: 50%;
	background-color: $u-theme-color;
}
.float-search2 {
	opacity: 0.9;
	position: fixed;
	right: 20rpx;
	bottom: 150rpx;
	padding: 20rpx;
	border-radius: 50%;
	background-color: $u-theme-color;
}






.scoped-list-pdf {
	.slp-item {
		padding: 20rpx;
		border-bottom: 1PX solid #eee;
		position: relative;

		.slp-info {
			width: calc(80%);
		}

		.p1 {
			font-size: 32rpx;
			font-weight: bold;
			color: #313131;
			padding-bottom: 10rpx;
		}
		.p2 {
			font-size: 28rpx;
			color: #666;
		}
		.img {
			position: absolute;
			right: 20rpx;
			bottom: 20rpx;
		}
	}
}


</style>