<template>
<!-- 初稿意见征集 -->
<div class="planningFirstOpinion pageContent">
<a-space class="search">
	规划名称:<a-input v-model:value="SearchForm._规划名称" />
	<div class="btnBox">
		<a-button type="primary" @click="onSearch"> 查询 </a-button>
		<a-button @click="onReset"> 重置 </a-button>
		<a-button class="pub" @click="onAddRow"> 新增 </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="edit" @click="onEditRow(record)">编辑</a-button>
				<a-button class="remove" @click="onDeleteRow(record)">删除</a-button>
				<a-button class="opinion" @click="onOpinionRow(record)">查看意见</a-button>
			</template>
		</template>
	</a-table>
</div>
<a-modal v-model:visible="AddEditDialog.open" :title="AddEditDialog.title" @ok="onDialogOk" width="800px">

	<a-form ref="DialogForm" :model="AddEditDialog.form" v-if="['add','edit'].includes(AddEditDialog.mode)" :rules="AddEditDialog.formRules">
		<a-form-item v-for="item in AddEditDialog.formOptions" :key="item.label"
			:label="item.label" :name="item.prop"
		>
			<a-input v-if="item.type === 'input'" v-model:value="AddEditDialog.form[item.prop]" :disabled="item.disabled"></a-input>
			<a-textarea v-if="item.type === 'textarea'" :auto-size="{minRows:3}" v-model:value="AddEditDialog.form[item.prop]" :disabled="item.disabled"></a-textarea>
			<a-select v-else-if="item.type === 'select'" v-model:value="AddEditDialog.form[item.prop]" :disabled="item.disabled">
				<a-select-option v-for="citem in item.values" :key="citem.valiue" :value="citem.value">{{citem.label}}</a-select-option>
			</a-select>
			<DIYUPLoad v-else-if="item.type === 'upload'" v-model="AddEditDialog.form[item.prop]" :change="changeUpload" :disabled="item.disabled" />
		</a-form-item>
	</a-form>
	<a-descriptions v-else-if="AddEditDialog.mode === 'view'" :column="2">
		<a-descriptions-item v-for="item in AddEditDialog.formOptions"
			:label="item.label" :key="item.label" :span="item.span"
		>{{AddEditDialog.form[item.prop]}}</a-descriptions-item>
	</a-descriptions>
	<template #footer v-if="AddEditDialog.mode === 'view'"></template>
</a-modal>
</div>
</template>
<script setup name="planningFirstOpinion">
import global from "@/api/basic.info/global.js";
import { useRouter } from "vue-router";

const router = useRouter();
const SearchForm = reactive({
	_规划名称:'',
});
const tableColumns = [
	{title:'序号',width:100,align:'center',key:'INDEX'},
	{title:'规划名称',dataIndex:'_规划名称'},
	{title:'开始日期',dataIndex:'_开始日期'},
	{title:'结束日期',dataIndex:'_结束日期'},
	{title:'操作',width:400,key:'CZ'},
];
const tablePage = reactive({
	total:0,
	current:1,
	size:20,
});
const tableData = ref([{'':'12456789'}]);
const DialogForm = ref(null);
const AddEditDialog = reactive({
	open:false,
	title:'',
	mode:'add',
	formRules:{
		'_规划名称':[{required:true,trigger:'change',message:'请输入规划名称！'}],
		'_收集处室':[{required:true,trigger:'change',message:'请选择收集处室！'}],
		'_规划正文':[{required:true,trigger:'change',message:'请输入规划正文！'}],
	},
	formOptions:[
		{label:'规划名称',prop:'_规划名称',type:'select',span:1},
		{label:'收集处室',prop:'_收集处室',type:'select',span:1,},
		{label:'规划正文',prop:'_规划正文',type:'textarea',disabled:true,span:2},
		{label:'附件',prop:'_附件',type:'upload',disabled:true,span:2},
	],
	form:{}
});
function onSearch(){

}
function onReset(){
	SearchForm._规划名称 = '';
	tablePage.current = 1;
	onSearch();
}

function onChangePage(ev){
	console.log(ev);
	Object.assign(tablePage,ev);
	onSearch();
}
function changeUpload(fd){
	return global.uploadFile(fd).then(reg=>{
		return reg;
	})
}
function onViewRow(row){
	AddEditDialog.form = JSON.parse(JSON.stringify(row));
	AddEditDialog.mode = 'view';
	AddEditDialog.title = '查看规划';
	AddEditDialog.open = true;
}
function onAddRow(){
	AddEditDialog.form = {};
	AddEditDialog.mode = 'add';
	AddEditDialog.title = '添加规划';
	AddEditDialog.open = true;
}

function onEditRow(row){
	AddEditDialog.form = JSON.parse(JSON.stringify(row));
	AddEditDialog.mode = 'edit';
	AddEditDialog.title = '编辑规划';
	AddEditDialog.open = true;
}
function onDeleteRow(row){

}
function onOpinionRow(row){
	router.push({path:"/basic.info/planningFirstOpinionView",query:{id:row.id}});
}
function onDialogOk(){
	const URLs = {
		add:'',
		edit:'',
	}
	DialogForm.value.validate().then(reg=>{

	})
}
</script>
<style lang="less" scoped>
.view { background-color: rgba(112, 125, 233); color: #fff; }
.edit { background-color: rgba(210, 176, 61); color: #fff; }
.remove { background-color: rgba(255, 70, 70); color: #fff; }
.add { 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>