<template>
	<view>
		<view class="card">
			<view>设备名:{{info?info.name:''}}</view>
			<view>设备型号:{{info?info.model:''}}</view>
			<view>设备编号:{{info?info.in_number:''}}</view>
			<view>检测项目:{{info?info.check_item:''}}</view>
			<view>检测目的:{{info?info.check_aim:''}}</view>
		</view>
		<view class="from">
			<picker  @change="bindTypeCircle($event,typeCircle)" :value="typeCircleIds" :range="typeCircle" :range-key="'title'" >
			<view class="list">
				<view>检测周期</view>
				<view class="right">
					<text>{{typeCircle[typeCircleIds].title}}</text>
					<image class="next" src="../../static/next.png"></image>
				</view>
			</view>
			</picker>
			<picker  @change="bindMaterial" :value="materialIds" :range="material"  >
			<view class="list">
				<view>保养情况</view>
				<view class="right">
					<text>{{material[materialIds]}}</text>
					<image class="next" src="../../static/next.png"></image>
				</view>
			</view>
			</picker>
			<view class="remark">
				<view>
					备注
				</view>
				<textarea v-model="from.device[0].remark" placeholder="" />
			</view>
			<view class="remark">
				<view>
					设备其他情况
				</view>
				<textarea v-model="from.remark" placeholder="" />
			</view>
		</view>
		<view class="submit-btn" >
			<button type="primary" :disabled="buttonState==false?true:false" @tap="submit()">提交</button>
		</view>
	</view>
</template>

<script>
	import {deviceRecord} from "../../api/user.js"
	export default {
		data() {
			return {
				type:0,
				info:{},
				lineId:0,
				typeCircle:[
					{id:1,title:'半月检'},
					{id:2,title:'月检'},
					{id:3,title:'半年检'}
				],
				typeCircleIds:0,
				material:["未完成","已完成"],
				materialIds:0,
				from:{
					line_id:0,
					remark:'',//设备其他情况
					type:1,//类型：1=半月检，2=月检，3=半年检,
					device:[
						{
							device_id:'',
							status:1,
							remark:'' 
						}
					]
				},
				buttonState:true
			};
		},onLoad(e) {
			this.type=e.type;
			this.info = JSON.parse(decodeURIComponent(e.planInfo));
			this.lineId=e.id
		},methods:{
			bindTypeCircle(e,list){
				this.typeCircleIds=e.detail.value
			},
			bindMaterial(e){
				this.materialIds=e.detail.value
			},
			submit(){
				this.from.line_id=this.lineId;
				this.from.type=this.typeCircle[this.typeCircleIds].id;
				this.from.device[0].status=this.materialIds+1;
				this.from.device[0].device_id=this.info.id;
				this.buttonState=false
				deviceRecord(this.from).then(res=>{
					this.buttonState=false
					this.$functions.success("操作成功").then(() => {
						uni.navigateBack()
					}).catch(res=>{
							this.buttonState=true
						})
					console.log("biaodan",this.from)
				})
			}
		}
	}
</script>

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