<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">
			<method-btn
				v-if="tableBtn.length"
				slot="handleBtn"
				:width="90"
				label="操作"
				:method-list="tableBtn"
				@clickBtn="handleClick" />
		</base-table>
		<pagination
			:limit.sync="listQuery.pageSize"
			:page.sync="listQuery.pageNo"
			:total="listQuery.total"
			@pagination="getDataList" />
		<add-or-update
			v-if="addOrUpdateVisible"
			ref="addOrUpdate"
			@refreshDataList="getDataList" />
	</div>
</template>

<script>
import basicPage from '../mixins/basic-page';
import { parseTime } from '../mixins/code-filter';
import codeFilter from '../mixins/code-filter';
import { getWarehousePklbPage } from '@/api/asrs/warehousePklb';
import AddOrUpdate from './add-or-updata';

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: '状态',
		filter: codeFilter('mainTaskState'),
	},
	{
		prop: 'statepk',
		label: '盘库状态',
		filter: codeFilter('statepk'),
	},
	{
		prop: 'taskSource',
		label: '任务来源',
		filter: codeFilter('taskSource'),
		width: 100,
	},
	{
		prop: 'createTime',
		label: '创建时间',
		filter: parseTime,
		width: 150,
	},
];
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,
	},
];
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,
	},
	{
		name: '已处理',
		id: 9,
	},
];
export default {
	mixins: [basicPage],
	data() {
		return {
			urlOptions: {
				getDataListURL: getWarehousePklbPage,
			},
			listQuery: {
				pageSize: 10,
				pageNo: 1,
				total: 1,
			},
			tableProps,
			tableBtn: [
				{
					type: 'check',
					btnName: '检查',
					showParam: {
						type: '&',
						data: [
							{
								type: 'equal',
								name: 'mainTaskState',
								value: 5,
							},
						],
					},
				},
				{
					type: 'detail',
					btnName: '详情',
					showParam: {
						type: '&',
						data: [
							{
								type: 'equal',
								name: 'mainTaskState',
								value: 9,
							},
						],
					},
				},
			],
			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: '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',
				},
			],
		};
	},
	components: {
		AddOrUpdate,
	},
	created() {
		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.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,
					};
					this.getDataList();
					break;
				default:
					console.log(val);
			}
		},
		otherMethods(val) {
			if (val.type === 'check') {
				this.addOrUpdateVisible = true;
				this.addOrEditTitle = '盘货明细表';
				this.$nextTick(() => {
					this.$refs.addOrUpdate.init(val.data, false);
				});
			} else if (val.type === 'detail') {
				this.addOrUpdateVisible = true;
				this.addOrEditTitle = '盘货明细表';
				this.$nextTick(() => {
					this.$refs.addOrUpdate.init(val.data, true);
				});
			}
		},
	},
};
</script>
