<template>
	<div>
		<el-dialog v-model="dialogVisible" :close-on-click-modal="false" draggable width="1200px" height="500px">
			<el-card :body-style="cardBodyStyle">
				<el-form inline :model="query">
					<el-form-item label="开户行名称" style="margin-bottom: 5px;">
						<el-input v-model="query.bankNm" placeholder="请输入" style="width: 200px; margin-right: 10px;" clearable></el-input>
					</el-form-item>
				</el-form>
			</el-card>

			<el-card :body-style="cardBodyStyle">
				<el-button type="primary" @click="search">查询</el-button>
			</el-card>

			<el-card :body-style="cardBodyStyle">
				<el-table :data="tableData" border highlight-current-row>
					<el-table-column v-if="true" prop="beneficiaryAccount" label="收款账号" header-align="center"
						align="center" show-overflow-tooltip>
					</el-table-column>
					<el-table-column v-if="true" prop="bankNo" label="联行号" header-align="center" align="center"
						show-overflow-tooltip>
					</el-table-column>
					<el-table-column v-if="true" prop="bankNm" label="开户行名称" header-align="center" align="center"
						show-overflow-tooltip>
					</el-table-column>
					<el-table-column v-if="true" prop="bankProvince" label="省" header-align="center" align="center"
						show-overflow-tooltip>
						<template #default="{ row }">
							{{ dicList.PROVINCE_CODE.find(item => item.dicCode === row.bankProvince)?.dicName }}
						</template>
					</el-table-column>
					<el-table-column v-if="true" prop="bankCity" label="市" header-align="center" align="center"
						show-overflow-tooltip>
					</el-table-column>
					<el-table-column label="操作" header-align="center" align="center" show-overflow-tooltip width="200px"
						fixed="right">
						<template #default="scope">
							<el-button plain @click="handleSelect(scope.row)">选择</el-button>
						</template>
					</el-table-column>
				</el-table>
				<el-pagination v-model:current-page="currentPage" v-model:page-size="pageSize" :page-sizes="pageSizes"
					:total="totalRows" background="background" layout="total, sizes, prev, pager, next, jumper"
					@size-change="handleSizeChange" @current-change="handleCurrentChange">
				</el-pagination>
			</el-card>
		</el-dialog>
	</div>
</template>

<script setup>

import {
	ref,
	onMounted,
	watch,
	getCurrentInstance
} from 'vue'

const {
	proxy
} = getCurrentInstance()

import tools from '@/tools'

const cardBodyStyle = ref(tools.style.card)

const dialogVisible = ref(false)
const open = () => {
	dialogVisible.value = true
}
const close = () => {
	dialogVisible.value = false
}

const props = defineProps({
	fId: {
		type: String,
		required: true,
	},
	url: {
		type: String,
		default: 'pur/PayBank/query'
	},
})

const query = ref({
	bankNm: '',
	fId: ''
})

const emit = defineEmits(['receiveFromChild'])
const handleSelect = (row) => {
	emit('receiveFromChild', row)
	close()
}
const currentPage = ref(1)
const pageSize = ref(10)
const pageSizes = ref([10, 20, 30, 40])
const tableData = ref([])
const totalRows = ref()
const initTableData = () => {
	tableData.value = []
	query.value.fId = props.fId

	var url = props.url
	var param = {
		page: currentPage.value,
		rows: pageSize.value,
		params: JSON.stringify(query.value)
	}

	proxy.$axios.get(url, param).then(response => {
		if (response.data.code == '0') {
			tableData.value = response.data.data.records
			totalRows.value = response.data.data.total
			console.log()
		} else {
			ElMessage.error('操作失败！' + response.data.msg)
		}
	})
}

const search = () => {
	initTableData()
}
const handleSizeChange = (val) => {
	pageSize.value = val
	initTableData()
}
const handleCurrentChange = (val) => {
	currentPage.value = val
	initTableData()
}

onMounted(() => {
	initTableData()
	getDictList()
})
watch(dialogVisible, (newValue, oldValue) => {
	if (newValue) {
		initTableData()
	} else {

	}
})
defineExpose({
	open,
	close
})

/**
 *  查询字典
 */
const dicList = ref({
	PROVINCE_CODE: [],
})
const getDictList = () => {
	var url = 'framework/Common/querySelectorList'
	var param = {
		type: JSON.stringify(['PROVINCE_CODE'])
	}
	proxy.$axios.get(url, param).then(response => {
		if (response.data.code == '0') {
			dicList.value = response.data.data
		} else {
			ElMessage.error('操作失败！' + response.data.msg)
		}
	})
}
/**
 *  查询字典
 */
</script>

<style></style>