<template>
	<view class="post" :class="AppStyle" style="background-color: #f6f6f6;">
		<view class="header" :style="[{height:CustomBar + 'px'}]" v-if="showContent">
			<view class="cu-bar bg-white" :style="{'height': CustomBar + 'px','padding-top':StatusBar + 'px'}">
				<view class="action" @tap="isback">
					<text class="cuIcon-back"></text>
				</view>
				<view class="content text-bold" :style="[{top:StatusBar + 'px'}]">
					<block v-if="type=='edit'">
						修改文章
					</block>
					<block v-else>
						发布文章
					</block>
				</view>
				<!--  #ifdef H5 || APP-PLUS -->
				<view class="action" @click="toDraft()" style="display: flex;color: #333;">
					<!-- <text class="cuIcon-upload"></text> -->
					<block v-if="type=='add'">
						<text style="margin-right: 5px;">草稿箱</text>
						<span class="tn-icon-edit-form" style="font-size: 40upx;"></span></span>
					</block>
				</view>
				<!--  #endif -->
			</view>
		</view>
		<view :style="[{padding:(NavBar+10) + 'px 10px 0px 10px'}]"></view>
		<form>
			<view class="cu-form-group margin-sm bg-white" style="border-radius: 20upx;">
				<input placeholder="输入文章标题" name="input" v-model="title" @focus="ToisText(0)" @blur="ToisText(0)"
					:adjust-position="false" :focus="false"></input>
				<view class="picker" @tap="toCategory">
					<block v-if="categoryText==''">
						选择分类
					</block>
					<block v-else>
						<text class="text-shojo">{{categoryText}}</text>
					</block>
				</view>
			</view>
			<view class="bg-white margin-sm" style="border-radius: 20upx;">
				<view class="margin-sm">
					<cu-editor ref="editor" :mrPoster="videoPoster" :SPimg="SPimg" :musicpic='musicpic'
						editorId='editor' :NavBar="NavBar" @editorFocus="handleEditorFocus"
						@editorBlur="handleEditorBlur" :url="this.$API.upload()" :formData="formData" :content="text"
						:MusicUpload='MusicUpload' :uploadTime="uploadTime" :isPay="false" :isWz="true"
						@custom-event="setShop" @save="onSave"></cu-editor>
				</view>
			</view>
			<view :style="showContent?'':'display:none'" class="bg-white margin-sm"
				style="border-radius: 20upx; padding: 14px;">
				<view class="flex flex-row justify-between items-center" style="align-items: center;"
					@click="tagsShow=true">
					<text>选择标签</text>
					<text>
						<block v-if="curTag.length==0">
							选择
						</block>
						<block v-else>
							已选择
						</block>
					</text>
				</view>
				<view class="margin-top-sm modal-concent" v-if="curTag.length!=0">
					<view class="tag-list">
						<view class="tag-box-2" v-for="(item,index) in curTag">
							#{{item.name}}
						</view>
					</view>
				</view>
			</view>
			<view :style="showContent?'':'display:none'">
				<!--#ifdef APP-PLUS || H5 -->
				<view v-if="type=='add'" class="margin-sm" style="display: flex;justify-content: space-between;">
					<tn-button type="button" fontColor="#333" width="35%" class="form-btn"
						@click="submit(false)">保存草稿</tn-button>
					<tn-button type="button" backgroundColor="rgb(1, 190, 255)" fontColor="#fff" width="60%"
						class="form-btn" @click="submit(true)">发布文章</tn-button>
				</view>
				<!--#endif -->
				<!--#ifdef MP-WEIXIN -->
				<view v-if="type=='add'" class="margin-sm">
					<tn-button type="button" class="form-btn" fontColor="#333" width="100%"
						@click="submit(false)">保存草稿</tn-button>
					<view class="margin-top-sm">
						<tn-button type="button" backgroundColor="rgb(1, 190, 255)" fontColor="#fff" width="100%"
							class="form-btn margin-top-sm" @click="submit(true)">发布文章</tn-button>
					</view>
				</view>
				<!--#endif -->

				<view v-else class="margin-sm">
					<tn-button type="button" backgroundColor="rgb(1, 190, 255)" fontColor="#fff" width="100%"
						class="form-btn" @click="submit(true)">
						<block v-if="draft==0">
							修改文章
						</block>
						<block v-if="draft==1">
							发布文章
						</block>
					</tn-button>
				</view>
				<!--  #ifdef MP-WEIXIN -->
				<view class="margin-sm">
					<tn-button type="button" fontColor="#333" width="100%" class="form-btn" @click="toDraft()">
						<text style="margin-right: 5px;">草稿箱</text>
						<span class="tn-icon-edit-form" style="font-size: 30upx;"></span></span>
					</tn-button>
				</view>
				<!--  #endif -->


			</view>
		</form>
		<view class="setShop" v-if="isShop==1">
			<view class="setShop-box">
				<view class="setShop-main" style="box-shadow: 0px 4upx 40upx #d4d4d4;border-radius: 20upx;">
					<view class="setShop-title">
						选择商品插入文章
						<text class="setShop-close cuIcon-close" style="right: 0px;top: 0px;" @tap="isShop=0"></text>

					</view>

					<scroll-view class="setShop-list" scroll-y>
						<view class="setShop-list-box" v-for="(item,index) in shopList" @tap="toShop(item.id)"
							:class="item.id==shopID?'cur':''" :key="index">
							<view class="setShop-list-main">
								<text class="cuIcon-moneybagfill text-red"></text>{{item.title}}
							</view>
							<view class="setShop-status">
								<text v-if="item.cid!=-1">CID：{{item.cid}}</text>
								<text v-else class="text-green">未插入</text>
							</view>

						</view>

					</scroll-view>
				</view>
			</view>
		</view>
		<div class="modal hasSearch" :class="tagsShow?'show':''">
			<div class="modal-bg" @click="tagsShow=false">
			</div>
			<div class="modal-main">
				<div class="modal-title" style="color: #333;">
					选择标签
					<a href="javascript:;" @click="tagsShow=false">关闭</a>
				</div>
				<div class="modal-search">
					<input placeholder="输入关键词" type="text" v-model="tagsText" @input="searchTags()" />
					<button type="button"><i class="tn-icon-search"></i></button>
				</div>
				<div class="modal-concent">
					<div class="tag-list">
						<div class="tag-box" v-for="(item,index) in tagList" :class="item.active==1?'action':''"
							@click="toTagContents(item.name,item.mid,index)">
							#{{item.name}}
						</div>
					</div>
				</div>
			</div>
		</div>
	</view>
