<template>
	<view>
		<view class="white-card">
			<view class="list-list">
				<view class="list-title">物料编号</view>
				<view class="list-right">
					<text>{{CyInfo.product_number}}</text>
				</view>
			</view>
			<view class="list-list">
				<view class="list-title">填报日期</view>
				<view class="list-right">
					<text>{{CyInfo.production}}</text>
				</view>
			</view>
			<view class="list-list">
				<view class="list-title">线别</view>
				<view class="list-right">
					<text>{{CyInfo.line_title}}</text>
					<!-- <image class="next" src="../../static/next.png"></image> -->
				</view>
			</view>	
			<picker @change="bindline" :value="froms.frequency" :range="line">
			<view class="list-list">
				<view class="list-title">班次</view>
				<view class="list-right">
					<text>{{line[froms.frequency]}}</text>
					<image class="next" src="../../static/xiala.png"></image>
				</view>
			</view>
			</picker>
		</view>
		<view class="white-card" style="margin-top: 30upx;">
			<picker @change="bindReason" :value="reasonIds" :range="reason">
			<view class="list-list">
				<view class="list-title">停线原因</view>
				<view class="list-right">
					<text>{{reason[reasonIds]}}</text>
					<image class="next" src="../../static/next.png"></image>
				</view>
			</view>
			</picker>
		</view>
		<view class="big-titlt">模具维修</view>
		<view class="white-card">
			<picker @change="bindmouldIds" :value="froms.device[0].device_id" :range="deviceNo">
			<view class="list-list">
				<view class="list-title">设备编号</view>
				<view class="list-right">
					<text>{{deviceNo[froms.device[0].device_id-1]}}</text>
					<image class="next" src="../../static/next.png"></image>
				</view>
			</view>
			</picker>
			<view class="list-list">
				<view class="list-title">异常现象</view>
				<view class="list-right">
					<input placeholder="请输入异常现象" v-model="froms.device[0].unusual_phenomenon" />
				</view>
			</view>
			<view class="list-list">
				<view class="list-title">原因分析</view>
				<view class="list-right">
					<input placeholder="请输入原因分析" v-model="froms.device[0].cause_analysis" />
				</view>
			</view>
			<view class="list-list">
				<view class="list-title">维修描述</view>
				<view class="list-right">
					<input placeholder="请输入维修描述"  v-model="froms.device[0].repair_description"  />
				</view>
			</view>
			<view class="list-list">
				<view class="list-title">维修时长</view>
				<view class="list-right">
					<input placeholder="请输入维修时长" v-model="froms.device[0].repair_time"  />
				</view>
			</view>
			<view class="list-list">
				<view class="list-title">维修人员</view>
				<view class="list-right">
					<input placeholder="请输入维修人员" v-model="froms.device[0].repair_staff"  />
				</view>
			</view>
			<view class="bzqk-card">
				<textarea value=""  v-model="froms.device[0].remark"  placeholder="备注情况说明" />
			</view>
		</view>
		<view class="big-titlt">设备维修</view>
		<view class="white-card">
			<picker @change="bindmodeIds" :value="froms.mode[0].mode_id" :range="mould">
			<view class="list-list">
				<view class="list-title">模具编号</view>
				<view class="list-right">
					<text>{{mould[froms.mode[0].mode_id-1]}}</text>
					<image class="next" src="../../static/next.png"></image>
				</view>
			</view>
			</picker>
			<view class="list-list">
				<view class="list-title">异常现象</view>
				<view class="list-right">
					<input placeholder="请输入异常现象" v-model="froms.mode[0].unusual_phenomenon" />
				</view>
			</view>
			<view class="list-list">
				<view class="list-title">原因分析</view>
				<view class="list-right">
					<input placeholder="请输入原因分析" v-model="froms.mode[0].cause_analysis" />
				</view>
			</view>
			<view class="list-list">
				<view class="list-title">维修描述</view>
				<view class="list-right">
					<input placeholder="请输入维修描述"  v-model="froms.mode[0].repair_description"  />
				</view>
			</view>
			<view class="list-list">
				<view class="list-title">维修时长</view>
				<view class="list-right">
					<input placeholder="请输入维修时长" v-model="froms.mode[0].repair_time"  />
				</view>
			</view>
			<view class="list-list">
				<view class="list-title">维修人员</view>
				<view class="list-right">
					<input placeholder="请输入维修人员" v-model="froms.mode[0].repair_staff"  />
				</view>
			</view>
			<view class="bzqk-card">
				<textarea value="" placeholder="备注情况说明" v-model="froms.mode[0].remark" />
			</view>
			
		</view>
		<view class="submit-btn">
			<button type="primary" @tap="stopLine()">提交并发起审核</button>
		</view>
	</view>
</template>

<script>
	import {stopLineReason,device,mode,stopRecord} from "../../api/user.js"
	export default {
		data() {
			return {
				line:["A线","B线"],
				lineIndex:0,
				frequency:["白班","夜班"],
				frequencyIds:0,
				reason:["模具维修","设备维修","品质待定","辅料短缺","偶发停电"],
				reasonIds:0,
				mould:["1","2","3"],
				mouldIds:0,
				deviList:[],
				CyInfo:{},
				resonList:[],
				deviceNo:[],
				froms:{
					plan_id:"",
					frequency:'1',
					reason_id:'',
					remake:'',
					device:[
						{device_id:'1',unusual_phenomenon:'',cause_analysis:'',repair_description:'',repair_time:'',repair_staff:'',remark:''}
					],
					mode:[
						{mode_id:'',unusual_phenomenon:'',cause_analysis:'',repair_description:'',repair_time:'',repair_staff:'',remark:''}
					],	
				},
			};
		},
		onLoad(e) {
			this.getReson();
			 this.getDevice();
			this.getMode()
			this.CyInfo = JSON.parse(decodeURIComponent(e.planInfo));
			this.froms.plan_id=this.CyInfo.plan_id;
			console.log('picker发送选择改变，携带值为',this.CyInfo)
		},
		methods:{
		 getDevice(){
			device().then(res=>{
			let newArr= []
			newArr=res.map(item=>item.name)
				this.deviceNo=newArr
				console.log("设备编号11",this.deviceNo)
			})
		 },
		 getMode(){
		 	mode().then(res=>{
				
				let newArr=[]
				newArr=res.map(item=>item.title)
				this.mould=newArr
		 		console.log("mode",this.mould)
		 	})
			},
			getReson(){
				stopLineReason().then(res=>{
					let arr = [];
					for (let i in res) {
					     arr.push(res[i])
					}
					this.reason=arr
					
				})
			},
			bindline: function(e) {
				this.froms.frequency = e.target.value;
				console.log("forms",this.froms)
			},
			// bindfrequencyIds(e){
			// 	this.froms.frequency = e.target.value
			// 	console.log("forms",this.froms)
			// },
			bindReason(e){
				
				this.reasonIds = e.target.value;
				this.froms.reason_id=e.target.value+1;
				
			},
			bindmouldIds(e){
				
				this.froms.device[0].device_id = e.target.value+1
				console.log("设备id",this.froms.device[0].device_id)
			}
			,bindmodeIds(e){
				this.froms.mode[0].mode_id = e.target.value+1
			},
			stopLine(){
				stopRecord(this.froms).then(res=>{
					uni.navigateBack({
						delta: -1
					});
					console.log("提交表单",res)
					//return false;
				})
			}
		}
	}
</script>

<style lang="scss">
@import "./index.scss"
</style>
