<template>
	<view class="content">
		<view class="param">
			<view class="all-text">创建项目需求</view>
			<view class="proName">项目标题</view>
			<input class="proINname" v-model="pName" placeholder="请输入项目标题"/>
			<view class="proMiao">项目描述</view>
			<textarea class="proINname proIMi" v-model="projectContent" 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' 
					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/word/xlsx格式，单个文件大小不超过5MB</span>
			<view class="proMiao">主办单位</view>
			<uni-data-select class="proINname"
				v-model="value" placeholder="请选择主办单位"
				:localdata="range"
				@change="change1"
			></uni-data-select>
			<view class="proMiao">主办人</view>
			<uni-data-select class="proINname"
				v-model="peopleValue" placeholder="请选择主办人"
				:localdata="rangePeople"
				@change="change"
			></uni-data-select>
			<view class="proMiao">协办单位</view>
			<mySelectCheckbox class="proINname" placeholder="请选择协办单位" v-model="value2" multiple dataKey="label" dataValue="value" :localdata="data"
				@change="changeXie"></mySelectCheckbox>
			<view class="proMiao">协办人</view>
			<mySelectCheckbox class="proINname" placeholder="请选择协办人" v-model="peopleValue2" multiple dataKey="label" dataValue="value" :localdata="dataPeople"
				@change="changeXiePeo"></mySelectCheckbox>
			
			<view class="proMiao">项目级别</view>
			<uni-data-select class="proINname"
				v-model="jibieValue" placeholder="请选择项目级别"
				:localdata="jibie"
				@change="change"
			></uni-data-select>
			<!-- <view class="proMiao">关联流程</view>
			<uni-data-select class="proINname"
				v-model="value" placeholder="请选择关联流程"
				:localdata="range"
				@change="change"
			></uni-data-select> -->
			<view class="proMiao">项目来源</view>
			<uni-data-select class="proINname"
				v-model="fromValue" placeholder="请选择项目来源"
				:localdata="from"
				@change="change"
			></uni-data-select>
			<!-- <view class="proMiao jindu">完成进度</view>
			<view class="weidu">维度权重40%</view>
			<view class="addRen" @click="addRen">新增任务</view> -->
			<!-- 任务列表 -->
			<!-- <view style="width: 100%;margin: 50rpx 0 0 20rpx;">
				<view class="renwu" v-for="(item,index) in renwu" :key="index" @click="clickRenwu">
					<view>{{item.name}}</view>
					<view>{{item.time}}</view>
					<view style="display: flex;">
						<view class="renwu-bu bianji">编辑</view>
						<view class="renwu-bu delete">删除</view>
					</view>
				</view>
			</view> -->
			<view class="proMiao">项目评分人</view>
			<mySelectCheckbox class="proINname" placeholder="请选择项目评分人" v-model="value2" multiple dataKey="label" dataValue="value" :localdata="data"
				@change="changeXie"></mySelectCheckbox>
			<view class="project">
				<view class="butt quxiao" @click="quxiao">取消</view>
				<view class="butt queren" @click="addProject">确认创建</view>
			</view>
			<view style="width: 100%;height: 60rpx;"></view>
		</view>
	</view>
</template>

