<template>
	<view>
		<u--form labelPosition="left" labelAlign="center" :model="content" ref="uForm" :rules="rules"
			:labelStyle="{fontSize:'32rpx'}" labelWidth="130"> <u-form-item label="督办事项:" borderBottom prop="title">
				<u--input placeholder='请输入督办事项' v-model="content.title" border="none"></u--input>
			</u-form-item>
			<!-- <u-form-item label="处室及负责人:" borderBottom prop="departmentHead">
						<u--input v-model="content.departmentHead" border="none" readonly></u--input>
					</u-form-item> -->
			<!-- <u-form-item label="信息类别:" borderBottom prop="infoType">
						<u--textarea type="textarea" v-model="content.infoType" placeholder="请输入信息类别"
							border="none"></u--textarea>
					</u-form-item> -->
			<u-form-item label="督办来源:" borderBottom prop="infoSource">
				<uni-data-select @change="infoSourceChange" v-model="content.infoSource" :clear="false"
					placeholder="请选择督办来源" :localdata="InfoList"></uni-data-select>
			</u-form-item>
			<u-form-item label="督办内容:" borderBottom prop="infoSourceContent">
				<u--textarea type="textarea" v-model="content.infoSourceContent" :placeholder="infoSourceContent"
					border="none"></u--textarea>
			</u-form-item>

			<u-form-item label="完成时限:" @click="typeChange('shixian')" borderBottom prop="doneTime">
				<view>
					{{content.doneTime}}
				</view>
				<!-- <u--input v-model="content.doneTime" border="none" readonly></u--input> -->
			</u-form-item>

			<u-form-item label="责任处室:" borderBottom prop="prersonLiable">
				<u--textarea disabled style="width: 190rpx;" type="textarea" v-model="content.prersonLiable"
					placeholder="请选择责任处室" border="none"></u--textarea>
				<u-button size="small" type="primary" text="选择" @click="handelSelect"
					style="margin-top: 40rpx;width: 50rpx;margin-right: 10rpx;"></u-button>
			</u-form-item>
			<!-- <u-form-item label="各处室进度详情:" style="" borderBottom prop="ywSupervisionItemList"> -->
			<view style="text-align: center;font-size: 34rpx;margin-top: 50rpx;font-weight: 700;" class="">
				各处室进度详情:
			</view>
			<view v-for="item in content.ywSupervisionItemList" :key="item.id"
				style="padding: 20rpx 40rpx;border-bottom: 1px solid #ceccca;background-color: #fff;">
				<uni-card style="width:600rpx">

					<view style='margin:20rpx 40rpx' class="">
						<text> 部门： {{item.deptName}}</text>
						<br />
						<text> 姓名： {{item.userName}}</text>
						<br />
						<text>
							进展情况：<view v-if="
                            userId == item.userId &&
                            item.submitState != '1' " class="">
								<u--textarea type="textarea" v-model="item.progress"
									placeholder="请输入进展情况"></u--textarea><br />
							</view>

							<span v-else class="">
								{{item.progress}}
								<br />
							</span>
						</text>
						<text>
							完成佐证材料：<view v-if="
                            userId == item.userId &&
                            item.submitState != '1' " class="example-body">
								<uni-file-picker file-mediatype="all" mode="grid" @select="select" @progress="progress"
									@success="success" @fail="fail">
								</uni-file-picker>
							</view>
							<view v-else
								style="border-radius: 8rpx;background-color: #f3f3f3;margin-top: 40rpx;padding: 20rpx 40rpx;">
								<!-- <view style="display: flex;align-items: center;margin-bottom: 20rpx;f">
									<u-icon name="file-text-fill" color="#000"></u-icon>
									附件
								</view> -->
								<view style="margin-bottom: 30rpx;" v-for="v in item.ywFileList" :key="v.fileId">
									<u--text :lines="1" size="15" color="#2979FF" decoration="underline" :text="v.name"
										@click="downLoad(v.url)">{{v.name}}</u--text>
								</view>
							</view>
						</text>
						<br />
						<text>
							领导意见：<u--textarea v-if="
                            userId == item.leaderUserId &&
                            item.submitState == '1'
                          " type="textarea" v-model="item.leaderMsg" placeholder="请输入领导意见"></u--textarea></text>
					</view>
					<span style="display: flex;" v-if="item.leaderApprove == '0'">
						<u-button style="width: 100rpx;" v-if="
					                              userId == item.leaderUserId &&
					                              item.submitState == '1'
					                            " size="small" @click="sendBackInfo(item)" type="error">退回
						</u-button>
						<u-button style="width: 100rpx;margin-left:20rpx" v-if="
					                              userId == item.leaderUserId &&
					                              item.submitState == '1'
					                            " size="small" @click="pass(item)" type="primary">通过
						</u-button>
					</span>
				</uni-card>
				<!-- <view v-if="showTijiao" style="padding: 0 20rpx;"> -->
				<!-- <u-button v-if="title=='督办编辑'" type="primary" text="保存" @click="keep"
					style="margin-top: 40rpx;"></u-button> -->
				<u-button type="primary" text="提交" @click="sumbitSupervise" style="margin-top: 40rpx;"></u-button>
				<!-- <u-button v-else type="warning" text="提交" @click="submit" style="margin-top: 40rpx;"></u-button> -->
				<!-- </view> -->
			</view>

			<!-- </u-form-item> -->

		</u--form>
		<u-calendar placeholder="请选择日期" :show="show1" mode="single" allowSameDay @confirm="confirmOne"
			@close="show1 = false"></u-calendar>
		<u-modal :show="peoShow1" title="请选择接收领导" showCancelButton @cancel="cancel1" @confirm="queren1">
			<view style="width: 100%;height: 40vh;overflow: auto;" v-if="peoShow1 == true">
				<u-radio-group v-model="value1" @change="radioChange1" iconPlacement="right">
					<u-collapse accordion style="width: 100%;">
						<u-collapse-item :title="v.Name" :name="v.No" :key="v.No" v-for="v in deptList"
							style="width: 100%;">
							<view style="font-size: 32rpx; padding: 20rpx 0; border-bottom: 1px solid #eaeaea;"
								v-for=" i in userList" :key="i.NO" v-if="i.FK_Dept == v.No">
								<u-radio :label="i.Name" :name="i"></u-radio>
							</view>
						</u-collapse-item>
					</u-collapse>
				</u-radio-group>
			</view>
		</u-modal>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				userId: '',
				uploadUrl: uni.getStorageSync('baseUrl') + "/system/file/fileupload",
				baseURL: null,
				dataSubmit: {
					ywFileList: [],
					leaderUserName: ""
				},
				rowThis: {},
				peoShow1: false,
				show1: false,
				typeDate: '',
				content: {
					ywSupervisionStartUserList: [],
					prersonLiable: ''
				},
				rules: {},
				InfoList: [],
				infoSourceContent: '',
				db_template: [],
				title: '',
				deptList: [],
				userList: [],
				dataInfo: {},
				Optionsid: null,
				showTijiao: false,
				tijiaoBtn: false
			}
		},
		onLoad(options) {
			// console.log('config.baseURL', this.arg)
			this.baseURL = uni.getStorageSync('baseUrl');
			this.Optionsid = options.id
			this.getDictsInfo()
			this.getPeoList('016')
			uni.setNavigationBarTitle({
				title: options.title
			})
			this.title = options.title

			uni.$u.http.get('/getInfo').then((res) => {
				console.log('res1', res)
				this.userId = res.user.userId
				setTimeout(() => {
					uni.$u.http.get('/offcial/supervision/' + options.id).then((res) => {
						console.log('res2222', res)
						console.log(this.userId)
						this.content = res.data
						this.dataInfo.supervisionId = res.data.id;
						this.content.prersonLiable = ''
						this.content.ywSupervisionStartUserList = []

						this.tijiaoBtn = res.data.submitState == "1" ? true : false;
						this.showTijiao = false;
						for (let i = 0; i < this.content.ywSupervisionItemList.length; i++) {
							if (
								this.content.ywSupervisionItemList[i].userId == this.userId &&
								this.content.ywSupervisionItemList[i].submitState == "0"
							) {
								this.showTijiao = true;
							}
						}
					})
				}, 200)

			})

		},
		onShow() {
			uni.$once('query', (query) => {
				if (query.a == 'two') {
					if (this.content.prersonLiable != null) {
						// let arrPeo = this.content.prersonLiable.split(",");
						// let arr = getApp().globalData.zerenList.split(',')
						// arr = arr.concat(this.content.prersonLiable)
						this.content.prersonLiable = getApp().globalData.zerenList
						// this.content.prersonLiable = arr.join(" , ");
						this.content.ywSupervisionStartUserList = getApp().globalData.ywListZR
					} else {
						this.content.prersonLiable = getApp().globalData.zerenList
					}
				}
			})
		},
		methods: {
			sumbitSupervise() {
				this.content.submitState = '1'
				this.content.id = null
				this.content.ywSupervisionStartUserList.forEach((item) => {
					item.id = null
				})
				uni.$u.http.post('/offcial/supervision', this.content).then((res) => {
					uni.showToast({
						title: "提交成功",
						icon: "none",
						mask: true,
						duration: 3000
					})
					uni.navigateBack()
					uni.$emit('query', {
						a: 'back'
					})
				})
			},
			downLoad(path) {
				console.log('’', path)
				uni.downloadFile({
					url: path,
					success: (res) => {
						var filePath = res.tempFilePath;
						uni.openDocument({
							filePath: filePath,
							showMenu: true,
							success: function(res) {
								console.log('打开文档成功');
							}
						});
					}
				})
			},
			sendBackInfo(row) {
				if (
					row.leaderMsg == "" ||
					row.leaderMsg == null ||
					row.leaderMsg == undefined
				) {
					uni.showToast({
						title: "请填写领导意见",
						icon: "none",
						mask: true,
						duration: 3000
					})
					return;
				} else {
					this.dataInfo.id = row.id;
					this.dataInfo.leaderMsg = row.leaderMsg;
					this.dataInfo.leaderApprove = "1";
					uni.$u.http.post('/offcial/supervision/leaderApprove', this.dataInfo).then(res => {
						uni.showToast({
							title: "退回成功",
							icon: "none",
							mask: true,
							duration: 3000
						})
						uni.$u.http.get('/offcial/supervision/' + Optionsid).then((res) => {
							console.log('res', res)
							this.content = res.data
							this.dataInfo.supervisionId = res.data.id;
							this.tijiaoBtn = res.data.submitState == "1" ? true : false;
							this.showTijiao = false;
							for (let i = 0; i < this.content.ywSupervisionItemList.length; i++) {
								if (
									this.content.ywSupervisionItemList[i].userId == this.userId &&
									this.content.ywSupervisionItemList[i].submitState == "0"
								) {
									this.showTijiao = true;
								}
							}
						})
					})
				}
			},
			pass(row) {
				if (
					row.leaderMsg == "" ||
					row.leaderMsg == null ||
					row.leaderMsg == undefined
				) {
					uni.showToast({
						title: "请填写领导意见",
						icon: "none",
						mask: true,
						duration: 3000
					})
					return;
				} else {
					this.dataInfo.id = row.id;
					// this.dataInfo.supervisionId = row.id;
					this.dataInfo.leaderMsg = row.leaderMsg;
					this.dataInfo.leaderApprove = "2";
					uni.$u.http.post('/offcial/supervision/leaderApprove', this.dataInfo).then(res => {
						uni.showToast({
							title: "通过成功",
							icon: "none",
							mask: true,
							duration: 3000
						})
						uni.$u.http.get('/offcial/supervision/' + Optionsid).then((res) => {
							console.log('res', res)
							this.content = res.data
							this.dataInfo.supervisionId = res.data.id;
							this.tijiaoBtn = res.data.submitState == "1" ? true : false;
							this.showTijiao = false;
							for (let i = 0; i < this.content.ywSupervisionItemList.length; i++) {
								if (
									this.content.ywSupervisionItemList[i].userId == this.userId &&
									this.content.ywSupervisionItemList[i].submitState == "0"
								) {
									this.showTijiao = true;
								}
							}
						})
					})
				}
			},
			select(e) {
				console.log('e', e)
			},
			process(e) {
				console.log('process', e)
			},
			queren1() {
				this.peoShow1 = false
			},
			radioChange1(e) {
				console.log('65846', e)
				this.content.params.toEmps = e.NO
				this.content.toEmpsName = e.Name
			},
			cancel1() {
				this.peoShow1 = false
				this.content.params.toEmps = null
				this.content.toEmpsName = null
				this.value1 = null
			},
			submit() {
				this.peoShow1 = true
			},
			//获取接收人信息
			getPeoList(v) {
				uni.$u.http.get(`/jflow/restful/GenerNextStepNodeEmpsNoWorkId?flowNo=${v}&toNodeID=602`).then(
					res => {
						this.deptList = res.Depts
						this.userList = res.Emps
						console.log(this.deptList)
						console.log(this.userList)
					})
			},
			keep() {
				uni.showLoading({
					title: "保存中...",
					mask: true
				})
				uni.$u.http.put("/offcial/supervision", this.content).then(res => {
					uni.showToast({
						title: "保存成功",
						icon: "none",
						mask: true,
						duration: 3000
					})
					uni.hideLoading()
					uni.$emit('query', {
						a: 'back'
					})
					setTimeout(() => {
						uni.navigateBack()
					}, 2000)
				}).catch((err) => {
					uni.showToast({
						title: err.msg,
						icon: "none",
						mask: true,
						duration: 3000
					})
					uni.hideLoading()
				})

			},
			handelSelect() {
				uni.navigateTo({
					url: `/pages/zerenchushi/zerenchushi?zaici=` + '1'
				})
			},
			confirmOne(e) {
				if (this.typeDate == 'shixian') {
					console.log('11')
					this.content.doneTime = e[0]
				}
				this.show1 = false
			},
			typeChange(e) {
				this.show1 = true
				this.typeDate = e
			},
			infoSourceChange(val) {
				console.log("db_template", this.db_template);
				console.log('val', val);
				this.infoSourceContent = this.db_template[val - 1].text;
			},
			getDictsInfo() {
				uni.$u.http.get('/system/dict/data/type/info_source').then(res => {
					this.InfoList = res.data.map((item, index) => {
						let obj = {
							value: item.dictValue,
							id: item.dictValue,
							text: item.dictLabel
						}
						return obj
					})
				})
				uni.$u.http.get('/system/dict/data/type/db_template').then(res => {
					this.db_template = res.data.map((item, index) => {
						let obj = {
							value: item.dictValue,
							id: item.dictValue,
							text: item.dictLabel
						}
						return obj
					})
				})
			}
		}
	}
</script>

<style>

</style>