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

		<view class="topLayout">
			<view class="topLayout_item" @click="topClik(1)">
				<text :class="{'topLayout_item_left1': parameter.isShowBaseInfo== true, 'topLayout_item_left2': parameter.isShowBaseInfo== false}">1</text>
				<text :class="{'topLayout_item_right2': parameter.isShowBaseInfo== true, 'topLayout_item_right2': parameter.isShowBaseInfo== false}">基本信息</text>
			</view>
			<view class="topLayout_item" @click="topClik(2)">
				<text :class="{'topLayout_item_left1': parameter.isShowActivityItem== true, 'topLayout_item_left2': parameter.isShowActivityItem== false}">2</text>
				<text :class="{'topLayout_item_right2': parameter.isShowActivityItem== true, 'topLayout_item_right2': parameter.isShowActivityItem== false}">设置活动项目</text>
			</view>
			<view class="topLayout_item" @click="topClik(3)">
				<text :class="{'topLayout_item_left1': parameter.isShowNotesOther== true, 'topLayout_item_left2': parameter.isShowNotesOther== false}">3</text>
				<text :class="{'topLayout_item_right2': parameter.isShowNotesOther== true, 'topLayout_item_right2': parameter.isShowNotesOther== false}">奖项及其他</text>
			</view>
		</view>
		
		
		<view v-if="parameter.isShowBaseInfo" class="ativity-create-info">
			<view class="menu-item">
				<view><h1>[标题]</h1></view>
				<EditText hint="请输入活动名称" @onTextChange="textName" :text="data.name"></EditText>
			</view>
			
			<view class="line-thin"></view>
			<view class="menu-item" @click="toEditIntroduction()">
				<text class="field">活动简介</text>
				<text class="explain">编辑</text>
				<image class = "more" src="../../static/img/public/more.png" ></image>
			</view>
			<view style="display: flex;margin-left: 30rpx; margin-right: 30rpx;">
				<editor id="editor1" style="height: 50rpx; white-space: pre-wrap;" placeholder="点击进行编辑..." showImgSize
					showImgToolbar showImgResize :read-only="true" @click="toEditIntroduction()" @ready="onEditorIntroduction">
				</editor>
			</view>
			
			<view class="line-thin"></view>
			<pick-regions :defaultRegion="defaultRegionCode" @getRegion="handleGetRegion">
				<view class="menu-item">
					<text class="field">地区</text>
					<text class="explain">{{this.IsEmpty(page.adName) ?"请选择地区":page.adName}}</text>
					<image class = "more" src="../../static/img/public/more.png" ></image>
				</view>
			</pick-regions>
			
			<view class="line-thin"></view>
			<view class="menu-item" @click="clickItem('宣传海报')">
				<text class="field">宣传海报</text>
				<text class="explain">上传</text>
				<image class = "more" src="../../static/img/public/more.png" ></image>
			</view>
			
			<scroll-view style="width: 100%;white-space: nowrap;" scroll-x="true">
				<view v-for="(item,index) in data.listActivityImage" :key="index"
					style="display: inline-block;">
					<view style="margin-left: 20rpx;margin-right: 20rpx;display: flex;">
						<image :src="item.imageUrl" style="width: 220rpx;height: 150rpx;z-index: 1;" mode="aspectFill"
							@click="showImage(index)">
						</image>
						<image src="../../static/img/activity/delete.png"
							style="margin-left: -40rpx;margin-top: 10rpx;width: 30rpx;height: 30rpx;z-index: 2;"
							@click="deleteImage(item)">
						</image>
					</view>
				</view>
			</scroll-view>
			<view class="line-thin"></view>
			
			<view class="menu-item">
				<text class="field">体育活动标签</text>
				<text class="explain">{{data.sportCategoryName}}</text>
			</view>
			
			<view class="line-thin"></view>
			<biaofun-datetime-picker :defaultValue="data.enrollStartTime" @change="enrollStartTimeChange" >
				<view class="menu-item">
					<text class="field">报名开始时间</text>
					<text class="explain">{{data.enrollStartTime}}</text>
					<image class = "more" src="../../static/img/public/more.png" ></image>
				</view>
			</biaofun-datetime-picker>
				

			<view class="line-thin"></view>
			
			<biaofun-datetime-picker :defaultValue="data.enrollEndTime" @change="enrollEndTimeChange">
				<view class="menu-item">
					<text class="field">报名截止时间</text>
					<text class="explain">{{data.enrollEndTime}}</text>
					<image class = "more" src="../../static/img/public/more.png" ></image>
				</view>
			</biaofun-datetime-picker>
			
			<view class="line-thin"></view>
			<view class="menu-item" @click="toSetLinker()">
				<text class="field">联系方式</text>
				<text class="explain">{{page.nameAndMobile}}</text>
				<image class = "more" src="../../static/img/public/more.png" ></image>
			</view>
			
			<view class="line-thin"></view>
			<view class="menu-item" @click="toEditDisclaimer()">
				<text class="field">免责声明</text>
				<text class="explain">编辑</text>
				<image class = "more" src="../../static/img/public/more.png" ></image>
			</view>
			<view style="display: flex;margin-left: 30rpx; margin-right: 30rpx;">
				<editor id="editor2" style="white-space: pre-wrap;" placeholder="点击进行编辑..." showImgSize showImgToolbar
					showImgResize :read-only="true" @click="toEditDisclaimer()" @ready="onEditorDisclaimer">
				</editor>
			</view>
			
			<view class="line-thin"></view>
			<view class="menu-item"  @click="clickCancelEnrollRefund()">
				<text class="field">参赛者取消报名</text>
				<text class="explain">{{page.cancelEnrollRefundDesc}}</text>
				<image class = "more" src="../../static/img/public/more.png" ></image>
			</view>
			
			<view class="line-thin"></view>
			<view class="menu-item" @click="clickInviteType()">
				<text class="field">公开类型</text>
				<text class="explain">{{page.inviteTypeDesc}}</text>
				<image class = "more" src="../../static/img/public/more.png" ></image>
