<template>
	<view class="bodyContainer">
		<uni-nav-bar @clickLeft="goBack()" class="nav-bar" height="110rpx" leftWidth="200rpx" leftText="许可证详情"
			leftIcon="left" border backgroundColor="#2cade8" color="#fff" fixed statusBar shadow></uni-nav-bar>
		<view class="wrap-view wrap-top">
			<view class="item title"> <text class="blueLine"></text>许可证信息：</view>
			<view class="item">
				<view class="title">编号</view>
				<view class="content">
					<text>{{formData.number}}</text>
				</view>
			</view>
			<view class="item">
				<view class="title">作业级别</view>
				<view class="content">
					<text>{{formData.level}}</text>
				</view>
			</view>
			<view class="item">
				<view class="title">预计开始</view>
				<view class="content">
					<text>{{formData.start_time}}</text>
				</view>
			</view>
			<view class="item">
				<view class="title">预计结束</view>
				<view class="content">
					<text>{{formData.end_time}}</text>
				</view>
			</view>
			<view class="item">
				<view class="title">状态</view>
				<view class="content">
					<!-- <text v-if="formData.ticket_">{{formData.ticket_.state_.name}}</text> -->
				</view>
			</view>
			<view class="item">
				<view class="title">作业部门</view>
				<view class="content">
					<text>{{formData.dept_do_.name}}</text>
				</view>
			</view>
			<view class="item">
				<view class="title">作业负责人</view>
				<view class="content">
					<text>{{formData.charger_.name}}</text>
				</view>
			</view>
			<view class="item">
				<view class="title">作业监护人</view>
				<view class="content">
					<text>{{formData.monitor_.name}}</text>
				</view>
			</view>
			<view class="item">
				<view class="title">风险分析</view>
				<view class="content">
					<text v-for="item in formData.risks_checked_" :key="item.id">
					{{item.name}}|
					</text>
				</view>
			</view>
			<view class="item">
				<view class="title">控制措施</view>
				<view class="content">
					<text v-for="item in formData.measures_checked_" :key="item.id">
					{{item.name}}|
					</text>
				</view>
			</view>
			<view class="item">
				<view class="title">监控状态</view>
				<view class="content contentFlex">
					<text v-if="formData.mtask_uid" style="width: 200upx;">进行中</text>
					<text v-else style="width: 200upx;">未进行</text>
					<text class="bindBtn" @click="mtaskStateChange('start')">开始</text>
					<text class="bindBtn2" @click="mtaskStateChange('end')">停止</text>
				</view>
			</view>
		</view>
		<view class="wrap-view wrap-top">
			<view class="item title"> <text class="blueLine"></text>作业人员：</view>
			<view class="visitorsWrap">
				<view class="visitorsItem itemTitle">
					<text class="visitorCell">姓名</text>
					<text class="visitorCell">职责</text>
					<text class="visitorCell">证书</text>
					<text class="visitorCell">操作</text>
				</view>
				<view class="visitorsItem" v-for="item in workerList" :key="item.id">
					<text class="visitorCell" @click="viewWorker(item)" style="color:blue">{{item.worker_name}}</text>
					<text class="visitorCell">{{item.duty}}</text>
					<text class="visitorCell">{{item.certificates.length}}张</text>
					<view class="visitorCell">
						<!-- <text class="bindBtn" @click="bindBtl(item,10)" v-if="item.worker_.blt_===null||item.worker_.blt_===undefined">绑卡</text>
						<text class="bindBtn" @click="bindBtl(item,20)" v-else>解绑</text> -->
					</view>
				</view>
			</view>
		</view>
		<view class="wrap-view wrap-top">
			<view class="item title"> <text class="blueLine"></text>气体检测记录：</view>
			<view class="visitorsWrap">
				<view class="visitorsItem itemTitle">
					<text class="visitorCell">检测部位</text>
					<text class="visitorCell">可燃气体(V%LEL)</text>
					<text class="visitorCell">检验结论</text>
				</view>
				<view class="visitorsItem" v-for="item1 in gasList" :key="item1.id">
					<text class="visitorCell">{{item1.check_place}}</text>
					<text class="visitorCell"></text>
					<text class="visitorCell">
						<span v-if="item1.is_ok">正常</span>
						<span v-else>异常</span>
					</text>
				</view>
			</view>
		</view>
	</view>
</template>

