<template>
	<view class="list-body">
		<uni-nav-bar @clickLeft="goBack()" class="nav-bar" height="110rpx" leftWidth="400rpx" leftText="气体检测记录"
			leftIcon="left" border backgroundColor="#2cade8" color="#fff" fixed statusBar shadow></uni-nav-bar>
		<view class="apply-info">
			<view class="row" v-for="(row,index) in gasCheckList" :key="index" @tap="select(row)">
				<view class="center">
					<view class="name-tel">
						<view class="name">检测部位：{{row.check_place}}</view>
						<view class="tel">O₂(%)：{{row.o2}}</view>
						<view class="tel">CO：{{row.co}}</view>
						<view class="tel">可燃气体(V%LEL)：{{row.lel}}</view>
						<view class="tel">检验结论：{{row.is_ok}}</view>
						<view class="tel">检测人：{{row.checker_.name}}</view>
						<view class="tel">检验时间：{{row.check_time}}</view>
					</view>
				</view>
				<view class="right">
					<view class="icon bianji" @tap.stop="edit(row)">
					</view>
				</view>
			</view>
			<button type="primary" class="select" @click="addGasCheck">新增记录</button>
		</view>
		<button type="primary" class="addNew" @click="add">新增人员</button>
		<view class="dialogWrap" v-if="limitedDialog">
			<view class="dialogCont">
				<view class="dialogTitle">
					<view>气体检测记录</view>
					<view class="dialogCloseImg" @click="closeDialog"></view>
				</view>
				<form @submit="formSubmit">
					<view class="uni-form-item">
						<view class="title">检测时间：</view>
						<uni-datetime-picker v-model="formData.check_time" :border="false" />
						<!-- <picker mode="date" :value="formData.check_time" class="content" @change="timeChange">
							<view class="uni-input">{{formData.check_time}}</view>
						</picker> -->
					</view>
					<view class="uni-form-item">
						<view class="title">检测部位：</view>
						<input class="content" type="text" v-model="formData.check_place" maxlength="50"
							placeholder="请输入" />
					</view>
					<view class="uni-form-item">
						<view class="title">O2(%)：</view>
						<input class="content" type="text" v-model="formData.o2" maxlength="50"
							placeholder="请输入" />
					</view>
					<view class="uni-form-item">
						<view class="title">CO：</view>
						<input class="content" type="text" v-model="formData.co" maxlength="50"
							placeholder="请输入" />
					</view>
					<view class="uni-form-item">
						<view class="title">可燃气体：</view>
						<input class="content" type="text" v-model="formData.lel" maxlength="50"
							placeholder="请输入" />
					</view>

					<view class="uni-form-item">
						<view class="title">检验结论：</view>
						<radio-group @change="checkboxMeasuresChange" class="content">
							<label style="margin-right: 20rpx;margin-bottom: 20rpx;">
								<radio value="true" :checked="formData.is_ok" />正常
							</label>
							<label style="margin-right: 20rpx;margin-bottom: 20rpx;">
								<radio value="false" :checked="!formData.is_ok" />不正常
							</label>
						</radio-group>
					</view>
					<view class="uni-form-item">
						<view class="title">检测人：</view>
						<uni-data-select class="content" :localdata="workerRange" v-model="formData.checker">
						</uni-data-select>
					</view>
					<view class="uni-btn-v">
						<button class="mini-btn" type="primary" size="mini" form-type="submit">确定</button>
					</view>
				</form>
			</view>
		</view>
		<view class="apply-info" style="min-height: fit-content;display: flex;">

			<button type="primary" plain="true" style="width: 25%;" @click="goBack">上一步</button>
			<button v-for=" item in initform.transitions" :key="item.id" @click="submitticket(item.id)" type="primary" style="width: 25%;">{{item.name}}
			</button>
			<button plain="true" style="width: 25%;" @click="nexStep">退出</button>
		</view>

	</view>
</template>

