<template>
<el-container>
	<el-header>
		<div class="left-panel">
			<el-button type="primary" icon="el-icon-plus" @click="add"></el-button>
		</div>
		<div class="right-panel">
			<div class="right-panel-search">
				<el-input v-model="search.title" placeholder="名称" clearable></el-input>
				<el-button type="primary" icon="el-icon-search" @click="upsearch"></el-button>
			</div>
		</div>
	</el-header>
	<el-main class="nopadding">
		<scTable ref="table" :apiObj="list.apiObj" :column="list.column" row-key="id" @selection-change="selectionChange" :params="search">
			<el-table-column type="selection" width="50" />
			<el-table-column label="操作" fixed="right" width="140">
				<template #default="scope">
					<el-button-group>
						<el-button type="primary" size="small" @click="table_edit(scope.row, scope.$index)">编辑</el-button>
						<el-popconfirm title="您确定删除该数据" @confirm="table_del(scope.row, scope.$index)">
							<template #reference>
								<el-button type="danger" size="small">删除</el-button>
							</template>
						</el-popconfirm>
					</el-button-group>
				</template>
			</el-table-column>
		</scTable>
	</el-main>
</el-container>
<save ref="saveBox" v-if="dialog.save" @success="upsearch"></save>
</template>

<script>
import save from './save.vue'

export default {
	name: 'member.lists',
	data(){
		return {
			dialog: {save: false},
			list: {
				apiObj: this.$API.member.level.list,
				column: [
					{prop: 'id', label: 'ID', width: 80},
					{prop: 'title', label: '等级名称'},
					{prop: 'name', label: '等级标识'},
					{prop: 'icon', label: '图标'},
					{prop: 'status', label: '状态', width: 100},
					{prop: 'created_at', label: '添加时间', width: 140},
					{prop: 'updated_at', label: '更新时间', width: 140},
				]
			},
			search: {
				title: null,
			},
			selection: []
		}
	},
	components: {
		save
	},
	created(){
	},
	methods:{
		upsearch(){
			this.$refs.table.reload(this.search);
		},
		moreUpsearch(search){
			this.search = search;
			this.upsearch();
		},
		moreSearch(){
			this.dialog.search = true
			this.$nextTick(() => {
				this.$refs.searchBox.open().setData(this.search)
			})
		},
		//表格选择后回调事件
		selectionChange(selection){
			this.selection = selection;
		},
		batch_del(){

		},
		table_show(row){
			this.dialog.detail = true
			this.$nextTick(() => {
				this.$refs.detailBox.open().setData(row)
			})
		},
		add(){
			this.dialog.save = true
			this.$nextTick(() => {
				this.$refs.saveBox.open().setData({})
			})
		},
		table_edit(row){
			this.dialog.save = true
			this.$nextTick(() => {
				this.$refs.saveBox.open('edit').setData(row)
			})
		},
		async table_del(row){
			var reqData = {id: row.id}
			var res = await this.$API.member.level.delete.post(reqData);
			if(res.code == 1){
				//这里选择刷新整个表格 OR 插入/编辑现有表格数据
				this.upsearch()
				this.$message.success("删除成功")
			}else{
				this.$alert(res.message, "提示", {type: 'error'})
			}
		}
	}
}
</script>

<style scoped>
</style>
