<template>
	<RefreshView ref="mescrollRef" :hasBack="true" text="新增赞助商" :useDownScroll="false" :useUpScroll="false"
		@backClick="backClick" useTitleRightBtn="1" titleRightBtnSource="保存" @rightBtn='rightBtnClick'>

		<PublishItem leftText="赞助商名称" :isShowRight="false"></PublishItem>
		<EditText hint="请输入赞助商名称" @onTextChange="text" :text="info.name"></EditText>
		<view class=" line"></view>

		<PublishItem leftText="单位地址" :isShowRight="false"></PublishItem>
		<EditText hint="请输入单位地址" @onTextChange="address" :text="info.address"></EditText>
		<view class=" line"></view>

		<PublishItem leftText="网址" :isShowRight="false"></PublishItem>
		<EditText hint="请输入网址" @onTextChange="webUrl" :text="info.webUrl"></EditText>
		<view class=" line"></view>

		<PublishItem leftText="联系方式" :middleText="name_mobile" rightText="编辑" :isShowRight="true"
			@rightClick="clickItem('联系方式')"></PublishItem>
		<view class="line"></view>

		<PublishItem leftText="宣传海报" rightText="上传" :isShowRight="true" @rightClick="clickItem('宣传海报')"></PublishItem>
		<!-- <scroll-view style="width: 100%;white-space: nowrap;" scroll-x="true">
			<view v-for="(item,index) in info.logo" :key="index" style="display: inline-block;">
				<view style="margin-left: 20rpx;margin-right: 20rpx;display: flex;">
					<image :src="item" style="width: 220rpx;height: 150rpx;z-index: 1;" mode="aspectFill"
						@click="showImage(item)">
					</image>
					<image src="../../static/event-icon/delete1.png"
						style="margin-left: -60rpx;margin-top: 10rpx;width: 50rpx;height: 50rpx;z-index: 2;"
						@click="deleteItem(item)">
					</image>
				</view>

			</view>
		</scroll-view> -->

		<view v-if="info.logo!=''&&info.logo!=undefined" style="margin-left: 20rpx;margin-right: 20rpx;display: flex;margin-bottom: 20rpx;">
			<image :src="info.logo" style="width: 220rpx;height: 150rpx;z-index: 1;" mode="aspectFill">
			</image>
			<image src="../../static/event-icon/delete1.png"
				style="margin-left: -60rpx;margin-top: 10rpx;width: 50rpx;height: 50rpx;z-index: 2;"
				@click="deleteItem()">
			</image>
		</view>
		<view class="line"></view>

		<PublishItem leftText="单位简介" rightText="编辑" :isShowRight="true" @rightClick="clickItem('单位简介')">
		</PublishItem>
		<view style="display: flex;margin-left: 30rpx; margin-right: 30rpx;">
			<editor id="editor" style="white-space: pre-wrap;" placeholder="点击进行编辑..." showImgSize showImgToolbar
				showImgResize :read-only="true" @click="clickItem('单位简介')" @ready="onEditorReady">
			</editor>
		</view>

	</RefreshView>
</template>

<script>
	export default {
		data() {
			return {
				name_mobile: "",
				info: {
					name: "",
					address: "",
					introduction: "",
					linkerName: "",
					linkerPhone: "",
					logo: "",
					webUrl: "",
					userSid: ""
				}
			}
		},
		onShow() {
			let backResult = this.OnActivityResult();
			if (backResult != undefined) {
				console.log("结果>" + JSON.stringify(backResult))
				if (!this.IsEmpty(backResult.linkerName)) {
					console.log("电话>" + JSON.stringify(this.info))
					this.name_mobile = backResult.linkerName + "\u3000" + backResult.linkerPhone
					this.info.linkerName = backResult.linkerName
					this.info.linkerPhone = backResult.linkerPhone
					console.log("电话>" + JSON.stringify(this.info))
				}
				if (!this.IsEmpty(backResult.introduction)) {
					this.info.introduction = backResult.introduction
					this.onEditorReady()
				}
			}

		},
		methods: {
			rightBtnClick() {
				console.log("info>" + JSON.stringify(this.info))
				let _this = this
				this.Login()
					.then((res) => {

						_this.info.userSid = res

						_this.HTTP({
							url: 'aos/v1/sponsorManagement/saveSponsor',
							method: 'POST',
							data: _this.info,
							paramsType: "JSON",
							loading: true
						}).then((res) => {
							this.SetResult("")
							console.log('=======', res)
						});

					})


			},
			text(e) {
				this.info.name = e
			},
			address(e) {
				this.info.address = e
			},
			webUrl(e) {
				this.info.webUrl = e
			},
			onEditorReady() {

				// #ifdef  APP-PLUS
				uni.createSelectorQuery().select('#editor').context((res) => {
					this.editorCtx1 = res.context
					this.editorCtx1.setContents({
						html: this.info.introduction
					})
				}).exec()
				// #endif

				// #ifdef H5 || MP-WEIXIN
				this.createSelectorQuery().select('#editor').context((res) => {
					this.editorCtx1 = res.context
					this.editorCtx1.setContents({
						html: this.info.introduction
					})
				}).exec()
				// #endif
			},
			clickItem(e) {
				let _this = this
				switch (e) {
					case "宣传海报":
						this.chooseUpload(9)
							.then((res) => {
								console.log("url>>>>", res);
								// _this.info.logo.push(res.data)
								// let a = _this.info.logo.concat(res.urls)
								// _this.info.logo = a
								_this.info.logo = res.urls[0]
								console.log("list", _this.info.logo)

							})
						break;
					case "联系方式":
						uni.navigateTo({
							url: "mobileInfoActivity?linkerName=" + _this.info.linkerName +
								"&linkerPhone=" + _this.info.linkerPhone
						})
						break;
					case "单位简介":
						uni.navigateTo({
							url: "explainActivity?introduction=" + _this.info.introduction
						})
						break;
				}
			},

			deleteItem(item) {
				let _this = this
				uni.showModal({
					title: '温馨提示',
					content: '确定要删除宣传图片吗？',
					success(res) {
						if (res.confirm) {
							_this.info.logo.splice(_this.info.logo.indexOf(item), 1)
						}
					}
				});

			},
		}

	};
</script>

<style lang="scss">
	.line {
		width: 100%;
		height: 5rpx;
		background-color: #f5f4f9;
	}
</style>
