<template>
	<!-- 配料任务 -->
	<view>
		<uni-card :title="title">
			<text>{{ note }}</text>
		</uni-card>
		<uni-list style="width: 100%">
			<uni-list-item v-for="(item, index) in workOrderTaskList" :key="index" :title="item.title" link rightText="任务详情" @click="onListItemClick(item)"></uni-list-item>
		</uni-list>
		<view>
			<button type="primary" @click="toScanBatching">扫码配料</button>
		</view>
	</view>
</template>

<script>
import { getWorkOrderTaskList, getTaskInfoList } from '@/api/preparationTask/index.js';
import { tansParams } from '@/utils/common';
export default {
	onLoad: function (option) {
		this.workOrder = option.workOrder;
		this.title = option.title;
		this.note = option.note;
	},
	onShow:function(){
		this.$nextTick(() => {
			this.doGetWorkOrderTaskList();
		});
	},
	data() {
		return {
			title: '',
			note: '',
			workOrder: '',
			workOrderTaskList: []
		};
	},
	methods: {
		doGetWorkOrderTaskList() {
			uni.showLoading();
			const params = {
				workorder: this.workOrder
			};
			getWorkOrderTaskList(params)
				.then((res) => {
					if (res.code === 200) {
						this.workOrderTaskList = res.data.map((item) => {
							return {
								id: item.id,
								workOrder: item.fkWorkorder,
								taskCode: item.taskCode,
								title: `任务号：${item.taskCode}`,
								taskList: []
							};
						});
					}
				})
				.finally(() => {
					uni.hideLoading();
				});
		},
		// 工单点击
		onListItemClick(item) {
			const params = {
				taskCode: item.taskCode,
				title: item.title
			};
			uni.navigateTo({
				url: '/pages/materialManagement/materialPreparation/taskDetail?' + tansParams(params)
			});
		},
		toScanBatching() {
			const params = {
				workOrder: this.workOrder
			};
			uni.navigateTo({
				url: '/pages/materialManagement/materialPreparation/scanAddBatching?' + tansParams(params)
			});
		}
	}
};
</script>

<style></style>