<!-- 				<view class="explain">
					<switch class="tui-fr" :checked="switchCheckedInviteType" @change="switchChangeInviteType"></switch>
				</view> -->
			</view>
			<view class="row" @click="toEnrollRequired()">
				<text class="field">报名必填</text>
				<text>{{page.enrollRequiredName}}</text>
				<image class = "more" src="../../static/img/public/more.png" ></image>
			</view>
			<text style="font-size: 24rpx; color:#ff0000 ; margin-left: 30rpx;">注：非公开赛事在“我的赛事”可见，分享后好友可报名。</text>
			<view style="height: 300rpx;"></view>
			<text class="btn" @click="toSetActivityItem()">设置活动项目</text>
		</view>
		<view v-if="parameter.isShowActivityItem">
			<view>
				<view v-for="(item,index) in data.listActivityItem" :key="index">
					<view class="items">
						<view class="layout1">
							<text class="number">{{index+1}}</text>
							<input class="name" type="text" @input="nameText($event, index)" placeholder="请输入活动项目名称"
								:value="item.name" />
							<view style="display: flex;padding-left: 36rpx; align-items: center;"
								@click="deleteItem(item)">
								<image style="width: 34rpx;height: 38rpx;" src="../../static/img/activity/delete.png"
									mode="aspectFit">
								</image>
							</view>
						</view>
						<view class="line-thin"></view>
						<view class="layout2">
							<textarea class="explain" auto-height="true" style="min-height: 80rpx;"
								@input="explainText($event, index)" placeholder="活动项目说明（点击编辑）"
								:value="item.introduction" />
						</view>
						<view class="line-thin"></view>

						<view class="line-thin"></view>
						<view class="menu-item">
							<text class="field">报名类型</text>
							<radio-group @change="radioChange($event, index)" >
								<radio :checked="item.enrollMold==0" :value="item.enrollMold==0">个人</radio>
								<radio :checked="item.enrollMold==1"  :value="item.enrollMold ==1" :disabled="true" style="margin-left: 50rpx;">团体</radio>
							</radio-group>
						</view>
						
						<view class="line-thin"></view>
						<view class="menu-item"  @click="toInputEnrollNumbersLimitMoney(index)">
							<text class="field">人数费用</text>
							<text class="explain">{{item.enrollNumbersLimit==0?"不限人数":item.enrollNumbersLimit + "人"}} / {{item.enrollMoney==0?"免费":item.enrollMoney+'元'}}</text>
							<image class = "more" src="../../static/img/public/more.png" ></image>
						</view>

						<view class="line-thin"></view>
						<biaofun-datetime-picker :defaultValue="item.startTime" @change="dateChange1($event, index)">
							<view class="menu-item">
								<text class="field">开始时间</text>
								<text class="explain">{{item.startTime}}</text>
								<image class = "more" src="../../static/img/public/more.png" ></image>
							</view>
						</biaofun-datetime-picker>					
						<view class="line-thin"></view>
						<picker mode="date" :value="item.endTime" @change="dateChange2($event, index)">
							<view class="menu-item">
								<text class="field">结束时间</text>
								<text class="explain">{{item.endTime}}</text>
								<image class = "more" src="../../static/img/public/more.png" ></image>
							</view>
						</picker>
						
						<view class="line-thin"></view>
						<view class="menu-item">
							<text class="field">活动地点</text>
						</view>
						<EditText hint="请输入活动地点" @onTextChange="address($event, index)" :text="item.address" >
						</EditText>
						<view class="line-thin"></view>
						<view class="menu-item" @click="toEnrollCondition(index)">
							<text class="field">报名条件</text>
							<text>{{convertConditionText(item.listEnrollConditionRelationSexAge)}}</text>
							<!-- <text>{{convertAgeRangeText(10,20)}}</text> -->
							<image class = "more" src="../../static/img/public/more.png" ></image>
						</view>
						
						<view class="line-wide"></view>

					</view>
				</view>
			</view>

			<view style="height: 100rpx;background: #FFFFFF;" v-if="data.listActivityItem.length<6">
				<view class="addData" @click="addData()">
					<image style="width: 48rpx;height: 48rpx;" src="../../static/img/activity/add.png" mode="aspectFit">
					</image>
					<text style="color: #898989 ; margin-left: 10rpx;">点击继续添加活动项目</text>
				</view>
			</view>
			<view style="height: 150px;"></view>
			<text class="btn" @click="toNoteAndOther()">奖项及其他设置</text>
		</view>
		<view v-if="parameter.isShowNotesOther">
			<view class="menu-item">
				<text class="field">奖品设置</text>
			</view>

			<view class="line-thin"></view>
			<view class="menu-item">
				<textarea class="explain" @input="notesText" auto-height="true" style="min-height: 80rpx;"
					placeholder="奖品设置（点击编辑）" :value="data.notes" />
			</view>
			
