<template>
	<a-card :bordered="false" class="xn-mb10">
		<a-form ref="searchFormRef" name="advanced_search" :model="searchFormState" class="ant-advanced-search-form">
			<a-row :gutter="24">
				<a-col :span="6">
					<a-form-item label="充值人" name="rechargeSearchKey">
						<a-input v-model:value="searchFormState.rechargeSearchKey" placeholder="请输入充值人姓名或手机号" />
					</a-form-item>
				</a-col>
				<a-col :span="6">
					<a-form-item label="推荐人" name="recommendSearchKey">
						<a-input v-model:value="searchFormState.recommendSearchKey" placeholder="请输入推荐人姓名或手机号" />
					</a-form-item>
				</a-col>
				<a-col :span="6">
					<a-form-item label="状态" name="rebateStatus">
						<a-select v-model:value="searchFormState.rebateStatus" :options="statusData" placeholder="请选择" />
					</a-form-item>
				</a-col>
				<a-col :span="6">
					<a-button type="primary" @click="tableRef.refresh()">查询</a-button>
					<a-button style="margin: 0 8px" @click="reset">重置</a-button>
				</a-col>
			</a-row>
		</a-form>
	</a-card>
	<a-card :bordered="false">
		<s-table ref="tableRef" :columns="columns" :data="loadData" bordered :row-key="(record) => record.id">
			<template #bodyCell="{ column, record, index }">
				<template v-if="column.dataIndex === 'serial'">
					{{ index + 1 }}
				</template>
				<template v-if="column.dataIndex === 'rebateRatio'">
					{{ record.rebateRatio + ' %' }}
				</template>
				<template v-if="column.dataIndex === 'rebateStatus'">
					<a-tag v-if="record.rebateStatus === '2'" color="green">已生效</a-tag>
					<a-tag v-else color="orange">待生效</a-tag>
				</template>
				<!--				<template v-if="column.dataIndex === 'action'">-->
				<!--					<a-space>-->
				<!--						<a @click="formRef.onOpen(record)" v-if="hasPerm('bizRebateRecordEdit')">编辑</a>-->
				<!--					</a-space>-->
				<!--				</template>-->
			</template>
		</s-table>
	</a-card>
	<Form ref="formRef" @successful="tableRef.refresh()" />
</template>

<script setup name="rebaterecord">
	import { cloneDeep } from 'lodash-es'
	import Form from './form.vue'
	import bizRebateRecordApi from '@/api/biz/bizRebateRecordApi'
	import tool from '@/utils/tool'
	const searchFormState = ref({})
	const searchFormRef = ref()
	const tableRef = ref()
	const formRef = ref()
	const columns = [
		{
			title: '序号',
			dataIndex: 'serial',
			width: 80,
			align: 'center',
		},
		{
			title: '充值人',
			dataIndex: 'rechargeUserName',
			align: 'center',
		},
		{
			title: '充值金额（元）',
			dataIndex: 'rechargeAmount',
			align: 'center',
		},
		{
			title: '推荐人',
			dataIndex: 'recommendUserName',
			align: 'center',
		},
		{
			title: '返利积分（个）',
			dataIndex: 'rebateAmout',
			align: 'center',
		},
		{
			title: '返利比例',
			dataIndex: 'rebateRatio',
			align: 'center',
		},
		{
			title: '充值时间',
			dataIndex: 'rechargeTime',
			align: 'center',
		},
		{
			title: '状态',
			dataIndex: 'rebateStatus',
			align: 'center',
		}
	]
	// // 操作栏通过权限判断是否显示
	// columns.push({
	// 	title: '操作',
	// 	dataIndex: 'action',
	// 	align: 'center',
	// 	width: 150
	// })
	const statusData = tool.dictList('rebate_status')
	const loadData = (parameter) => {
		const searchFormParam = cloneDeep(searchFormState.value)
		return bizRebateRecordApi.bizRebateRecordPage(Object.assign(parameter, searchFormParam)).then((data) => {
			return data
		})
	}
	// 重置
	const reset = () => {
		searchFormRef.value.resetFields()
		tableRef.value.refresh(true)
	}
</script>
