<template>
	<view class="page-container">
		<view class="condition-box bg-top">
			<view class="condition-input-box">
				<view class="condition-input-container">
					<icon class="ml-20" type="search" size="20"></icon>
					<input class="condition-input-text" :value="keywords" @input="inputKeywords"
						@confirm="doSearchKeyWord" placeholder-style="font-size:28rpx;" type="text"
						confirm-type="search" placeholder="搜索" />
					<view class="icon-clear size-32 mr-10" v-if="keywords != ''" @click="clearSearch"></view>
				</view>
			</view>
			<view class="search-time-box">
				<view class="search-time-item">
					<uni-datetime-picker type="date" @change="selectStartDate" v-model="startDate">
						<view>{{startDate==''?'请选择开始时间':startDate}}</view>
					</uni-datetime-picker>
					<view v-if="startDate==''" class="icon-arrow-solid size-16"></view>
					<view v-else class="icon-clear size-32" @click="clearStart"></view>
				</view>
				<view class="search-time-item ml-20">
					<uni-datetime-picker type="date" @change="selectEndDate" v-model="endDate">
						<view>{{endDate==''?'请选择结束时间':endDate}}</view>
					</uni-datetime-picker>
					<view v-if="endDate ==''" class="icon-arrow-solid size-16"></view>
					<view v-else class="icon-clear size-32" @click="clearEnd"></view>
				</view>
			</view>
		</view>
		<!-- #ifdef MP-TOUTIAO || MP-WEIXIN -->
		<ContainerLoading :loadingVisible="loadingState" style="height: 82vh;margin-top: 154rpx;"
			@doRefresh="doRefreshList">
		<!-- #endif -->
			<!-- #ifndef MP-TOUTIAO || MP-WEIXIN -->
			<ContainerLoading :loadingVisible="loadingState" style="height: 82vh;margin-top: 120rpx;"
				@doRefresh="doRefreshList">
			<!-- #endif -->

				<scroll-view scroll-y style="height: 82vh;" :lower-threshold="100" refresher-background="#FFFFFF00"
					@scrolltolower="doLoadMore">
					<view class="order-box">
						<block v-for="(item,index) in recordList" :key="index">
							<view class="order-item">
								<view class="record-title-box">
									<view class="record-title-type-box">
										<text
											:class="['record-title-type',payTypeColor(item.type)]">{{payType(item.type)}}</text>
										<view class="record-title-order-box" v-if="item.orderId != ''">
											<view class="record-title-order-type">{{appTitle}}</view>
											<view class="record-title-order-num">{{item.orderId}}</view>
										</view>
									</view>
									<view class="record-money">
										<view class="record-money-type-text">
											{{payTypeSign(item.type)}} {{item.accountMoney/100}}
										</view>
										<view class="money">{{item.accountAfterMoney/100}}</view>
									</view>
								</view>
								<view class="record-desc">{{item.description}}</view>
								<view class="record-bottom-box">
									<view class="record-before">交易前余额<text
											style="padding-left: 15rpx;color: black;font-weight: bold;">{{item.accountBeforeMoney/100}}</text>
									</view>
									<view class="record-date">{{item.gmtCreate}}</view>
								</view>
							</view>
						</block>
						<uni-load-more :status="hasMore"></uni-load-more>
					</view>
				</scroll-view>
			</ContainerLoading>
	</view>
</template>

