<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="80"
				label="操作"
				:method-list="tableBtn"
				@clickBtn="handleClick" />
		</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 { getMainTaskPage, deleteMainTask } from '@/api/oth/mainTask';

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: 'agv',
		label: 'agv',
	},
	{
		prop: 'mainTaskState',
		label: '状态',
		filter: codeFilter('mainTaskState'),
    width:110
	},
	{
		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,
	},
];
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,
	},
];
const agvArr = [
	{
		name: 'A1',
		id: 1,
	},
	{
		name: 'A2',
		id: 2,
	},
	{
		name: 'A3',
		id: 3,
	},
];
export default {
	mixins: [basicPage],
	data() {
		return {
			urlOptions: {
				getDataListURL: getMainTaskPage,
				deleteURL: deleteMainTask,
			},
      listQuery: {
        pageSize: 10,
        pageNo: 1,
        total: 1,
      },
			tableProps,
			tableBtn: [
				{
					type: 'canlce',
					btnName: '取消',
				},
			],
			tableData: [],
			formConfig: [
				{
					type: 'input',
					label: '任务编码',
					placeholder: '任务编码',
					param: 'code',
				},
				{
					type: 'select',
					label: '任务类型',
					selectOptions: mainTaskType,
					param: 'taskType',
					defaultSelect: '',
					filterable: true,
				},
				{
					type: 'select',
					label: '状态',
					selectOptions: mainTaskState,
					param: 'status',
					defaultSelect: '',
					filterable: true,
				},
				{
					type: 'select',
					label: 'agv',
					selectOptions: agvArr,
					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: {},
	created() {},
	methods: {
		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.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 = {
						pageSize: 10,
						pageNo: 1,
						total: 1,
					};
					this.getDataList();
					break;
				default:
					console.log(val);
			}
		},
    otherMethods(val){
      this.$confirm(`确定对${'[任务编码=' + val.data.mainTaskCode + ']'}进行取消操作?`, "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning",
      })
        .then(() => {
          this.urlOptions.deleteURL(val.data.id).then(({ data }) => {
            this.$message({
              message: "操作成功",
              type: "success",
              duration: 1500,
              onClose: () => {
                this.getDataList();
              },
            });
          });
        })
        .catch(() => { });
    },
	},
};
</script>
