<template>
	<div class="app-container">
		<search-bar
			:formConfigs="formConfig"
			ref="searchBarForm"
			:isFold="true"
			@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 { getPage, exportExcel } from '@/api/oth/rollMessage';

const tableProps = [
	{
		prop: 'workOrderCode',
		label: '入库单号',
		width: 170,
	},
	{
		prop: 'process',
		label: '工序',
	},
	{
		prop: 'trayCode',
		label: '托盘编码',
	},
	{
		prop: 'warehouseCode',
		label: '库房编码',
	},
	{
		prop: 'lineId',
		label: '行号',
	},
	{
		prop: 'cureTime',
		label: '已熟化时间',
		width: 90,
	},
	{
		prop: 'inventory',
		label: '膜卷号',
		width: 167,
	},
	{
		prop: 'locationType',
		label: '货位类型',
	},
	{
		prop: 'batchCode',
		label: '批次号',
	},
	{
		prop: 'containerCode',
		label: '托盘',
	},
	{
		prop: 'subContainerCode',
		label: '悬臂',
	},
	{
		prop: 'productCode',
		label: '物料编码',
		width: 120,
	},
	{
		prop: 'description',
		label: '产品名',
	},
	{
		prop: 'planQty',
		label: '数量',
	},
	{
		prop: 'orderFrom',
		label: '产出工单',
		width: 100,
	},
	{
		prop: 'finishTime',
		label: '完成日期',
		filter: parseTime,
		width: 150,
	},
	{
		prop: 'customerSpName',
		label: '客户',
	},
	{
		prop: 'destPoint',
		label: '目的码头',
	},
	{
		prop: 'resources',
		label: '资源',
	},
	{
		prop: 'grade',
		label: '品质',
	},
	{
		prop: 'bugCode',
		label: '复判缺陷',
	},
	{
		prop: 'gradingExplain',
		label: '复判不良说明',
		width: 100,
	},
	{
		prop: 'model',
		label: '型号',
	},
	{
		prop: 'itype',
		label: '物料类型',
	},
	{
		prop: 'itypeDes',
		label: '物料类型描述',
		width: 100,
	},
	{
		prop: 'customCode',
		label: '客户编码',
	},
	{
		prop: 'sfcCreateTime',
		label: '膜卷生产时间',
		filter: parseTime,
		width: 150,
	},
	{
		prop: 'createTime',
		label: '创建时间',
		filter: parseTime,
		width: 150,
	},
];
export default {
	mixins: [basicPage],
	data() {
		return {
			urlOptions: {
				getDataListURL: getPage,
				exportURL: exportExcel,
			},
			tableProps,
			tableData: [],
      getTrayCode: undefined,
			formConfig: [
				{
					type: 'input',
					label: '托盘编码',
					placeholder: '托盘编码',
					param: 'code',
				},
				{
					type: 'input',
					label: '工序',
					placeholder: '工序',
					param: 'process',
				},
				{
					type: 'input',
					label: '膜卷号',
					placeholder: '膜卷号',
					param: 'rollCode',
				},
				{
					type: 'input',
					label: '产品名',
					placeholder: '产品名',
					param: 'productName',
				},
				{
					type: 'input',
					label: '品质',
					placeholder: '品质',
					param: 'grade',
				},
				{
					type: 'input',
					label: '入库单号',
					placeholder: '入库单号',
					param: 'workOrderCode',
				},
				{
					type: 'datePicker',
					label: '创建时间',
					dateType: 'datetimerange',
					format: 'yyyy-MM-dd HH:mm:ss',
					valueFormat: 'yyyy-MM-dd HH:mm:ss',
					rangeSeparator: '-',
					startPlaceholder: '开始时间',
					endPlaceholder: '结束时间',
					param: 'searchTime',
				},
				{
					type: 'button',
					btnName: '搜索',
					name: 'search',
					color: 'primary',
				},
				{
					type: 'button',
					btnName: '导出',
					name: 'export',
					color: 'primary',
					plain: true,
				},
			],
		};
	},
	components: {},
	created() {
    this.listQuery.trayCode = this.$route.query && this.$route.query.trayCode
    this.formConfig[0].placeholder = this.listQuery.trayCode || '托盘编码'
    this.getDataList();
  },
	methods: {
		buttonClick(val) {
			switch (val.btnName) {
				case 'search':
					this.listQuery.pageNo = 1;
					this.listQuery.pageSize = 10;
					this.listQuery.trayCode = val.code.trim() || null;
					this.listQuery.process = val.process.trim() || null;
					this.listQuery.rollCode = val.rollCode.trim() || null;
					this.listQuery.productName = val.productName.trim() || null;
					this.listQuery.grade = val.grade.trim() || null;
					this.listQuery.workOrderCode = val.workOrderCode.trim() || null;
					this.listQuery.startTime = val.searchTime ? val.searchTime[0] : null;
					this.listQuery.endTime = val.searchTime ? val.searchTime[1] : null;
					this.getDataList();
					break;
				case 'reset':
					this.$refs.searchBarForm.resetForm();
					this.listQuery = {
						pageSize: 10,
						pageNo: 1,
						total: 1,
					};
					this.getDataList();
					break;
				case 'export':
					this.listQuery.trayCode = val.code || null;
					this.listQuery.process = val.process || null;
					this.listQuery.rollCode = val.rollCode || null;
					this.listQuery.productName = val.productName || null;
					this.listQuery.grade = val.grade || null;
					this.listQuery.workOrderCode = val.workOrderCode || null;
					this.listQuery.startTime = val.searchTime ? val.searchTime[0] : null;
					this.listQuery.endTime = val.searchTime ? val.searchTime[1] : null;
					this.handleExport();
					break;
				default:
					console.log(val);
			}
		},
		/** 导出按钮操作 */
		handleExport() {
			// 处理查询参数
			this.$modal
				.confirm('是否确认导出所有数据项?')
				.then(() => {
					this.exportLoading = true;
					return this.urlOptions.exportURL(this.listQuery);
				})
				.then((response) => {
					this.$download.excel(response, '膜卷信息.xls');
					this.exportLoading = false;
				})
				.catch(() => {});
		},
	},
};
</script>
