<template>
	<el-container class="mainBox mainHeaderNoBorderPadding">
		<el-header>
			<div class="left-panel">
				<el-button type="primary" :size="size" icon="el-icon-plus" @click="add">新增BOM</el-button>
			</div>
			<div class="right-panel">
				<scExport :size="size" @exportData="exportData" @updateShow="exportChangeShow" :show="exportShow" type="33">
					<el-button :size="size" v-auth="'bomListExport'" icon="sc-icon-Download" :disabled="exportShow" @click="exportData">下载</el-button>
				</scExport>
			</div>
		</el-header>
		<el-main class="nopadding">
			<div class="searchMain searchMainNoTop">
				<scSearch ref="scSearch" :searchList="searchList" @fetchSelectData="getSelectData"></scSearch>

				<div class="searchItem searchBtn">
					<el-button :size="size" :icon="searchShow?'el-icon-ArrowUpBold':'el-icon-ArrowDownBold'" @click="searchShowClick">{{searchShow?'收起':'更多'}}</el-button>
					<el-button :size="size" type="primary" icon="el-icon-search" @click="upSearch">查询</el-button>
					<el-button :size="size" type="info" icon="el-icon-RefreshRight" @click="reset">重置</el-button>
				</div>
			</div>
			<scTable ref="table" :apiObj="list.apiObj" :column="list.column" row-key="id" stripe :size="size" @selection-change="selectionChange">
				<el-table-column type="selection" align="center" width="40"></el-table-column>
				<sc-table-column label="序号" align="center" type="index"></sc-table-column>
<!--				<template #active_status="scope">-->
<!--					<el-switch :size="size" v-model="scope.row.active_status" @change="changeSwitch($event, scope.row)" :loading="scope.row.$switch_status" :active-value="true" :inactive-value="false"></el-switch>-->
<!--				</template>-->
<!--				<el-table-column label="操作" fixed="right" align="center" width="150">-->
<!--					<template #default="scope">-->
<!--						<el-dropdown>-->
<!--							<el-button class="noBorderBtn" icon="el-icon-more" :size="size"></el-button>-->
<!--							<template #dropdown>-->
<!--								<el-dropdown-menu>-->
<!--									<el-dropdown-item @click="table_show(scope.row, 'see')" icon="sc-icon-See">查看详情</el-dropdown-item>-->
<!--									<el-dropdown-item @click="table_edit(scope.row, 'edit')" icon="sc-icon-Edit">编辑公司</el-dropdown-item>-->
<!--									<el-dropdown-item  icon="sc-icon-AbilityAuthorization" @click="table_empower(scope.row)" divided>功能授权</el-dropdown-item>-->
<!--									<el-dropdown-item  icon="sc-icon-DataAuthorization">数据授权</el-dropdown-item>-->
<!--									<el-dropdown-item  icon="sc-icon-UserList" @click="table_user_ist(scope.row)" divided>用户列表</el-dropdown-item>-->
<!--									<el-dropdown-item @click="table_del(scope.row, 'delete')" icon="sc-icon-Delete">删除公司</el-dropdown-item>-->
<!--								</el-dropdown-menu>-->
<!--							</template>-->
<!--						</el-dropdown>-->
<!--					</template>-->
<!--				</el-table-column>-->
			</scTable>
		</el-main>
	</el-container>

</template>

<script>

