<template>
	<view class="content">
		<view class="param">
			<view class="proMiao">任务名称</view>
			<input class="proINname" v-model="renwuName" placeholder="请输入任务名称"/>
			<view class="proMiao">评分标准</view>
			<textarea class="proINname proIMi" v-model="scoreStandard" placeholder="请输入评分标准"/>
			<view class="proMiao">附件</view>
			<view class="upload-img">
				<uni-file-picker limit="3" 
					@select='selectUpload' 
					@delete="deleteHandle"
					:auto-upload='false' 
					file-extname='pdf,docx,jpg,png,jpeg,doc,docm,dot,dotm,dotx,xlsx,xls,csv,xlsm,slxb,xlt,xltx' 
					file-mediatype="all" 
					@success='uploadSuccess'	
					@fail='uploadFail' 
					:list-styles='listStyles' 
					v-model='fileList'
				></uni-file-picker>
			</view>
			<span style="margin: 20rpx 0 0 20rpx;">支持pdf,docx,jpg,png,jpeg,doc,docm,dot,dotm,dotx,xlsx,xls,csv,xlsm,slxb,xlt,xltx格式，单个文件大小不超过5MB</span>
			<view class="proMiao">评分上限</view>
			<input class="proINname" placeholder="请输入评分上限" type="number" v-model="scoreLimit"/>
			<view class="proMiao">权重</view>
			<input class="proINname" placeholder="请输入权重" type="digit" v-model="weight"/>
			<view class="proMiao">任务负责人</view>
			<view @click="toggle()">
				<view class="proINname" v-if="peopleValue==''">请选择任务负责人</view>
				<view class="proINname" v-else>{{peopleValue}}</view>
				<!-- <input class="proINname" v-model="peopleValue" placeholder="请选择任务负责人"/> -->
				<!-- <uni-data-select class="proINname" :disabled="true"
					v-model="peopleValue" placeholder="请选择主办人"
					:localdata="rangePeople"
				></uni-data-select> -->
			</view>
			
			<view class="proMiao">提醒时间</view>
			<uni-datetime-picker class="proINname" type="datetime" v-model="remindTime" @change="changeLog" />
			<view class="proMiao">预警时间</view>
			<uni-datetime-picker class="proINname" type="datetime" v-model="warnTime" @change="changeLog" />
			<view class="proMiao">任务周期</view>
			<uni-datetime-picker class="proINname" v-model="datetimerange" type="datetimerange" rangeSeparator="至" />
			<!-- 操作键 -->
			<view class="project">
				<view class="butt quxiao" @click="quxiao">取消</view>
				<view class="butt queren" @click="addRenwu">确认创建</view>
			</view>
			<view style="width: 100%;height: 60rpx;"></view>
			
			<!-- 任务负责人弹出框-->
			<uni-popup ref="popup" background-color="#fff">
				
					<view class="popup-content">
						<view class="popup-title">
							<view @click="quPopup">取消</view>
							<view>选择任务负责人</view>
							<view style="color: rgba(0, 97, 255, 1);" @click="selectPeo">确定</view>
						</view>
						<scroll-view scroll-y="true" class="scroll_view_style">
							<view class="popup-list">
								<radio-group @change="radioChange" v-for="(item,index) in people" :key="index">
								<view class="l-line"></view>
								<view class="l-kuang">
									<view class="l-circle"></view>
									<view style="margin-left: 20rpx;width: 320px;">
										<view style="font-size: 28rpx;">{{item.userName}}</view>
										<view style="font-size: 24rpx;">{{item.department}}</view>
									</view>
									<label class="l-label">
										<view>
											<radio :id="item.userName" :value="item.userName" :checked="index==peopleCruuent"></radio>
										</view>
									</label>
								</view>
								</radio-group>
							</view>
						</scroll-view>
					</view>
				
			
			</uni-popup>
		</view>
	</view>
</template>

