<template>
	<view class='content'>
		<view class='search_wrap'>
			<input type="text" v-model='state.value' placeholder='搜索卡号' @confirm="doSearch" /><button size='mini'
				@click='search()'>搜索</button>
		</view>
		<view class='item' v-for="(item,index) in state.newList">
			<view class='time'><text>时间：{{item.tradeTime}}</text><text>￥{{item.fee/100}}</text></view>
			<!-- <view>对公账户：{{item.corporateAccountId}}</view> -->
			<view>卡号：{{item.cardId}}</view>
			<!-- item.status 1 圈存成功  0 半条 -->
			<view class="but-wrap" v-if="item.status ==0">
				<text @click="toTrap(item.fee)">修复</text>
			</view>
		</view>
	</view>
</template>

<script lang="ts" setup>
	import { reactive } from "vue";
	import { request } from "@/utils/network/request.js";
	import { transactionRecord } from "@/utils/network/api.js";
	import { stringToJson } from "@/utils/network/encryption.js";
	import { onLoad, onShow } from "@dcloudio/uni-app";
	import { getCodeName } from "@/datas/queryKey.js";
	const state = reactive({
		list: '',  //所有数据
		newList: '', //最终展示的
		name: '',
		value: '',//input框里的值
	})
	onLoad((option : any) => {
		console.log("option", option)
		state.name = option.name;
		// getList();
	})
	onShow(() => {
		getList();
	})
	const getList = () => {
		const options = {
			type: 2,
			data: {
				'accountId': state.name,
				'accountTransactionType': 1
			},
			method: "POST",
			showLoading: true,
		};
		request(transactionRecord, options).then((res) => {
			const data = stringToJson(res.bizContent);
			state.list = data.qtkCorporateAccountDetails;
			for (var i = 0; i < state.list.length; i++) {
				state.list[i]['tradeTime'] = state.list[i]['tradeTime'].replace("T", " ")
			}
			state.newList = state.list;
			console.log("交易记录", data)
		})
	}
	const search = () => {
		state.newList = [];
		for (var i = 0; i < state.list.length; i++) {
			if (state.list[i].cardId.indexOf(state.value) >= 0) {
				state.newList.push(state.list[i]);
			}
		}
	}
	const doSearch = () => {
		search();
	}
	const toTrap = (rechargeMoney) => {
		uni.navigateTo({
			url: `/subpackage/personal-center/trapping-and-repairing-account/recharge-pay?rechargeMoney=${rechargeMoney}&&payMoney=0&&accountId=${state.name}`
		})
	}
</script>

<style scoped>
	.content {
		background-color: #EEF7F7;
		min-height: 100vh;
		padding: 0 30rpx;
		overflow: hidden;
		font-size: 32rpx;
	}

	.search_wrap {
		display: flex;
		margin: 20rpx 0;
	}

	.search_wrap>input {
		background-color: white;
		width: 76%;
		height: 40rpx;
		line-height: 40rpx;
		padding: 10rpx 10rpx;
		border-radius: 10rpx 0 0 10rpx;
	}

	.item {
		width: 100%;
		border-radius: 10rpx;
		box-sizing: border-box;
		padding: 30rpx 20rpx;
		margin-top: 30rpx;
		background: linear-gradient(-90deg, #43a1e0 0%, #13e7c1 100%);
		color: white;
	}

	.time {
		display: flex;
		margin-bottom: 16rpx;
		justify-content: space-between;
	}

	.but-wrap {
		display: flex;
		justify-content: flex-end;
		margin-top: 10rpx;
	}

	.but-wrap>text {
		border: 1px solid white;
		color: white;
		height: 50rpx;
		line-height: 50rpx;
		border-radius: 30rpx;
		padding: 0 24rpx;
		font-size: 28rpx;
		box-sizing: border-box;
		margin-left: 12rpx;
	}
</style>