<template>
	<view>
		<view class="sm-box">
			<view class="card">
				<view class="title">填写说明:</view>
				<view class="content">1、产品新开机台生产时，由最终工序准备好3个样件置于待检区，检查判定合格后生产。</view>
				<view class="content">2、检验员判定合格后从样品中随机挑选1个样件，进行首件标识。</view>
				<view class="content">4、检查结果:合格项目打“√”，不合格项目打“×”，无此检查项目不填写”</view>
			</view>
		</view>
		<view class="content-box">
			<view class="content-box-card">
				<view class="content-box-card-ul">
					<view class="content-box-card-list">
						<view class="content-box-card-title">物料名称:</view>
						<text>{{palnInfo.product_name}}</text>
					</view>
				</view>
				<view class="content-box-card-ul">
					<view class="content-box-card-list">
						<view class="content-box-card-title">物料编号:</view>
						<text>{{palnInfo.product_number}}</text>
					</view>
				</view>
				<view class="content-box-card-ul">
					<view class="content-box-card-list">
						<view class="content-box-card-title">检验日期:</view>
						<text>{{crrentTime}}</text>
					</view>
				</view>
				<view class="content-box-card-ul">
					<view class="content-box-card-list">
						<view class="content-box-card-title">生产日期:</view>
						<text>{{palnInfo.production}}</text>
					</view>
				</view>
				<view class="content-box-card-ul-two">
					<view class="content-box-card-list">
						<view class="content-box-card-title">机型:</view>
						<text>{{palnInfo.product_size}}</text>
					</view>
					<view class="content-box-card-list">
						<view class="content-box-card-title">线别:</view>
						<text>{{palnInfo.line_title}}</text>
					</view>
				</view>
				<view class="content-box-card-ul" >
					<view class="content-box-card-list" style="align-items: center;">
						<view class="content-box-card-title">首检信息:</view>
						<view class="right-check">
							<view class="other-input" v-if="type==1">
								<input type="text" v-model="forms.msg" @input="samplingInput" placeholder="首检信息" />
							</view>
							<view class="other-input" v-if="type==2">
								{{info.msg}}
							</view>
						</view>
					</view>
				</view>
				<view class="content-box-card-ul">
					<view class="content-box-card-list">
						<view class="content-box-card-title">抽样方式:</view>
						<view class="right-check">
							<view class="check-list" v-if="type==1" v-for="(item,index) in msg" :key="index"
								@tap="radioChange(item.name)">
								<image :src="item.name==forms.sampling?'../../static/xz.png':'../../static/wxz.png'">
								</image>
								<text>{{item.name}}</text>
							</view>
							<view  v-if="type==1" class="other-input">
								<input type="text" v-model="msgModel" @input="msgInput" placeholder="其他" />
							</view>
							<view  v-if="type==2">
								<text>{{info.sampling}}</text>
							</view>
						</view>
					</view>
				</view>
				<view class="content-box-card-ul">
					<view class="content-box-card-list">
						<view class="content-box-card-title">检验依据:</view>
						<view class="right-check">
							<view class="check-list" v-if="type==1" v-for="(item,index) in jyBasis" :key="index"
								@tap="jyBasisChange(item)">
								<image :src="item==forms.basis?'../../static/xz.png':'../../static/wxz.png'"></image>
								<text>{{item}}</text>
							</view>
							<view class="other-input" v-if="type==1">
								<input type="text" v-model="basisModel" @input="basisInput" placeholder="其他" />
							</view>
							<view  v-if="type==2">
								<text>{{info.basis}}</text>
							</view>
						</view>
					</view>
				</view>
			</view>
		</view>
		<view class="content-box">
			<view class="content-box-card">
				<view class="content-box-card-ul">
					<view class="content-box-card-list">
						<view class="content-box-card-title">检验标准:</view>
					</view>
				</view>
				<view class="content-box-card-ul-two" v-for="(value, key, index) in info.reference">
					<view class="content-box-card-list">
						<view class="content-box-card-title">规格:</view>
						<text>{{key}}</text>
					</view>
					<view class="content-box-card-list">
						<view class="content-box-card-title">公差:</view>
						<text>{{value}}</text>
					</view>
				</view>

				<view class="sj-card">
					<view class="sj-title">实际检测</view>
					<view class="sj-nav">
						<view class="left">
							<view>规格</view>
							<view>规格</view>
						</view>
						<view class="right">
							<view class="right-list">
								<view class="num-div">1</view>
								<view class="num-div">2</view>
								<view class="num-div">3</view>
							</view>
							<view class="right-list"  v-if="type==1" v-for="(items,index) in forms.item" :key="index">
								<view class="gg-div">
									<input type="number" v-model="items.one" />
								</view>
								<view class="gg-div">
									<input type="number" v-model="items.two" />
								</view>
								<view class="gg-div">
									<input type="number" v-model="items.their" />
								</view>
							</view>
							<view class="right-list"  v-if="type==2" v-for="(items,index) in info.FirstCheckValue" :key="index">
								<view class="gg-div">
									<input disabled="true" type="number" v-model="items.one" />
								</view>
								<view class="gg-div">
									<input  disabled="true" type="number" v-model="items.two" />
								</view>
								<view class="gg-div">
									<input  disabled="true" type="number" v-model="items.their" />
								</view>
							</view>
						</view>
					</view>
				</view>
				<view class="beizhu">
					<textarea  v-if="type==1" v-model="forms.remake" placeholder="请输入备注" />
					<textarea  v-if="type==2" v-model="info.remake" disabled="true" />
				</view>
			</view>
		</view>
		<view class="content-box">
			<view class="content-box-card">
				<view class="content-box-card-ul">
					<view class="content-box-card-list">
						<view class="content-box-card-title">外观:</view>
						<view class="right-check">
							<view class="check-list" v-if="type==1" v-for="(item,index) in appearance" :key="index"
								@tap="appearanceChange(item)">
								<image :src="item==forms.appearance?'../../static/xz.png':'../../static/wxz.png'">
								</image>
								<text>{{item}}</text>
							</view>
							<view class="other-input" v-if="type==1" >
								<input type="text" v-model="appearanceModel" @input="appearanceInput"
									placeholder="其他" />
							</view>
							<view v-if="type==2" >{{info.appearance}}</view>
						</view>
					</view>
				</view>
				<view class="content-box-card-ul">
					<view class="content-box-card-list">
						<view class="content-box-card-title">结构性能:</view>
						<view class="right-check">
							<view class="check-list" v-if="type==1" v-for="(item,index) in structure" :key="index"
								@tap="structureChange(item)">
								<image :src="item==forms.structure?'../../static/xz.png':'../../static/wxz.png'">
								</image>
								<text>{{item}}</text>
							</view>
							<view class="other-input" v-if="type==1">
								<input type="text" v-model="structureModel" @input="structureInput" placeholder="其他" />
							</view>
							<view v-if="type==2">{{info.structure}}</view>
						</view>
					</view>
				</view>
			</view>
		</view>
		<view class="content-box">
			<view class="content-box-card">
				<view class="content-box-card-ul">
					<view class="content-box-card-list">
						<view class="content-box-card-title">最终判定:</view>
						<view class="right-check" >
							<view class="check-list" v-if="type==1" v-for="(item,index) in ifQualified" :key="index"
								@tap="ifQualifiedChange(index+1)">
								<image :src="forms.result==index+1?'../../static/xz.png':'../../static/wxz.png'">
								</image>
								<text>{{item}}</text>
							</view>
							<view>
								<text v-if="info.result==1">合格</text>
								<text v-if="info.result==2">不合格</text>
							</view>
						</view>
					</view>
				</view>
				<view class="content-box-card-ul">
					<view class="content-box-card-list">
						<view class="content-box-card-title">是否量产:</view>
						<view class="right-check" >
							<view v-if="type==1" class="check-list" v-for="(item,index) in ifProduction" :key="index"
								@tap="ifProductionChange(index+1)">
								<image :src="forms.agree==index+1?'../../static/xz.png':'../../static/wxz.png'"></image>
								<text>{{item}}</text>
							</view>
							<view>
								<text v-if="info.agree==1">是</text>
								<text v-if="info.agree==2">否</text>
							</view>
						</view>
					</view>
				</view>
				<view class="beizhu" v-if="forms.result==2&&forms.agree==1">
					<textarea v-model="forms.information" placeholder="情况说明" />
				</view>
			</view>
			<view class="submit-btn">
				<button type="primary" v-if="type==1" @tap="submits">提交并发起审核</button>
				<button type="primary" @tap="firstCheckSureBtn()" v-if="palnInfo.check==1&&type==2" >审核</button>
			</view>

		</view>
	</view>
