<template>
	<view style="background-color: #fff;" v-if="content != null">
		<view
			style="height: 100rpx;display: flex;align-items: center;justify-content: space-around;border-bottom: 1px solid #ceccca;background-color: #fff;"
			v-if="type == 0">
			<!-- <u-tabs :list="list1"  :current="current" @click="click"></u-tabs> -->
			<view class="tab" :class="current==0?'active':''" @click="current = 0">
				基本信息
			</view>
			<view style="border-left: 1px solid #ceccca;height: 80%;">

			</view>
			<view class="tab" :class="current==0?'':'active'" @click="current = 1">
				流转记录
			</view>
		</view>
		<swiper style="background-color:#fff ;" :style="{height:type==0?'calc(100vh - 100rpx)':'100vh'}"
			:current="current" disable-touch>
			<swiper-item>
				<view style="height: 100%;overflow: auto;">
					<u--form labelPosition="left" labelAlign="center" :model="content" ref="uForm"
						:labelStyle="{fontSize:'32rpx'}" labelWidth="100">
						<view v-if="fkFlow == '006'">
							<u-form-item label="出差处室:" borderBottom ref="item1">
								<view class="content">
									{{content.outWorkDept}}
								</view>
							</u-form-item>
							<u-form-item label="出差人:" borderBottom ref="item1">
								<view class="content">
									{{content.userName}}
								</view>
							</u-form-item>
							<u-form-item label="目的地:" borderBottom ref="item1">
								<view class="content">
									{{content.destination}}
								</view>
							</u-form-item>
							<u-form-item label="起止日期:" borderBottom ref="item1">
								<view class="content">
									{{content.startTime+' 至 '+content.endTime}}
								</view>
							</u-form-item>
						</view>
						<view v-if="fkFlow == '007'">
							<u-form-item label="申请人:" borderBottom ref="item1">
								<view class="content">
									{{content.userName}}
								</view>
							</u-form-item>
							<u-form-item label="邀请单位:" borderBottom ref="item1">
								<view class="content">
									{{content.inviteUnit}}
								</view>
							</u-form-item>
							<u-form-item label="培训名称:" borderBottom ref="item1">
								<view class="content">
									{{content.trainName}}
								</view>
							</u-form-item>
							<u-form-item label="目的地:" borderBottom ref="item1">
								<view class="content">
									{{content.destination}}
								</view>
							</u-form-item>
							<u-form-item label="起止日期:" borderBottom ref="item1">
								<view class="content">
									{{content.startTime+' 至 '+content.endTime}}
								</view>
							</u-form-item>
							<u-form-item label="授课题目:" borderBottom ref="item1">
								<view class="content">
									{{content.teacherTitle}}
								</view>
							</u-form-item>
							<u-form-item label="参加人数:" borderBottom ref="item1">
								<view class="content">
									{{content.numberOfParticipants}}
								</view>
							</u-form-item>
						</view>
						<view v-if="type==0" style="padding-bottom: 40rpx;">
							<u-form-item label="下一节点:" borderBottom ref="item1" v-if="overType==false">
								<uni-data-select v-model="content.jdindex" :clear="false" placeholder="请选择下一节点" :localdata="list"
									@change="change"></uni-data-select>
							</u-form-item>
							<!-- <u-form-item label="下发人员:" borderBottom v-if="DeliveryWay==4" ref="item1"
								@click="choosePeo">
								<view :style="{color:content.users==null?'rgb(192, 196, 204)':''}">
									{{content.users==null?'请选择人员': content.userList}}
								</view>
							</u-form-item> -->
							<u-form-item label="审批意见:" borderBottom ref="item1" v-if="gdType == false">
								<u--textarea v-model="content.reviewMsg" placeholder="请输入审批意见" autoHeight
									border="none"></u--textarea>
							</u-form-item>
							<view v-if="gdType == true">
								<u-form-item label="档案编号:" borderBottom ref="item1">
									<u--input v-model="content.archiveNo" placeholder="请输入档案编号"
										border="none"></u--input>
								</u-form-item>
								<u-form-item label="档案分类:" borderBottom ref="item1" @click="chooseGd">
									<view :style="{color:content.typeId==null?'rgb(192, 196, 204)':''}">
										{{content.typeId==null?'请选择档案分类': content.gdtype}}
									</view>
								</u-form-item>
							</view>
							<view style="margin-top: 40rpx;padding: 0 20rpx;box-sizing: border-box;"
								v-if="gdType == false">
								<u-button type="primary" text="提交" @click="submit"></u-button>
							</view>
							<view style="margin-top: 40rpx;padding: 0 20rpx;box-sizing: border-box;" v-else>
								<u-button type="primary" text="归档" @click="save"></u-button>
							</view>
						</view>
						<view style="padding: 20rpx;box-sizing: border-box;" v-else>
							<!-- <view v-for="(v,i) in record" :key="i" >
								<view v-if="v.ActionType22 != undefined">
									<view v-for="(item,index) in v.ActionType22" :key="index" style="border-radius: 10rpx;box-shadow: 0 0 10rpx #ccc;padding: 20rpx;margin-bottom: 30rpx;">
										<view style="font-size: 32rpx;padding-bottom: 6rpx;border-bottom: 1px solid #ccc;margin-bottom: 6rpx;">
											{{v.ActionType==2?item.NDFromT+"（"+v.ActionTypeText+"）":item.NDFromT}}
										</view>
										<view style="font-size: 28rpx;">
											收文部门：{{item.NodeData.split("DeptName=")[1]}}
										</view>
										<view style="font-size: 28rpx;">
											处理人：{{item.Exer.split(',')[1]}}
										</view>
										<view style="font-size: 28rpx;">
											处理时间：{{item.RDT}}
										</view>
										<view style="font-size: 28rpx;">
											审核意见：{{item.Msg}}
										</view>
									</view>
								</view>
								<view v-else style="border-radius: 10rpx;box-shadow: 0 0 10rpx #ccc;padding: 20rpx;margin-bottom: 30rpx;">
									<view style="font-size: 32rpx;padding-bottom: 6rpx;border-bottom: 1px solid #ccc;margin-bottom: 6rpx;">
										{{v.ActionType==2?v.NDFromT+"（"+v.ActionTypeText+"）":v.NDFromT}}
									</view>
									<view style="font-size: 28rpx;">
										收文部门：{{v.NodeData.split("DeptName=")[1]}}
									</view>
									<view style="font-size: 28rpx;">
										处理人：{{v.Exer.split(',')[1]}}
									</view>
									<view style="font-size: 28rpx;">
										处理时间：{{v.RDT}}
									</view>
								</view>
							</view> -->
							<u-steps :current="100" direction="column" v-if="record != null">
								<view v-for="(v,i) in record" :key="i">
									<view v-if="v.ActionType22 != undefined">
										<u-steps-item :error="v.ActionType==2?true:false" v-for="(item,index) in v.ActionType22" :key="index" :title='v.ActionType==2?item.NDFromT+"（"+v.ActionTypeText+"）":item.NDFromT'>
											<view slot="desc" style="color:#606266;">
												<view style="font-size: 28rpx;">
													收文部门：{{item.NodeData.split("DeptName=")[1]}}
												</view>
												<view style="font-size: 28rpx;">
													处理人：{{item.Exer.split(',')[1]}}
												</view>
												<view style="font-size: 28rpx;">
													处理时间：{{item.RDT}}
												</view>
												<view style="font-size: 28rpx;">
													审核意见：{{item.Msg}}
												</view>
											</view>
										</u-steps-item>
									</view>
									<u-steps-item :error="v.ActionType==2?true:false" :title='v.ActionType==2?v.NDFromT+"（"+v.ActionTypeText+"）": v.NDFromT' v-else>
										<view slot="desc" style="color: #606266">
											<view style="font-size: 28rpx;">
												收文部门：{{v.NodeData.split("DeptName=")[1]}}
											</view>
											<view style="font-size: 28rpx;">
												处理人：{{v.Exer.split(',')[1]}}
											</view>
											<view style="font-size: 28rpx;">
												处理时间：{{v.RDT}}
											</view>
										</view>
									</u-steps-item>
								</view>
							</u-steps>
						</view>
					</u--form>
				</view>

			</swiper-item>
			<swiper-item>
				<view
					style="padding: 20rpx;box-sizing: border-box;width: 100%;box-sizing: border-box;height: 100%;overflow: auto;">
					<!-- <view v-for="(v,i) in record" :key="i"  >
						<view v-if="v.ActionType22 != undefined">
							<view v-for="(item,index) in v.ActionType22" :key="index" style="border-radius: 10rpx;box-shadow: 0 0 10rpx #ccc;padding: 20rpx;margin-bottom: 30rpx;">
								<view style="font-size: 32rpx;padding-bottom: 6rpx;border-bottom: 1px solid #ccc;margin-bottom: 6rpx;">
									{{v.ActionType==2?item.NDFromT+"（"+v.ActionTypeText+"）":item.NDFromT}}
								</view>
								<view style="font-size: 28rpx;">
									收文部门：{{item.NodeData.split("DeptName=")[1]}}
								</view>
								<view style="font-size: 28rpx;">
									处理人：{{item.Exer.split(',')[1]}}
								</view>
								<view style="font-size: 28rpx;">
									处理时间：{{item.RDT}}
								</view>
								<view style="font-size: 28rpx;">
									审核意见：{{item.Msg}}
								</view>
							</view>
						</view>
						<view v-else style="border-radius: 10rpx;box-shadow: 0 0 10rpx #ccc;padding: 20rpx;margin-bottom: 30rpx;">
							<view style="font-size: 32rpx;padding-bottom: 6rpx;border-bottom: 1px solid #ccc;margin-bottom: 6rpx;">
								{{v.ActionType==2?v.NDFromT+"（"+v.ActionTypeText+"）":v.NDFromT}}
							</view>
							<view style="font-size: 28rpx;">
								收文部门：{{v.NodeData.split("DeptName=")[1]}}
							</view>
							<view style="font-size: 28rpx;">
								处理人：{{v.Exer.split(',')[1]}}
							</view>
							<view style="font-size: 28rpx;">
								处理时间：{{v.RDT}}
							</view>
						</view>
					</view> -->
					<u-steps :current="100" direction="column" v-if="record != null">
						<view v-for="(v,i) in record" :key="i">
							<view v-if="v.ActionType22 != undefined">
								<u-steps-item :error="v.ActionType==2?true:false" v-for="(item,index) in v.ActionType22" :key="index" :title='v.ActionType==2?item.NDFromT+"（"+v.ActionTypeText+"）":item.NDFromT'>
									<view slot="desc" style="color:#606266;">
										<view style="font-size: 28rpx;">
											收文部门：{{item.NodeData.split("DeptName=")[1]}}
										</view>
										<view style="font-size: 28rpx;">
											处理人：{{item.Exer.split(',')[1]}}
										</view>
										<view style="font-size: 28rpx;">
											处理时间：{{item.RDT}}
										</view>
										<view style="font-size: 28rpx;">
											审核意见：{{item.Msg}}
										</view>
									</view>
								</u-steps-item>
							</view>
							<u-steps-item :error="v.ActionType==2?true:false" :title='v.ActionType==2?v.NDFromT+"（"+v.ActionTypeText+"）": v.NDFromT' v-else>
								<view slot="desc" style="color: #606266">
									<view style="font-size: 28rpx;">
										收文部门：{{v.NodeData.split("DeptName=")[1]}}
									</view>
									<view style="font-size: 28rpx;">
										处理人：{{v.Exer.split(',')[1]}}
									</view>
									<view style="font-size: 28rpx;">
										处理时间：{{v.RDT}}
									</view>
								</view>
							</u-steps-item>
						</view>
					</u-steps>
				</view>
			</swiper-item>
		</swiper>

	</view>
