<template>
	<view class="bg-f9 lineManagement">
		<header-bar :title="submitType === 'add' ? '线边详情' : '线边详情'"></header-bar>
		<view class="commons-dtl-box">
			 <view class="">
			 	<span>产线名称</span> 车间/3ml生产线
			 </view>
			 <view class=""> 
			 	<span>产品名称</span> pp 原料
			 </view> 
			 <view class="">
			 	<span>线边数量</span> 8000
			 </view> 
		</view>
		<view style="line-height: 60rpx;font-size: 24rpx;padding: 0 20rpx;"> 
		 	今日统计
		</view>
		<view class="today-num" style="border-bottom: 1px solid #dcdcdc;">
			<p>今日领料</p>
			<span>3000</span> 
		</view>
		<view class="today-num">
			<p>今日消耗</p>
			<span>3000</span>
		</view>
		<view style="line-height: 60rpx;font-size: 24rpx;padding: 0 20rpx;">
		 	今日明细 
		</view>
		<ul>
			<li>
				<view>
					<span>操作人</span> 张三
				</view>
				<view>
					<span>操作时间</span> 2032-22-11
				</view>
				<view>
					<span>领料数量</span> 1500
				</view>
			</li>
			<li>
				<view>
					<span>操作人</span> 张三
				</view>
				<view>
					<span>操作时间</span> 2032-22-11
				</view>
				<view>
					<span>领料数量</span> 1500
				</view>
			</li>
		</ul>
		<view style="height:200rpx">
			
		</view>
		<button class="submit" @click="toSubmit">消耗登记</button>
	</view>
</template>

<script>
	import headerBar from '../../../components/header-bar/index.vue'
	import {formateObjToParamStr} from '../../../util/uitl.js'
	import Vue from 'vue'
	export default {
		components: {
			headerBar
		},
		data() {
			return {
				form: {
					name: '',
					type: null,
					classifyId: null,
					code: null,
					unit: null,
					introduce: null,
				},
				types: [{
					text: '半成品',
					value: '0'
				}, {
					text: '成品',
					value: '1'
				}],
				rules: {
					// 对name字段进行必填验证
					name: {
						rules: [{
							required: true,
							errorMessage: '请输入产品名称',
						}, ]
					},
					// 对email字段进行必填验证
					type: {
						rules: [{
							required: true,
							errorMessage: '请选择工作人员',
						}, ]
					},
					unit: {
						rules: [{
							required: true,
							errorMessage: '请输入完工数量',
						}, ]
					},
					num: {
						rules: [{
							required: true,
							errorMessage: '请输入本次入库',
						}, ]
					},
					
					
				},
				submitType: 'add',
				treeData: [],
			}
		},
		onLoad(e) {
			if (e.id) {
				this.form.id = e.id
				this.form.remarks = e.remarks
				this.form.type = e.type
				this.form.name = e.name
				this.submitType = 'edit'
			}
			this.getTree()
		},
		methods: {
			toSubmit(){
				uni.navigateTo({
					url: '/pages/lineManagement/submit?' + formateObjToParamStr(this.form)
				})
			},
			treeChange() {},
			getTree() {
				const v = this
				v.$post('/api/basics//classify/tree', {
					type: 1
				}).then(res => {
					if (res.code === 200) {
						v.treeData = res.data
					}

				})
			},
			submitForm() {
				const v = this
				this.$refs.form.validate().then(res => {
					uni.showLoading({
						title: '加载中'
					});
					v.$post('/api/syringe-management/product/' + this.submitType, v.form).then(res => {
						if (res.code === 200) {
							uni.showToast({
								title: this.submitType == 'add' ? '添加成功' : '修改成功',
								duration: 1000,
								icon: 'success'
							})
						}
						uni.hideLoading()
						let pages = getCurrentPages(); // 获取页面栈
						let prePage = pages[pages.length - 2]; //获取上一页
						prePage.$vm.needRefresh = true; // 需要刷新
						setTimeout(() => {
							uni.navigateBack(1)
						}, 1000)
					})
				}).catch(err => {
					console.log('表单错误信息：', err);
				})
			},
		},
	}
</script>

<style lang="less">
	.lineManagement{
		ul{
			background-color: #fff;
			font-size: 24rpx;
			padding: 10rpx 20rpx;
			line-height: 60rpx;
			li{
				 list-style: none;
				 border-bottom: 1rpx solid #dcdcdc;
				 span{
					 display: inline-block;
					 width: 150rpx; 
					 color: #666;
				 }
			}
		}
	}
	.today-num{
		background-color: #fff;
		padding:10rpx 20rpx;
		font-size: 24rpx;
		color: #333;
	}
</style>