<script>
	import configdata from '@/common/config.js'
	export default {
		data() {
			return {
				renwuName:'',//任务名称
				projectId:'',//项目id
				scoreStandard:'',//评价标准
				scoreLimit:'',//评分上限
				weight:'',//权重
				remindTime: '',//提醒时间
				warnTime:'',//预警时间
				datetimerange: [],
				people:[],
				peopleCruuent:0,
				peopleValue:'',
				// 附件
				fileList: [],
				fileList2: [],
				fileList22:'',
				listStyles: {
					"borderStyle": {
						"width": "0", // 边框宽度
					},
					"border": false, // 是否显示边框
					"dividline": false
				},
				
				page:1,
				size:10,
				totalCount:0,
			}
		},
		onLoad(option) {
			this.projectId=option.proId
			this.people=JSON.parse(decodeURIComponent(option.people))
		},
		methods: {
			// 任务负责人弹框
			toggle() {
				console.log('dd')
				// open 方法传入参数 等同在 uni-popup 组件上绑定 type属性
				this.$refs.popup.open('bottom')
				// this.getPeople()
			},
			//取消弹框
			quPopup(){
				this.$refs.popup.close()
			},
			//确定负责人
			selectPeo(){
				this.$refs.popup.close()
				this.peopleValue=this.people[this.peopleCruuent].userName
			},
			// 选择负责人
			radioChange: function(evt) {
				console.log(evt)
				for (let i = 0; i < this.people.length; i++) {
					if (this.people[i].userName === evt.detail.value) {
						this.peopleCruuent = i;
						this.peopleValue=this.people[this.peopleCruuent].userName
						break;
					}
				}
			},
			//选择负责人
			getPeople(){
				this.people=[]
				uni.showLoading({
					title: '加载中',
					mask: true, // 是否显示透明蒙层，防止触摸穿透
				});
				this.$Request.postJson('/api/sysProject/queryCoUsers',{}).then(res => {
					if (res.code==200) {
						// var lianji=[]
						// for(var i=0;i<res.data.length;i++){
						// 	if(res.data[i].organize==acc){
						// 		lianji=res.data[i].userList
						// 	}
						// }
						// console.log(lianji,'评分')
						// this.scorePeople =lianji.map(item =>{
						// 	return {
						// 		value: item.id,
						// 		label: item.userName,
						// 	}
						// })
						
						if (this.page == 1) {
							console.log('哈')
							this.people = res.data.rows
						} else {
							this.people = this.people.concat(res.data.rows)
						}
						console.log(this.people,'人')
					}else{
						var ii=JSON.stringify(res)
						console.log(res,res.data)
						console.log(JSON.parse(res))
						console.log(JSON.parse(ii))
					}
					uni.hideLoading();
				});
			},
			//取消
			quxiao(){
				uni.redirectTo({
					url:'/pages/project/projectChange'
				})
			},
			//新增任务
			addRenwu(){
				let that = this
				if (!that.renwuName) {
					that.$queue.showToast("请输入任务名称");
				}else if (!that.scoreStandard) {
					that.$queue.showToast("请输入评分标准");
				}else if (!that.scoreLimit) {
					that.$queue.showToast("请输入评分上限");
				}else if (!that.weight) {
					that.$queue.showToast("请输入权重");
				}else if (!that.remindTime) {
					that.$queue.showToast("请选择提醒时间");
				}else if (!that.warnTime) {
					that.$queue.showToast("请选择预警时间");
				}else if (!that.datetimerange) {
					that.$queue.showToast("请选择周期");
				}else {
					uni.showLoading({
						title: '加载中',
						mask: true, // 是否显示透明蒙层，防止触摸穿透
					});
					var data={
						"taskName": that.renwuName,   // 任务名称
						"projectId": that.projectId,   // 项目ID
						"scoreStandard": that.scoreStandard,   // 评价标准
						"fileUrl": that.fileList22,  // 附件
						"scoreLimit": that.scoreLimit,   // 评分上限
						"weight": that.weight,   // 权重
						"remindTime": that.remindTime,   // 提醒时间
						"warnTime": that.warnTime,    // 预警时间
						"header": that.people[that.peopleCruuent].id,    // 负责人
						"startTime": that.datetimerange[0],   // 周期-起始时间
						"endTime": that.datetimerange[1]    // 周期-结束时间
					}
					that.$Request.postJson('/api/sysTask/add',data).then(res => {
						if (res.code==200) {
							uni.showToast({
								title: '添加成功',
								icon: 'none',
								duration:800
							});
							uni.hideLoading()
											
							setTimeout(function() {
								uni.switchTab({
									url:'/pages/project/index'
								})
							}, 1000)
						} else {
							uni.hideLoading();
							uni.showToast({
								title: res.message,
								icon: 'none',
								duration:800
							});
						}
					});
				}
			},
			// 上传附件
			uploadSuccess(e) {
			console.log('上传成功', e)
			},
			uploadFail(e) {
				console.log('上传失败：', e)
			},
			//删除文件
			deleteHandle(index){
				console.log(index)
				this.fileList2.splice(index.index,1)
				// console.log(this.fileList2)
				this.fileList22=this.fileList2.join(",")
			},
			async selectUpload(e) {
				console.log('上传：', e)
				 let data = new FormData();
				  data.set("file", e.tempFiles[0].file);
				  let res = await this.$axios({
				    method: "post",
				    url: this.config('APIHOST1') + "/api/sysFile/upload",
				    headers: {
						tokenW: sessionStorage.getItem("token"),
						"Content-Type": "multipart/form-data"
				    },
				    data: data,
				  });
					// return res
				  console.log(res, "图片上传成功");
				  if (res.data.code == 200) {
					console.log(this.fileList)
				    this.fileList2.push(res.data.data);
					this.fileList22=this.fileList2.join(",")
					// console.log(this.fileList2.join(","))
				  } else if(res.message=="登录凭证已过去，请重新登录"){
					sessionStorage.removeItem("token")
					sessionStorage.removeItem("roleId")
					uni.showModal({
						title: '提示',
						content: '用户信息失效，请重新登录！',
						showCancel: false, // 是否显示取消按钮，默认为 true // 是否显示取消按钮，默认为 true
						success: function(res) {
							if (res.confirm) {
							}
						}
					});
				   }else {
			    		uni.showToast({
							title: res.message,
							icon: 'none',
							duration:800
						});
				    }
			},
			config: function (name) {
				var info = null
				if (name) {
					var name2 = name.split('.') //字符分割
					if (name2.length > 1) {
						info = configdata[name2[0]][name2[1]] || null
					} else {
						info = configdata[name] || null
					}
					if (info == null) {
						let web_config = cache.get('web_config')
						if (web_config) {
							if (name2.length > 1) {
								info = web_config[name2[0]][name2[1]] || null
							} else {
								info = web_config[name] || null
							}
						}
					}
				}
				return info
			},
		}
	}
