<template>
	<RefreshView ref="mescrollRef" :hasBack="true" text="发起活动" :useDownScroll="false" :useUpScroll="false"
		:isInterceptBack="true" @backClick="backClick" :useTitleLeftBtn="isCreate==0?1:0" titleLeftBtnSource="存草稿"
		@leftBtn='leftBtnClick' :useTitleRightBtn="1" titleRightBtnSource="发布" @rightBtn='rightBtnClick'>

		<view class="topLayout">
			<view class="topLayout_item" @click="topClik(1)">
				<!-- <image style="width: 34rpx;height: 38rpx;" src="../../static/event-icon/finished.png" mode="aspectFit">
			</image> -->
				<text class="topLayout_item_left1">1</text>
				<text style="font-size: 28rpx;color: #262626;margin-left: 10rpx;">基本信息</text>
			</view>

			<view class="topLayout_item" @click="topClik(2)">
				<!-- <image style="width: 34rpx;height: 38rpx;" src="../../static/event-icon/finished.png" mode="aspectFit">
			</image> -->
				<text class="topLayout_item_left1">2</text>
				<text
					style="font-size: 28rpx; font-family: Adobe Heiti Std;font-weight: normal;color: #262626;margin-left: 10rpx;">设置活动项目</text>
			</view>

			<view class="topLayout_item">
				<!-- <image style="width: 34rpx;height: 38rpx;" src="../../static/event-icon/unfinished.png"
				mode="aspectFit">
			</image> -->
				<text class="topLayout_item_left1">3</text>
				<text style="font-size: 28rpx;color: #979797;margin-left: 10rpx;">奖项及其他</text>
			</view>
		</view>

		<PublishItem leftText="奖品设置" :isShowRight="false">
		</PublishItem>
		<view class="line"></view>
		<view class="layout">
			<textarea class="explain" @input="notesText" placeholder="奖品设置（点击编辑）"
				:value="info.activityNotesOther.notes" />
		</view>
		<view class="line"></view>

		<PublishItem leftText="特别鸣谢" rightText="选择赞助商" :isShowRight="true" @rightClick="clickItem()">
		</PublishItem>

		<view style="display: flex;margin-left: 40rpx;margin-right: 40rpx;flex-direction: column;">
			<view v-for="(item,index) in info.activityNotesOther.listSponsor " :key="index">
				<view
					style="display: flex; width: 100%; padding-top: 10rpx;padding-bottom: 15rpx;justify-content: center;">
					<text style="color: #898989;font: size 50rpx;flex: 1;"
						@click="showDetail(item.sid)">{{item.name}}</text>
					<image style="width: 30rpx;height: 30rpx;" src="../../static/event-icon/delete.png" mode="aspectFit"
						@click="deleteItem(index)">
					</image>
				</view>
			</view>
		</view>

		<view class="line"></view>

		<PublishItem leftText="主办方" :isShowRight="false"></PublishItem>
		<EditText hint="请输入主办方名称" @onTextChange="organizerText" :value="info.activityNotesOther.organizer">
		</EditText>
		<view class="line"></view>

		<PublishItem leftText="承办方" :isShowRight="false"></PublishItem>
		<EditText hint="请输入承办方名称" @onTextChange="cocosponsorrText" :value="info.activityNotesOther.cosponsor">
		</EditText>

		<!-- <text class="btn" @click="jump()">发布</text> -->
		</view>

	</RefreshView>
</template>