<script>
	import ContainerLoading from '@/components/container-loading.vue'
	import UserApi from '@/common/js/net/UserApi.js'
	import {
		payTypeColor,
		payType,
		payTypeSign
	} from '@/common/js/conver.js'
	import {
		inject,
		isReactive
	} from 'vue';
	export default {
		components: {
			ContainerLoading
		},
		setup() {
			const globalData = inject('globalData')
			return {
				globalData
			}
		},
		data() {
			return {
				recordList: [], //订单列表
				appTitle: this.globalData.appTitle,
				pageData: {
					page: 1,
					rows: 10,
					keywords: '',
					startTime: '',
					endTime: ''
				}, //检索参数
				loadingState: 'loading', //加载状态
				listRefreshTrig: false, //list刷新状态
				isLoadMore: false, //加载更多的状态
				hasMore: 'more', //是否有更多数据
				keywords: '', //搜索关键字
				startDate: '',
				endDate: ''
			};
		},
		onLoad(options) {
			uni.setNavigationBarTitle({
				title: "资金流水",
			});
			uni.setNavigationBarColor({
				frontColor: "#000000",
				backgroundColor: "#F0F0F0",
				animation: {
					duration: 500,
					timingFunc: "easeIn",
				},
			});
			this.doRefreshList()
		},
		methods: {
			payTypeColor,
			payType,
			payTypeSign,
			inputKeywords(e) {
				this.keywords = e.detail.value
			},
			doSearchKeyWord() {
				this.doRefreshList()
			},
			clearSearch() {
				this.keywords = ''
				this.doRefreshList()
			},
			selectStartDate(e) {
				console.log('开始时间', e)
				this.startDate = e
				this.doRefreshList()
			},
			selectEndDate(e) {
				console.log('结束时间', e)
				this.endDate = e
				this.doRefreshList()
			},
			clearStart() {
				this.startDate = ''
				this.doRefreshList()
			},
			clearEnd() {
				this.endDate = ''
				this.doRefreshList()
			},
			doRefreshList() {
				console.log('正在刷新...')
				const _self = this
				_self.loadingState = 'loading'
				_self.hasMore = 'more'
				_self.pageData.page = 1
				_self.pageData.keywords = _self.keywords
				_self.pageData.startTime = _self.startDate
				_self.pageData.endTime = _self.endDate
				_self.isLoadMore = false
				_self.doGetMinePayRecord(true)
			},
			doLoadMore() {
				//判断是否正在加载中 与是否存在更多数据
				const _self = this
				if (_self.isLoadMore || _self.hasMore == 'noMore') {
					return
				}
				_self.isLoadMore = true
				_self.hasMore = 'loading'
				_self.pageData.page = ++_self.pageData.page
				_self.pageData.keywords = _self.keywords
				_self.pageData.startTime = _self.startDate
				_self.pageData.endTime = _self.endDate
				_self.doGetMinePayRecord(false)
			},
			//获取列表
			doGetMinePayRecord(isRefresh) {
				const _self = this
				_self.recordList = isRefresh ? [] : _self.recordList
				_self.loadingState = isRefresh ? 'loading' : ''
				UserApi.doGetMinePayRecord(_self.pageData)
					.then(res => {
						var status = 'success'
						status = res.rows && res.rows.length > 0 ? 'success' : 'empty'
						_self.loadingState = isRefresh ? status : ''
						_self.recordList = _self.recordList.concat(res.rows)
						_self.isLoadMore = false
						_self.hasMore = _self.recordList.length < res.total ? 'more' : 'noMore'
					})
					.catch(err => {
						_self.loadingState = 'error'
						_self.isLoadMore = false
						_self.hasMore = 'more'
					})
			},
		},
		onPullDownRefresh() {
			uni.stopPullDownRefresh()
		}
	};
</script>

