<template>
	<div class="layout-padding">
		<div class="layout-padding-auto layout-padding-view">
			<el-row class="ml10" v-show="showSearch">
				<el-form :inline="true" :model="state.queryForm" @keyup.enter="getDataList" ref="queryRef">
					<el-form-item label="代理账号" prop="userId">
						<el-input placeholder="请输入代理账号" style="max-width: 180px" v-model="state.queryForm.userId" />
					</el-form-item>
					<el-form-item label="流水类型" prop="flowType">
						<el-select v-model="state.queryForm.flowType" placeholder="请选择流水类型">
							<el-option label="全部" value=""></el-option>
							<el-option label="充值" value="1"></el-option>
							<el-option label="提现" value="2"></el-option>
							<el-option label="消费" value="3"></el-option>
						</el-select>
					</el-form-item>
					<el-form-item>
						<el-button @click="getDataList" icon="search" type="primary">
							{{ $t('common.queryBtn') }}
						</el-button>
						<el-button @click="resetQuery" icon="Refresh">{{ $t('common.resetBtn') }} </el-button>
					</el-form-item>
				</el-form>
			</el-row>
			<el-row>
				<div class="mb8" style="width: 100%">
					<right-toolbar
						@queryTable="getDataList"
						class="ml10"
						style="float: right; margin-right: 20px"
						v-model:showSearch="showSearch"
					></right-toolbar>
				</div>
			</el-row>
			<el-table
				:data="state.dataList"
				@sort-change="sortChangeHandle"
				style="width: 100%"
				v-loading="state.loading"
				border
				:cell-style="tableStyle.cellStyle"
				:header-cell-style="tableStyle.headerCellStyle"
			>
				<el-table-column label="序号" fixed type="index" width="60" />
				<el-table-column label="代理账号" prop="userId" show-overflow-tooltip width="120" />
				<el-table-column label="代理商名称" prop="agentName" show-overflow-tooltip width="150" />
				<el-table-column label="流水类型" prop="flowType" show-overflow-tooltip width="100" />
				<el-table-column label="金额" prop="amount" show-overflow-tooltip width="120" />
				<el-table-column label="余额" prop="balance" show-overflow-tooltip width="120" />
				<el-table-column label="备注" prop="remark" show-overflow-tooltip width="200" />
				<el-table-column label="创建时间" prop="createTime" show-overflow-tooltip width="180" />
			</el-table>
			<pagination @current-change="currentChangeHandle" @size-change="sizeChangeHandle" v-bind="state.pagination" />
		</div>
	</div>
</template>

<script lang="ts" name="systemAgentFlow" setup>
import { BasicTableProps, useTable } from '/@/hooks/table';
import { useI18n } from 'vue-i18n';

const { t } = useI18n();

// 搜索变量
const queryRef = ref();
const showSearch = ref(true);

// 临时的空数据列表函数
const fetchList = () => {
	return Promise.resolve({
		data: {
			records: [],
			total: 0,
		},
	});
};

const state: BasicTableProps = reactive<BasicTableProps>({
	queryForm: {},
	pageList: fetchList,
	descs: ['create_time'],
});

//  table hook
const { getDataList, currentChangeHandle, sizeChangeHandle, sortChangeHandle, tableStyle } = useTable(state);

// 清空搜索条件
const resetQuery = () => {
	// 清空搜索条件
	queryRef.value.resetFields();
	getDataList();
};
</script>
