<template>
	<view>
		<view class="title">检测申请方填写</view>

		<view class="form_group">
			<view class="label">委托单编号</view>
			<view class="tag">
				<text class="icon more">&#xe631;</text>
				<text class="span">{{item.wt_num}}</text>
			</view>
		</view>
		<view class="form_group">
			<view class="label">标题</view>
			<view class="tag">
				<text class="icon more">&#xe631;</text>
				<text class="span">{{item.title}}</text>
			</view>
		</view>
		<view class="form_group">
			<view class="label">申请单位/部门</view>
			<view class="tag">
				<text class="icon more">&#xe631;</text>
				<text class="span">{{item.dept}}</text>
			</view>
		</view>
		<view class="form_group">
			<view class="label">试验目的</view>
			<view class="tag">
				<text class="icon more">&#xe631;</text>
				<text class="span">{{item.purpose}}</text>
			</view>
		</view>

		<view class="form_group">
			<view class="label">申请人</view>
			<view class="tag">
				<text class="icon more">&#xe631;</text>
				<text class="span">{{item.applicant}}</text>
			</view>
		</view>
		<view class="form_group">
			<view class="label">电话</view>
			<view class="tag">
				<text class="icon more">&#xe631;</text>
				<text class="span">{{item.tel}}</text>
			</view>
		</view>
		<view class="form_group">
			<view class="label">试验部门</view>
			<view class="tag">
				<text class="icon more">&#xe631;</text>
				<text class="span">{{item.test_dept}}</text>
			</view>
		</view>
		<view class="form_group">
			<view class="label">所属项目﻿</view>
			<view class="tag">
				<text class="icon more">&#xe631;</text>
				<text class="span">{{item.item}}</text>
			</view>
		</view>
		<view class="form_group">
			<view class="label">试验类型﻿</view>
			<view class="tag">
				<text class="icon more">&#xe631;</text>

				<text class="span"> {{item.product}} </text>

				<text class="span"> {{item.experiment_type}} </text>
			</view>
		</view>
		<view class="form_group">
			<view class="label">﻿项目编号﻿﻿</view>
			<view class="tag">
				<text class="icon more">&#xe631;</text>
				<text class="span">{{item.item_num}}</text>
			</view>
		</view>
		<view class="form_group">
			<view class="label">结果形式</view>
			<view class="tag">
				<u-subsection :list="radio" :current="current" @change="change"></u-subsection>
			</view>
		</view>
		<view class="form_group">
			<view class="label">﻿模板﻿﻿</view>
			<view class="tag">
				<text class="icon more">&#xe631;</text>
				<text class="span">{{item.item_num}}</text>
			</view>
		</view>


		<view class="title">设置审批人员</view>
		<view class="form_group" @click="select('1')">
			<view class="label omit" style="width: 200px;">需求审核-产品经理或主管人员</view>
			<view class="tag">
				<text class="icon more">&#xe631;</text>
				<text class="span">{{item.WTXQSH}}</text>
			</view>
		</view>
		<view class="form_group" @click="select('2')">
			<view class="label omit" style="width: 200px;">试验审核-试验对接人</view>
			<view class="tag">
				<text class="icon more">&#xe631;</text>
				<text class="span">{{item.WTSYSH}}</text>
			</view>
		</view>
		<view class="form_group" @click="select('3')">
			<view class="label omit" style="width: 200px;">需求批准-本部门领导</view>
			<view class="tag">
				<text class="icon more">&#xe631;</text>
				<text class="span">{{item.WTXQPZ}}</text>
			</view>
		</view>
		<view class="form_group" @click="select('4')">
			<view class="label omit" style="width: 200px;">试验批准</view>
			<view class="tag">
				<text class="icon more">&#xe631;</text>
				<text class="span">{{item.WTSYPZ}}</text>
			</view>
		</view>
		<view class="form_group" @click="select('5')">
			<view class="label omit" style="width: 200px;">任务分派-任务分派人</view>
			<view class="tag">
				<text class="icon more">&#xe631;</text>
				<text class="span">{{item.WTRWFP}}</text>
			</view>
		</view>
		<view class="title">样机</view>
		<view class="form_group">
			<view class="label">GH560</view>
			<view class="tag">
				<text class="icon more">&#xe631;</text>
				<text class="span">XH890656565556</text>
			</view>
		</view>
		<view class="form_group">
			<view class="label">GH560</view>
			<view class="tag">
				<text class="icon more">&#xe631;</text>
				<text class="span">XH890656565556</text>
			</view>
		</view>




		<view>
			<u-popup :show="show" mode="bottom">
				<view class="content">
					<scroll-view scroll-y="true" style="height: 300rpx;">
						<view>
							<view>提交流程面板</view>
							<view v-for="(item, index) in nextNodes" :key="index" style="float: left;">
								{{item.name}}:
							</view>
							<u-radio-group @change="radioGroupChange">
								<u-radio v-for="(item, index) in nextNodes" :key="index" :name="item.id">

								</u-radio>
							</u-radio-group>

						</view>
					</scroll-view>
					<view class="confrim-btn">
						<u-button @click="submit()">确定</u-button>
					</view>
				</view>
			</u-popup>
			<u-popup :show="bshow" mode="bottom">
				<view class="content">
					<scroll-view scroll-y="true" style="height: 300rpx;">
						<view>
							<view>回退流程面板</view>
							<view v-for="(item, index) in backNodes" :key="index" style="float: left;">
								{{item.name}}:
							</view>
							<u-radio-group @change="radioGroupChange">
								<u-radio v-for="(item, index) in backNodes" :key="index" :name="item.id">

								</u-radio>
							</u-radio-group>

						</view>
					</scroll-view>
					<view class="confrim-btn">
						<u-button @click="workflowsback()">确定</u-button>
					</view>
				</view>
			</u-popup>

		</view>
		<view class="footer">

			<button class="btn ws" @click="submission()" v-if="btnshow">提交</button>
			<button class="btn ws" @click="back()" v-if="btnshow&& state == 1">回退</button>
		</view>



	</view>






