<template>
	<view>
		<view class="sm-box">
			<view class="content-box-card">
				<view class="content-box-card-ul-two">
					<view class="content-box-card-list">
						<view class="content-box-card-title">物料编号:</view>
						<text>{{ CyInfo.product_number }}</text>
					</view>
					<!-- <view class="content-box-card-list">
						<view class="content-box-card-title">规格:</view>
						<text>{{ CyInfo.product_size }}</text>
					</view> -->
				</view>
				<view class="content-box-card-ul-two">
					<view class="content-box-card-list">
						<view class="content-box-card-title">生产线:</view>
						<text>{{ CyInfo.line_title }}</text>
					</view>
					<view class="content-box-card-list">
						<view class="content-box-card-title">物料名称:</view>
						<text>{{ CyInfo.product_name }}</text>
					</view>
				</view>
			</view>
		</view>
		<view class="big-title">
			巡检记录
		</view>
		<view class="white-card">
			<view class="lists" v-for="(item,index) in list" :key="index">
				<view class="list-left">
					<view class="list-left-up">
						<view class="list-left-up-left">巡检人:{{item.one}}</view>
						<view class="list-left-up-mid">巡检时间:{{item.create_time}}</view>
						<view class="list-left-up-right-ok" v-if="item.result==1">OK</view>
						<view class="list-left-up-right-no" v-if="item.result==2">NG</view>
					</view>
					<view class="list-left-dow">
						<view class="list-left-dow-left">审核人:{{item.two}}</view>
						<view class="list-left-dow-btn">
							<view @tap="firstInspectionInfo(item.id,item)">
								查看详情
							</view>
							<view class="red" @tap="firstInspectionInfoSh(item.id,item)" v-if="item.two_id==0" >
								审核
							</view>
						</view>
					</view>
				</view>
				<view class="list-right" v-if="list.length==1||index==0">
					首
				</view>
				<view class="list-right" v-if="list.length>=2&&list.length-1==index">
					末
				</view>
			</view>
			<view class="submit-btn">
				<button type="primary" v-if="isMenu(39)" @tap="addRecord()">新增巡检记录</button>
			</view>
		</view>
	</view>
</template>

<script>
	import {
		newTcqLists
	} from "../../api/user.js"
	import {
		mapGetters,
		mapMutations
	} from 'vuex';
	export default {
		data() {
			return {
				plan_id: '',
				CyInfo: {},
				info: {},
				power: [],
				jurisdiction: [],
				product_id:0,
				list: [],
				limit: 10,
				page: 1
			};
		},
		computed: {
			...mapGetters(['userInfo', 'roleType'])

		},
		onShow() {
			this.getData()
		},
		onLoad(e) {
			this.plan_id = e.plan_id;
			this.CyInfo = JSON.parse(decodeURIComponent(e.planInfo));
			this.product_id=this.CyInfo.product_id;
			this.power = this.userInfo.power
			this.getArr();
			this.isMenu();
		},
		methods: {
			getArr() {
				if (this.power.length > 0) {
					let newArr = this.power.map(item => {
						this.jurisdiction.push(item.id)
			
					})
			
				}
				console.log("xinshuzu", this.jurisdiction)
			
			},
			isMenu(id) {
				console.log("id", id)
				return this.jurisdiction.includes(id);
			},
			getData() {
				let param = {
					plan_id: this.plan_id,
					limit: this.limit,
					page: this.page
				};
				newTcqLists(param).then(res => {
					this.info = res,
					this.list = this.info.lists.data;
					console.log("详情", res)
				})
			},
			addRecord() {
				uni.navigateTo({
					url: `../tcqInfo/tcqInfo?plan_id=${this.plan_id}&type=1&planInfo=${encodeURIComponent(JSON.stringify(this.CyInfo))}`,
					success: res => {},
					fail: () => {},
					complete: () => {}
				});
			},
			firstInspectionInfo(id,type) {
				uni.navigateTo({
					url: `../tcqInfo/tcqInfo?plan_id=${this.plan_id}&product_id=${this.product_id}&id=${id}&planInfo=${encodeURIComponent(JSON.stringify(this.CyInfo))}&type=2`,
					success: res => {},
					fail: () => {},
					complete: () => {}
				});
			},
			firstInspectionInfoSh(id,type) {
				uni.navigateTo({
					url: `../tcqInfo/tcqInfo?plan_id=${this.plan_id}&&type=3&product_id=${this.product_id}&id=${id}&planInfo=${encodeURIComponent(JSON.stringify(this.CyInfo))}`,
					success: res => {},
					fail: () => {},
					complete: () => {}
				});
			}
		}
	}
</script>

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