<template>
	<view>
		<RefreshView ref="mescrollRef" :hasBack="true" text="编辑内容" :useDownScroll="false" :useUpScroll="false"
			useTitleRightBtn="1" titleRightBtnSource="确定" @rightBtn='rightBtnClick'>

			<RichTextEditor ref="rich" placeholder="请输入...." :html="htmlStr" :removeHeight="topBarHeight"
				@insertPic="insert">
			</RichTextEditor>

		</RefreshView>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				topBarHeight: '0px',
				htmlStr: "",
				data: {
					introduction: "",
				}
			};
		},
		onLoad: function(option) {
			// this.activityBaseInfo.introduction = option.introduction;
			console.log("options>>>", option)
			// let t = JSON.parse(decodeURIComponent(option.introduction));
			// this.htmlStr = t.html
			let t = option.introduction == "undefined" ?"":option.introduction;
			this.htmlStr = t

		},
		created() {
			this.topBarHeight = getApp().globalData.totalHeightPx
		},
		mounted() {

		},
		methods: {
			insert(e) {
				this.chooseUpload(9)
					.then((res) => {
						console.log("url>>>>", res);
						this.$refs.rich.insertUrlImage(res.urls)
					})
			},
			getHtml() {
				return this.$refs.rich.getHtml();
			},
			rightBtnClick() {
				console.log(this.getHtml())
				let reg1 = new RegExp('<p>', 'g') //g代表全部
				let reg2 = new RegExp('</p>', 'g') //g代表全部
				let reg3 = new RegExp('<br>', 'g') //g代表全部
				let reg4 = new RegExp('"', 'g') //g代表全部
				let newMsg = JSON.stringify(this.getHtml()).replace(reg1, '').replace(reg2, '\n').replace(reg3, '')
					.replace(reg4, '');
				// let articleData = this.getHtml().replace('</p>*$<p>', /\n/g)

				console.log(newMsg)
				this.data.introduction = newMsg
				// this.data.activityBaseInfo.introduction = this.getHtml()
				this.SetResult(this.data)
			},
		}

	};
</script>

<style>

</style>