<script>
	import configdata from '@/common/config.js'
	import mySelectCheckbox from '../../components/my-selectCheckbox.vue'
	export default {
		components:{mySelectCheckbox},
		data() {
			return {
				pName:'',//项目标题
				projectContent:'',//项目描述
				//主办单位
				value: '',
				range: [],
				//主办人
				peopleValue:'',
				rangePeople:[],
				//协办
				value2:[],
				data: [],
				xieban:[],//协办传入值数组
				xieValue:[],//协办传入id
				//协办人
				peopleValue2:[],
				dataPeople: [],
				xiebanPeople:[],//协办传入值数组
				xieValuePeople:[],//协办传入id
				// 项目级别
				jibieValue:0,
				jibie:[
					{ value: 0, text: "正常" },
					{ value: 1, text: "紧急" },
				],
				// 项目来源
				fromValue:0,
				from:[
					{ value: 0, text: "涉内" },
					{ value: 1, text: "涉外" },
				],
				fileList: [],
				fileList2: [],
				fileList22:'',
				listStyles: {
					"borderStyle": {
						"width": "0", // 边框宽度
					},
					"border": false, // 是否显示边框
					"dividline": false
				},
				renwu:[
					{name:'xxx任务',time:'2024-04-11'},
					{name:'xxx任务',time:'2024-04-11'},
					{name:'xxx任务',time:'2024-04-11'},
				],
			}
		},
		onLoad() {
			this.getDanwei()
		},
		methods: {
			// 主办单位
			change1(e) {
			   console.log("e:", e);
			   this.getPeople()
			},
			//协办单位选择
			changeXie(e){
				this.xieban=[]
				this.xieValue=[]
				console.log('e:', e);
				e.map(item =>{
					this.xieban.push(item.label)
					this.xieValue.push(item.value)
				})
			},
			//协办人选择
			changeXiePeo(e){
				this.xieban=[]
				this.xieValue=[]
				console.log('e:', e);
				e.map(item =>{
					this.xieban.push(item.label)
					this.xieValue.push(item.value)
				})
			},
			//获取单位
			getDanwei(){
				this.range=[]
				this.data=[]
				uni.showLoading({
					title: '加载中',
					mask: true, // 是否显示透明蒙层，防止触摸穿透
				});
				this.$Request.postT('/api/Organize/query').then(res => {
					if (res.code==200&&res.data) {
						this.range =res.data.map(item =>{
							return {
								value: item.id,
								text: item.oname,
							}
						})
						this.data =res.data.map(item =>{
							return {
								value: item.id,
								label: item.oname,
							}
						})
						console.log(this.range)
					}
					uni.hideLoading();
				});
			},
			//根据单位获取人员
			getPeople(){
				this.rangePeople=[]
				uni.showLoading({
					title: '加载中',
					mask: true, // 是否显示透明蒙层，防止触摸穿透
				});
				this.$Request.postJson('/api/sysUser/queryPage?page=1&rows=10',{
					"userName": null,      // 姓名
					"roleName": null,      // 角色名称
					"department": this.range[this.value].text,     // 部门
					"createBy": "",   // 创建时间-开始日期
					"updateBy": ""    // 创建时间-结束日期
				}).then(res => {
					if (res.code==200&&res.data.total>0) {
						var total=res.data.total
						this.$Request.postJson('/api/sysUser/queryPage?page=1&rows='+total,{
							"userName": null,      // 姓名
							"roleName": null,      // 角色名称
							"department": this.range[this.value].text,     // 部门
							"createBy": "",   // 创建时间-开始日期
							"updateBy": ""    // 创建时间-结束日期
						}).then(res => {
							if (res.code==200&&res.data) {
								this.rangePeople =res.data.rows.map(item =>{
									return {
										value: item.id,
										text: item.userName,
									}
								})
								console.log(this.rangePeople,'人')
							}
						});
					}
					uni.hideLoading();
				});
			},
			//取消
			quxiao(){
				uni.switchTab({
					url:'/pages/project/index'
				})
			},
			//新增项目
			addProject(){
				console.log(this.jibie[this.jibieValue].text)
				let that = this
				if (!that.pName) {
					that.$queue.showToast("请输入项目标题");
				}else if (!that.projectContent) {
					that.$queue.showToast("请输入项目描述");
				} else if (!that.value) {
					that.$queue.showToast("请选择主办单位");
				} else if (!that.value2) {
					that.$queue.showToast("请选择协办单位");
				}else {
					uni.showLoading({
						title: '加载中',
						mask: true, // 是否显示透明蒙层，防止触摸穿透
					});
					var data={
						"projectName": that.pName,   // 项目名称
						"projectFrom": that.from[that.fromValue].text,    // 项目来源
						"projectLevel": that.jibie[that.jibieValue].text,    // 项目等级
						"projectContent": that.projectContent,    // 项目描述
						"fileUrl": that.fileList22,   // 附件
						"organize": that.range[that.value].text,   // 主办单位-单选
						"sposoner": '26',//that.peopleValue,   // 主办人ID-单选
						"coOrganize": that.xieban.join(","),   // 协办单位-多选
						"coSposoner": '22,20'//that.xieValue.join(",")    // 协办人ID-多选
					}
					that.$Request.postJson('/api/sysProject/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
							});
						}
					});
				}
			},
			//新增任务
			addRen(){
				uni.navigateTo({
					url:'/pages/project/addRenwu'
				})
			},
			//任务详情
			clickRenwu(){
				uni.navigateTo({
					url:'/pages/project/renwuX'
				})
			},
			// 上传附件
			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: localStorage.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=="登录凭证已过去，请重新登录"){
					uni.removeStorageSync("tokenW")
					uni.removeStorageSync("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);
	}
	.all-text{
		margin: 22rpx 0 0 20rpx;
		font-size: 32rpx;
		font-weight: 500;
		color: rgba(0, 0, 0, 1);
	}
	.proName{
		margin: 23rpx 0 0 20rpx;
	}
	.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;
	}
	.proMiao{
		margin: 31rpx 0 0 20rpx;
	}
	/* 上传附件 */
	.upload-img{
		/* margin: 25rpx 0 0 21rpx;
		width: 200rpx;
		opacity: 1;
		border-radius: 13rpx;
		background: rgba(0, 97, 255, 0.1);
		
		border: 1rpx solid rgba(0, 97, 255, 1); */
	}
	.jindu{
		font-size: 32rpx;
		font-weight: 500;
		line-height: 46rpx;
	}
	.weidu{
		margin: 7rpx 0 0 20rpx;
		font-size: 24rpx;
		line-height: 35rpx;
		color: rgba(128, 128, 128, 1);
	}
	.addRen{
		margin: -80rpx 0 0 581rpx;
		width: 149rpx;
		height: 59rpx;
		border-radius: 92rpx;
		background: rgba(0, 97, 255, 1);
		font-size: 28rpx;
		line-height: 59rpx;
		color: rgba(255, 255, 255, 1);
		text-align: center;
	}
	/* 任务列表 */
	.renwu{
		display: flex;
		margin-top: 6rpx;
		width: 709rpx;
		height: 90rpx;
		border-radius: 13rpx;
		background: rgba(245, 248, 252, 1);
		border: 1rpx solid rgba(229, 229, 229, 1);
		font-size: 28rpx;
		justify-content: space-evenly;
		align-items: center;
	}
	.renwu-bu{
		width: 105rpx;
		height: 50rpx;
		border-radius: 110rpx;
		line-height:50rpx;
		text-align: center;
	}
	.bianji{
		border: 1rpx solid rgba(0, 97, 255, 1);
		color: rgba(0, 97, 255, 1);
	}
	.delete{
		margin-left: 20rpx;
		border: 1rpx solid rgba(212, 48, 48, 1);
		color: rgba(212, 48, 48, 1);
	}
	.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);
	}
</style>