<template>
	<view>
		<uni-nav-bar fixed="true" statusBar="true" left-icon="back" title="选择备品备件" @clickLeft="back"></uni-nav-bar>
		<SparePart @submitList="submit"></SparePart>
	</view>
</template>

<script>
	import SparePart from '@/components/SparePart.vue'
	import {
		get,
		postJ
	} from "@/utils/api.js"
	export default {
		components: {
			SparePart
		},
		data() {
			return {
				pageId: '',
				list: []
			}
		},
		onLoad(options) {
			//巡检点
			this.pageId = options.id;
		},
		methods: {
			submit(data) {
				let list = data;
			
				let pickData = list.filter((item) => {
					return item.checked && !item.disabled && (item.num > 0)
				})
			
				if (pickData.length == 0) {
					uni.showToast({
						title: "请选择备品备件数量",
						icon: 'none',
						duration: 2000
					})
					return
				}
				
				
				pickData.forEach(el=>{
					el.goodsName=el.type.name
					el.goodsBatch = el.batchNo
					if (el.type) {
					  el.goodsTypeCode = el.type.id;
					}
					el.manageType = el.manageType.id;
					delete el.type;
					delete el.status;
				})
				
				let form = {
					"goodsType": 3,
					"supplier": {
						"id": "7",
						"name": "回到家撒卡卡"
					},
					"executor": {
						"id": 4,
						"name": "欧阳峰"
					},
					"warehouse": {
						"id": "5",
						"name": "凯凯仓库"
					},
					"attaments": [],
					"outType": 2,
					"receiveName": "黄凯",
					"receiveTime": "2023-05-26 00:00:00",
					"receivePhone": "15512341234",
					"remark": "出库备注",
					"details": pickData
				}
				this.back()
				// postJ(this.apiWebUrl+ "/api/repair/worksheet/applyspare?id="+this.pageId,form).then(res=>{
				// 	console.log(res)
				// 	this.back()
				// }).catch(err=>{
				// 	uni.showToast({
				// 		title:'操作失败',
				// 		icon:'none'
				// 	})
				// })
				//this.$store.dispatch("tour_tally/setSparepart", sparepartInfo);
				
				

			}
			

		}
	}
</script>

<style lang="scss" scoped>
	
</style>
