<template>
	<div class="app-container">
		<el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="98px">
		    <el-form-item label="生产日期" prop="productDateArray">
				<el-date-picker
					v-model="queryParams.productDateArray"
					value-format="yyyy-MM-dd"
					type="daterange"
					range-separator="至"
					start-placeholder="开始日期"
					end-placeholder="结束日期">
				</el-date-picker>
			</el-form-item>
			<el-form-item label="工单编号" prop="workorderCode">
				<el-input
					v-model="queryParams.workorderCode"
					placeholder="请输入工单编号"
					clearable
				/>
			</el-form-item>
			<el-form-item label="订单编码" prop="orderCode">
				<el-input
					v-model="queryParams.orderCode"
					placeholder="请输入订单编号"
					clearable
				/>
			</el-form-item>
			<el-form-item label="产品编号" prop="productCode">
				<el-input
					v-model="queryParams.productCode"
					placeholder="请输入产品编码"
					clearable
				/>
			</el-form-item>
			<el-form-item label="产品名称" prop="productName">
				<el-input
					v-model="queryParams.productName"
					placeholder="请输入产品名称"
					clearable
					@keyup.enter.native="handleQuery"
				/>
			</el-form-item>
			<el-form-item label="规格型号" prop="productSpc">
				<el-input
					v-model="queryParams.productSpc"
					placeholder="请输入规格型号"
					clearable
					@keyup.enter.native="handleQuery"
				/>
			</el-form-item>

			<el-form-item>
				<el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
				<el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
			</el-form-item>
		</el-form>

		<el-row :gutter="10" class="mb8">
			<el-col :span="1.5">
				<el-button
					type="warning"
					plain
					icon="el-icon-download"
					size="mini"
					@click="handleExport"
					v-hasPermi="['mes:prepare:export']"
				>导出</el-button>
			</el-col>
			<right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
		</el-row>

		<el-table v-loading="loading" :data="prepareList">
			<el-table-column type="selection" width="55" align="center" />
			<!-- 序号 -->
            <el-table-column type="index" align="center" :index="indexMethod" label="序号"/>
			<el-table-column label="工单生产日期" align="center" prop="productDate" width="120">
				<!--<template slot-scope="scope"><span>{{ parseTime(scope.row.productDate, '{y}-{m}-{d}') }}</span></template>-->
			</el-table-column>
			<el-table-column label="订单编号" align="center" prop="orderCode" width="130"/>
			<el-table-column label="工单编号" align="center" prop="workorderCode" width="130"/>
			<el-table-column label="产品编码" align="center" prop="productCode" width="130"/>
			<el-table-column label="产品名称" align="center" prop="productName" width="160"/>
			<el-table-column label="规格型号" align="center" prop="productSpc" />
			<el-table-column label="工序编码" align="center" prop="processCode" />
			<el-table-column label="工序名称" align="center" prop="processName" width="90"/>
			<el-table-column label="工单排产数量" align="center" prop="quantity" width="100"/>
			<el-table-column label="已生产数量" align="center" prop="quantityFeedback" width="100"/>
			<el-table-column label="单位" align="center" prop="unit" />
		</el-table>

		<pagination
			v-show="total>0"
			:total="total"
			:page.sync="queryParams.pageNum"
			:limit.sync="queryParams.pageSize"
			@pagination="getList"
		/>

		
	</div>
</template>

<script>
import { getProcessFinishList} from "@/api/mes/reportWork";
import moment from 'moment';
export default {
	name: "Prepare",
	data() {
		return {
			// 遮罩层
			loading: true,
			// 选中数组
			ids: [],
			// 非单个禁用
			single: true,
			// 非多个禁用
			multiple: true,
			// 显示搜索条件
			showSearch: true,
			// 总条数
			total: 0,
			// 备料单表格数据
			prepareList: [],
			// 弹出层标题
			title: "",
			// 是否显示弹出层
			open: false,
			// 查询参数
			queryParams: {
				productDateArray: [new Date(),new Date()],
				pageNum: 1,
				pageSize: 10,
				workorderCode: null,
				workorderName: null,
				parentOrder: null,
				orderId: null,
				orderCode: null,
				productId: null,
				productCode: null,
				prodType: null,
				productName: null,
				productSpc: null,
				wetDetailPlanId: null,
				productDate: null,
				shiftId: null,
				ancestors: null,
				status: null,
				attr1: null,
				attr2: null,
				attr3: null,
				attr4: null,
				factoryCode: null
			},
			// 表单参数
			form: {},
			// 表单校验
			rules: {}
		};
	},
	created() {
		this.getList();
	},
	methods: {
		indexMethod(index){
		   return index+1 ;
		},
		/** 查询备料单列表 */
		getList() {

			if(this.queryParams.productDateArray!=null){
				this.queryParams.productDateStart = moment(this.queryParams.productDateArray[0]).format('YYYY-MM-DD');
				this.queryParams.productDateEnd = moment(this.queryParams.productDateArray[1]).format('YYYY-MM-DD');
			}
			
			this.loading = true;
			getProcessFinishList(this.queryParams).then(response => {
				this.prepareList = response.rows;
				this.total = response.total;
				this.loading = false;
			});
		},
		// 取消按钮
		cancel() {
			this.open = false;
			this.reset();
		},
		// 表单重置
		reset() {
			this.form = {
				prepareId: null,
				workorderCode: null,
				workorderName: null,
				parentOrder: null,
				orderId: null,
				orderCode: null,
				productId: null,
				productCode: null,
				prodType: null,
				productName: null,
				productSpc: null,
				wetDetailPlanId: null,
				productDate: null,
				shiftId: null,
				ancestors: null,
				status: null,
				remark: null,
				attr1: null,
				attr2: null,
				attr3: null,
				attr4: null,
				createBy: null,
				createTime: null,
				updateBy: null,
				updateTime: null,
				factoryCode: null
			};
			this.resetForm("form");
		},
		/** 搜索按钮操作 */
		handleQuery() {
			this.queryParams.pageNum = 1;
			this.getList();
		},
		/** 重置按钮操作 */
		resetQuery() {
			this.resetForm("queryForm");
			this.handleQuery();
		},

		/** 导出按钮操作 */
		handleExport() {
			this.download('mes/reportWork/processFinishExport', {
				...this.queryParams
			}, `processFinish_${new Date().getTime()}.xlsx`)
		}
	}
};
</script>