<!-- 			<view class="line-thin"></view>
			<view class="menu-item" @click="clickItem('赞助商')">
				<text class="field">特别鸣谢</text>
				<text class="explain">选择赞助商</text>
				<image class = "more" src="../../static/img/public/more.png" ></image>
			</view>

			<view style="display: flex;margin-left: 40rpx;margin-right: 40rpx;flex-direction: column;">
				<view v-for="(item,index) in nameList " :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;">{{item}}</text>
						<image style="width: 30rpx;height: 30rpx;" src="../../static/img/activity/delete.png"
							mode="aspectFit" @click="deleteSponsor(index)">
						</image>
					</view>
				</view>
			</view> -->

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

			<!-- 	<PublishItem leftText="主办方" :isShowRight="false"></PublishItem>
			<EditText hint="请输入主办方名称" @onTextChange="organizerText" :text="data.organizer">
			</EditText>
			<view class="line-thin"></view>
			 -->
			
			<view class="menu-item">
				<text class="field">主办方</text>
				<input class="explain" type="text" placeholder="请输入主办方名称" @input="organizerText"
					:value="data.organizer" />
			</view>

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

			<!-- <PublishItem leftText="承办方" :isShowRight="false"></PublishItem>
			<EditText hint="请输入承办方名称" @onTextChange="cocosponsorrText" :text="data.cosponsor">
			</EditText>
			 -->
			<view class="menu-item">
				<text class="field">承办方</text>
				<input class="explain" type="text" placeholder="请输入承办方名称"
					@input="cocosponsorrText" :value="data.cosponsor" />
			</view>
			
			<text class="btn" @click="publish()">发布</text>
		</view>
	</RefreshView>
</template>

