<template>
	<div class="app-container">
		<search-bar
			:isFold="true"
			:formConfigs="formConfig"
			ref="searchBarForm"
			@headBtnClick="buttonClick" />
		<base-table
			v-loading="dataListLoading"
			:table-props="tableProps"
			:page="listQuery.pageNo"
			:limit="listQuery.pageSize"
			:table-data="tableData">
		</base-table>
		<pagination
			:limit.sync="listQuery.pageSize"
			:page.sync="listQuery.pageNo"
			:total="listQuery.total"
			@pagination="getDataList" />
	</div>
</template>

<script>
import basicPage from '../mixins/basic-page';
import { parseTime } from '../mixins/code-filter';
import codeFilter from '../mixins/code-filter';
import { getMainTaskHistoryPage,exportMainTaskHistoryExcel } from '@/api/oth/mainTaskHistory';
import point from './point';

const tableProps = [
	{
		prop: 'mainTaskCode',
		label: '任务编码',
	},
	{
		prop: 'inOutWarehouseName',
		label: '出入移库库位',
	},
	{
		prop: 'relocationWarehouseName',
		label: '移库终点库位',
	},
	{
		prop: 'mainTaskType',
		label: '任务类型',
		filter: codeFilter('mainTaskType'),
    width:100
	},
	{
		prop: 'stacker',
		label: '堆垛机',
    width:110
	},
	{
		prop: 'barCode',
		label: '托盘编码',
	},
	{
		prop: 'agv',
		label: 'agv',
	},
	{
		prop: 'agvStartPoint',
		label: 'AGV起点',
	},
	{
		prop: 'agvEndPoint',
		label: 'AGV终点',
	},
	{
		prop: 'mainTaskState',
		label: '状态',
    subcomponent: point
	},
	{
		prop: 'taskSource',
		label: '任务来源',
		filter: codeFilter('taskSource'),
    width:100
	},
	{
		prop: 'createTime',
		label: '创建时间',
		filter: parseTime,
    width:150
	},
	{
		prop: 'cancellation',
		label: '是否取消',
		filter: codeFilter('cancellation'),
    width:90
	},
];
const mainTaskType = [
	{
		name: '入库',
		id: 1,
	},
	{
		name: '出库',
		id: 2,
	},
	{
		name: '移库',
		id: 3,
	},
	{
		name: '出库+移库',
		id: 4,
	},
	{
		name: '不带agv入库',
		id: 5,
	},
	{
		name: '不带agv出库',
		id: 6,
	},
	{
		name: '入库+6臂空托盘出库',
		id: 7,
	},
	{
		name: '不带agv出库+移库',
		id: 8,
	},
	{
		name: '入库+12臂空托盘出库',
		id: 9,
	},
	{
		name: '平库移库',
		id: 10,
	},
	{
		name: '盘库出库',
		id: 11,
	},
	{
		name: '盘库入库',
		id: 12,
	},
	{
		name: '盘库出库+移库',
		id: 13,
	},
];
const mainTaskState = [
	{
		name: '开始',
		id: 0,
	},
	{
		name: '已发送agv',
		id: 1,
	},
	{
		name: 'agv运行中',
		id: 2,
	},
	{
		name: '已发送堆垛机',
		id: 3,
	},
	{
		name: '堆垛机运行中',
		id: 4,
	},
	{
		name: '完成',
		id: 5,
	},
	{
		name: '已发送传输线',
		id: 6,
	},
	{
		name: '传输线运行中',
		id: 7,
	},
	{
		name: '暂时无空托盘',
		id: 8,
	},
];
const stackerArr = [
	{
		name: 'DDJ1',
		id: 1,
	},
	{
		name: 'DDJ2',
		id: 2,
	},
	{
		name: 'DDJ3',
		id: 3,
	},
	{
		name: 'DDJ4',
		id: 4,
	},
];
export default {
	mixins: [basicPage],
	data() {
		return {
			urlOptions: {
				getDataListURL: getMainTaskHistoryPage,
				exportURL: exportMainTaskHistoryExcel,
			},
			tableProps,
			tableData: [],
			formConfig: [
				{
					type: 'input',
					label: '任务编码',
					placeholder: '任务编码',
					param: 'code',
				},
				{
					type: 'select',
					label: '任务类型',
					selectOptions: mainTaskType,
					param: 'taskType',
					defaultSelect: '',
					filterable: true,
				},
				{
					type: 'input',
					label: '托盘编码',
					placeholder: '托盘编码',
					param: 'tcode',
				},
				// {
				// 	type: 'select',
				// 	label: '状态',
				// 	selectOptions: mainTaskState,
				// 	param: 'status',
				// 	defaultSelect: '',
				// 	filterable: true,
				// },
				{
					type: 'select',
					label: '堆垛机',
					selectOptions: stackerArr,
					param: 'stacker',
					defaultSelect: '',
					filterable: true,
				},
				{
					type: 'select',
					label: 'agv',
					selectOptions: [],
					param: 'agv',
					defaultSelect: '',
					filterable: true,
				},
				{
					type: 'datePicker',
					label: '选择日期',
					dateType: 'daterange',
					format: 'yyyy-MM-dd',
					valueFormat: 'yyyy-MM-dd HH:mm:ss',
					rangeSeparator: '-',
					startPlaceholder: '开始时间',
					endPlaceholder: '结束时间',
					param: 'searchTime',
				},
				{
					type: 'button',
					btnName: '搜索',
					name: 'search',
					color: 'primary',
				},
				{
					type: 'button',
					btnName: '重置',
					name: 'reset',
				},
				{
					type: 'button',
					btnName: '导出',
					name: 'export',
					color: 'primary',
					plain: true,
				},
			],
		};
	},
	components: {},
	created() {
    this.listQuery.mainTaskState = 5;
    this.setFormConfig();
	},
	methods: {
		setFormConfig() {
			for (let i = 1; i <= 16; i++) {
				const obj = {
					id: i,
					name: i,
				};
				this.formConfig[4].selectOptions.push(obj);
			}
		},
		buttonClick(val) {
			switch (val.btnName) {
				case 'search':
					this.listQuery.pageNo = 1;
					this.listQuery.pageSize = 10;
					this.listQuery.mainTaskCode = val.code;
					this.listQuery.mainTaskType = val.taskType;
					this.listQuery.barCode = val.tcode;
					// this.listQuery.mainTaskState = val.status;
					this.listQuery.mainTaskState = 5;
					this.listQuery.stacker = val.stacker;
					this.listQuery.agv = val.agv;
					this.listQuery.createTime = val.searchTime;
					this.listQuery.startTime = val.searchTime ? val.searchTime[0] : '';
					this.listQuery.endTime = val.searchTime ? val.searchTime[1] : '';
					this.getDataList();
					break;
				case 'reset':
					this.$refs.searchBarForm.resetForm();
					this.listQuery = {
						warehouseId: '1696803324030865409',
						pageSize: 10,
						pageNo: 1,
						total: 1,
            mainTaskState : 5
					};
					this.getDataList();
					break;
				case 'export':
					this.listQuery.pageNo = undefined;
					this.listQuery.pageSize = undefined;
					this.listQuery.mainTaskCode = val.code;
					this.listQuery.mainTaskType = val.taskType;
					this.listQuery.barCode = val.tcode;
					// this.listQuery.mainTaskState = val.status;
					this.listQuery.mainTaskState = 5;
					this.listQuery.stacker = val.stacker;
					this.listQuery.agv = val.agv;
					this.listQuery.createTime = val.searchTime;
					this.listQuery.startTime = val.searchTime ? val.searchTime[0] : '';
					this.listQuery.endTime = val.searchTime ? val.searchTime[1] : '';
					this.handleExport(this.listQuery, '历史任务导出');
					break;
				default:
					console.log(val);
			}
		},
	},
};
</script>
