<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 v-if="title=='督办编辑'" size="small" type="primary" text="选择" @click="handelSelect"
					style="margin-top: 40rpx;width: 50rpx;margin-right: 10rpx;"></u-button>
			</u-form-item>
			<view v-if="title!='督办编辑'" class="">
				<view style="text-align: center;font-size: 34rpx;margin-top: 50rpx;font-weight: 700;" class="">
					各处室进度详情:
				</view>
				<view v-if="content.ywSupervisionItemList.length!=0" class="">
					<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="fileMediatype === 'image'" mode="grid"
									@select="select($event,item)" @progress="progress" @delete="deleteFile"
									@success="success" @fail="fail">
								</uni-file-picker> -->
										<u-button type="primary" @click="uploadPic(item)">上传</u-button>
										<!-- 展示 -->

										<view style="margin-bottom: 30rpx;display: flex;margin-top: 4rpx;"
											v-for="v in item.ywFileList" :key="v.fileId">
											<u-icon style="margin-top: 4rpx;color: #2979FF;"
												name="attach"></u-icon><u--text :lines="1" size="14" color="#2979FF"
												decoration="underline" :text="v.name"
												@click="downLoad(v.url)">{{v.name}}</u--text><u-icon @click="delFile(v)"
												style="margin-top: 0rpx;" name="close"></u-icon>
										</view>
										<u-action-sheet @select="selectClick" :actions="list"
											:closeOnClickOverlay="true" :closeOnClickAction="true" title="请选择"
											:show="showUpload"></u-action-sheet>

									</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>
									<span v-else> {{item.leaderMsg}}</span>
								</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>
				</view>
				<view style="margin-top: 60rpx;text-align: center;" v-else class="">
					暂无
				</view>
			</view>

			<view style="padding: 0 20rpx;">
				<u-button v-if="title=='督办编辑'" type="primary" text="保存" @click="keep"
					style="margin-top: 40rpx;"></u-button>
				<!-- <u-button type="primary" v-else text="提交" @click="submit" style="margin-top: 40rpx;"></u-button> -->
			</view>
		</u--form>
		<u-calendar placeholder="请选择日期" :show="show1" mode="single" allowSameDay @confirm="confirmOne"
			@close="show1 = false"></u-calendar>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				show1: false,
				typeDate: '',
				content: {
					ywSupervisionStartUserList: [],
					prersonLiable: ''
				},
				rules: {},
				InfoList: [],
				infoSourceContent: '',
				db_template: [],
				title: ''
			}
		},
		onLoad(options) {
			this.getDictsInfo()
			uni.setNavigationBarTitle({
				title: options.title
			})
			this.title = options.title
			uni.$u.http.get('/offcial/supervision/' + options.id).then((res) => {
				console.log('res', res)
				this.content = res.data
				getApp().globalData.ywListZR = this.content.ywSupervisionStartUserList
				getApp().globalData.zerenList = this.content.prersonLiable
			})
		},
		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: {
			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`
				})
			},
			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>