<script>
	export default {
		name: "gasList",
		data() {
			return {
				limitedDialog: false,
				formData: {
					opl: '',
					check_time: '选择日期',
					check_place:'',
					o2:'',
					co:'',
					lel:'',
					is_ok:true,
					checker:'',
				},
				initform: {},
				oplDetail:{},
				gasCheckList: [],
				workerRange: [],
				certificateRange: [],
			}
		},
		onLoad(params) {
			this.oplId = params.oplId;
		},
		onShow() {
			this.gasCheckList = [];
			this.getOplDetail();
			this.getWorkerRange();
			this.getGasCheckList();
			this.getInit();
		},
		methods: {
			timeChange(e){
				// debugger;
				console.log(e.detail.value)
				this.formData.check_time = e.detail.value;
			},
			formSubmit(val) {
				let that = this;
				that.formData.opl = that.oplId;
				that.$u.api.oplGasCreate(that.formData).then(res => {
					if (res.err_msg) {} else {
						that.getGasCheckList();
						this.limitedDialog = false;
					}
				})
			},
			getOplDetail(){
				let that = this;
				that.$u.api.oplItem(that.oplId).then((res) => {
					that.oplDetail = res; //作业开始时间
					debugger;
					console.log(res);
				});
			},
			//工
			getWorkerRange() {
				let that = this;
				that.$u.api.userList({
					page: 0
				}).then(res => {
					let workerRange = [];
					let obj = {};
					res.forEach(item => {
						obj = item;
						obj.value = item.id;
						obj.text = item.name;
						workerRange.push(obj);
					})
					that.workerRange = workerRange
				})
			},
			//获取该工作的气体检测记录
			getGasCheckList() {
				let that = this;
				that.workerList = [];
				that.$u.api.oplGasList({
					page: 0,
					opl: this.oplId
				}).then(res => {
					that.gasCheckList = res;
				})
			},
			checkboxMeasuresChange(e) {

				let value = e.detail.value;
				if (value === 'true') {
					this.formData.is_ok = true;
				} else {
					this.formData.is_ok = false;
				}
			},
			addGasCheck() {
				this.limitedDialog = true;
			},
			closeDialog() {
				this.limitedDialog = false;
			},
			select(row) {},
			goBack() {
				uni.navigateBack({
					delta: 1
				})
			},
			edit(row) {},

			nexStep() {
				uni.navigateTo({
					url: '/pages/workSpace/operation/operationList'
				})
			},

			getInit() {
				this.$u.api.workflowInit('opl_fire').then((res) => {
					this.initform = res;

				});
			},
			//提交工单
			submitticket(id) {
				let that = this;
				let ticket = {};
				ticket.workflow = that.initform.workflow;
				ticket.ticket_data = {
					opl: that.oplId
				};
				ticket.transition = id;
				ticket.title = that.oplDetail.operation_.name + that.oplDetail.cate_name + '申请';
				that.$u.api.ticketCreate(ticket).then((res) => {
					if (res.err_msg) {} else {
						uni.reLaunch({
							url: '/pages/workSpace/operation/operationList'
						})
					}
				});

			}
		}
	}
</script>

<style>
	>>>.uni-navbar__header,
	>>>.uni-status-bar {
		background-image: linear-gradient(90deg, #164cc3 0%, #2c6fd9 100%), linear-gradient(#e60012, #e60012) !important;
	}

	.list-body {
		background-color: #f3fbff;
		padding-bottom: 113px;
	}

	.apply-info {
		min-height: 70vh;
		width: 710upx;
		margin: 0 auto;
		background-color: #FFFFFF;
		border-radius: 5px;
		padding: 12px 16px;
		box-sizing: border-box;
		margin-top: 12px;
	}

	.row {
		padding: 10upx;
		margin-bottom: 20upx;
		border-bottom: 1upx solid #eeeeee;
	}

	.uni-list-cell {
		display: flex;
		padding: 10upx;
		margin-bottom: 20upx;
		border-bottom: 1upx solid #eeeeee;
	}

	.addNew {
		width: 50px;
		height: 50px;
		border-radius: 25px;
		line-height: 50px;
		box-shadow: 0 0 6px 2px rgba(0, 0, 0, .3);
		z-index: 100;
		position: fixed;
		bottom: 20px;
		right: 20px;
	}

	.select {
		margin: auto;
		box-shadow: 0upx 5upx 10upx rgba(0, 0, 0, 0.4);
		width: 400rpx;
		height: 80rpx;
		line-height: 80rpx;
		font-size: 30rpx;
	}

	.save-btn {
		height: 80rpx;
		color: #fff;
		font-size: 30upx;
		justify-content: center;
		align-items: center;
	}

	.dialogWrap {
		position: fixed;
		width: 100vw;
		height: 100vh;
		background-color: rgba(0, 0, 0, .3);
		top: 0;
		left: 0;
		z-index: 110;
	}

	.dialogCont {
		width: 80vw;
		position: absolute;
		top: 50%;
		margin: auto;
		background-color: #ffffff;
		left: 10vw;
		transform: translateY(-50%);
		padding: 20rpx;
		border-radius: 20rpx;
	}

	.dialogTitle {
		font-size: 36rpx;
		padding-bottom: 20rpx;
		border-bottom: 1upx solid #eeeeee;
		display: flex;
		justify-content: space-between;
	}

	.uni-form-item {
		padding: 10px 0;
		display: flex;
		border-bottom: 1upx solid #eeeeee;
	}

	.uni-form-item>.title,
	>>>uni-input,
	>>>.uni-input,
	>>>.uni-input-wrapper,
	>>>.input-placeholder {
		height: 80upx;
		line-height: 80upx;
		font-size: 32upx;
		width: 160upx;
	}

	>>>uni-input,
	>>>.uni-input,
	>>>.uni-input-wrapper,
	>>>.input-placeholder {
		width: 100%;
	}

	.content {
		flex: 1;
	}

	.uni-btn-v {
		text-align: center;
	}

	.dialogCloseImg {
		width: 52rpx;
		height: 52rpx;
		background-image: url('../../../static/my/my_apply/zuofei.png');
		background-repeat: no-repeat;
		background-size: cover;
	}

	.uni-label-pointer {
		min-width: 50%;
		margin: 0 !important;
		line-height: 90upx;
	}

	>>>uni-radio-group {
		display: flex;
	}
</style>