<script>
	export default {
		data() {
			return {
				isCreate: 0,
				raceSid: "",
				info: {
					activityBaseInfo: {},
					listActivityItems: [],
					activityNotesOther: {
						cosponsor: "",
						organizer: "",
						notes: "",
						listSponsor: [
							// {
							// 	sid: "",
							// 	name: "啊大大大add的方式达到",
							// 	introduction: "",
							// 	address: "",
							// 	linkerName: "",
							// 	linkerPhone: "",
							// 	logo: "",
							// 	webUrl: "",
							// },
							// {
							// 	sid: "",
							// 	name: "啊a士大夫士大夫大师傅是第三方士大夫达到",
							// 	introduction: "",
							// 	address: "",
							// 	linkerName: "",
							// 	linkerPhone: "",
							// 	logo: "",
							// 	webUrl: "",
							// }
						]
					}
				}
			}

		},
		onLoad: function(option) {
			this.isCreate = option.isCreate
			console.log('option.isCreate', option.isCreate)
		},
		onShow() {
			let backResult = this.OnActivityResult();
			if (backResult != undefined) {
				if (!this.IsEmpty(backResult)) {
					this.info.activityNotesOther.listSponsor = backResult
					console.log("list=====>" + JSON.stringify(backResult))
					console.log("sponsorList=====>" + JSON.stringify(this.info.activityNotesOther.listSponsor))
				}
			}

		},
		methods: {
			backClick() {
				let that = this
				uni.showModal({
					title: '提示',
					content: '赛事未发布，是否保存草稿？',
					success: function(res) {
						if (res.confirm) { //这里是点击了确定以后
							console.log('用户点击确定')
							that.WriteGameCahce(that.info)
							uni.navigateBack({
								delta: 3
							})
						} else { //这里是点击了取消以后
							console.log('用户点击取消')
							uni.navigateBack({
								delta: 3
							})
						}
					}
				})
			},
			leftBtnClick() {
				this.WriteGameCahce(this.info)
				uni.navigateBack({
					delta: 3
				})

			},
			rightBtnClick() {

				if (this.IsEmpty(getApp().globalData.memberSid)) {
					console.log('createSid', "无sid")
				} else {
					this.info.createSid = getApp().globalData.memberSid
					console.log('createSid', JSON.stringify(this.info))
					// this.HTTP({
					// 	url: 'v1/activityManagement/saveActivity',
					// 	method: 'POST',
					// 	data: this.info,
					// 	paramsType: "FORM",
					// 	loading: true
					// }).then((res) => {
						// this.ClearGameCache(this.info)
					// 		wx.navigateBack({
					// 		delta: 3
					// 	})

					// });
				}



			},
			topClik(index) {
				this.WriteGameCahce(this.info)
				switch (index) {
					case 1:
						uni.navigateTo({
							url: "exemptionActivity?isCreate=" + this.isCreate +
								"&info=" + JSON.stringify(this.info) // 页面 A
						})
						break
					case 2:
						uni.navigateTo({
							url: "setEventActivity?isCreate=" + this.isCreate +
								"&info=" + JSON.stringify(this.info) // 页面 A
						})
						break
				}
			},
			clickItem() {

				uni.navigateTo({
					url: "sponsorList"
				})
			},
			notesText(e) {
				this.info.activityNotesOther.notes = e.detail.value
			},
			cocosponsorrText(e) {
				this.info.activityNotesOther.cosponsor = e
			},
			organizerText(e) {
				this.info.activityNotesOther.organizer = e
			},
			showDetail() {

			},
			deleteItem(item) {
				let _this = this
				console.log("====>" + _this.info.activityNotesOther.listSponsor.length);

				uni.showModal({
					title: '温馨提示',
					content: '确定要删除此赞助商吗？',
					success(res) {
						if (res.confirm) {
							_this.info.activityNotesOther.listSponsor.splice(_this.info.activityNotesOther
								.listSponsor.indexOf(item),
								1);
							console.log("====>" + _this.info.activityNotesOther.listSponsor.length);
						}
					}
				});
			},
			jump() {
				if (this.IsEmpty(this.info.activityNotesOther.cosponsor)) {
					this.Toast("请输入承办方名称")
					return
				}
				if (this.IsEmpty(this.info.activityNotesOther.organizer)) {
					this.Toast("请输入主办方名称")
					return
				}

			}

		}


	}
</script>

<style lang="scss">
	.tripList_root {

		top: 0px;

		left: 0px;

		width: 100%;

		height: 100%;

		overflow: hidden;

		position: fixed;

		z-index: 0;

	}

	.topLayout {
		background: #F7F7F7;
		display: flex;
		padding: 30rpx 60rpx;
		flex-direction: row;
		align-items: center;
		flex-direction: row;
		justify-content: space-between;

		.topLayout_item {
			display: flex;
			flex-direction: row;
			align-items: center;

			.topLayout_item_left1 {
				width: 48rpx;
				height: 48rpx;
				background-color: #007AFF;
				border-radius: 50%;
				color: #FFFFFF;
				font-size: 36rpx;
				text-align: center;
			}

			.topLayout_item_left2 {
				width: 48rpx;
				height: 48rpx;
				border: 1rpx solid #D9D9D9;
				border-radius: 50%;
				color: #D9D9D9;
				font-size: 36rpx;
				text-align: center;
			}
		}
	}

	.line {
		width: 100%;
		height: 5rpx;
		background-color: #f5f4f9;
	}

	.layout {
		background: #FFFFFF;
		display: flex;
		margin: 15px;
		height: auto;

		.notes {
			width: 100%;
		}
	}

	.btn {
		justify-content: center;
		width: 100%;
		margin-top: 100rpx;
		padding: 30rpx;
		font-size: 28rpx;
		color: #FFFFFF;
		background: #007AFF;
		text-align: center;
		flex: 1;
		position: absolute;
		bottom: 0;
	}
</style>