</template>

<script>
	import {
		firstCheckDetail,
		firstCheckAdd,
		firstCheckSure
	} from "../../api/user.js"
	export default {

		data() {
			return {
				type:0,
				pId: 0, //计划id
				id:0,
				palnInfo: {}, //详情
				crrentTime: '', //当前时间
				line: ["A线", "B线", "C线", "D线"],
				lineIndex: 0,
				current: -1,
				ifQualifiedIds: 0,
				samplingModel: '',
				basisModel: '',
				msgModel:'',
				cyMethod: [{
						name: "开机首检",
						check: false
					},
					{
						name: "开机末检",
						check: false
					},
					{
						name: "修模首件",
						check: false
					},
					{
						name: "转产首件",
						check: false
					},
					{
						name: "生产参数变更",
						check: false
					},
					{
						name: "材料变更",
						check: false
					}
				],
				jyBasisIds: -1,
				jyBasis: [
					"工程图纸",
					"标准样件",
					"制程检验标准",
					"产品标准"
				],
				cyMethod:"",
				msg: [{
						name: "开机首检",
						check: false
					},
					{
						name: "关机末件",
						check: false
					},
					{
						name: "修模首件",
						check: false
					},
					{
						name: "转产首件",
						check: false
					},
					{
						name: "生产参数变更",
						check: false
					},
					{
						name: "材料变更",
						check: false
					}
				],
				appearance: ["划伤", "压痕", "拉痕", "摁伤", "油污", "水渍", "少孔", "开裂", "变形", "起皱、叠料", "毛刺", "印字"],
				appearanceIds: -1,
				structure: ["缺料", "螺纹", "铆接", "折弯", "膜厚", "附着力", "直线度", "平整度", "试装配", "表面处理"],
				structureIds: -1,
				ifQualified: ["是", "否"],
				qualifiedIds: -1,
				ifProduction: ["是", "否"],
				ProductionIds: -1,
				forms: {
					machine: "",
					msg: "",
					sampling:'',
					item: [{
							one: "",
							two: "",
							their: ''
						},
						{
							one: "",
							two: "",
							their: ''
						}
					],
					basis: "",
					appearance: "",
					structure: "",
					result: 1,
					agree: 1,
					remake: "",
					information: "",

				},
				appearanceModel: '',
				structureModel: '',
				productId: 0,
				info: {
					reference: []
				}
			};
		},

		onLoad(e) {
			this.type=e.type;
			this.id=e.id;
			this.pId = e.plan_id;
			this.productId = e.product_id;
			this.palnInfo = JSON.parse(decodeURIComponent(e.planInfo));
			console.log('详情', this.palnInfo);
			this.getTime();
			if(this.type==2){
				this.getInfo();
			}
			
		},
		onShow() {

		},
		methods: {
			
			appearanceInput(e) {
				this.forms.appearance = e.detail.value;
			},
			samplingInput(e) {
				this.forms.sampling = e.detail.value;
			},
			structureInput(e) {
				this.forms.structure = e.detail.value;
			},
			msgInput(e) {
				this.forms.msg = e.detail.value;
			},
			basisInput(e) {
				this.forms.basis = e.detail.value;
			},
			getTime: function() {

				var date = new Date(),
					year = date.getFullYear(),
					month = date.getMonth() + 1,
					day = date.getDate(),
					hour = date.getHours() < 10 ? "0" + date.getHours() : date.getHours(),
					minute = date.getMinutes() < 10 ? "0" + date.getMinutes() : date.getMinutes(),
					second = date.getSeconds() < 10 ? "0" + date.getSeconds() : date.getSeconds();
				month >= 1 && month <= 9 ? (month = "0" + month) : "";
				day >= 0 && day <= 9 ? (day = "0" + day) : "";
				var timer = year + '-' + month + '-' + day + ' ' + hour + ':' + minute + ':' + second;
				console.log("当前时间", date);
				this.crrentTime = timer
				return timer;

				console.log("当前时间", timer)
			},
			getInfo() {
				firstCheckDetail({
					plan_id: this.pId,
					id: this.id,
					product_id:this.productId
				}).then(res => {
					this.info = res;
				})
			},
			firstCheckSureBtn(){
				let parm={
					plan_id:this.info.plan_id,
					oneCheck:this.info.oneCheck,
					check_id:this.info.id
				};
				firstCheckSure(parm).then(res=>{
					uni.navigateBack({
						delta:1
					})
				})
			},
			bindline: function(e) {
				console.log('picker发送选择改变，携带值为', e.target.value)
				this.lineIndex = e.target.value
			},
			radioChange(name) {
				this.forms.sampling = name;
				this.msgModel = "";
			},
			jyBasisChange: function(name) {
				this.forms.basis = name;
				this.basisModel = "";
			},
			appearanceChange(name) {
				this.forms.appearance = name;
				this.appearanceModel = '';
			},
			structureChange(name) {
				this.forms.structure = name;
				this.structureModel = '';
			},
			ifQualifiedChange(index) {
				this.forms.result = index
			},
			ifProductionChange(index) {
				this.forms.agree = index
			},
			submits() {
			
				if (this.forms.sampling == '') {
					this.$functions.error("请选择抽样方法");
					return false;
				}
				if (this.forms.basis == '') {
					this.$functions.error("请选择检测依据");
					return false;
				}
				let flag = true;
				this.forms.item.map(item => {
					if (!item.one || !item.two || !item.their) {
						flag = false;
						return false;
					}
				})

				if (!flag) {
					this.$functions.error("请完整填写实际检测数据");
					return false;
				}
				if (this.forms.appearance == '') {
					this.$functions.error("请选择外观");
					return false;
				}
				if (this.forms.structure == '') {
					this.$functions.error("请选择结构");
					return false;
				}
				this.forms.machine = this.palnInfo.product_size;
				this.forms.plan_id = this.pId;
				firstCheckAdd(this.forms).then(res => {
					uni.navigateBack({
						delta:1
					})
				})
			}
		}
	}
</script>

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