<!--
 * @Author: zhp
 * @Date: 2023-09-11 14:21:21
 * @LastEditTime: 2023-09-11 14:26:04
 * @LastEditors: zhp
 * @Description:
-->
<template>
	<div class="app-container">
		<search-bar
			:formConfigs="formConfig"
			ref="searchBarForm"
			@headBtnClick="buttonClick" />
		<base-table
			v-loading="dataListLoading"
			:table-props="tableProps"
			:page="listQuery.pageNo"
			:limit="listQuery.pageSize"
			:table-data="tableData" />
		<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 { getLineBindProductLogPage } from '@/api/core/base/lineBindProductLog';
import { getProductionLinePage } from '@/api/core/base/productionLine';
import { getWorkshopSectionPage } from '@/api/core/base/workshopSection';

const tableProps = [
	{
		prop: 'productionLineName',
		label: '产线名称',
		align: 'center',
	},
  {
    prop: '',
    label: '工段名称',
    align: 'center',
  },
  {
    prop: '',
    label: '进片数量/片',
    align: 'center',
  },
  {
    prop: '',
    label: '出片数量/片',
    align: 'center',
  },
  {
    prop: '',
    label: '损耗数量/片',
    align: 'center',
  },
  {
    prop: '',
    label: '损耗面积/m²',
    align: 'center',
  },
  {
    prop: '',
    label: '损耗比例/%',
    align: 'center',
  }
];

export default {
	mixins: [basicPage],
	data() {
		return {
			urlOptions: {
				getDataListURL: getLineBindProductLogPage,
			},
			tableProps,
			tableData: [],
      optionArrUrl: [getProductionLinePage, getWorkshopSectionPage],
			formConfig: [
				{
					type: 'select',
					label: '产线',
					selectOptions: [],
					param: 'productionLineId',
					defaultSelect: '',
					filterable: true,
				},
				{
					type: 'datePicker',
					label: '时间',
					dateType: 'daterange',
					format: 'yyyy-MM-dd',
					valueFormat: 'yyyy-MM-dd HH:mm:ss',
					rangeSeparator: '-',
					startPlaceholder: '开始时间',
					endPlaceholder: '结束时间',
					param: 'createTime',
				},
				{
					type: 'button',
					btnName: '搜索',
					name: 'search',
					color: 'primary',
				},
				{
					type: 'button',
					btnName: '导出',
					name: 'export',
				},
			],
		};
	},
	components: {
	},
	created() {
		this.getArr();
	},
	methods: {
		getArr() {
			const params = {
				page: 1,
				limit: 500,
			};
			this.optionArrUrl.forEach((item, index) => {
				item(params).then((response) => {
					this.formConfig[index].selectOptions = response.data.list;
				});
			});
		},
		buttonClick(val) {
			switch (val.btnName) {
				case 'search':
					this.listQuery.pageNo = 1;
					this.listQuery.pageSize = 10;
					this.listQuery.productionLineId = val.productionLineId;
					this.listQuery.productId = val.productId;
					this.listQuery.createTime = val.createTime;
					this.getDataList();
					break;
				case 'reset':
					this.$refs.searchBarForm.resetForm();
					this.listQuery = {
						pageSize: 10,
						pageNo: 1,
						total: 1,
					};
					this.getDataList();
					break;
				default:
					console.log(val);
			}
		},
	},
};
</script>