<script>
	import fuiButton from "@/components/firstui/fui-dropdown-menu/fui-dropdown-menu.vue"
	export default {
		components: {
			"fuiButton": fuiButton
		},
		data() {
			return {
				parameter:{
					isCreate: "0",  // 判断是不是创建	
					isShowBaseInfo: true,
				    isShowActivityItem: false,
					isShowNotesOther: false,
					activityItemIndex:0 ,//活动项目索引
					listIsDelActivityImageSid:[],
					listIsDelActivityItemSid:[],
					listIsSponsorSid:[]
				},
				data: {
					sid: "",
					name:"",
					enrollStartTime: this.TimeFormat(this.CurrentMillions(), "yyyy-MM-dd HH:mm"),
					enrollEndTime: this.TimeFormat(this.CurrentMillions(), "yyyy-MM-dd HH:mm"),
					linkerName:"",
					linkerPhone:"",
					cancelEnrollRefund:1,
					cosponsor:"",
					organizer:"",
					introduction:"",
					notes:"",
					disclaimer:"",
					inviteType:0,
					adCode:this.ReadPreference("find_city_code"),
					sportCategorySid: "",
					sportCategoryName: "",
					sysUserSid:"",
					listSponsor:[],
					listCoverImageUrl:[],
					listActivityImage:[],
					listActivityItem:[
						{
							sid:"",
							name:"",
							introduction:"",
							enrollMold:0,
							enrollNumbersLimit:0,
							enrollMoney:0,
							startTime:this.TimeFormat(this.CurrentMillions(), "yyyy-MM-dd HH:mm"),
							endTime: this.TimeFormat(this.CurrentMillions(), "yyyy-MM-dd"),
							address:"",
							listEnrollConditionRelationSexAge:[{
								enrollConditionRelationsid: "",
								conditionSid: "",
								sex: 0,
								minAge: 0,
								maxAge: 0
								}
							]
						}
					],	
					enrollRequired:{
						sid:"",
						activitySid:"",
						onRealName:0,
						onSex:0,
						onBirthday:0,
						onAdCode:0
					}
				},
				page:{
					adName:this.ReadPreference("find_city"),
					nameAndMobile:"",
					numAndMoney:"",
					cancelEnrollRefundDesc:"",
					inviteTypeDesc:"",
					enrollRequiredName:"",
					ageRangeText:""
				},
				control: {
					listCancelEnrollRefund:["不退报名费","退还报名费"],
					listInviteType:["全部可见","被邀请并报名后可见"]
				}
			};
		},
		onLoad: function(options) {

			console.log("传递的参数：",options)
			// 如果传送回活动Sid，则调用进行修改
			let _this = this
			if (!_this.IsEmpty(options.sid)) {
				let activitySid = options.sid
				_this.HTTP({
					url: 'aos/v1/activity/getActivityCreateInfo/' + activitySid,
					method: 'GET',
					paramsType: "FORM",
					loading: true
				}).then((res) => {
					// _this.WriteGameCahce(res.data)
					_this.data = res.data
					// 页面参数赋值
					_this.page.cancelEnrollRefundDesc = _this.control.listCancelEnrollRefund[_this.data.cancelEnrollRefund]
					_this.page.inviteTypeDesc = _this.control.listInviteType[_this.data.inviteType]
					_this.page.nameAndMobile = _this.data.linkerName + "\u3000" + _this.data.linkerPhone
					console.log("活动详情：",_this.data)
					this.setEnrollRequiredName()
					this.onEditorIntroduction()
					this.onEditorDisclaimer()
					
					// _this.switchCheckedInviteType = res.data.activityBasedata.cancelEnrollRefund == 1 ?
					// 	true : false
					// _this.switch2Checked = res.data.activityBasedata.inviteType == 1 ? true : false
					// _this.onEditorReady1()
					// _this.onEditorReady2()
					// console.log('=======', res)
				});
			}else{
				// 如果用户已经登陆
				console.log('options.sportCategoryName', options.sportCategoryName)
				console.log('options.sportCategorySid', options.sportCategorySid)
				this.data.sportCategoryName = options.sportCategoryName    // 活动类型名称
				this.data.sportCategorySid = options.sportCategorySid      // 活动类型sid
				
				// 控件赋值
				this.page.cancelEnrollRefundDesc = this.control.listCancelEnrollRefund[1]
				this.page.inviteTypeDesc = this.control.listInviteType[0]
				this.setEnrollRequiredName()
				// this.data.disclaimer = options.disclaimer                  // 默认免责声明
				_this.HTTP({
					url: 'aos/v1/sportCategory/getSportCategory/' + this.data.sportCategorySid,
					method: 'GET',
					paramsType: "FORM",
					loading: true
				}).then((res) => {
					this.data.disclaimer  = res.data.disclaimerTemplate
					// console.log('=============================================================',_this.disclaimerTemplate)
				})
				
			}

		},
		onShow() {
			let backResult = this.OnActivityResult();
			if (backResult != undefined) {
				console.log("结果>" + JSON.stringify(backResult))
				// 联系方式
				if (!this.IsEmpty(backResult.linkerName)) {
					this.page.nameAndMobile = backResult.linkerName + "\u3000" + backResult.linkerPhone
					this.data.linkerName = backResult.linkerName
					this.data.linkerPhone = backResult.linkerPhone
				}
				// 活动介绍
				if (!this.IsEmpty(backResult.introduction)) {
					this.data.introduction = backResult.introduction
					this.onEditorIntroduction()
				}
				// 报名必填项
				if (!this.IsEmpty(backResult.disclaimer)) {
					this.data.disclaimer = backResult.disclaimer
					this.onEditorDisclaimer()
				}
				if (!this.IsEmpty(backResult.onRealName)) {
					this.data.enrollRequired.onRealName = backResult.onRealName
				}
				if (!this.IsEmpty(backResult.onSex)) {
					this.data.enrollRequired.onSex = backResult.onSex
				}
				if (!this.IsEmpty(backResult.onBirthday)) {
					this.data.enrollRequired.onBirthday = backResult.onBirthday
					
				}
				if (!this.IsEmpty(backResult.onAdCode)) {
					this.data.enrollRequired.onAdCode = backResult.onAdCode
				}
				this.setEnrollRequiredName()
				// 报名条件
				
				
				if (!this.IsEmpty(backResult.listEnrollConditionRelationSexAge)) {
					
					let listEnrollConditionRelationSexAge = []
					for (let enrollConditionRelationSexAge of backResult.listEnrollConditionRelationSexAge){
						listEnrollConditionRelationSexAge.push(JSON.parse(enrollConditionRelationSexAge))
					}
					console.log("111111111111111111111111111111111",listEnrollConditionRelationSexAge)
				
					this.data.listActivityItem[this.parameter.activityItemIndex].listEnrollConditionRelationSexAge = listEnrollConditionRelationSexAge
					console.log("222222222222222222222222222222222",this.data.listActivityItem[this.parameter.activityItemIndex].listEnrollConditionRelationSexAge)
					this.convertConditionText(this.data.listActivityItem[this.parameter.activityItemIndex].listEnrollConditionRelationSexAge)
					
				}
				// 球馆
				if (!this.IsEmpty(backResult.sid)) {
					console.log("选择的球馆>" + JSON.stringify(backResult))
					// 选择的球馆
					this.data.listActivityItem[this.pos].gymnasiumSid = backResult.sid
					this.data.listActivityItem[this.pos].gymnasiumName = backResult.name
					console.log("选择的球馆>" + JSON.stringify(this.data.listActivityItem))
				}
				// 报名费用人数
				if (!this.IsEmpty(backResult.enrollMoney)) {
					// 人数费用
					console.log("enrollMoney>" + backResult.enrollMoney)
					let num = backResult.enrollNumbersLimit == 0 ? "不限制人数" : backResult.enrollNumbersLimit + "人"
					let price = backResult.enrollMoney == 0 ? "免费" : backResult.enrollMoney + "元"
					this.data.listActivityItem[this.parameter.activityItemIndex].enrollMoney = backResult.enrollMoney
					this.data.listActivityItem[this.parameter.activityItemIndex].enrollNumbersLimit = backResult.enrollNumbersLimit
				}
				
				if (!this.IsEmpty(backResult.sidList)) {
					console.log("list=====>" + JSON.stringify(backResult.sidList))
					this.data.listSponsorSid = backResult.sidList
					this.nameList = backResult.nameList
				}
			}

		},
		methods: {
			convertAgeRangeText(minAge,maxAge){
				if(minAge == 0 && maxAge == 0 ){
					return "不限年龄"
				}
				if(minAge == 0 && maxAge > 0 ){
					return maxAge + "岁以下"
				}
				if(minAge > 0 && maxAge == 0 ){
					return minAge + "岁以上"
				}
				if(minAge > 0 && maxAge > 0 ){
					return minAge + "岁  至  " + maxAge +"岁"
				}
			},
			convertConditionText(listEnrollConditionRelationSexAge){
				if (listEnrollConditionRelationSexAge != null && listEnrollConditionRelationSexAge.length > 0){
					let conditionText = ""
					for (let conditionRelationSexAge of listEnrollConditionRelationSexAge){
						let sex = conditionRelationSexAge.sex
						if (sex == 0){
							conditionText += "不限性别"
						}
						if (sex == 1){
							conditionText += "男子"
						}
						if (sex == 2){
							conditionText += "女子"
						}
						let minAge = conditionRelationSexAge.minAge
						let maxAge = conditionRelationSexAge.maxAge
						if(minAge == 0 && maxAge == 0 ){
							conditionText += "不限年龄"
						}
						if(minAge == 0 && maxAge > 0 ){
							conditionText += maxAge + "岁以下"
						}
						if(minAge > 0 && maxAge == 0 ){
							conditionText += minAge + "岁以上"
						}
						if(minAge > 0 && maxAge > 0 ){
							conditionText += minAge + "岁  至  " + maxAge +"岁"
						}
					}
					return conditionText
				}
				else
				{
					return "无报名条件限制"
				}
			},
			setEnrollRequiredName(){
				let enrollRequiredName = ""
				if (this.data.enrollRequired.onRealName == 1){
					enrollRequiredName += "姓名"
				}
				if (this.data.enrollRequired.onSex == 1){
					if (this.data.enrollRequired.onRealName == 1){
						enrollRequiredName += " / "
					}
					enrollRequiredName += "性别"
				}
				if (this.data.enrollRequired.onBirthday == 1){
					if (this.data.enrollRequired.onSex == 1  || this.data.enrollRequired.onRealName == 1){
						enrollRequiredName += " / "
					}
					enrollRequiredName += "生日"
				}
				if (this.data.enrollRequired.onAdCode == 1){
					if (this.data.enrollRequired.onSex == 1  || this.data.enrollRequired.onRealName == 1 || this.data.enrollRequired.onBirthday == 1){
						enrollRequiredName += " / "
					}
					enrollRequiredName += "地区"
				}
				this.page.enrollRequiredName = enrollRequiredName
			},
			// 获取选择的地区
			handleGetRegion(region) {
				let _this = this
				_this.region = region
				let code = _this.region.map(item => item.code)
				let name = _this.region.map(item => item.name)
				_this.data.adCode = code[2]
				_this.page.adName = name[0] + " " + name[1] + " " + name[2]
			},
			clickCancelEnrollRefund() {
				let _this = this;
				uni.showActionSheet({
					itemList: _this.control.listCancelEnrollRefund,
					success: function(res) {
						_this.selectCancelEnrollRefund(res.tapIndex)
					}
				});
			},
			selectCancelEnrollRefund(id) {
				let _this = this
				switch (id) {
					case 0:
						_this.data.cancelEnrollRefund = 0
						_this.page.cancelEnrollRefundDesc = _this.control.listCancelEnrollRefund[0]
						break;
					case 1:
						_this.data.cancelEnrollRefund = 1
						_this.page.cancelEnrollRefundDesc = _this.control.listCancelEnrollRefund[1]
						break;
				}
			},
			clickInviteType(){
				let _this = this;
				uni.showActionSheet({
					itemList: _this.control.listInviteType,
					success: function(res) {
						_this.selectInviteType(res.tapIndex)
					}
				});
			},
			selectInviteType(id){
				let _this = this
				switch (id) {
					case 0:
						_this.data.inviteType = 0
						_this.page.inviteTypeDesc = _this.control.listInviteType[0]
						break;
					case 1:
						_this.data.inviteType = 1
						_this.page.inviteTypeDesc = _this.control.listInviteType[1]
						break;
				}
			},
			toInputEnrollNumbersLimitMoney(index) {
				this.parameter.activityItemIndex = index
				let _this = this
				
				uni.navigateTo({
					url: "InputEnrollNumbersLimitMoney?enrollNumbersLimit=" +
						(_this.data.listActivityItem[index].enrollNumbersLimit == undefined ? "" :
							_this.data.listActivityItem[index].enrollNumbersLimit) +
						"&enrollMoney=" + (_this.data.listActivityItem[index].enrollMoney ==
							undefined ? "" :
							_this.data.listActivityItem[index].enrollMoney) +
						"&type=" + (_this.data.listActivityItem[index].type == undefined ? "" :
							_this.data.listActivityItem[index].type),
				})			
			},
			toEnrollRequired(){
				let _this = this
				uni.navigateTo({
					url: "EnrollRequired?onRealName=" + _this.data.enrollRequired.onRealName 
					+ "&onSex=" + _this.data.enrollRequired.onSex 
					+ "&onBirthday=" + _this.data.enrollRequired.onBirthday 
					+ "&onAdCode=" + _this.data.enrollRequired.onAdCode
				})
			},
			toEnrollCondition(index){
				let _this = this
				_this.parameter.activityItemIndex = index
				console.log("-----------------------------------------------", JSON.stringify(_this.data.listActivityItem[index].listEnrollConditionRelationSexAge))
				uni.navigateTo({
					url: "EnrollCondition?listEnrollConditionRelationSexAge=" + JSON.stringify(_this.data.listActivityItem[index].listEnrollConditionRelationSexAge)
				})
			},
			toEditIntroduction(){
				let _this = this
				uni.navigateTo({
					url: "EditIntroduction?introduction=" + _this.data.introduction
				})
			},
			toSetLinker(){
				let _this = this
				uni.navigateTo({
					url: "SetLinker?linkerName=" + _this.data.linkerName + "&linkerPhone=" + _this.data.linkerPhone
				})
			},
			toEditDisclaimer(){
				let _this = this
				uni.navigateTo({
					url: "EditDisclaimer?disclaimer=" + _this.data.disclaimer
				})
			},
			toSetActivityItem() {
				if (!this.verifyData(1)){
					return
				}
				this.parameter.isShowBaseInfo = false
				this.parameter.isShowActivityItem = true
				this.parameter.isShowNotesOther = false
			},
			toNoteAndOther() {
				if (!this.verifyData(2)){
					return
				}
				this.topClik(3)
			},
			backClick() {
				uni.navigateBack({
					delta: 1
				})
			},
			leftBtnClick() {
				console.log('用户点击确定')
				this.WriteGameCahce(this.data)
				uni.navigateBack({
					delta: 1
				})

			},
			topClik(index) {
				switch (index) {
					case 1:
						this.parameter.isShowBaseInfo = true
						this.parameter.isShowActivityItem = false
						this.parameter.isShowNotesOther = false
						break
					case 2:
						this.parameter.isShowBaseInfo = false
						this.parameter.isShowActivityItem = true
						this.parameter.isShowNotesOther = false
						break
					case 3:
						this.parameter.isShowBaseInfo = false
						this.parameter.isShowActivityItem = false
						this.parameter.isShowNotesOther = true
						break
				}
			},
			textName(e) {
				this.data.name = e
			},
			clickItem(e) {
				let _this = this
				switch (e) {
					case "宣传海报":
						this.chooseUpload(9)
							.then((res) => {
								for (var j = 0; j < res.urls.length; j++) {
									_this.data.listActivityImage.push({
										sid:"",
										activitySid:_this.data.sid,
										imageUrl:res.urls[j],
										sort:0
									})
								}
								console.log("url>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>", _this.data.listActivityImage);
								// let a = _this.data.listActivityImage.concat(res.urls)
								// _this.data.listCoverImageUrl = a
							})
						break;
					case "赞助商":
						uni.navigateTo({
							url: "sponsorList"
						})
						break;
				}
			},
			onEditorIntroduction() {
				// #ifdef  APP-PLUS
				uni.createSelectorQuery().select('#editor1').context((res) => {
					this.editorCtx1 = res.context
					this.editorCtx1.setContents({
						html: this.data.introduction
					})
				}).exec()
				// #endif

				// #ifdef H5 || MP-WEIXIN
				this.createSelectorQuery().select('#editor1').context((res) => {
					this.editorCtx1 = res.context
					this.editorCtx1.setContents({
						html: this.data.introduction
					})
				}).exec()
				// #endif
			},
			onEditorDisclaimer() {

				// #ifdef  APP-PLUS
				uni.createSelectorQuery().select('#editor2').context((res) => {
					this.editorCtx2 = res.context
					this.editorCtx2.setContents({
						html: this.data.disclaimer
					})
				}).exec()
				// #endif

				// #ifdef H5 || MP-WEIXIN
				this.createSelectorQuery().select('#editor2').context((res) => {
					this.editorCtx2 = res.context
					this.editorCtx2.setContents({
						html: this.data.disclaimer
					})
				}).exec()
				// #endif
			},
			deleteImage(item) {
				let _this = this
				uni.showModal({
					title: '温馨提示',
					content: '确定要删除宣传图片吗？',
					success(res) {
						if (res.confirm) {
							// let listIsDelActivityImageSid = []
							// _this.$set(_this.data,"listIsDelActivityImageSid",listIsDelActivityImageSid)
							_this.parameter.listIsDelActivityImageSid.push(item.sid)
							console.log("==============================================",JSON.stringify(_this.parameter.listIsDelActivityImageSid))
							_this.data.listActivityImage.splice(_this.data.listActivityImage.indexOf(item), 1)
						}
					}
				});
			},
			showImage(index) {
				// 预览图片
				let imgsArray = [];
				for (var j = 0; j < this.data.listActivityImage.length; j++) {
					let url = this.data.listActivityImage[j].imageUrl
					imgsArray[j] = url
				}
				uni.previewImage({
					current: index,
					urls: imgsArray
				});
			},
			filterTap() {
				this.$refs.ddmtype.show()
				this.typeShow = true;
			},
			typeItemClick(e) {
				this.type = e.text
				this.data.activityBasedata.cancelEnrollRefund = e.value
				this.typeClose()
			},
			typeClose() {
				this.typeShow = false;
			},
			enrollStartTimeChange(e) {
				this.data.enrollStartTime = e.f1 + " " + e.hh + ":" + e.mm
				console.log(e)
			},
			enrollEndTimeChange(e) {
				this.data.enrollEndTime = e.f1 + " " + e.hh + ":" + e.mm
			},
			switchChangeInviteType: function(e) {
				this.switchCheckedInviteType = !this.switchCheckedInviteType;
				this.data.inviteType = this.switchCheckedInviteType == true ? 0 : 1;
			},
			nameText(e, index) {
				this.data.listActivityItem[index].name = e.detail.value
			},
			explainText(e, index) {
				this.data.listActivityItem[index].introduction = e.detail.value
			},
			radioChange(e, index) {
				console.log(e);
				console.log(this.data)
				let radio = this.data.listActivityItem[index].enrollMold == 0
				radio = !radio
				this.data.listActivityItem[index].enrollMold = radio ? 0 : 1
			},
			getData(info) {
				console.log("info>" + JSON.stringify(info))
				let num = data.enrollNumbersLimit == 0 ? "不限制人数" : data.enrollNumbersLimit + "人"
				let price = data.enrollMoney == 0 ? "免费" : data.enrollMoney + "元"
				return num + " / " + price
			},
			dateChange1(e, index) {
				this.data.listActivityItem[index].startTime = e.f1 + " " + e.hh + ":" + e.mm
			},
			dateChange2(e, index) {
				this.data.listActivityItem[index].endTime = e.detail.value
			},
			deleteItem(item) {
				let _this = this
				uni.showModal({
					title: '温馨提示',
					content: '确定要删除这条活动项目吗？',
					success(res) {
						if (res.confirm) {
							_this.parameter.listIsDelActivityItemSid.push(item.sid)
							_this.data.listActivityItem.splice(_this.data.listActivityItem.indexOf(item),
								1);
						}
					}
				});
			},

			address(e, index) {
				console.log(e)
				this.data.listActivityItem[index].address = e
			},
			addData() {
				this.data.listActivityItem.push({
					name: "活动项目" + (this.data.listActivityItem.length + 1),
					introduction:"",
					enrollMold:0,
					enrollNumbersLimit:0,
					enrollMoney:0,
					startTime:this.TimeFormat(this.CurrentMillions(), "yyyy-MM-dd HH:mm"),
					endTime: this.TimeFormat(this.CurrentMillions(), "yyyy-MM-dd"),
					address:"",
					activityItemCondition:{
						sid: "",
						sex: 0,
						minAge: 0,
						maxAge: 0
					}
				})
			},
			notesText(e) {
				this.data.notes = e.detail.value
			},
			cocosponsorrText(e) {
				this.data.cosponsor = e
			},
			organizerText(e) {
				this.data.organizer = e
			},
			deleteSponsor(item) {
				let _this = this
				console.log("====>" + _this.data.listSponsorSid.length);

				uni.showModal({
					title: '温馨提示',
					content: '确定要删除此赞助商吗？',
					success(res) {
						if (res.confirm) {
							_this.parameter.listIsSponsorSid.push(item.sid)
							_this.data.listSponsorSid.splice(_this.data
								.listSponsorSid.indexOf(item),
								1);
						}
					}
				});
			},
			organizerText(e) {
				this.data.organizer = e.detail.value
			},
			cocosponsorrText(e) {
				this.data.cosponsor = e.detail.value
			},
			verifyData(index){
				if (index == 1 || index == 0){
					if (this.IsEmpty(this.data.name)) {
						this.Toast("赛事名称不能为空");
						return false;
					}
					if (this.IsEmpty(this.data.introduction)) {
						this.Toast("活动介绍不能为空");
						return false;
					}
					if (this.data.listActivityImage.length == 0) {
						this.Toast("宣传图片不能为空")
						return false
					}
					if (this.IsEmpty(this.data.linkerName)  || this.IsEmpty(this.data.linkerPhone)) {
					// if (this.IsEmpty(this.data.linkerName) || this.IsEmpty(this.data.linkerPhone)) {
						this.Toast("联系方式不能为空");
						return false;
					}
					if (this.IsEmpty(this.data.disclaimer)) {
						this.Toast("免责声明不能为空");
						return false;
					}
					if (this.IsEmpty(this.data.adCode) || this.data.adCode == null){
						this.Toast("城市项必填");
						return false;
					}
				}
				if (index == 2 || index == 0){
					let listActivityItem = this.data.listActivityItem;
					if (listActivityItem.length == 0) {
						this.Toast("请添加活动项目")
						return false
					}
					// 设置比赛项目
					for (var i = 0; i < listActivityItem.length; i++) {
						if (this.IsEmpty(listActivityItem[i].name)) {
							this.Toast("请输入活动项目名称")
							return false
						}
						if (this.IsEmpty(listActivityItem[i].introduction)) {
							this.Toast("请输入活动项目说明")
							return false
						}
						if (this.IsEmpty(listActivityItem[i].address)) {
							this.Toast("请选择活动地点")
							return false
						}
					}
				}
				return true
			},
			publish() {
				// 数据校验
				if (!this.verifyData(0)){
					return
				}
				// 判断是否登陆
				let _this = this
				if (!_this.isLogin){
					this.WxAuthLogin()
				}
				// 保存活动
				_this.data.sysUserSid = getApp().globalData.sysUserSid
				// 更新时所用
				_this.$set(_this.data,"listIsDelActivityImageSid",_this.parameter.listIsDelActivityImageSid)
				_this.$set(_this.data,"listIsDelActivityItemSid",_this.parameter.listIsDelActivityItemSid)
				_this.$set(_this.data,"listIsSponsorSid",_this.parameter.listIsSponsorSid)
				
				_this.HTTP({
					url: 'aos/v1/activity/saveActivity',
					method: 'POST',
					data: _this.data,
					paramsType: "JSON",
					loading: true
				})
				.then((res) => {
					
					if (res.code == "200"){
						_this.ClearGameCache(_this.data)
						this.Toast("活动创建成功")
						wx.navigateBack({
							delta: 1
						})
					}else
					{
						this.Toast(res.msg)
					}
				});	
			}
		}
	};