</template>

<script>
	import cuEditor from '@/components/cu-editor/cu-editor'
	import mpHtml from '@/components/mp-html/mp-html'
	import {
		localStorage
	} from '../../js_sdk/mp-storage/mp-storage/index.js'
	// #ifdef APP-PLUS
	import owo from '../../static/app-plus/owo/OwO.js'
	// #endif
	// #ifdef H5
	import owo from '../../static/h5/owo/OwO.js'
	// #endif
	// #ifdef MP
	var owo = [];
	// #endif
	export default {
		components: {
			cuEditor
		},
		data() {
			return {
				modelVisible: true,
				StatusBar: this.StatusBar,
				CustomBar: this.CustomBar,
				NavBar: this.StatusBar + this.CustomBar,
				AppStyle: this.$store.state.AppStyle,
				tempFiles: '',
				pageScrollTop: 0,
				modalName: "",
				contentEdit: '',
				token: "",
				isShow: false,
				curHeight: 0,
				jpHeight: 0,
				tagsShow: false,
				screenHeight: 0,
				postheight: 0,
				poststyle: "",
				readstyle: "",
				draft: 0,

				uploadTime: this.$API.getuploadTime(),
				isText: 0,
				//文章表单部分
				title: "",
				category: "",
				tag: "",
				categoryText: "",
				text: '',
				content: "",
				name: "",
				textRead: "",
				link: {
					title: "",
					url: "",
				},
				MusicUpload: this.$API.SPstarMusicUpload(),
				musicpic: this.$API.SPmusicpic(),
				videoPoster: this.$API.getVideoPoster(),
				SPimg: this.$API.SPimgs(),

				shopList: [],
				isShop: 0,
				shopID: -1,
				//页面状态
				type: "add",
				cid: 0,
				showContent: true,
				isOwO: false,
				owo: owo,
				owoList: [],
				OwOtype: "paopao",
				tagList: [],
				curNum: 0,
				curTagNum: 0,
				curTag: [],
				postlinktype: 0,
				tagsText: "",
				start: -1,
				tagYes: false,
				isLoading: false,
				toImg: false,
				isSpace: false,
				formData: {},

			}
		},
		onPullDownRefresh() {
			var that = this;

		},
		onShow() {
			var that = this;
			// #ifdef APP-PLUS

			plus.navigator.setStatusBarStyle("dark")
			// #endif

			if (localStorage.getItem('userinfo')) {
				var userInfo = JSON.parse(localStorage.getItem('userinfo'));
				that.token = userInfo.token;
				if (userInfo.screenName) {
					that.name = userInfo.screenName;
				} else {
					that.name = userInfo.name;
				}
				that.formData = {
					'token': userInfo.token,
					'username': that.name
				}
			}
			if (localStorage.getItem('clist')) {
				that.categoryText = "已选择";
				that.category = localStorage.getItem('clist');
			}
			if (localStorage.getItem('ctag')) {
				that.tag = localStorage.getItem('ctag');
			}
			if (localStorage.getItem('serImage')) {
				that.modalName = null;
				var serImage = localStorage.getItem('serImage');
				var h = "";
				if (that.text != "") {
					h = "\n";
				}
				var text = h + "![图片名称](" + serImage + ")";
				//that.text+=text;
				that.insetText(text);
				localStorage.removeItem('serImage');
			}
			that.getTaglist();
			// #ifdef APP-PLUS || H5
			that.owoList = that.owo.data.paopao.container;
			// #endif
		},
		onHide() {
			var that = this;
			//localStorage.removeItem('clist')
		},
		onPageScroll(e) {
			console.log(e)
			this.pageScrollTop = e.scrollTop
		},
		onLoad(res) {

			const modelViewTime = uni.getStorageSync('modelView');
			localStorage.setItem('isSaveWz', "false");
			if (modelViewTime) {
				console.log(modelViewTime);
				const nowDate = +new Date();
				const isVisible = nowDate - modelViewTime > 1000 * 60 * 60 * 24;
				if (!isVisible) {
					this.modelVisible = false;
				}
			}


			var that = this;
			// #ifdef APP-PLUS || MP
			that.NavBar = this.CustomBar;
			// #endif
			if (res.type) {
				that.type = res.type;
				if (res.cid) {
					that.cid = res.cid;
					that.setloading();
					var timer = setTimeout(function() {
						that.getInfo(that.cid);
					}, 500)

				}
			}
			if (res.draft) {
				that.draft = res.draft;
			}
			if (res.isSpace) {
				if (res.isSpace == 1) {
					that.isSpace = true;
				}
			}
			that.getShopList();

			//键盘弹出相关
			let screenHeight = uni.getSystemInfoSync().screenHeight;
			let statusHeight = uni.getSystemInfoSync().statusBarHeight;
			let inputHeight = screenHeight - statusHeight - 290;
			// #ifdef APP-PLUS
			inputHeight = screenHeight - statusHeight - 300;
			// #endif
			// #ifdef H5
			inputHeight = 400;
			// #endif

			that.screenHeight = screenHeight - that.NavBar;
			that.postheight = inputHeight;
			//
			//that.poststyle = "height:200upx";
			that.poststyle = "height:" + inputHeight + "px";
			that.readstyle = "height:" + (inputHeight + 30) + "px;white-space: pre-wrap;";
			// #ifdef H5
			//that.h5Keyboard();
			// #endif
			// #ifdef APP-PLUS
			uni.onKeyboardHeightChange(res => {
				//监听软键盘的高度 
				//当点击软键盘自带的收起按钮的时候也就是会隐藏软键盘 这时候监听到的软键盘的高度就是0 、
				//让输入框取消焦点 这时候再去输入内容的时候 输入框就会弹起
				if (res.height == 0) {

					that.focalize(res.height);
					that.poststyle = "height:" + inputHeight + "px";

				} else {
					that.curHeight = res.height;
					var keyHeight = inputHeight - res.height;
					that.focus(res.height);
					that.poststyle = "height:" + keyHeight + "px";
				}
			});
			// #endif
			localStorage.removeItem('clist')
		},
		methods: {

			okBtn() {
				const nowDate = +new Date();
				uni.setStorageSync('modelView', nowDate);
				this.cancleBtn();
			},
			handleEditorFocus() {
				this.showContent = false;
				this.NavBar = this.StatusBar;
			},
			handleEditorBlur() {
				this.showContent = true;
				this.NavBar = this.CustomBar;
			},
			cancleBtn() {
				this.modelVisible = false;
			},
			onSave(e) {
				var that = this
				that.content = e.html;
				console.log(e.html);
			},
			toSpace(e) {
				this.isSpace = e.detail.value
			},
			setloading() {
				var that = this;
				if (!that.isLoading) {
					uni.showLoading({
						title: '获取数据中',
					});
				} else {
					uni.hideLoading();
				}

			},
			markHtml(text) {
				var that = this;
				text = that.replaceAll(text, "@!!!", "@@@@");
				text = that.replaceAll(text, "!!!", "");
				text = that.replaceAll(text, "@@@@", "@!!!");
				var owoList = that.owoList;
				for (var i in owoList) {
					if (text.indexOf(owoList[i].data) != -1) {
						text = that.replaceAll(that.replaceSpecialChar(text), owoList[i].data, "<img src='" + owoList[i]
							.icon + "' class='tImg' />")

					}
				}
				console.log(JSON.stringify(text));
				//text = text.replace(/(?<!\r)\n(?!\r)/g, "\n\n");
				//兼容垃圾的Safari浏览器
				text = text.replace(/([^\r])\n([^\r])/g, "$1\n\n$2");
				text = that.replaceAll(text, "||rn||", "\n\n");
				return text;
			},
			replaceSpecialChar(text) {
				if (!text) {
					return false;
				}
				text = text.replace(/&quot;/g, '"');
				text = text.replace(/&amp;/g, '&');
				text = text.replace(/&lt;/g, '<');
				text = text.replace(/&gt;/g, '>');
				text = text.replace(/&nbsp;/g, ' ');
				return text;
			},
			replaceAll(string, search, replace) {
				return string.split(search).join(replace);
			},
			ToisText(i) {
				var that = this;
				that.isText = i;
				if (that.curHeight != 0 && that.isText == 1) {
					that.focus(that.curHeight);
				}
				uni.getSelectedTextRange({
					success: res => {
						//console.log('getSelectedTextRange res', res.start, res.end);
						that.start = res.start;
					}
				})
			},
			insetText(newStr) {
				var that = this;
				var start = that.start;
				var text = that.text;
				if (start == -1) {
					text += newStr;
				} else {
					text = text.slice(0, start) + newStr + text.slice(start);
				}
				that.text = text;
				that.textRead = that.text;
			},
			focus(h) {
				var that = this;
				if (that.isText == 0) {
					return false;
				}
				// #ifdef APP-PLUS
				// let screenHeight = uni.getSystemInfoSync().screenHeight;
				// let statusHeight= uni.getSystemInfoSync().statusBarHeight;
				// let inputHeight = screenHeight - statusHeight - 240;
				// that.screenHeight = screenHeight - statusHeight - 5;
				// let height = h;
				// let postheight = that.postheight - height;

				// that.jpHeight =height - statusHeight;


				// that.postheight = postheight;
				// that.poststyle = "height:"+postheight+"px";
				// that.readstyle = "height:"+(inputHeight+30)+"px";
				// #endif
			},
			focalize(h) {
				var that = this;
				// #ifdef APP-PLUS
				// let screenHeight = uni.getSystemInfoSync().screenHeight;
				// let statusHeight= uni.getSystemInfoSync().statusBarHeight;
				// that.screenHeight = screenHeight - that.NavBar;
				// let inputHeight = screenHeight - statusHeight - 250;
				// that.jpHeight =0;
				// that.postheight = inputHeight;
				// that.poststyle = "height:"+inputHeight+"px";
				// #endif
			},
			back() {
				localStorage.removeItem('clist');
				localStorage.removeItem('isSaveWz')
				uni.navigateBack({
					delta: 1
				});
			},
			PickerChange(e) {
				this.index = e.detail.value
			},
			showModal(e) {
				this.modalName = e.currentTarget.dataset.target
			},
			hideModal() {
				this.modalName = null
			},
			textareaAInput() {
				var that = this;
				uni.getSelectedTextRange({
					success: res => {
						//console.log('getSelectedTextRange res', res.start, res.end);
						that.start = res.start;
					}
				})
				that.textRead = that.text;

			},
			//编辑器工具开始
			toBold() {
				var that = this;
				var h = "";
				var text = h + "**加粗文字**";
				//that.text+=text;
				that.insetText(text);

			},
			toHideText() {
				var that = this;
				var h = "";
				var text = h + "[hide]这是回复可见的内容[/hide]";
				//that.text+=text;
				that.insetText(text);
			},
			toItalic() {
				var that = this;
				var h = "";
				var text = h + "*斜体文字* ";
				//that.text+=text;
				that.insetText(text);

			},
			toTitle(num) {
				var that = this;
				var text = "";
				for (var i = 0; i < num; i++) {
					text = text + "#";
				}
				var h = "";
				if (that.text != "") {
					h = "\n";
				}
				var title = h + text + " 标题文字";
				//that.text+=title;
				that.insetText(title);

				that.hideModal();
			},
			toDraft() {
				uni.navigateTo({
					url: '/pages/user/draftList'
				});

			},
			getTaglist() {
				var that = this;
				var params = {
					"type": "tag"
				}
				var data = {
					"searchParams": JSON.stringify(params),
					"limit": 100,
					"page": 1,
					"order": "order",
					"searchKey": that.tagsText,
				}
				that.$Net.request({
					url: that.$API.getMetasList(),
					header: {
						'Content-Type': 'application/x-www-form-urlencoded'
					},
					data: data,
					method: "get",
					dataType: 'json',
					success: function(res) {
						if (res.data.code == 1) {
							var tagList = res.data.data;
							for (var i in tagList) {
								tagList[i].active = 0;
							}
							that.tagList = tagList;
							that.tagYes = true;
						}
					},
					fail: function(res) {
						console.log(res);
					},
				})
			},
			searchTags() {
				var that = this;
				var tagList = that.tagList;
				for (var i in tagList) {
					tagList[i].active = 0;
				}
				that.tagList = tagList;
				that.getTaglist();
			},
			toIsShow(isTo) {
				var that = this;
				var group = "";
				if (localStorage.getItem('userinfo')) {

					var userInfo = JSON.parse(localStorage.getItem('userinfo'));
					var group = userInfo.group;
				}
				if (!isTo && !that.isShow) {
					if (group == 'administrator' || group == 'editor') {
						if (that.text.indexOf("<script>") != -1 || that.text.indexOf("<form>") != -1 || that.text.indexOf(
								"<iframe>") != -1 || that.text.indexOf("<frame>") != -1) {

							that.modalName = "xss"
							return false;
						}
					}
				}
				that.modalName = null;
				that.textRead = that.text;
				that.isShow = !that.isShow;



			},
			submit(isPost) {
				var that = this;
				var type = that.type;
				if (isPost) {
					if (type == "add") {
						that.$refs.editor.save()
						setTimeout(function() {
							that.contentsAdd(false);
						}, 200)
					} else {
						that.$refs.editor.save();
						setTimeout(function() {
							that.contentsUpdate();
						}, 200)

					}
				} else {
					if (type == "add") {
						that.$refs.editor.save()
						setTimeout(function() {
							that.contentsAdd(true);
						}, 200)
					}
				}

				// if(that.shopID!=-1){
				// 	that.mountShop();
				// }

			},
			toTagContents(title, id, index) {
				var that = this;

				if (that.tagList[index].active == 1) {
					that.curNum--;
					that.tagList[index].active = 0;
				} else {
					if (that.curNum > 4) {
						uni.showToast({
							title: '最多选择五个标签',
							icon: 'none',
							duration: 2000
						});
						return false;
					}
					that.curNum++;
					that.tagList[index].active = 1;
				}
				var curTag = [];
				var tagList = that.tagList;
				for (var i in tagList) {
					if (tagList[i].active == 1) {
						curTag.push(tagList[i]);
					}
				}
				that.curTag = curTag;

			},
			isback() {
				var that = this;

				var isSave = localStorage.getItem('isSaveWz');
				if (isSave == 'true') {
					that.back()
				} else {
					uni.showModal({
						title: '提示',
						content: '编辑的内容还没保存，确定要退出吗？',
						cancelText: '退出',
						confirmText: '留下',
						success: function(res) {
							if (res.confirm) {

							} else if (res.cancel) {
								that.back()
							}
						}
					});
				}
			},
			contentsAdd(Draft) {
				var that = this;
				if (that.title == "") {
					uni.showToast({
						title: "标题不可为空",
						icon: 'none',
						duration: 1000,
						position: 'bottom',
					});
					return false
				}
				if (that.content == '<p><br></p>' || that.content == '') {
					uni.showToast({
						title: "内容不可为空",
						icon: 'none',
						duration: 1000,
						position: 'bottom',
					});
					return false
				}
				if (that.category == "") {
					uni.showToast({
						title: "请选择分类",
						icon: 'none',
						duration: 1000,
						position: 'bottom',
					});
					return false
				}
				var isSpace = 0;
				var tag = "";
				if (that.curTag.length > 0) {
					var curTag = that.curTag;
					for (var i in curTag) {
						if (curTag[i].active == 1) {
							tag += "," + curTag[i].mid;
						}
					}
				}
				var isDraft = 0;
				if (Draft) {
					isDraft = 1
				}
				console.log(that.curTag);
				console.log(tag);
				var data = {
					'title': that.title,
					'category': that.category,
					'tag': tag,
					'sid': that.shopID
				}
				var text = that.content;
				text = text.replace(/\r\n/g, "||rn||");
				text = text.replace(/\n/g, "||rn||");
				uni.showLoading({
					title: "加载中"
				});
				that.$Net.request({

					url: that.$API.contentsAdd(),

					data: {
						"params": JSON.stringify(that.$API.removeObjectEmptyKey(data)),
						"token": that.token,
						'text': text,
						"isDraft": isDraft,
						"isSpace": 0,
						'isMd': 0
					},
					header: {
						'Content-Type': 'application/x-www-form-urlencoded'
					},
					method: "post",
					dataType: 'json',
					success: function(res) {
						setTimeout(function() {
							uni.hideLoading();
						}, 1000);
						if (res.data.code == 1) {
							if (!Draft) {
								uni.showToast({
									title: res.data.msg,
									mask: false,
									icon: 'icon-success',
									duration: 3000
								})
								var timer = setTimeout(function() {
									that.back();
								}, 1000)
							} else {
								localStorage.setItem('isSaveWz', "true");
								uni.showToast({
									title: '已保存到草稿箱',
									icon: 'none',
									duration: 2000
								})
							}

						} else {
							uni.showToast({
								title: res.data.msg,
								mask: false,
								icon: 'icon-error',
								duration: 3000
							})
						}
					},
					fail: function(res) {
						setTimeout(function() {
							uni.hideLoading();
						}, 1000);
						uni.showToast({
							title: "网络开小差了哦",
							icon: 'none'
						})
						uni.stopPullDownRefresh()
					}
				})
			},
			contentsUpdate() {
				var that = this;
				if (that.title == "") {
					uni.showToast({
						title: "标题不可为空",
						icon: 'none',
						duration: 1000,
						position: 'bottom',
					});
					return false
				}
				if (that.content == '<p><br></p>' || that.content == '') {
					uni.showToast({
						title: "内容不可为空",
						icon: 'none',
						duration: 1000,
						position: 'bottom',
					});
					return false
				}
				if (that.category == "") {
					uni.showToast({
						title: "请选择分类",
						icon: 'none',
						duration: 1000,
						position: 'bottom',
					});
					return false
				}
				var tag = "";
				if (that.curTag.length > 0) {
					var curTag = that.curTag;
					for (var i in curTag) {
						if (curTag[i].active == 1) {
							tag += "," + curTag[i].mid;
						}
					}
				}
				var data = {
					'cid': that.cid,
					'title': that.title,
					'category': that.category,
					'tag': tag,
					'sid': that.shopID
				}
				uni.showLoading({
					title: "加载中"
				});
				var text = that.content;
				text = text.replace(/\r\n/g, "||rn||");
				text = text.replace(/\n/g, "||rn||");
				that.$Net.request({

					url: that.$API.contentsUpdate(),
					data: {
						"params": JSON.stringify(that.$API.removeObjectEmptyKey(data)),
						"token": that.token,
						'text': text,
						'isMd': 0,
					},
					header: {
						'Content-Type': 'application/x-www-form-urlencoded'
					},
					method: "post",
					dataType: 'json',
					success: function(res) {
						setTimeout(function() {
							uni.hideLoading();
						}, 1000);
						uni.showToast({
							title: res.data.msg,
							icon: 'none'
						})
						if (res.data.code == 1) {
							localStorage.removeItem('clist');
							localStorage.removeItem('ctag');
							var timer = setTimeout(function() {
								that.back();
							}, 1000)

						}
					},
					fail: function(res) {
						setTimeout(function() {
							uni.hideLoading();
						}, 1000);
						uni.showToast({
							title: "QAQ信号君失踪了~",
							icon: 'none'
						})
						uni.stopPullDownRefresh()
					}
				})
			},
			getInfo(cid) {
				var that = this;
				if (!that.tagYes) {
					console.log('标签未加载');
					that.getInfo(cid)
					return false
				}
				var token = "";
				if (localStorage.getItem('userinfo')) {

					var userInfo = JSON.parse(localStorage.getItem('userinfo'));
					token = userInfo.token;

				}
				var data = {
					"key": that.cid,
					"token": token,

				}

				that.$Net.request({
					url: that.$API.getContentsInfo(),
					data: data,
					header: {
						'Content-Type': 'application/x-www-form-urlencoded'
					},
					method: "get",
					dataType: 'json',
					success: function(res) {
						if (res.data.title) {

							that.title = res.data.title;
							if (res.data.category.length > 0) {
								that.categoryText = "已选择";
								var list = res.data.category;
								var clist = "";
								for (var i in list) {

									clist += "," + list[i].mid;

								}
								localStorage.setItem('clist', clist);
								that.category = clist;

							}
							if (res.data.tag.length > 0) {
								var curTag = res.data.tag;
								for (var i in curTag) {
									var curMid = curTag[i].mid;
									for (var j in that.tagList) {
										if (that.tagList[j].mid === curMid) {
											that.tagList[j].active = 1;
											that.curNum++;
											break;
										}
									}
								}
								that.curTag = curTag

								console.log(curTag);
							}

							that.text = res.data.text;
							that.isLoading = true;
							that.setloading();
						}
					},
					fail: function(res) {}
				})
			},
			toMate(data) {
				var that = this;
				that.categoryText = data.name;
				that.category = data.mid,
					that.hideModal();
			},
			setShop() {
				var that = this;
				that.isShop = 1;
			},
			toShop(id) {
				var that = this;
				that.shopID = id;
				that.isShop = 0;
				uni.showToast({
					title: "已插入该商品",
					icon: 'none',
					duration: 1000,
					position: 'center',
				});
			},
			getShopList() {
				var that = this;
				var uid = 0;
				if (localStorage.getItem('userinfo')) {

					var userInfo = JSON.parse(localStorage.getItem('userinfo'));
					uid = userInfo.uid;

				} else {
					uni.showToast({
						title: "请先登录",
						icon: 'none',
						duration: 1000,
						position: 'bottom',
					});
					var timer = setTimeout(function() {
						uni.navigateTo({
							url: '/pages/user/login'
						});
						clearTimeout('timer')
					}, 1000)
					return false
				}
				var data = {
					"uid": uid,
					"status": 1,
					"type": 1,
				}
				that.$Net.request({
					url: that.$API.shopList(),
					data: {
						"searchParams": JSON.stringify(that.$API.removeObjectEmptyKey(data)),
						"limit": 1000,
						"page": 1,
					},
					header: {
						'Content-Type': 'application/x-www-form-urlencoded'
					},
					method: "get",
					dataType: 'json',
					success: function(res) {

						if (res.data.code == 1) {
							var list = res.data.data;
							that.shopList = list;


							if (that.cid != 0) {
								for (var i in list) {
									if (list[i].cid == that.cid) {

										that.shopID = list[i].id;
									}
								}
							}

						}
					},
					fail: function(res) {
						uni.showToast({
							title: "QAQ信号君失踪了~",
							icon: 'none'
						})

					}
				})
			},
			toOwO(text) {
				var that = this;
				that.OwOtype = text;
				if (text == "paopao") {
					that.owoList = that.owo.data.paopao.container;
				}
				if (text == "adai") {
					that.owoList = that.owo.data.adai.container;
				}
				if (text == "alu") {
					that.owoList = that.owo.data.alu.container;
				}
				if (text == "quyinniang") {
					that.owoList = that.owo.data.quyinniang.container;
				}

			},
			setOwO(data) {
				var that = this;
				var text = data.data;
				//that.text+=text;
				that.insetText(text);
				that.isOwO = false;
				that.textRead = that.markHtml(that.text);
			},
			OwO() {
				var that = this;
				that.isOwO = !that.isOwO;
			},
			toCategory() {
				var that = this;
				uni.navigateTo({
					url: '/pages/contents/allcategory?type=edit'
				});
			},
			addTag() {
				var that = this;
				uni.navigateTo({
					url: '/pages/contents/alltag?type=edit'
				});
			},
			toPostlinktype(i) {
				var that = this;
				that.postlinktype = i;
			},
			toAddShop() {
				var that = this;
				uni.navigateTo({
					url: '/pages/edit/addshop'
				});
			},
			goImgData() {
				var that = this;
				uni.navigateTo({
					url: '/pages/contents/imagetoday?type=post'
				});
			},

		}
	}