</template>

<script>
	export default {
		data() {
			return {
				current: 0,
				content: null,
				statusList: [],
				//流转记录
				record: null,
				//待办已办
				type: 0,
				//节点列表
				list: [],
				//是否选择下发人员
				selectType: 3,
				workid: null,
				flowNo: null,
				id: null,
				//tabs
				list1: [{
						name: '待办内容'
					},
					{
						name: '流转记录'
					}
				],
				DeliveryWay: null, //判断是否需要审核意见
				gd: null, //密级列表
				gdType: false, //判断是否是归档
				overType: false, //判断是否结束
				//上个页面传过来的参数
				parameter: null,
				fkFlow:null,// 006 中层出差  007 外出授课备案
			}
		},
		onLoad(options) {
			let that = this
			that.parameter = options
			that.fkFlow = options.fkFlow
			that.getContent(options.workid)
			that.getRecord(options.workid)
			if (options.nodeName.indexOf('归档') != -1) {
				that.gdType = true
				that.getgd()
			}
			that.getDicts()
			that.type = options.type
			that.workid = options.workid
			that.flowNo = options.flowNo
			uni.setNavigationBarTitle({
				title: options.title
			})
			// if (options.type == 0) {
			// 	// that.jdList(options.workid, options.flowNo)
			// 	setTimeout(() => {
			// 		this.isOver(options)
			// 	}, 500)
			// 	// this.getjsPeo(options.workid, options.flowNo)
			// }
			
		},
		onShow() {
			uni.$once('query', (query) => {
				if (query.a == 1) {
					this.content.users = getApp().globalData.peoIdList
					this.content.userList = getApp().globalData.peoList
					this.$forceUpdate()
				} else if (query.a == 2) {
					this.content.typeId = getApp().globalData.gdId.split(",")[0]
					this.content.gdtype = getApp().globalData.gdId.split(",")[1]
					this.$forceUpdate()
				}
			})
		},
		methods: {
			click(e) {
				this.current = e.index
			},
			//查询收文详情
			getContent(id) {
				if(this.fkFlow == '006'){
					uni.$u.http.get('/system/work/sel/' + id).then(res => {
						// console.log(res)
						this.content = res.data
						if (this.gdType == true) {
							this.content.typeId = null //归档分类
							this.content.levels = null //密级
							this.content.archiveNo = null //档案编号
							this.content.archiveFormNo = null
							this.content.printNum = null //打印份数
							this.content.name = res.data.title //档案名称
							this.content.gdtype = null //分类名称
						}
						if(this.type==0){
							this.isOver(this.parameter)
						}
						this.statusList.forEach(item => {
							if (item.dictValue == res.data.emergencyDegree) {
								this.content.status = item.dictLabel
							}
						})
					})
				}else if(this.fkFlow == '007'){
					uni.$u.http.get('/system/registration/sel/' + id).then(res => {
						// console.log(res)
						this.content = res.data
						if (this.gdType == true) {
							this.content.typeId = null //归档分类
							this.content.levels = null //密级
							this.content.archiveNo = null //档案编号
							this.content.archiveFormNo = null
							this.content.printNum = null //打印份数
							this.content.name = res.data.title //档案名称
							this.content.gdtype = null //分类名称
						}
						if(this.type==0){
							this.isOver(this.parameter)
						}
						this.statusList.forEach(item => {
							if (item.dictValue == res.data.emergencyDegree) {
								this.content.status = item.dictLabel
							}
						})
					})
				}
				
			},
			// 查询字典数据详细  紧急程度
			getDicts() {
				uni.$u.http.get('/system/dict/data/type/urgent_type').then(res => {
					this.statusList = res.data
				})
			},
			//查询归档字典  秘籍
			getgd() {
				uni.$u.http.get('/system/dict/data/type/archive_levels').then(res => {
					this.gd = res.data.map((item, index) => {
						let obj = {
							value: item.dictCode,
							id: item.dictCode,
							text: item.dictLabel,
						}
						return obj
					})
				})
			},
			//查询流转记录
			getRecord(id) {
				uni.$u.http.get('/jflow/restful/getWfGenerWorkList', {
					params: {
						workID: id,
						token: uni.getStorageSync('jtoken')
					}
				}).then(res => {
					// console.log(res)
					this.record = res.trackList
					if (this.type == 0) {
						// this.content.jdindex = null //下一节点索引
						// this.content.nodeId = null //下一节点ID
						// this.content.optionName = null //节点名称
						this.content.reviewMsg = null //审批意见
						this.content.users = null //发送给指定人员
						// this.content.toNodeId = null 
						this.content.userList = null //人员列表
						this.content.workid = this.workid

					}
				})
			},
			//查询下一步所有节点
			jdList(id, flow) {
				uni.$u.http.get('/jflow/restful/GenerNextStepNode', {
					params: {
						workid: id,
						token: uni.getStorageSync('jtoken'),
						flowNo: flow
					}
				}).then(res => {
					this.id = res[0].id
					this.content.jdindex = 0 //下一节点索引
					this.DeliveryWay = res[0].DeliveryWay //下一节点状态
					this.content.toNodeId = res[0].id //下一节点ID
					this.content.nodeId = res[0].id //下一节点ID
					this.content.optionName = res[0].text //节点名称
					this.list = res.map((item, index) => {
						let obj = {
							value: index,
							id: item.NodeID,
							text: item.Name,
							DeliveryWay: item.DeliveryWay
						}
						return obj
					})
				})
			},
			//节点选择
			change(e) {
				if (e >= 0) {
					this.id = this.list[e].id
					this.DeliveryWay = this.list[e].DeliveryWay
					this.content.toNodeId = this.list[e].id
					this.content.nodeId = this.list[e].id
					this.content.optionName = this.list[e].text
				}

			},
			//选择人员相关
			choosePeo() {
				if (this.id == null) {
					uni.showToast({
						title: "请先选择下一节点",
						icon: "none"
					})
				} else {
					uni.navigateTo({
						url: `/pages/peoChoose/peoChoose?workid=${this.workid}&flowNo=${this.flowNo}&id=${this.id}`,
					})
				}
			},
			//选择归档分类
			chooseGd() {
				uni.navigateTo({
					url: "/pages/file/file"
				})
			},
			//判断是否为最后一步
			isOver(v) {
				uni.$u.http.get("/jflow/restful/judgeNode", {
					params: {
						nodeId: v.nodeId
					}
				}).then(res => {
					if (res.msg == "Y") {
						this.overType = true
					} else {
						this.overType = false
						this.jdList(v.workid, v.flowNo)
					}
				})
			},
			//提交待办
			submit() {
				if (this.overType == false && this.id == null) {
					uni.showToast({
						title: "请先选择下一节点",
						icon: "none"
					})
				} else if (this.content.reviewMsg == null) {
					uni.showToast({
						title: "请填写审核意见",
						icon: "none"
					})
				} else {
					uni.showLoading({
						title: "提交中...",
						mask: true
					})
					uni.$u.http.post("/offcial/receive/sendFlowToUsers", this.content, {
						header: {
							// 'content-Type: 'multipart/form-data'
							'content-Type': 'application/x-www-form-urlencoded'
						}
					}).then(res => {
							// uni.hideLoading()
						if (res.data.VarAcceptersName != "" && res.data.VarAcceptersName != "结束") {
							uni.showToast({
								title: "已发送到" + res.data.VarToNodeName + "节点，接收人：" + res
									.data.VarAcceptersName,
								icon: "none",
								mask: true,
								duration:3000
							})
						} else if (res.data.VarAcceptersName == "结束") {
							uni.showToast({
								title: res.data.Message,
								icon: "none",
								mask: true,
								duration:3000
							})
						} else {
							uni.showToast({
								title: res.data.Message.replaceAll("@", ""),
								icon: "none",
								mask: true,
								duration:3000
							})
						}
						
						uni.$emit('query', {
							a: 'back'
						})
						setTimeout(() => {
							uni.navigateBack()
						}, 2000)
					}).catch(res => {
						uni.hideLoading()
						uni.showToast({
							title:"请稍后重试",
							icon:"none"
						})
					})
				}
			},
			//保存归档
			save() {
				if (this.content.archiveNo == null) {
					uni.showToast({
						title: "请填写档案编号",
						icon: "none"
					})
				} else if (this.content.typeId == null) {
					uni.showToast({
						title: "请选择归档分类",
						icon: "none"
					})
				}else {
					this.content.reviewMsg = "同意"
					uni.showLoading({
						title: "提交中...",
						mask: true
					})
					uni.$u.http.post("/offcial/archive/save", this.content).then(res => {
						uni.$u.http.get('/jflow/restful/GenerNextStepAllNode', {
							params: {
								workid: this.parameter.workid,
								token: uni.getStorageSync('jtoken'),
								flowNo: this.parameter.flowNo,
							}
						}).then(qwe => {
							uni.showToast({
								title: "归档成功",
								icon: "none",
								mask: true
							})
							uni.$emit('query', {
								a: 'back'
							})
							setTimeout(() => {
								uni.navigateBack()
							}, 2000)
						})
					}).catch(res => {
						uni.hideLoading()
						uni.showToast({
							title:"请稍后重试",
							icon:"none"
						})
					})
				}
			}
		}
	}
</script>

<style lang="scss" scoped>
	.content {
		font-size: 32rpx;
	}

	.tab {
		width: 48%;
		height: 100%;
		box-sizing: border-box;
		display: flex;
		align-items: center;
		justify-content: center;
	}

	.active {
		color: #2979ff
	}
</style>