<template>
	<el-container>
		<el-header>
			<div class="left-panel">
				<el-button type="primary" icon="el-icon-plus" @click="table_add" v-auth="'mgroup.create'">新增</el-button>
			</div>
			<div class="right-panel">
				<el-input style="margin-right: 5px;" v-model="query.search" placeholder="名称" clearable></el-input>
				<el-button type="primary" icon="el-icon-search" @click="handleQuery"></el-button>
			</div>
		</el-header>
		<el-main class="nopadding">
			<scTable ref="table" :apiObj="apiObj" row-key="id" hidePagination :params="params">
				<el-table-column label="#" type="index" width="50"></el-table-column>
				<el-table-column label="工段名称" prop="name" min-width="100"></el-table-column>
				<el-table-column label="所在工序" prop="cate" min-width="100">
					<template #default="scope">
						<span>{{ scope.row.process_cate }} - {{ scope.row.process_name }}</span>
					</template>
				</el-table-column>
				<el-table-column label="所属部门" prop="belong_dept_name" min-width="150"></el-table-column>
				<el-table-column label="排序" prop="sort" min-width="80"></el-table-column>
				<el-table-column label="创建时间" prop="create_time" min-width="150"></el-table-column>
				<el-table-column label="操作" fixed="right" align="center" width="180">
					<template #default="scope">
						<el-button link size="small" @click="table_edit(scope.row)" v-auth="'mgroup.update'"
							type="primary">编辑</el-button>
						<el-divider direction="vertical"></el-divider>
						<el-popconfirm title="确定删除吗？" @confirm="table_del(scope.row, scope.$index)">
							<template #reference>
								<el-button link size="small" v-auth="'mgroup.delete'" type="danger">删除</el-button>
							</template>
						</el-popconfirm>
					</template>
				</el-table-column>
			</scTable>
		</el-main>
	</el-container>
	<save-dialog 
		v-if="dialog.save" 
		ref="saveDialog" 
		@success="handleSaveSuccess"
		@closed="dialog.save = false">
	</save-dialog>
</template>
<script>
import saveDialog from "./mgroup_form.vue";
export default {
	name: 'mgroup',
	components: {
		saveDialog
	},
	data() {
		return {
			apiObj: this.$API.mtm.mgroup.list,
			params: { 'cate': 'photon' },
			query: {},
			dialog: {
				save: false,
				permission: false,
			},
			tableData: [],
			selection: [],
			cates_: {
				'section': '工序',
				'other': '其他',
			},
		}
	},
	mounted() {
	},
	methods: {
		//添加
		table_add() {
			this.dialog.save = true;
			this.$nextTick(() => {
				this.$refs.saveDialog.open("add");
			});
		},
		//编辑
		table_edit(row) {
			this.dialog.save = true;
			this.$nextTick(() => {
				this.$refs.saveDialog.open("edit").setData(row);
			});
		},
		//删除测点集
		async table_del(row) {
			var id = row.id;
			var res = await this.$API.mtm.mgroup.delete.req(id);
			if (res.err_msg) {
				this.$message.error(res.err_msg)
			} else {
				this.$refs.table.refresh();
				this.$message.success("删除成功")
			}
		},
		//表格选择后回调事件
		selectionChange(selection) {
			this.selection = selection;
		},
		//搜索
		handleQuery() {
			this.$refs.table.queryData(this.query)
		},
		//本地更新数据
		//新增岗位后更新数据
		handleSaveSuccess(data, mode) {
			this.dialog.save = true;
			this.$refs.table.refresh();
		},
	}
}
</script>
<style scoped>
.treeMain {
	width: 100%;
	height: 280px;
	overflow: auto;
	border: 1px solid #dcdfe6;
	margin-bottom: 10px;
}
</style>
