<template>
	<el-container>
		<el-header>
			<div class="left-panel">
				<el-input v-model="search.keyword" placeholder="关键词" style="width:150px; margin-right: 10px;" clearable></el-input>
				<el-button-group style="margin-left: 10px;">
					<el-button type="primary" icon="el-icon-search" @click="upsearch">搜索</el-button>
				</el-button-group>
			</div>
			<div class="right-panel">
				<el-button-group>
					<el-button type="danger" icon="el-icon-plus" @click="add">添加</el-button>
				</el-button-group>
			</div>
		</el-header>
		<el-main class="nopadding">
			<scTable tableName="member" ref="table" :apiObj="list.apiObj" :column="list.column" row-key="id" :params="search" @selection-change="selectionChange" border stripe size="small">
				<el-table-column type="selection" width="50"></el-table-column>
				<el-table-column label="操作" fixed="right" align="center" width="120">
					<template #default="scope">
						<el-button-group>
							<el-button type="primary" size="small" @click="store_show(scope.row, scope.$index)">查看</el-button>
							<el-button type="warning" size="small" @click="table_edit(scope.row, scope.$index)">编辑</el-button>
						</el-button-group>
					</template>
				</el-table-column>
			</scTable>
		</el-main>
		<save v-if="dialog.save" ref="saveBox" @success="upsearch" @closed="dialog.save=false" />
	</el-container>
</template>

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

export default {
	components:{
		save
	},
	data(){
		return {
			dialog: {save: false},
			list: {
				apiObj: this.$API.store.merchant.list,
				column: [
					{prop: 'id', label: 'ID', width: 80},
					{prop: 'merchant_name', label: '商户名称'},
					{prop: 'merchant_short_name', label: '商户简称', width: 180},
					{prop: 'merchant_code', label: '商户号', width: 180},
					{prop: 'lawyer_name', label: '法人代表', width: 180},
					{prop: 'lawyer_phone', label: '法人电话', width: 180},
					{prop: 'status', label: '状态', width: 80},
					{prop: 'created_at', label: '添加时间', width: 140},
					{prop: 'updated_at', label: '更新时间', width: 140},
				]
			},
			selection: [],
			search: {}
		}
	},
	mounted(){
	},
	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;
		},
		add(){
			this.dialog.save = true
			this.$nextTick(() => {
				this.$refs.saveBox.open()
			})
		},
		table_edit(row){
			this.dialog.save = true
			this.$nextTick(() => {
				this.$refs.saveBox.open('edit').setData(row)
			})
		},
		store_show(row){
			this.dialog.save = true
			this.$nextTick(() => {
				this.$refs.saveBox.open('show').setData(row)
			})
		}
	}
}
</script>

<style scoped>
</style>
