<template>
<el-container>
	<el-header>
		<div class="left-panel">
			<el-button type="primary" icon="el-icon-plus" @click="add" v-auth="'addCompany'"></el-button>
			<el-button type="danger" plain icon="el-icon-delete" :disabled="selection.length==0" @click="batch_del" v-auth="'deleteCompany'"></el-button>
			<div style="padding: 10px;" v-auth="'insertCompany'"><el-upload :before-upload="beforeUpload" :show-file-list="false"><el-button type="primary" icon="el-icon-upload">导入</el-button></el-upload></div>
		</div>
		<div class="right-panel">
			<div class="right-panel-search">
				<el-input v-model="search.name" placeholder="公司名称" style="width:150px" clearable></el-input>
				<el-button type="primary" icon="el-icon-search" @click="upsearch"></el-button>
				<el-button type="primary" icon="el-icon-arrow-down-bold" @click="moreSearch"></el-button>
				<el-button type="primary" icon="el-icon-download" @click="upsearch"></el-button>
			</div>
		</div>
	</el-header>
	<el-main class="nopadding">
		<scTable ref="table" :apiObj="apiObj" :column="columnList" row-key="id" @selection-change="selectionChange" stripe>
			<el-table-column type="selection" width="50"></el-table-column>
			<el-table-column label="操作" fixed="right" align="center" width="200">
				<template #default="scope">
					<el-button type="text" size="small" @click="table_show(scope.row, scope.$index)" v-auth="'showDetail'">查看</el-button>
					<el-button type="text" size="small" @click="table_edit(scope.row, scope.$index)" v-auth="'editCompany'">编辑</el-button>
					<el-popconfirm title="确定删除吗？" @confirm="table_del(scope.row, scope.$index)">
						<template #reference>
							<el-button type="text" size="small" v-auth="'deleteCompany'">删除</el-button>
						</template>
					</el-popconfirm>
				</template>
			</el-table-column>
		</scTable>
	</el-main>
	<search v-if="dialog.search" ref="searchBox" @success="moreUpsearch" @closed="dialog.search=false"></search>
	<save-box v-if="dialog.save" ref="saveBox"></save-box>
</el-container>
</template>

<script>
import search from './search.vue';
import saveBox from './save.vue';
import imports from '@/mixin/import';

export default{
	components:{
		search,
		saveBox
	},
	mixins: [imports],
	data(){
		return {
			dialog: {
				search: false
			},
			apiObj: this.$API.customer.company.list,
			selection: [],
			columnList: [
				{label: "公司名称", prop: "name", width: "150"},
				{label: "区域", prop: "area_t", width: "150"},
				{label: "行业", prop: "industry_t", width: "150"},
				{label: "注册资金", prop: "reg_capital", width: "150"},
				{label: "员工人数", prop: "staff_num", width: "150", hide: true},
				{label: "社保人数", prop: "social_insurance", width: "150"},
				{label: "上市状态", prop: "is_ipo", width: "150"},
				{label: "营收规模", prop: "turnover", width: "150"},
				{label: "企业状态", prop: "status", width: "150"},
			],
			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;
		},
		batch_del(){

		},
		table_show(row){
			this.$router.push('/company/detail?id='+row.id)
		},
		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)
			})
		},
		table_del(){
			
		}
	}
}
</script>