| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977 | <template>	<view class="publish">		<statusBar :item="navBarData"></statusBar>		<view class="" style="background-color: #ffffff;">			<view class="pubTitle">				<input class="title" style="" placeholder="活动标题" v-model="activitytitle" />			</view>			<view class="pubMid">				<view class="mid">					<view class="txt">						<textarea class="txtClass" value="" placeholder="请输入内容" v-model="activityintro" />					</view>					<!-- <uni-file-picker :v-model="imageValue" fileMediatype="image" file-extname="png,jpg,jpeg"						@select="select" @success="success" limit="1"> -->					<!-- 上传图片 -->					<view class="pic" @click="uploadPic">						<view class="picCont">							<image :src="pic" mode="aspectFill"></image>							<view								style="font-size: 24rpx;line-height: 40rpx;font-weight: 400;color: rgba(0, 0, 0, 0.6);">								添加图片							</view>							<view								style="font-size: 20rpx;line-height: 36rpx;font-weight: 400;color: rgba(0, 0, 0, 0.4);">								(0/1)							</view>						</view>						<view class="pic_show" v-if="imageValue!==''">							<image :src="imageValue" mode="aspectFill"></image>						</view>					</view>					<!-- <view class="pic_show">						<image :src="imageValue" mode="aspectFill"></image>					</view> -->					<!-- </uni-file-picker> -->					<!-- <beUpload @getFile="getFile" :navName="'上传文件'" :accept="accept" :progress="progress"></beUpload> -->				</view>			</view>			<view class="userOptionsBox">				<view class="optionsItemBox">					<picker mode="selector" :range="classifyList" :value="index" @change="handelclassify">						<view class="optionItem">							<view class="option_left">								<text class="option_text">									活动分类								</text>							</view>							<view class="option_right">								<view class="input_details">									<view class="details">										<view class="uni-input text">{{classifyList[index]==null?'请选择':classifyList[index]}}</view>									</view>									<view class="arrow">										<image											src="https://teacherapi.cocorobo.cn/teaching-file/static//mine/arrow-right.png"											mode="aspectFill"></image>									</view>								</view>							</view>						</view>					</picker>				</view>			</view>			<view class="userOptionsBox">				<view class="optionsItemBox">					<picker mode="selector" :range="recruitmentList" @change="handelRecruitment">						<view class="optionItem">							<view class="option_left">								<text class="option_text">									招募人数								</text>							</view>							<view class="option_right">								<view class="input_details">									<view class="details">										<view class="uni-input text">{{recruitment}}</view>									</view>									<view class="arrow">										<image											src="https://teacherapi.cocorobo.cn/teaching-file/static//mine/arrow-right.png"											mode="aspectFill"></image>									</view>								</view>							</view>						</view>					</picker>				</view>			</view>			<view class="userOptionsBox">				<view class="optionsItemBox">					<picker mode="selector" :range="activityformList" @change="handelActivityform">						<view class="optionItem">							<view class="option_left">								<text class="option_text">									活动形式								</text>							</view>							<view class="option_right">								<view class="input_details">									<view class="details">										<view class="uni-input text">{{activityform}}</view>									</view>									<view class="arrow">										<image											src="https://teacherapi.cocorobo.cn/teaching-file/static//mine/arrow-right.png"											mode="aspectFill"></image>									</view>								</view>							</view>						</view>					</picker>				</view>			</view>			<view class="userOptionsBox">				<view class="optionsItemBox">					<picker mode="selector" :range="addressList" @change="handeladdress">						<view class="optionItem">							<view class="option_left">								<text class="option_text">									活动地址								</text>							</view>							<view class="option_right">								<view class="input_details">									<view class="details">										<view class="uni-input text">{{address}}</view>									</view>									<view class="arrow">										<image											src="https://teacherapi.cocorobo.cn/teaching-file/static//mine/arrow-right.png"											mode="aspectFill"></image>									</view>								</view>							</view>						</view>					</picker>				</view>			</view>			<view class="userOptionsBox">				<view class="optionsItemBox">					<!-- <picker mode="date" :value="activityDate" :start="startDate" :end="endDate"						@change="activityDateChange">						<view class="optionItem">							<view class="option_left">								<text class="option_text">									活动时间								</text>							</view>							<view class="option_right">								<view class="input_details">									<view class="details">										<view class="uni-input text">{{ activityDate }}</view>									</view>									<view class="arrow">										<image src="https://teacherapi.cocorobo.cn/teaching-file/static//mine/arrow-right.png" mode="aspectFill"></image>									</view>								</view>							</view>						</view>					</picker> -->					<view class="optionItem" @click="show = true">						<view class="option_left">							<text class="option_text">								活动时间							</text>						</view>						<view class="option_right">							<view class="input_details">								<view class="details">									<!-- <view class="uni-input text">{{ activityDate }}</view> -->									<u-calendar :show="show" :mode="mode" @confirm="confirm" :closeOnClickOverlay="true"										@close="show=false"></u-calendar>									<view class="text">										{{ activityDate }}									</view>								</view>								<view class="arrow">									<image										src="https://teacherapi.cocorobo.cn/teaching-file/static//mine/arrow-right.png"										mode="aspectFill"></image>								</view>							</view>						</view>					</view>				</view>			</view>			<view class="userOptionsBox">				<view class="optionsItemBox">					<picker mode="selector" :range="fundsList" @change="handelFunds">						<view class="optionItem">							<view class="option_left">								<text class="option_text">									活动费用(元)								</text>							</view>							<view class="option_right">								<view class="input_details">									<view class="details">										<view class="uni-input text">{{funds}}</view>									</view>									<view class="arrow">										<image											src="https://teacherapi.cocorobo.cn/teaching-file/static//mine/arrow-right.png"											mode="aspectFill"></image>									</view>								</view>							</view>						</view>					</picker>				</view>			</view>			<view class="userOptionsBox">				<view class="optionsItemBox">					<picker mode="date" :value="deadlineDate" :start="startDate" :end="endDate"						@change="deadlineDateChange">						<view class="optionItem">							<view class="option_left">								<text class="option_text">									报名截止								</text>							</view>							<view class="option_right">								<view class="input_details">									<view class="details">										<view class="uni-input text">{{ deadlineDate }}</view>									</view>									<view class="arrow">										<image											src="https://teacherapi.cocorobo.cn/teaching-file/static//mine/arrow-right.png"											mode="aspectFill"></image>									</view>								</view>							</view>						</view>					</picker>				</view>			</view>		</view>		<view class="" style="height: 10vh;width: 750rpx;position: relative;">			<view class="publish_now">				<button class="btn" @click="submitForm">{{ btntext }}</button>			</view>		</view>		<!-- 弹窗 -->		<view>			<view class="mask" v-show="showPopup" @click="closePopup"></view>			<view class="popup-container" v-show="showPopup">				<view class="popup">					<view class="header">						<text>确认{{ poptext }}</text>					</view>					<view class="footer">						<button class="cancel-btn" @click="closePopup">取消</button>						<button class="confirm-btn" @click="conf">确认</button>					</view>				</view>			</view>		</view>		<view>			<view class="mask" v-show="showPopupConfirm" @click="closePopup"></view>			<view class="popup-container" style="height: 175px;" v-show="showPopupConfirm">				<view class="popup">					<view class="header" style="margin-top: 15px;">						<image src="https://teacherapi.cocorobo.cn/teaching-file/static//gou1.png" mode="aspectFill">						</image>						<text style="margin-bottom: 24px;">{{ poptext }}成功</text>					</view>					<!-- <view class="footer" style="padding-top: 0px;">						<button class="confirm-btn_2" @click="closePopup">确认</button>					</view> -->				</view>			</view>		</view>	</view></template><script>	export default {		data() {			const currentDate = this.getDate({				format: true			})			return {				navBarData: {					title: '发布', //导航栏标题					btn: 1 //是否显示返回按钮 0不显示  1 显示				},				//时间选择器				show: false,				mode: 'range',				//控制弹窗				showPopup: false,				showPopupConfirm: false,				isFirstShow: true,				//按钮文本				btntext: '立即发布',				// 弹窗文本				poptext: '发布',				//acId				acId: '',				// 标题				activitytitle: '',				// 内容				activityintro: '',				// 图片				pic: 'https://teacherapi.cocorobo.cn/teaching-file/static//publish/photo.png',				imageValue: '',				// 分类				classifyList: ['直播活动', '常规教研活动', '专题教研活动','推荐课程'],				// index判断选择分类  0       1                   2         3   ,对应上面				index:null,				classify: '请选择',				// 人数				recruitmentList: Array.from({					length: 100				}, (_, index) => index + 1), //100人				recruitment: '请选择',				// 活动形式				activityformList: ['户外活动', 'xxxx', 'xxxx'],				activityform: '请选择',				// 活动地址				addressList: ['深圳xxxx大学', '深圳xxxx大学', '深圳xxxx大学'],				address: '请选择',				// 活动费用				fundsList: Array.from({					length: 30				}, (_, index) => (index + 1) * 100).map(item => item),				funds: '请选择',				// activityDate: currentDate,				activityDate: '请选择',				deadlineDate: '请选择',				activeList: [],				formData: {},										};		},		computed: {			startDate() {				return this.getDate('start');			},			endDate() {				return this.getDate('end');			}		},		methods: {			confirm(e) {				console.log(e);				console.log(e[0], e[e.length - 1]);				this.activityDate = e[0] + '~' + e[e.length - 1]				this.show = false			},						editPublish() {				const routes = getCurrentPages()				console.log(routes);				if (routes.length == 3) {					const acId = routes[2].options.acId					const type = routes[2].options.ty					if (acId) {						this.navBarData.title = '修改发布'						this.btntext = '修改发布'						this.poptext = '修改'						console.log(acId);						console.log(type);						let data = {							acId: acId,							ty: type						}						this.$request('/selectActivityID', "POST", data).then(res => {							console.log(res[0]);							// this.actItemList = res[0]							const item = res[0][0]							this.acId = item.acId							this.activitytitle = item.acName							this.activityintro = item.brief							this.imageValue = item.pic							this.classify = item.type							this.recruitment = item.pers							this.activityform = item.acshape							this.address = item.address							this.funds = item.cost							this.activityDate = item.begin_at							this.deadlineDate = item.endTime							if (this.classify == 0) {								this.classify = "直播活动"							} else if (this.classify == 1) {								this.classify = "常规教研活动"							} else {								this.classify = "专题教研活动"							}						})					}				}			},			submitForm() {				//判断表单内容是否完整				const conditions = [					// 添加提示信息					{						value: this.activitytitle,						message: '请填写活动标题'					},					{						value: this.activityintro,						message: '请填写活动内容'					},					{						value: this.index,						message: '请填写活动分类'					},					{						value: this.recruitment,						message: '请填写招募人数'					},					{						value: this.address,						message: '请填写活动地址'					},					{						value: this.activityDate,						message: '请填写活动时间'					},				];				for (const condition of conditions) {					if (!condition.value || condition.value === '请选择') {						uni.showToast({							title: condition.message,							icon: 'none'						});						return;					}				}				//判断没有填写的表单内容是否填写,如果没有替换				if (					this.imageValue == '' ||					this.activityform === '请选择' ||					this.funds === '请选择'				) {					this.imageValue = 'https://teacherapi.cocorobo.cn/teaching-file/static//zanwu_img.png'					this.activityform = '暂无'					this.funds = '暂无'				}				this.showPopup = true; //显示弹窗			},			closePopup() {				// 取消操作				this.showPopup = false;				this.showPopupConfirm = false;				uni.switchTab({					url:'/pages/activityPage/activityPage'				})			},			// 上传发布			conf() {								this.formData = {					// id: this.$store.state.user.openid,					id: this.btntext === '修改发布' ? this.acId : this.$store.state.user.openid,					activitytitle: this.activitytitle,					activityintro: this.activityintro,					img: this.imageValue,					recruitment: this.recruitment,					activityform: this.activityform,					address: this.address,					classify: this.index,					activityDate: this.activityDate,					deadlineDate: this.deadlineDate,					funds: this.funds				};								this.showPopup = false;				this.showPopupConfirm = true				// return console.log(formData);				console.log(this.btntext);																if (this.btntext === '修改发布') {					// formData.acId = this.acId					// console.log(formData);					this.$request('/updateMyPublish', 'POST', this.formData).then(res => {						console.log(res);						setTimeout(() => {							uni.navigateBack();						}, 500)					})				} else {					this.$request('/insertActive', 'POST', this.formData).then(res => {						console.log(res.data);						if (res.code == 200) {							this.activitytitle = ''							this.activityintro = ''							this.imageValue = ''							this.index = null							this.recruitment = '请选择'							this.activityform = '请选择'							this.address = '请选择'							this.funds = '请选择'							this.activityDate = '请选择'							this.deadlineDate = '请选择'							setTimeout(() => {								uni.switchTab({									url:'/pages/activityPage/activityPage'								})							}, 2000)						}					})				}			},			handelclassify(e) {				// console.log(e);								this.index=e.detail.value				console.log(this.index);				// this.classify = this.classifyList[e.detail.value]				// console.log(this.classify);			},			handelRecruitment(e) {				this.recruitment = this.recruitmentList[e.detail.value]				console.log(this.imageValue);			},			handelActivityform(e) {				this.activityform = this.activityformList[e.detail.value]			},			handeladdress(e) {				this.address = this.addressList[e.detail.value]			},			handelFunds(e) {				this.funds = this.fundsList[e.detail.value]			},			// activityDateChange: function(e) {			// 	this.activityDate = e.detail.value			// },			deadlineDateChange: function(e) {				this.deadlineDate = e.detail.value			},			getDate(type) {				const date = new Date();				let year = date.getFullYear();				let month = date.getMonth() + 1;				let day = date.getDate();				if (type === 'start') {					year = year - 60;				} else if (type === 'end') {					year = year + 2;				}				month = month > 9 ? month : '0' + month;				day = day > 9 ? day : '0' + day;				return `${year}-${month}-${day}`;			},			// 上传图片			uploadPic() {				uni.chooseImage({					count: 1, // 图片数量					sizeType: ['original', 'compressed'], //可以指定是原图还是压缩图,默认二者都有					sourceType: ['album', 'camera'], //从相册选择或者拍照					success: (res) => {						const tempFilePaths = res.tempFilePaths[0];						console.log(this);						let that = this						const uploadTask = uni.uploadFile({							url: 'http://139.159.246.165:7006/img', // post请求地址							// url: 'https://cxcy.ssti.net.cn/api/UploadFirmFile', // post请求地址							// filePath: tempFilePaths,							filePath: tempFilePaths,							name: 'file', // 待确认							header: {								// 不要写这个不然报错								// 'Content-Type': 'multipart/form-data',							},							success: function(res) {								// console.log(res.data);								that.imageValue = res.data								// let url = JSON.parse(res.data)								// console.log(url.data);							},							fail: function(uploadFileFail) {								console.log('Error:', uploadFileFail.data);							},							complete: () => {								// 接口调用结束的回调函数(调用成功、失败都会执行)								// console.log('Complete:');							}						});					}				});			},		},		onShow() {			if (this.isFirstShow) {				this.editPublish()				this.isFirstShow = false			}			this.formData = this.$store.state.formData			let data =uni.getStorageSync('formData')			console.log(data);			this.activitytitle = data.activitytitle			this.activityintro = data.activityintro			this.imageValue = data.imageValue			this.index = data.classify			this.recruitment = data.recruitment			this.activityform = data.activityform			this.address = data.address			this.funds = data.funds			this.activityDate = data.activityDate			this.deadlineDate = data.deadlineDate						console.log(this.index);		},		beforeDestroy() {			// 在组件销毁之前保存表单数据到 Vuex 中			let data = {				activitytitle: this.activitytitle,				activityintro: this.activityintro,				imageValue: this.imageValue,				classify: this.index,				recruitment: this.recruitment,				activityform: this.activityform,				address: this.address,				funds: this.funds,				activityDate: this.activityDate,				deadlineDate: this.deadlineDate			}			uni.setStorageSync('formData',data)			// this.$store.commit('saveformData', this.formData);			// console.log('Submitted formData:', this.formData);			// console.log('Current state.formData:', this.$store.state.formData);		},	}</script><style lang="scss" scoped>	.publish {		.liu {			//留白			width: 750rpx;			height: 68rpx;			position: absolute;			bottom: 0;			background-color: #ffffff;		}		.pubTitle {			width: 750rpx;			height: 96rpx;			padding: 24rpx 30rpx 0 30rpx;			.title {				font-size: 32rpx;				line-height: 48rpx;				font-weight: 500;			}		}		.pubMid {			width: 750rpx;			// height: 504rpx;			padding: 24rpx 30rpx 0 30rpx;			// background-color: #8BBEFF;			.mid {				width: 690rpx;				height: 440rpx;				// background-color: #f2f2f2;				.txt {					width: 690rpx;					height: 192rpx;					.txtClass {						width: 100%;						height: 100%;						font-size: 28rpx;						font-weight: 400;						line-height: 48rpx;					}				}				.pic {					width: 224rpx;					height: 224rpx;					background-color: rgba(242, 242, 242, 1);					display: flex;					position: relative;					justify-content: center;					align-items: center;					.pic_show {						position: absolute;						top: 0;						left: 0;						width: 100%;						height: 100%;						z-index: 10;						background-color: #8BBEFF;						image {							width: 100%;							height: 100%;						}					}					.picCont {						display: flex;						flex-direction: column;						justify-content: center;						align-items: center;						image {							width: 56rpx;							height: 66rpx;						}					}				}			}		}		// background-color: #fff;		height: 100vh;		.textCont {			padding: 16px;		}		.addPhoto {			background-color: #f2f2f2;			width: 224rpx;			height: 224rpx;			display: flex;			color: #616161;			flex-direction: column;			align-items: center;			justify-content: center;			margin-left: 30rpx;			image {				width: 50px;				height: 50px;				// margin-left: 48px;			}			.photo {				color: #000000A3;				// padding-left: 44px;				// font-size: 14px;			}			.num {				color: #919191;				// padding-left: 56px;				// font-size: 14px;			}		}		.userOptionsBox {			width: 750rpx;			height: 96rpx;			display: flex;			justify-content: center;			align-items: center;			.optionsItemBox {				width: 690rpx;				.optionItem {					display: flex;					justify-content: space-between;					align-items: center;					.option_left {						display: flex;						align-items: center;						font-size: 28rpx;						line-height: 48rpx;						font-weight: 400;					}					.option_right {						height: 40rpx;						.input_details {							display: flex;							align-items: center;							.details {								display: flex;								flex-direction: row;								.text {									font-size: 28rpx;									color: rgb(153, 153, 153);								}							}							.arrow {								display: flex;								image {									width: 32rpx;									height: 32rpx;								}							}						}					}				}			}		}		.publish_now {			position: absolute;			// bottom: 100rpx;			display: flex;			width: 750rpx;			justify-content: center;			padding-bottom: 50rpx;			.btn {				width: 432rpx;				height: 88rpx;				line-height: 88rpx;				// background-color: #8BBEFF;				background: rgba(0, 86, 168, 1);				color: #fff;				display: flex;				flex-direction: column;				align-items: center;				margin-top: 20px;			}		}		.mask {			position: fixed;			top: 0;			left: 0;			width: 100%;			height: 100%;			background-color: rgba(0, 0, 0, 0.3);			z-index: 999;			// display: none;		}		.popup-container {			position: fixed;			top: 50%;			left: 50%;			transform: translate(-50%, -50%);			width: 520rpx;			height: 260rpx;			z-index: 1000;			// display: none;			.popup {				width: 100%;				height: 100%;				display: flex;				flex-direction: column;				background-color: #fff;				border-radius: 16rpx;				.header {					flex: 1;					display: flex;					justify-content: center;					align-items: center;					flex-direction: column;					margin-top: 24px;					font-size: 34rpx;					font-weight: 600;					image {						width: 150rpx;						height: 150rpx;						margin-top: 15px;						margin-bottom: 15px;					}				}				.footer {					flex: 1;					display: flex;					justify-content: space-around;					align-items: end;					padding-top: 17px;					.cancel-btn {						width: 259rpx;						height: 100rpx;						background-color: #F7F7F7;						color: #000;						font-size: 34rpx;						text-align: center;						border-radius: 0;						border-bottom-left-radius: 16rpx;						line-height: 50px;					}					.confirm-btn {						width: 259rpx;						height: 100rpx;						background-color: #0081FE;						color: #fff;						font-size: 34rpx;						text-align: center;						border-radius: 0;						border-bottom-right-radius: 16rpx;						line-height: 50px;					}					.confirm-btn_2 {						width: 518rpx;						height: 100rpx;						background-color: #F7F7F7;						color: #000;						font-size: 34rpx;						text-align: center;						border-radius: 0;						border-bottom-left-radius: 16rpx;						border-bottom-right-radius: 16rpx;						line-height: 50px;					}				}			}		}	}</style>
 |