<template>
	<el-container class="mainBox mainHeaderNoBorderPadding">
		<el-main class="nopadding">
			<div class="flowPath">
				<flow :list="flowList"/>
			</div>
			<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 #repair_status="scope">
					<span v-for="(item,ind) in statusList" :key="ind">
						<span :style="{color:item.value==1?`var(--el-order-color-1)`:item.value==2?`var(--el-order-color-2)`:item.value==3?`var(--el-order-color-3)`:item.value==4?`var(--el-order-color-4)`:`var(--el-order-color-5)`}"
							  v-if="item.value == scope.row.repair_status">{{item.label}}</span>
					</span>
				</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  icon="sc-icon-MaintenanceSetup">执行维修</el-dropdown-item>
									<el-dropdown-item @click="table_show(scope.row, 'see')" icon="sc-icon-See">工单详情</el-dropdown-item>
								</el-dropdown-menu>
							</template>
						</el-dropdown>
					</template>
				</el-table-column>
			</scTable>
		</el-main>
	</el-container>

	<!--	<save-dialog v-if="dialog.save" ref="saveDialog" @success="handleSaveSuccess" @closed="dialog.save=false"></save-dialog>-->
	<!--	<see-dialog v-if="dialog.show" ref="showDialog" @closed="dialog.show=false"></see-dialog>-->

</template>

<script>
// import saveDialog from './save'
// import seeDialog from  './see'
import flow from '../orderList/components/flow'

export default {
	components: {
		flow,
		// saveDialog,
		// seeDialog,
	},
	data() {
		return {
			size:'small',
			flowList:[
				{name:'维修确认',left:false,right:true},
				{name:'维修中',left:true,right:true},
				{name:'维修完成',left:true,right:false},
			],
			dialog: {
				save: false,
				show: false,
			},
			list: {
				apiObj: this.$API.orders.order.repair.list,
				column: [],
			},
			selection: [],
			exportShow:false,
			searchShow:false,
			searchList:[
				{name:'创建日期',type:'date',code:'activation_date',show:true},
				{name:'维修单号',type:'text',code:'repair_order_no', data:[], placeholder:"请输入维修单号",show:true},
				{name:'故障类型',type:'select',code:'fault_type', data:[], placeholder:"请选择故障类型",show:true},
				{name:'状态',type:'select',code:'repair_status', data:[], placeholder:"请选择状态",isOpen:true,show:false},
				{name:'故障描述',type:'text',code:['fault_description'],placeholder:"请输故障描述",isOpen:true,show:false},
				{name:'关键字',type:'text',code:['fault_description','device_sn'],keyword:true,show:true},
			],
			params: {},
			statusList:[],
		}
	},
	mounted() {
		this.getStatusList();
	},
	methods: {
		async getStatusList() {
			const res = await this.$API.orders.order.maintenance.status.post();
			if (res.code == 200) {
				this.statusList = res.data;
			}
		},

		searchShowClick(){
			this.searchShow = !this.searchShow;
			this.searchList.forEach(item=>{
				if(item.isOpen){
					item.show = this.searchShow
				}
			})
		},
		getSelectData(item){
			let {data,params} = item;
			this.params = params;
			if(data.code == "id"){
				this.getCompanyList(data,params)
			}else if(data.code == "active_status"){
				this.getStatusList(data,params);
			}
		},

		async getCompanyList(data,params) {
			const res = await this.$API.system.company.select.post(params);
			if(res.data && res.data.length>0){
				res.data.forEach(item=>{
					item.label = item.full_name;
				})
			}
			if(res.code == 200){
				this.searchList.forEach(item=>{
					if(item.code == data.code){
						item.data = res.data;
					}
				})
			}
		},

		//添加
		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;
		},

		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>
.mainBox{
	padding:10px 0 0 0;
	.searchMain{
		margin-left: 10px;
		margin-right: 10px;
	}
	.scTable{
		padding: 0 10px;
	}
}
.logoCell{
	display: flex;
	align-items: center;
	height: 20px;
	margin: 0 auto;
}
</style>
