<template>
<div class="grainPriceCollectCitySum pageContent">
<a-space class="search">
		汇总期数:<a-input v-model:value="SearchForm.countPeriod" />
	汇总时间:
	<a-space direction="vertical" :size="12">
		<a-range-picker v-model:value="SearchForm.times" />
	</a-space>
	<div class="btnBox">
		<a-button type="primary" @click="onSearch"> 查询 </a-button>
		<a-button @click="onReset"> 重置 </a-button>
		<a-button class="pub" @click="onSum"> 汇总 </a-button>
	</div>
</a-space>
<div class="list">
	<a-table :dataSource="tableData" :pagination="tablePage" :columns="tableColumns" @change="onChangePage">
		<template #bodyCell="{ column, record,index }">
			<template v-if="column.key === 'INDEX'">{{index+1}}</template>
			<template v-else-if="column.key === 'CZ'">
				<a-button class="view" @click="onViewRow(record)">查看</a-button>
				<a-button class="reject" @click="onDeleteRow(record)">删除</a-button>
			</template>
		</template>
	</a-table>
</div>
</div>
</template>

<script setup name="grainPriceCollectCitySum">
import {reactive,ref} from "vue";
import unReporCityApi from '@/api/basic.info/unReporCityApi.js'
import bizGrainPriceCollectProvinceSumApi from '@/api/basic.info/bizGrainPriceCollectProvinceSumApi.js'
import { useRouter } from "vue-router";
import { message } from "ant-design-vue";
import { globalStore } from '@/store'
const global_store = globalStore()
const userInfo = computed(() => {
	return global_store.userInfo
})
const router = useRouter();
const tableColumns = [
	{title:'序号',key:'INDEX'},
	{title:'汇总人',dataIndex:'userName'},
	{title:'汇总时间',dataIndex:'sumTime'},
	{title:'操作',key:'CZ'},
];
const OrgOptions = ref([]);
const tablePage = reactive({
	total:0,
	current:1,
	size:20,
});
const SearchForm = reactive({
	countPeriod:'',
	times:[],
});
onMounted(()=>{
	getSiteDate();
	onSearch();
});
const tableData = ref([{}]);
function getSiteDate(){
	unReporCityApi.unReporCityquery().then((res) => {
		OrgOptions.value = res
	})
}
function onSearch(){
	let fd = JSON.parse(JSON.stringify(SearchForm));
	fd.current = tablePage.current;
	fd.size = tablePage.size;
	const times = fd.times;
	fd.times = null;
	if(times[0]){ fd.sumStartTime = times[0]; }
	if(times[1]){ fd.sumEndTime = times[1]; }
	bizGrainPriceCollectProvinceSumApi.bizGrainPriceCollectProvinceSumPage(fd).then(reg=>{
		tableData.value = reg.records;
		tablePage.total = reg.total;
	});
}
function onReset(){
	SearchForm.countPeriod = '';
	SearchForm.times = [];
	tablePage.current = 1;
	onSearch();
}
// 汇总
function onSum(){
	let orgId = userInfo.value.orgId;
	let userId = userInfo.value.id;
	bizGrainPriceCollectProvinceSumApi.bizGrainPriceCollectProvinceSumSum({orgId,userId}).then(reg=>{
		message.success('汇总成功！');
	})
}
function onViewRow(row){
	router.push({path:'/basic.info/bizGrainPriceCollectProvinceSumDetail',query:{id:row.id}})
}
function onDeleteRow(row){
	bizGrainPriceCollectProvinceSumApi.bizGrainPriceCollectProvinceSumDelete({id:row.id}).then(reg=>{
		message.success('删除成功！');
		onSearch();
	})
}
function onPubRow(row){}
function onChangePage(ev){
	Object.assign(tablePage,ev);
	onSearch();
}
</script>
<style lang="less" scoped>
.view { background-color: rgba(112, 125, 233); color: #fff; }
.reject { background-color: rgba(255, 70, 70); color: #fff; }
.pub { background-color: rgba(83, 184, 36); color: #fff; }
.pageContent{
	background:#fff; padding:10px 20px;
	.search{
		padding:10px 0;
		.btnBox{
			display:flex;
			>*{ margin-right:10px; }
		}
	}
}

</style>