<style lang="scss" scoped>
	.bg-top {
		background-color: $bg-top-color;
	}

	.order-box {
		display: flex;
		flex-direction: column;
		justify-content: center;
		padding-bottom: 30px;
	}

	.order-item {
		display: flex;
		flex-direction: column;
		flex-grow: 1;
		border-radius: 15rpx;
		padding: 20rpx;
		background-color: $white-color;
	}

	.order-item:nth-of-type(n+1) {
		margin-top: 15px;
		padding-bottom: 34rpx;
		border-bottom: 1rpx solid $divider-color;
	}

	.record-title-box {
		display: flex;
		flex-direction: row;
		justify-content: space-between;
	}


	.record-title-type-box {
		display: flex;
		flex-direction: row;
		align-items: center;
		flex: 1;
	}

	.record-title-type {
		width: 100rpx;
		height: 100rpx;
		display: flex;
		border-radius: 56rpx;
		align-items: center;
		justify-content: center;
		text-align: center;
		font-weight: bold;
		color: white;
		white-space: pre-wrap;
		font-size: 28rpx;
	}

	.type-z {
		background-color: $text-blue-color;
	}

	.type-g {
		background-color: $green-color-light;
	}

	.record-title-order-box {
		display: flex;
		flex-direction: column;
		margin-left: 10rpx;
	}

	.record-title-order-type {
		color: $text-color;
		font-size: 28rpx;
		text-align: left;
		font-family: PingFangSC-regular;
	}

	.record-title-order-num {
		color: $text-gray-hint-color;
		font-size: 24rpx;
		text-align: left;
		font-family: PingFangSC-light;
	}

	.record-money {
		display: flex;
		flex-direction: column;
		align-items: flex-end;
		justify-content: space-between;
	}

	.record-money-type-text {
		display: flex;
		flex-direction: row;
		align-items: center;
		justify-content: center;
		font-weight: bold;
	}

	.record-desc {
		margin-top: 22rpx;
		padding: 20rpx 30rpx;
		font-size: 24rpx;
		border-radius: 10rpx;
		min-height: 60rpx;
		color: $text-gray-desc-color;
		border-radius: 14rpx;
		background-color: rgba(242, 242, 242, 1);
	}

	.record-bottom-box {
		display: flex;
		flex-direction: row;
		justify-content: space-between;
		align-items: center;
		margin-top: 34rpx;
	}

	.money {
		color: $text-brown-color;
		font-size: 32rpx;
		text-align: center;
		padding-bottom: 15rpx;
	}


	.record-before {
		color: $text-color;
		font-size: 24rpx;
		text-align: left;
	}

	.record-date {
		color: $text-gray-desc-color;
		font-size: 24rpx;
		text-align: left;
	}

	.search-box {
		display: flex;
		flex-direction: column;
		justify-content: center;
	}

	.search-container {
		position: relative;
		align-self: center;
		border-radius: 5rpx;
		background-color: $white-color;
		padding: 5px;
		display: flex;
		flex-direction: row;
		width: 100%;
	}

	.search-input {
		width: 100%;
		box-sizing: border-box;
		color: $text-color;
		font-size: 28rpx;
		text-align: center;
	}

	.search-input::after {
		content: '';
		position: absolute;
		left: 10px;
		top: 50%;
		transform: translateY(-50%);
		width: 20px;
		height: 20px;
		margin-top: -1px;
		background-size: cover;
		background-image: url('data:image/svg+xml;charset=utf-8;base64,PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHhtbG5zOnhsaW5rPSJodHRwOi8vd3d3LnczLm9yZy8xOTk5L3hsaW5rIiB2aWV3Qm94PSI2NCA2NCA4OTYgODk2IiB3aWR0aD0iMTQiIGhlaWdodD0iMTkiIHN0eWxlPSIiIGZpbHRlcj0ibm9uZSI+CiAgICAKICAgIDxnPgogICAgPHBhdGggZD0iTTkwOS42IDg1NC41TDY0OS45IDU5NC44QzY5MC4yIDU0Mi43IDcxMiA0NzkgNzEyIDQxMmMwLTgwLjItMzEuMy0xNTUuNC04Ny45LTIxMi4xLTU2LjYtNTYuNy0xMzItODcuOS0yMTIuMS04Ny45cy0xNTUuNSAzMS4zLTIxMi4xIDg3LjlDMTQzLjIgMjU2LjUgMTEyIDMzMS44IDExMiA0MTJjMCA4MC4xIDMxLjMgMTU1LjUgODcuOSAyMTIuMUMyNTYuNSA2ODAuOCAzMzEuOCA3MTIgNDEyIDcxMmM2NyAwIDEzMC42LTIxLjggMTgyLjctNjJsMjU5LjcgMjU5LjZhOC4yIDguMiAwIDAgMCAxMS42IDBsNDMuNi00My41YTguMiA4LjIgMCAwIDAgMC0xMS42ek01NzAuNCA1NzAuNEM1MjggNjEyLjcgNDcxLjggNjM2IDQxMiA2MzZzLTExNi0yMy4zLTE1OC40LTY1LjZDMjExLjMgNTI4IDE4OCA0NzEuOCAxODggNDEyczIzLjMtMTE2LjEgNjUuNi0xNTguNEMyOTYgMjExLjMgMzUyLjIgMTg4IDQxMiAxODhzMTE2LjEgMjMuMiAxNTguNCA2NS42UzYzNiAzNTIuMiA2MzYgNDEycy0yMy4zIDExNi4xLTY1LjYgMTU4LjR6IiBmaWxsPSJyZ2JhKDIwNCwyMDQsMjA0LDEpIj48L3BhdGg+CiAgICA8L2c+CiAgPC9zdmc+');
	}

	.search-time-box {
		display: flex;
		flex-direction: row;
		padding: 10rpx 30rpx;
	}

	.search-time-item {
		flex: 1;
		display: flex;
		flex-direction: row;
		justify-content: space-between;
		font-size: 28rpx;
		align-items: center;
		padding: 15rpx 0rpx;
	}
</style>