</script>

<style>
	.content {
		display: flex;
		flex-direction: column;
		align-items: center;
		justify-content: center;
	}
	.param{
		margin: 20rpx 0 0 0;
		width: 100%;
		background-color: rgba(255, 255, 255, 1);
		font-size: 28rpx;
		font-weight: 400;
		line-height: 41rpx;
		color: rgba(0, 0, 0, 1);
	}
	.proMiao{
		margin: 31rpx 0 0 20rpx;
	}
	/* 上传附件 */
	.upload-img{
		/* margin: 25rpx 0 0 21rpx;
		width: 200rpx;
		height: 80rpx;
		opacity: 1;
		border-radius: 13rpx;
		background: rgba(0, 97, 255, 0.1);
		
		border: 1rpx solid rgba(0, 97, 255, 1); */
	}
	.proINname{
		margin: 25rpx 0 0 21rpx;
		width: 709rpx;
		height: 90rpx;
		border-radius: 13rpx;
		background: rgba(245, 248, 252, 1);
		border: 1rpx solid rgba(229, 229, 229, 1);
		font-size: 28rpx;
		line-height: 90rpx;
		/* color: rgba(179, 179, 179, 1); */
	}
	.proIMi{
		height: 315rpx;
	}
	/* 操作键 */
	.project{
		display: flex;
		margin: 61rpx 0 0 0;
		justify-content: space-evenly;
	}
	.butt{
		width: 330rpx;
		height: 90rpx;
		border-radius: 117rpx;
		font-size: 32rpx;
		line-height: 90rpx;
		text-align: center;
	}
	.quxiao{
		border: 1rpx solid rgba(0, 97, 255, 1);
		color: rgba(0, 97, 255, 1);
	}
	.queren{
		background: rgba(0, 97, 255, 1);
		color: rgba(255, 255, 255, 1);
	}
	/* 任务负责人弹出框 */
	.popup-content{
		height: 452px;
		overflow-x: hidden;
		.scroll_view_style{
			height: 100%;
		}
	}
	.popup-title{
		display: flex;
		width: 100%;
		height: 104rpx;
		font-size: 32rpx;
		line-height: 104rpx;
		justify-content: space-around;
		color: rgba(0, 0, 0, 1);
	}
	.l-line{
		width: 100%;
		border: 1rpx solid rgba(230, 230, 230, 1);
	}
	.l-kuang{
		margin: 40rpx 0 0 20rpx;
		display: flex;
	}
	.l-circle{
		width: 80rpx;
		height: 80rpx;
		border-radius: 50%;
		background-color:rgba(204, 204, 204, 1);
	}
	.l-label1{
		width: 50rpx;
		height: 50rpx;
		opacity: 1;
		border-radius: 50%;
		background-color: rgba(0, 97, 255, 1);
	}
	.l-label{
		/* margin-left: 404rpx; */
		/* width: 50rpx;
		height: 50rpx;
		opacity: 1;
		border-radius: 50%;
		border: 1rpx solid rgba(166, 166, 166, 1); */
	}
</style>