<template>
	<view class="homePage-container">
		<!-- 筛选弹框 -->
		<search-modal v-if="openScreen" :visible="openScreen" :defaultParams="searchForm" @refresh="refresh" @close="openScreen=false"></search-modal>
		<view class="homePage-head">
			<text class="homePage-tit">交易记录</text>
			<image class="filter-icon" src="@/static/filter.png" @tap="openScreen=true"></image>
		</view>
		<scroll-view class="scroll-con" scroll-y @scrolltolower="onreachBottom">
			<!-- 列表数据 -->
			<view class="cell-item-con">
				<view class="cell-item" v-for="(item, index) in listdata" :key="index">
					<view class="cell-item-c">
						<view class="cell-item-label">交易时间</view>
						<view class="cell-item-main">{{item.creatDate}}</view>
					</view>
					<view class="cell-item-c">
						<view class="cell-item-label">支付账户</view>
						<view class="cell-item-main">{{item.account}}</view>
					</view>
					<view class="cell-item-c">
						<view class="cell-item-label">交易数量（个）</view>
						<view :class="['cell-item-main', item.num>0 ? 'red' : 'blue']">{{item.num > 0 ? '+' + item.num : item.num }}</view>
					</view>
					<view class="cell-item-c">
						<view class="cell-item-label">备注</view>
						<view class="cell-item-main">{{item.des ? item.des : '--'}}</view>
					</view>
					<view class="cell-item-c handle-con">
						<view class="cell-item-label">操作</view>
						<view class="cell-item-main">
							<u-button type="primary" size="mini" v-if="item.state" class="handle-btn" @click="revokeFun(item)">撤销单据</u-button>
							<text v-else style="color: #909399;">单据已撤销</text>
						</view>
					</view>
				</view>
			</view>
			<u-empty class="nodata" :text="noDataText" v-if="listdata.length==0 && status!='loading'" mode="list"></u-empty>
			<view class="loadmore">
				<u-loadmore v-if="total>pageSize || status=='loading'" :status="status" />
			</view>
		</scroll-view>
	</view>
</template>

<script>
	import searchModal from './searchModal.vue'
	export default {
		components: { searchModal },
		data() {
			return {
				listdata: [
					{ creatDate: '2020-11-05 17:13', account: '15787878787', num: 154, state: 1, des: '备注备注备注11221备注'},
					{ creatDate: '2020-11-05 17:13', account: '15787878787', num: -15, state: 1, des: '描述秒回的时刻萨菲科技尸鬼封尽看嘎是否1备注'},
					{ creatDate: '2020-11-05 17:13', account: '15000000000', num: 4, state: 0, des: '备注备注备注11221备注'},
					{ creatDate: '2020-11-05 17:13', account: '15787878787', num: -8, state: 1, des: ''},
					{ creatDate: '2020-11-05 17:13', account: '15787878787', num: 50, state: 0, des: '备注备注备注11221备注'},
				],
				pageNo: 1,  //  当前页码
				pageSize: 10,  //  每页条数
				total: 0,  //  数据总条数
				noDataText: '暂无数据',  //  列表请求状态提示语
				status: 'loadmore',  //  加载中状态
				openScreen: false,  //  是否打开筛选
				searchForm: {  //  查询条件
					beginDate: '',  //  创建时间默认筛选近7天
					endDate: '',  //  创建时间默认筛选近7天
					account: ''  //  支付账户
				},
			}
		},
		onShow() {
			this.searchHandle(1)
		},
		methods:{
			// 获取查询参数 刷新列表
			refresh(params){
				this.searchForm = params
				this.listdata = []
				this.total = 0
				this.searchHandle(1)
			},
			//  撤销单据
			revokeFun(row){
				let _this = this
				uni.showModal({
				  title: '提示',
				  content: '撤销单据后乐豆将全部退回给原支付账号，确认撤销吗？',
				  success(res) {
				    if (res.confirm) {
				      
				    }
				  }
				})
			},
			// 搜索查询
			searchHandle (pageNo) {
				this.status = "loading"
				pageNo ? this.pageNo = pageNo : null
				// searchSuppliers({
				// 	pageNo: this.pageNo,
				// 	pageSize: this.pageSize,
				// 	queryWord: this.queryValue
				// }).then(res => {
				// 	if (res.status == 200) {
				// 		if(this.pageNo>1){
				// 			this.listdata = this.listdata.concat(res.data.list || [])
				// 		}else{
				// 			this.listdata = res.data.list || []
				// 		}
				// 		this.total = res.data.count || 0
				// 		this.listdata.length == 0 && this.queryValue != '' ? this.noDataText = '没有搜索到相关结果' : this.noDataText = '暂无数据'
				// 	} else {
				// 		this.noDataText = res.message
				// 		this.listdata = []
				// 		this.total = 0
				// 	}
					this.status = "loadmore"
				// })
			},
			// scroll-view到底部加载更多
			onreachBottom() {
				if(this.listdata.length < this.total){
					this.pageNo += 1
					this.searchHandle()
				}else{
					uni.showToast({ title: '已经到底了', icon: 'none' })
					this.status = "nomore"
				}
			}
		}
	}
</script>

<style lang="scss">
	.homePage-container {
		width: 100%;
		// 筛选菜单
		.homePage-head{
			display: flex;
			justify-content: space-between;
			align-items: center;
			position: fixed;
			top: 0;
			left: 0;
			z-index: 9;
			padding: 20rpx 30rpx;
			background-color: #fff;
			box-shadow: 0rpx 0rpx 14rpx rgba(0,0,0,.05);
			width: 100%;
			.homePage-tit{
				
			}
			.filter-icon{
				width: 36rpx;
				height: 36rpx;
			}
		}
		//  列表
		.scroll-con{
			height: calc(100% - 40);
			overflow: auto;
		}
		//  列表样式
		.cell-item-con{
			padding: 0 30rpx;
			margin-top: 10rpx;
			.cell-item{
				background-color: #fff;
				color: #606266;
				padding: 20rpx 30rpx 14rpx;
				margin-bottom: 20rpx;
				border-radius: 16rpx;
				.cell-item-c{
					display: flex;
					justify-content: space-between;
					padding: 10rpx 0;
					.cell-item-label{
						flex-shrink: 0;
						width: 200rpx;
						color: #303133;
					}
					.cell-item-main{
						flex-grow: 1;
						text-align: right;
						.handle-btn{
							border-color: #fcbd71!important;
							background-color: #fcbd71!important;
						}
					}
					.blue {
						color: #1890FF;
					}
					.green {
						color: #16b50e;
					}
					.red {
						color: red;
					}
				}
				.handle-con{
					align-items: center;
					border-top: 1rpx solid #f8f8f8;
					margin-top: 10rpx;
					padding-top: 18rpx;
				}
			}
		}
		
	}
</style>
