mui.init({
	beforeback: function() { 
		//获得父页面的webview
		var list = plus.webview.currentWebview().opener(); //触发父页面的自定义事件(refresh),从而进行刷新
		list.reload();
		//返回true,继续页面关闭逻辑
		return true;
	}
});
mui.plusReady(function(){
	window.self = plus.webview.currentWebview();
	var Id = self.noteId;
	var E = window.wangEditor
	window.editor = new E('#content')
	editor.customConfig.qiniu = true;
	editor.customConfig.debug = true;
	editor.create();
	var $createTime = $("#createTime");
	var $title = $("#title");
	if(Id == 0) {$createTime.text("现在");}
	else {
		$.ajax({
			url: qlgUrl("app/note/detail"),
			method: "GET",
			data: {
				id: Id,
			},
			dataType: "json",
			success: function(res){
				console.log(res);
				if(res.status == 1){
					$createTime.text(res.data.create_time);
					$title.val(res.data.title);
					editor.txt.html(res.data.content);
				}else{
					alert(res.msg);
					self.back();
				}
			},
			error: function(err){
				alert("请求失败");
				self.back();
			}
		})
	}
	$(".footer").on("tap", function(){
		var title = $title.val();
		var content = editor.txt.html();
		$.ajax({
			url: qlgUrl("app/note/save"),
			method: "POST",
			data: {
				id: Id,
				title: title,
				content: content,
			},
			dataType: "json",
			success: function(res){
				if(res.status != 1){
					mui.alert(res.msg);
				}else{
					mui.back();
				}
			},
			error: function(err){
				mui.alert("请求失败");
				self.back();
			}
		})
		
	})
})
