<template>
	<div class="hui-flex hui-content">
		<div class="hui-flex">
			<div class="hui-content-title">
				<div class="hui-title-item active">公司会议</div>
			</div>
			<div class="hui-flex-box hui-flex hui-table">
				<div class="hui-content-insert">
					<el-button type="primary" size="medium" @click="insert">新增会议</el-button>
				</div>
				<div class="hui-flex-box">
					<el-table :data="tableData" row-key="id" border height="100%">
						<el-table-column label="序号" width="50">
							<template slot-scope="scope">
								<div style="text-align: center;">{{scope.$index + 1}}</div>
							</template>
						</el-table-column>
						<el-table-column label="会议名称" prop="name"></el-table-column>
						<el-table-column label="会议时间" prop="date"></el-table-column>
						<el-table-column label="会议类型" prop="typeName"></el-table-column>
						<el-table-column label="发起人" prop="userName"></el-table-column>
						<el-table-column label="会议地点" prop="placeName"></el-table-column>
						<el-table-column label="会议纪要" prop="meetingMinutes"></el-table-column>
						<el-table-column label="操作" width="150">
							<template slot-scope="scope">
								<div class="hui-table-operation">
									<span class="table-operation" @click="detailItem(scope.row)">
										详情
									</span>
									<span class="table-operation" @click="updateItem(scope.row)">
										编辑
									</span>
									<span class="table-operation" @click="deleteItem(scope.row)">
										删除
									</span>
								</div>
							</template>
						</el-table-column>
						<template slot="empty">
							<empty description="暂无数据"></empty>
						</template>
					</el-table>
				</div>
				<div class="hui-content-pagination">
					<el-pagination :page-size="pageSize" :pager-count="9" layout="prev, pager, next" :total="totalCount"
						@current-change="currentChange">
					</el-pagination>
				</div>
			</div>
		</div>
		<el-dialog :close-on-click-modal="false" :title="isUpdate?'编辑':'新增'" :visible.sync="visible" width="900px" :append-to-body="true">
			<edit v-if="visible" @callback="callback" :isUpdate="isUpdate" :detailId="detailId" :type="type"></edit>
		</el-dialog>
		<el-drawer title="会议详情" :visible.sync="drawer" :size="400" :append-to-body="true">
			<detail v-if="drawer" :detailId="detailId" @callback="callback"></detail>
		</el-drawer>
	</div>
</template>

<script>
	import {
		getMeetingListByQuery,
		deleteMeetingById
	} from '@/httpApi/operation'
	import edit from '@/components/work/operation/meeting/edit'
	import detail from '@/components/work/operation/meeting/detail'
	export default {
		data() {
			return {
				tableData: [],
				currPage: 1,
				pageSize: 10,
				totalCount: 0,
				filterOption: {},
				type: 2,
				isUpdate: false,
				visible: false,
				detailId: '',
				drawer: false
			}
		},
		created() {
			this.init();
		},
		methods: {
			init() {
				let postData = {
					currPage: this.currPage,
					pageSize: this.pageSize,
					organizationId: this.$store.getters.organization.id,
					type: this.type
				}
				postData = Object.assign(postData, this.filterOption);
				getMeetingListByQuery(postData).then(res => {
					if (res.state) {
						this.tableData = res.data.dataList;
						this.totalCount = res.data.totalCount;
					}
				})
			},
			filterInit(option) {
				this.filterOption = option;
				this.currPage = 1;
				this.init();
			},
			insert() {
				this.detailId = '';
				this.isUpdate = false;
				this.visible = true;
			},
			updateItem(item) {
				this.detailId = item.id;
				this.isUpdate = true;
				this.visible = true;
			},
			detailItem(item) {
				this.detailId = item.id;
				this.drawer = true;
			},
			currentChange(currPage) {
				this.currPage = currPage;
				this.init();
			},
			deleteItem(item) {
				this.$confirm('确定要删除该会议记录?', () => {
					deleteMeetingById(item.id).then(res => {
						if (res.state) {
							this.$message({
								type: 'success',
								message: '操作成功'
							})
							this.init();
						}
					})
				});
			},
			callback(type) {
				if (type === 'init') this.init();
				this.visible = false;
			}
		},
		components: {
			edit,
			detail
		},
	}
</script>

<style>
</style>