</script>

<style>
	a {
		text-decoration: none;
		outline: none;
		border: none;
		color: #3cc9a4;
	}

	.form-tag,
	.tag-list {
		width: 100%;
		overflow: hidden;
	}

	.form-tag .form-tag-box,
	.tag-list .tag-box {
		float: left;
		margin: 5px;
		height: 16px;
		padding: 5px 10px;
		color: #3cc9a4;
		border: solid 1px #3cc9a4;
		border-radius: 14px;
		font-size: 12px;
	}

	.tag-box-2 {
		float: left;
		margin: 5px;
		height: 28px;
		padding: 5px 10px;
		color: #3cc9a4;
		border: solid 1px #3cc9a4;
		border-radius: 14px;
		font-size: 12px;
	}

	.tag-list .tag-box.action {
		color: #fff;
		background-color: #3cc9a4;
	}

	.modal {
		width: 100%;
		height: 100vh;
		position: fixed;
		z-index: 10089;
		top: 0;
		left: 0;
		visibility: hidden;
		opacity: 0;
		transition: all 0.3s;
	}

	.modal.show {
		opacity: 1;
		visibility: initial;
	}

	.modal-bg {
		background: #000;
		opacity: 0.4;
		width: 100%;
		height: 100vh;
		left: 0;
		top: 0;
		position: fixed;
	}

	.modal-main {
		width: 100%;
		background: #fff;
		height: 250px;
		bottom: 0;
		position: fixed;
		box-shadow: 0px 0px 15px rgba(0, 0, 0, 0.4);
		border-radius: 20px 20px 0px 0px;
		box-sizing: border-box;
		padding: 10px 20px;
	}

	.hasSearch .modal-main {
		height: 350px;
	}

	.categoryBox .modal-main {
		height: 400px;
	}

	.modal-title {
		font-weight: bold;
		height: 40px;
		line-height: 40px;
		font-size: 15px;
	}

	.modal-title a {
		float: right;
		font-weight: normal;
	}

	.modal-concent {
		height: calc(100% - 50px);
		width: 100%;
		overflow: auto;
	}

	.hasSearch .modal-concent {
		height: calc(100% - 85px);
	}

	.modal-search {
		width: 100%;
		overflow: hidden;
		height: 35px;
		box-sizing: border-box;
		border-bottom: solid 1px #f6f6f6;
	}

	.modal-search input {
		display: block;
		height: 35px;
		border: none;
		outline: none;
		width: calc(100% - 35px);
		float: left;
		box-sizing: border-box;
		padding: 0px 10px;
	}

	.modal-search button {
		border: none;
		display: block;
		height: 35px;
		outline: none;
		background: none;
		width: 35px;
		box-sizing: border-box;
		padding: 0px;
		text-align: center;
		color: #000;
		float: left;
	}

	.modal-title a.addShop {
		float: none;
		color: #f57070;
		margin-left: 5px;
	}
</style>