export default {
	name:"bom",
	components: {

	},
	data() {
		return {
			size:'small',
			dialog: {
				save: false,
				show: false,
			},
			list: {
				apiObj: this.$API.setup.bom.list,
				column: [],
			},
			selection: [],
			exportShow:false,
			searchShow:false,
			searchList:[
				{name:'创建时间',type:'date',code:'created_at',show: true},
				{name:'更新时间',type:'date',code:'updated_at',show: true},
				{name:'BOM版本',type:'text',code:'bom_version',placeholder:"请输入BOM版本",show:true},
				{name:'BOM简称',type:'text',code:'bom_abbreviation',placeholder:"请输入BOM简称",show:false},
				{name:'BOM分类',type:'text',code:['bom_classification'],placeholder:"请输入BOM分类",isOpen:true,show:false},
				{name:'BOM用途',type:'text',code:['bom_purpose'],placeholder:"请输入BOM用途",isOpen:true,show:false},
				{name:'父项物料编码',type:'text',code:['parent_material_code'],placeholder:"请输入父项物料编码",isOpen:true,show:false},
				{name:'父项物料名称',type:'text',code:['parent_material_name'],placeholder:"请输入父项物料名称",isOpen:true,show:false},
				{name:'父项物料单位',type:'text',code:['parent_material_unit'],placeholder:"请输入父项物料单位",isOpen:true,show:false},
				{name:'子项物料编码',type:'text',code:['child_material_code'],placeholder:"请输入子项物料编码",isOpen:true,show:false},
				{name:'子项物料名称',type:'text',code:['child_material_name'],placeholder:"请输入子项物料名称",isOpen:true,show:false},
				{name:'子项物料单位',type:'text',code:['child_material_unit'],placeholder:"请输入子项物料单位",isOpen:true,show:false},
				{name:'次项',type:'text',code:['item_sequence'],placeholder:"请输入次项",isOpen:true,show:false},
				{name:'子项类型',type:'text',code:['child_material_type'],placeholder:"请输入子项类型",isOpen:true,show:false},
				{name:'用量分母',type:'text',code:['usage_numerator'],placeholder:"请输入用量分母",isOpen:true,show:false},
				{name:'用量分子',type:'text',code:['usage_denominator'],placeholder:"请输入用量分子",isOpen:true,show:false},
				{name:'创建组织编码',type:'text',code:['create_org_code'],placeholder:"请输入创建组织编码",isOpen:true,show:false},
				{name:'创建组织名称',type:'text',code:['create_org_name'],placeholder:"请输入创建组织名称",isOpen:true,show:false},
				{name:'使用组织编码',type:'text',code:['use_org_code'],placeholder:"请输入使用组织编码",isOpen:true,show:false},
				{name:'使用组织名称',type:'text',code:['use_org_name'],placeholder:"请输入使用组织名称",isOpen:true,show:false},
				{name:'单据状态',type:'text',code:['document_status'],placeholder:"请输入单据状态",isOpen:true,show:false},
				{name:'禁用状态',type:'text',code:['disable_status'],placeholder:"请输入禁用状态",isOpen:true,show:false},
				{name:'关键字',type:'text',code:['bom_abbreviation'],keyword:true,show:true},
			],
			params: {},
		}
	},
	mounted() {
		console.log(32423)
	},
	methods: {
		searchShowClick(){
			this.searchShow = !this.searchShow;
			this.searchList.forEach(item=>{
				if(item.isOpen){
					item.show = this.searchShow
				}
			})
		},
		getSelectData(item){
			let {params} = item;
			this.params = params;
		},

		//添加
		add(){
			this.dialog.save = true;
			this.$nextTick(() => {
				this.$refs.saveDialog.open()
			})
		},

		//编辑
		table_edit(row){
			this.dialog.save = true
			this.$nextTick(() => {
				this.$refs.saveDialog.open('edit').setData(row)
			})
		},
		//查看
		table_show(row){
			this.dialog.show = true
			this.$nextTick(() => {
				this.$refs.showDialog.open('show').setData(row);
			})
		},
		//删除
		async table_del(row){
			this.$confirm(`确定删除 ${row.name} 吗？`, '提示', {
				type: 'warning'
			}).then(async () => {
				const reqData = {id: row.id};
				const res = await this.$API.system.company.delete.post(reqData);
				if(res.code == 200){
					this.$refs.table.refresh()
					this.$message.success("删除成功")
				}else{
					await this.$alert(res.message, "提示", {type: 'error'})
				}
			}).catch(()=>{})
		},

		//表格选择后回调事件
		selectionChange(selection){
			this.selection = selection;
		},
		// 下载导出
		exportChangeShow(params){
			if(params.type == 33){
				this.exportShow = params.status==0?true:false
			}
			console.log('我接受的消息：',params.type, params.status,this.exportShow)
		},
		async exportData() {
			if(this.exportShow) return
			const res = await this.$API.setup.bom.export.post(this.params);
			if(res.code == 200){
				this.$message.success('开始导出');
			}
		},
		upSearch(){
			this.$refs.table.upData(this.params);
		},
		reset(){
			this.params = {};
			this.$refs.scSearch.reload();
			this.$refs.table.reload();
		},
		handleSaveSuccess(){
			this.$refs.table.refresh();
		},
	}
}
</script>

<style lang="scss" scoped>
.logoCell{
	display: flex;
	align-items: center;
	height: 20px;
	margin: 0 auto;
}
</style>
