<template>
	<view>
		<view class="card" v-for="(item,index) in list" :key="index">
			<view class="card-left">
				<view class="card-up-list">
					<view class="card-up-list-list">
						<view>物料名称:</view><text>{{item.product_name}}</text>
					</view>
					<view class="card-right" @tap="open(item.plan_id,item.frequency)">
						人员统计
					</view>
				</view>
				<view class="card-up-list">
					<view class="card-up-list-list">
						<view>物料编号:</view><text>{{item.product_number}}</text>
					</view>
				</view>
				<view class="card-dow-list">
					<view class="card-up-list-list">
						<view>规格:</view><text>{{item.product_size}}</text>
					</view>
					<view class="card-up-list-list">
						<view>产线:</view><text>{{item.line_title}}</text>
					</view>
				</view>
			</view>
			<view class="btn-grounp">
				<view v-if="item.status!=1" @tap="openLine(item.plan_id)">开线</view>
				<view  class="btn-tx"  @tap="stopLine(item)">停线</view>
				<view v-if="item.status==1" class="btn-xx" @tap="offLine(item.plan_id)">下线</view>
				<view  class="btn-blp" @tap="badProduct(item)">不良品统计</view>
				<view  class="btn-back" @tap="rework(item)">返修</view>
			</view>
		</view>
		<uni-popup ref="popup" type="center">
			<view class="card-pop">
				<view class="pop-list">
					<text>班次:</text>
					<view class="right-pic">
						<text v-if="frequencyId==0">夜班</text>
						<text v-if="frequencyId==1">白班</text>
					<!-- 	<image src="../../static/next.png"></image> -->
					</view>
				</view>
				<view class="pop-list">
					<text>上线人数:</text>
					<input type="number" v-model="froms.in_line" placeholder="请输入上线人数" />
				</view>
				<!-- <view class="pop-list">
					<text>工时投入:</text>
					<input type="number" v-model="froms.peoples"  placeholder="请输入工时投入" />
				</view> -->
				<!-- <picker @change="bindStatus" :value="froms.status" :range="status">
				<view class="pop-list">
					<text>状态:</text>
					<view class="right-pic">
						<text>{{status[froms.status-1]}}</text>
						<image src="../../static/next.png"></image>
					</view>
				</view>
				</picker> -->
				<view class="submit" :disabled="buttonState==false?true:false" @tap="tjrsBtn()">提交</view>
			</view>
		</uni-popup>
	</view>
</template>

<script>
	import {
		firstCheckLists,
		openLine,
		trtj
	} from "../../api/user.js";
	import {
		mapGetters,
		mapMutations
	} from 'vuex';
	export default {
		computed: {
			...mapGetters(['userInfo', 'roleType'])
		
		},
		onLoad() {
			
			this.getArr();
			this.isMenu();
		},
		onShow() {
			this.getData()
		},
		data() {
			return {
				list:[],
				status:["冲压","喷涂"],
				frequency:["夜班", "白班"],
				buttonState:false,
				froms:{
					plan_id:'',
					//in_line:'',
					peoples:'',
					status:1,
					frequency:0
				},
				frequencyId:'',
				power: [],
				jurisdiction: [],
			};
		},methods:{
			getArr() {
				let newArr = this.power.map(item => {
					if (item.children) {
			
						item.children.map(items => {
							this.jurisdiction.push(items.title)
							return items
						})
					}
			
				})
				console.log("xinshuzu", this.jurisdiction)
			},
			isMenu(title) {
				return this.jurisdiction.includes(title);
			},
			bindline: function(e) {
				this.froms.frequency = e.target.value
			},
			bindStatus: function(e) {
				console.log("状态",e.target.value)
				this.froms.status = e.target.value+1
			},
			openLine(plan_id){
				openLine({id:plan_id}).then(res=>{
					this.$functions.success('操作成功').then(() => {
						this.getData()
					});
					
				})
			},
			getData(){
				firstCheckLists({type:1}).then(res => {
					this.list = res;
				})
			},
			stopLine(item){
				uni.navigateTo({
					url: `../stopLine/stopLine?planInfo=${encodeURIComponent(JSON.stringify(item))}`			
				});
			},
			offLine(plan_id){
				uni.navigateTo({
					url: `../offLine/offLine?plan_id=${plan_id}`				
				});
			},
			badProduct(item){
				uni.navigateTo({
					url: `../badProduct/badProduct?badProduct=${encodeURIComponent(JSON.stringify(item))}`		
				});
			}
			,
			rework(item){
				uni.navigateTo({
					url: `../rework/rework?badProduct=${encodeURIComponent(JSON.stringify(item))}`			
				});
			},
			open(e){
				
				this.froms.plan_id=e;
				console.log("id",this.froms)
			        // 通过组件定义的ref调用uni-popup方法 ,如果传入参数 ，type 属性将失效 ，仅支持 ['top','left','bottom','right','center']
			        this.$refs.popup.open('center')
			},
			tjrsBtn(id,frequencyId){
				this.frequencyId=frequencyId;
				this.buttonState = false;
				trtj(this.froms).then(res=>{
					this.$functions.success('提交成功').then(() => {
						 this.$refs.popup.close('center')
					}).catch(res => {
						this.buttonState = true;
					});
					
				})
			}
		}
	}
</script>

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