<script>
	export default {
		name: "oplDetail",
		data() {
			return {
				formData:{
					number:'',
					level:'',
					start_time:'',
					end_time:'',
					ticket_:{},
					dept_do_:{},
					charger_:{},
					monitor_:{},
					risks_checked_:{},
					measures_checked_:{},
					mtask_uid:null
				},
				msOptions:{
					"REVOKED": "已停止",
					"STARTED": "进行中",
					"SUCCESS": "已完成"
				},
				workerList:[],
				gasList:[],
				act_states: {
					0: "草稿中",
					1: "进行中",
					2: "被退回",
					3: "被撤回",
					4: "已完成",
					5: "已关闭",
				},
			}
		},
		onLoad(params) {
			this.oplId = params.oplId;
			this.getOpl();
		},
		onShow() {
			this.getworkerList();//工作人员
			this.getgasList();//气体检测记录
		},
		methods: {
			//获取工作operation
			getOpl() {
				debugger;
				let that = this;
				that.$u.api.oplItem(that.oplId).then((res) => {
					that.formData ={...res} ; 
				});
			},
			//
			//获取工作人员
			getworkerList() {
				let that = this;
				that.$u.api.oplWorker({opl: that.oplId, page: 0}).then(res => {
					that.workerList =res;
				})
			},
			//获取气体检测记录
			getgasList(){
				let that = this;
				that.$u.api.oplGasList({opl: that.oplId, page: 0}).then(res => {
					that.gasList =res;
				})
			},
			mtaskStateChange(type){
				let that = this;
				uni.showLoading({
					mask: true,
					title: '正在处理...'
				})
				if(type==='start'){
					that.$u.api.oplMtartMtask(that.oplId).then(res=>{
						uni.hideLoading()
						that.formData.mtask_uid=res.mtask_uid
					}).catch(e=>uni.hideLoading())
				}else{
					that.$u.api.oplStopMtask(that.oplId).then(res=>{
						uni.hideLoading()
						that.formData.mtask_uid=null
					}).catch(e=>uni.hideLoading())
				}
			},
			//解绑卡
			bindBtl(row,type){
				let that = this;
				let form = {};
				form.type = type;
				form.code = res.result;
				form.employee = row.visitor_.employee;
				if(type==10){
					uni.scanCode({
						 success: function (res) {
							 that.$u.api.thirdBltBind(form).then(res=>{
								 debugger;
								 uni.showToast({
									title: res,
									icon: "none"
								 })
							 })
						 }
					});
				}else{
					that.$u.api.thirdBltBind(form).then(res=>{
						 debugger;
						 uni.showToast({
							title: res,
							icon: "none"
						 })
					})
				}
				 
			},
			goBack() {
				uni.navigateBack({
					delta: 1
				})
			},
			viewWorker(item) {
				uni.showToast({
					title: item.id,
					icon: 'none'
				})
			}

		}
	}
</script>

<style scoped>
	uni-page-body {
	    color: #303133;
	    font-size: 15px;
	    height: 100%;
	    background: #f3fbff;
	}
	.bodyContainer {
	    background-color: #f3fbff;
	}
	>>>.uni-navbar__header,
	>>>.uni-status-bar {
		background-image: linear-gradient(254deg,
				#0ca7ee 0%,
				#005aff 100%,
				#2a8cff 100%,
				#54bdff 100%),
			linear-gradient(#e60012,
				#e60012);
	}
>>>uni-image{
	height: 200upx;
	width: 200upx;
}
	.my-data {
		background-color: #f3fbff;
		padding-bottom: 227rpx;
	}

	.nav-bar>>>.uni-navbar-btn-text text {
		font-size: 32rpx !important;
	}

	.wrap-view {
		width: 720rpx;
		margin: 0 auto;
		background-color: #ffffff;
		border-radius: 10rpx;
		line-height: 94rpx;
		font-family: PingFang-SC-Medium;
		font-size: 30rpx;
		padding-bottom: 30upx;
	}
	.wrap-top{
		line-height: 60upx;
		margin-top: 20upx;
	}
	.item {
		margin: 0rpx 32rpx;
		display: flex;
		margin-top: 10rpx;
	}
	.item.title{
		    height: 100upx;
		    line-height: 100upx;
		    border-bottom: 1upx solid #dddddd;
	}
	.item_bottom_border{
		border-bottom: 1rpx solid #eeeeee;
	}
	
	.title {
		color: #212121;
		flex: 1;
	}

	.content {
		flex: 3;
		color: #666666;
	}
	.contentFlex{
		display: flex;
		/* justify-content: space-between; */
	}
	.visitorsWrap{
		
	}
	
	.visitorsItem{
		display: flex;
		font-size: 28upx;
		align-items:center;
	}
	
	.itemTitle{
		height: 80upx;
		font-size: 32upx;
		line-height: 40upx;
	}
	.itemTitle>.visitorCell{
		color: #212121;
	}
	.visitorCell{
		flex: 1;
		color: #666666;
		text-align: center;
	}
	.blueLine{
		height: 24upx;
		width: 10upx;
		background: #2a8cff;
		margin-top: 39upx;
		margin-right: 12upx;
	}
	.bindBtn{
		    width: 80upx;
		    height: 50upx;
		    line-height: 50upx;
		    background: #2a8cff;
		    display: inline-block;
		    border-radius: 16upx;
		    color: #ffffff;
		    font-size: 25upx;
			text-align: center;
	}
	.bindBtn2{
		    width: 80upx;
		    height: 50upx;
		    line-height: 50upx;
		    background: #ff0000;
		    display: inline-block;
		    border-radius: 16upx;
		    color: #ffffff;
		    font-size: 25upx;
			text-align: center;
	}
</style>