</script>

<style lang="scss">
	@import url("../../static/columns.css");
	.topLayout {
		background: #F7F7F7;
		display: flex;
		padding: 30rpx 30rpx;
		flex-direction: row;
		align-items: center;
		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;
				justify-content: center;
				text-align: center;
				align-items: center;
			}

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

			.topLayout_item_right1 {
				font-size: 28rpx;
				color: #262626;
				justify-content: center;
				text-align: center;
				align-items: center;
				margin-left: 10rpx;
			}

			.topLayout_item_right2 {
				font-size: 28rpx;
				font-family: Adobe Heiti Std;
				font-weight: normal;
				justify-content: center;
				text-align: center;
				align-items: center;
				color: #262626;
				margin-left: 10rpx;
			}
		}
	}

	.layout {
		background: #FFFFFF 100%;
		display: flex;
		flex-direction: row;
		padding: 30rpx 15rpx;
		align-items: center;

		.layout_lift {
			display: flex;
			font-size: 30rpx;
			color: #101010;
		}

		.layout_right {
			display: flex;
			right: 32rpx;
			align-items: center;

			.tui-fr {
				zoom: .7
			}

		}
	}

	.fui-filter__item {
		height: auto;
		width: 300rpx;
		display: flex;
		flex-direction: row-reverse;
		align-items: center;
		font-size: 30rpx;
		/* #ifdef H5 */
		cursor: pointer;
		/* #endif */
	}

	.fui-filter__icon {
		transition: all .15s linear;
	}

	.fui-icon__ani {
		transform: rotate(180deg);
	}

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

	.tabLayout {
		background: #FFFFFF 100%;
		display: flex;
		flex-direction: row;
		padding-bottom: 20rpx;
	}

	.layout {
		background: #FFFFFF 100%;
		display: flex;
		flex-direction: row;
		padding: 30rpx 15rpx;
		align-items: center;

		.layout_lift {
			font-size: 30rpx;
			color: #101010;
		}

		.layout_right {
			display: flex;
			right: 32rpx;
			align-items: center;
		}
	}

	.items {
		display: flex;
		flex-direction: column;

		.layout1 {
			padding: 32rpx;
			display: flex;
			flex-direction: row;
			align-items: center;
			background: #FFFFFF;

			.number {
				width: 40rpx;
				height: 40rpx;
				background-color: #007AFF;
				border-radius: 50%;
				color: #FFFFFF;
				font-size: 32rpx;
				text-align: center;
				align-items: center;
				justify-content: center;
			}

			.name {
				margin-left: 20rpx;
				width: 80%;
			}
		}

		.layout2 {
			margin-top: 10rpx;
			background: #FFFFFF;
			display: flex;
			padding: 36rpx;
			height: auto;

			.explain {
				width: 100%;

			}
		}

		.layout3 {
			background: #FFFFFF;
			display: flex;
			margin-top: 10rpx;
			flex-direction: row;
			padding: 32rpx;

			.layout_lift {
				font-size: 28rpx;
				color: #101010;
			}

			.layout_mobile {
				display: flex;
				flex: 1;
				margin-left: 20rpx;
				font-size: 28rpx;
				color: #8F8F94;
			}

			.input {
				flex: 1;
				width: auto;
				margin-left: 20rpx;
			}

			.layout_right {
				display: flex;
				right: 32rpx;
				align-items: center;


				.layout_right_text {
					margin-right: 10rpx;
					font-size: 28rpx;
					color: #080808;
				}
			}
		}
	}

	.addData {
		display: flex;
		flex-direction: row;
		background: #FFFFFF;
		padding: 32rpx;
		align-items: center;
	}

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