<template>
<el-container>
	<el-header>
		<div class="left-panel">
			<el-input v-model="search.username" placeholder="请输入用户名" style="width: 180px; margin-right: 10px;" clearable />
			<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-group>
		</div>
	</el-header>
	<el-main class="nopadding">
		<scTable tableName="member" ref="table" :apiObj="list.apiObj" :column="list.column" row-key="id" @selection-change="selectionChange" border stripe size="small">
			<el-table-column type="selection" width="50"></el-table-column>
			<template #avatar="scope">
				<img :src="scope.row.avatar" style="width: 50px; height: 50px; border-radius: 50%;" />
			</template>
			<template #status="scope">
				<el-tag :type="scope.row.status == 1 ? 'success' : 'danger'">{{scope.row.status == 1 ? '已审核' : (scope.row.status == 2 ? '未审核' : '待审核')}}</el-tag>
			</template>
			<template #sex="scope">
				{{scope.row.sex == 1 ? '男' : (scope.row.sex == 2 ? '女' : '未知')}}
			</template>
			<el-table-column label="操作" fixed="right" align="center" width="100">
				<template #default="scope">
					<el-button type="primary" @click="table_audit(scope.row, scope.$index)" v-if="scope.row.status == 0">审核</el-button>
				</template>
			</el-table-column>
		</scTable>
	</el-main>
	<save v-if="dialog.save" ref="saveBox" @closed="dialog.save = false" @success="moreUpsearch" />
</el-container>
</template>

<script>
import save from './save'

export default{
	name: 'member.sign',
	components: {
		save
	},
	data(){
		return {
			dialog: {save: false},

			list: {
				apiObj: this.$API.member.promoter.list,
				column: [
					{prop: 'id', label: 'ID', width: 80},
					{prop: 'avatar', label: '头像', width: 80},
					{prop: 'name', label: '姓名'},
					{prop: 'mobile', label: '手机号码', width: 120},
					{prop: 'sex', label: '性别', width: 80},
					{prop: 'status', label: '状态', width: 120},
					{prop: 'created_at', label: '添加时间', width: 140},
					{prop: 'updated_at', label: '更新时间', width: 140},
				],
			},
			selection: [],
			search: {},
		}
	},
	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().setData({})
			})
		},
		table_audit(row, index){
			this.dialog.save = true
			this.$nextTick(() => {
				this.$refs.saveBox.open('audit').setData(row)
			})
		}
	}
}
</script>