</template>

<script>
	let qrcode = require('@/common/code.js');
	export default {
		data() {
			return {
				p: {},
				item: {},
				current: 0,
				radio: [{
					name: '正式报告'
				}, {
					name: '仅原始数据'
				}, {
					name: '协助试验'
				}],
				id: '',
				items: {
					document: {
						items: {}
					}
				},
				show: false,
				bshow: false,
				itemt: {},
				up: {},
				content: '标题',
				nextNodes: [],
				backNodes: [],
				touser: {
					nodeid: "1649917385058",
					isToPerson: true,
					userids: "__jFFZYvLIG6uFc7CdBMg"
				},
				btnshow: false,
                   state:0,
			};
		},
		onLoad(e) {

			this.id = e.id;
			//传过来的id
			this.state=e.ste;
			if (e.ste == 1) {
				/* this.http.request({
					url: this.http.urls.xxxx + e.id,
					success: res => {
						this.item = res.data.data;
					}
				}); */
				this.getDocuments();
			} else if (e.ste == 2) {
				this.empty();
			}
			//选中审批人员监听函数,其它类型的参考这个
			uni.$on('select', res => {
				console.log('asd2:' + JSON.stringify(res));
				if (res.ste == 1) {
					this.item.WTXQSH = res.items.__L5a8n9ZH5gJC0CL1s6X.value;
				} else if (res.ste == 2) {
					this.item.WTSYSH = res.items.__0ils0bIBD7Vf90TjVb3.value;
				} else if (res.ste == 3) {
					this.item.WTXQPZ = res.items.__uiMgMPHg9jmqTXzwdzl.value;
				} else if (res.ste == 4) {
					this.item.WTSYPZ = res.items.__WSh3KXD8wfeyU3FbipN.value;
				} else if (res.ste == 5) {
					this.item.WTRWFP = res.items.__IzBqxyYJhOYJntHpmEv.value;
				}
			});
		},
		methods: {

			// 选中任一radio时，由radio-group触发
			radioGroupChange(e) {
				// console.log(e);
				this.itemt.nextNodeIds = [];
				this.itemt.nextNodeIds.push(e);
			}, //详情
			getDocuments() {


				this.http.request({
					url: this.http.urls.documents + this.id,
					data: this.item,
					loading: 'false',
					success: res => {
						this.item = res.data.data.items;
						this.p = res.data.data;


						if (this.p.lastFlowOperation == undefined || this.p.auditorList.includes(this.getUser()
								.id)) {
							console.log('this.p1:' + JSON.stringify(this.p));
							this.btnshow = true;
						}


						//this.current=res.data.data.items.report_type;
						if (this.item.report_type == '正式报告') {
							this.current = 0;
						} else if (this.item.report_type == '仅原始数据') {
							this.current = 1;
						} else if (this.item.report_type == '协助试验') {
							this.current = 2;
						}
						this.iteml = res.data.data;

						this.items.applicationId = "__gAPYBW4YxB3UePM3lqO";
						this.items.docId = this.iteml.id;
						this.items.id = this.iteml.id;
						this.items.formId = this.iteml.formid;
						this.items.parentId = "";
						this.items.subSelects = [];
						this.items.templateForm = "";
						this.items.viewId = "";
						this.items.document.items = this.item;
						this.items.document.applicationId = "__gAPYBW4YxB3UePM3lqO";
						this.items.document.exparams = {};
						this.items.document.formId = this.iteml.formid;
						this.items.document.id = this.iteml.id;
						this.items.document.parentId = "";
						this.items.document.sign = "";
						this.items.document.stateId = this.iteml.stateid;
						this.items.document.subDocuments = [];
						this.items.document.templateForm = "";
						this.items.document.versions = "0";
					}
				});
			},
			empty() {
				this.btnshow = true;
				this.http.request({
					url: this.http.urls.empty,
					data: this.item,

					success: res => {
						console.log('res2:' + JSON.stringify(res));
						this.item = res.data.data.items;
						this.p = res.data.data;
						console.log('this.p1:' + JSON.stringify(this.p));
						//this.current=res.data.data.items.report_type;
						if (this.item.report_type == '正式报告') {
							this.current = 0;
						} else if (this.item.report_type == '仅原始数据') {
							this.current = 1;
						} else if (this.item.report_type == '协助试验') {
							this.current = 2;
						}
						this.iteml = res.data.data;

						this.items.applicationId = "__gAPYBW4YxB3UePM3lqO";
						this.items.docId = this.iteml.id;
						this.items.id = this.iteml.id;
						this.items.formId = this.iteml.formid;
						this.items.parentId = "";
						this.items.subSelects = [];
						this.items.templateForm = "";
						this.items.viewId = "";
						this.items.document.items = this.item;
						this.items.document.applicationId = "__gAPYBW4YxB3UePM3lqO";
						this.items.document.exparams = {};
						this.items.document.formId = this.iteml.formid;
						this.items.document.id = this.iteml.id;
						this.items.document.parentId = "";
						this.items.document.sign = "";
						this.items.document.stateId = this.iteml.stateid;
						this.items.document.subDocuments = [];
						this.items.document.templateForm = "";
						this.items.document.versions = "0";
					}
				});
			},
			//选择结果形式
			change(e) {
				this.current = e;
				console.log('aa:' + this.radio[this.current].name);
				this.item.report_type = this.radio[this.current].name;
			},
			//选择审批人员
			select(e) {
				uni.navigateTo({
					url: '/pages/index/select?ste=' + e
				});
			},
			//提交
			add() {
				this.http.request({
					url: this.http.urls.user_task_add,
					data: this.item,
					method: 'POST',
					success: res => {
						uni.showModal({
							title: '提示',
							content: '提交成功',
							showCancel: false,
							success: res => {
								if (res.confirm) {
									uni.navigateBack();
								}
							}
						});
					}
				});
			},
			//提交流程面板
			submission() {


				this.http.request({
					url: this.http.urls.documents + this.id + "/panels/submission",
					data: this.items,

					method: 'POST',
					success: res => {
						//this.item=res.data.data;
						console.log('zx22:' + JSON.stringify(res));
						this.show = true;

						this.title = res.data.data.name;
						this.nextNodes = res.data.data.nextNodes;
						this.itemt.flowId = res.data.data.flowId;
						this.itemt.flowType = "80";
						this.itemt.currentNodeId = res.data.data.currentNodeId;
						this.itemt.attitude = "";
						this.itemt.signature = "";
						this.itemt.submitTo = "";
						this.itemt.circulatorInfo = "";
						this.itemt.subFlowApproverInfo = "";
						this.itemt.subFlowApproverInfoAll = "";
						this.itemt.document = this.items.document;
						//this.content=res.data.data.formname;
					}
				});
			}, //提交流程
			submit() {
				//this.itemt.document.items.purpose="试验目的5656";
				//this.itemt.document.items.title="标题5656";
				this.itemt.applicationId = "__gAPYBW4YxB3UePM3lqO";
				this.itemt.docId = this.iteml.id;
				this.itemt.id = this.iteml.id;
				this.itemt.formId = this.iteml.formid;
				this.itemt.parentId = "";
				this.itemt.subFlowApprover = [];
				this.itemt.subSelects = [];
				this.itemt.submitTo = [];
				this.itemt.templateForm = "";
				this.itemt.viewId = "";
				this.http.request({
					url: this.http.urls.documents + this.id + "/workflows/submit",
					data: this.itemt,

					method: 'PUT',
					success: res => {
						//this.item=res.data.data;
						console.log('zx22:' + JSON.stringify(res));
						this.show = false;

						this.title = res.data.data.name;
						this.nextNodes = res.data.data.nextNodes;
						uni.$emit('index');
						uni.redirectTo({
							url: '/pages/index/index',

						});
						//this.content=res.data.data.formname;
					}
				});
			}, //刷新数据
			//回退流程面板
			back() {


				this.http.request({
					url: this.http.urls.documents + this.id + "/panels/back",
					data: this.items,

					method: 'POST',
					success: res => {
						//this.item=res.data.data;
						console.log('zx22:' + JSON.stringify(res.data.data));
						this.bshow = true;

						this.title = res.data.data.name;
						this.backNodes = res.data.data.backNodes;
						this.itemt.flowId = res.data.data.flowId;
						this.itemt.flowType = "81";
						this.itemt.currentNodeId = res.data.data.currentNodeId;
						this.itemt.attitude = "";
						this.itemt.signature = "";
						this.itemt.submitTo = "";
						this.itemt.circulatorInfo = "";
						this.itemt.subFlowApproverInfo = "";
						this.itemt.subFlowApproverInfoAll = "";
						this.itemt.document = this.items.document;
						//this.content=res.data.data.formname;
					}
				});
			}, //提交回退流程
			workflowsback() {
				//this.itemt.document.items.purpose="试验目的111";
				this.itemt.applicationId = "__gAPYBW4YxB3UePM3lqO";
				this.itemt.docId = this.iteml.id;
				this.itemt.id = this.iteml.id;
				this.itemt.formId = this.iteml.formid;
				this.itemt.parentId = "";
				this.itemt.subFlowApprover = [];
				this.itemt.subSelects = [];
				this.itemt.submitTo = [];
				this.itemt.templateForm = "";
				this.itemt.viewId = "";
				this.http.request({
					url: this.http.urls.documents + this.id + "/workflows/back",
					data: this.itemt,

					method: 'PUT',
					success: res => {
						//this.item=res.data.data;
						console.log('zx22:' + JSON.stringify(res));
						this.bshow = false;

						this.title = res.data.data.name;
						this.nextNodes = res.data.data.nextNodes;
						uni.$emit('index');
						uni.redirectTo({
							url: '/pages/index/index',

						});
						//this.content=res.data.data.formname;
					}
				});
			},
		}
	};
</script>

<style lang="scss">
	.title {
		padding: 12px;
		font-weight: bold;
		font-size: 16px;
	}

	.tag {
		float: right;
		margin-top: -18px;
		width: 70%;
		text-align: left;

		.span {
			float: right;
			color: #545555;
		}

		.code {
			font-size: 25px;
		}

		.more {
			float: right;
			margin-top: 2px;
			color: darkgray;
		}

		.uni-label-pointer {
			padding: 5px;
		}
	}
</style>
