mui.plusReady(function(){
	$('body').on('click', ".footer[data-app='app']", function(){
		app.create();
	})
})

const app = new Vue({
	el: '#app',
	data() {
		return {
			noteData: [
			],
		}
	},
	methods: {
		triggerDelete(index) {
			this.$set(this.noteData[index], 'currentDelete', true)
		},
		cancelDelete(index){
			this.$set(this.noteData[index], 'currentDelete', false)
		},
		confirmDelete(index){
			$.ajax({
				url: qlgUrl("app/note/delete"),
				method: "POST",
				data: {
					id: this.noteData[index].id,
				},
				dataType: "json",
				success: (res) => {
					if(res.status != 1){
						mui.alert(res.msg);
					}
					this.loadData();
				},
				error: (err) => {
					mui.alert("请求失败");
					this.loadData();
				}
			})
		},
		edit(index){
			mui.openWindow({
				url: "notepad_edit.html",
				id: "notepad_edit"+index,
				extras: {
					noteId: index
				},
				createNew: false, //是否重复创建同样id的webview,默认为false:不重复创建,直接显示
				waiting: {
					autoShow: true, //自动显示等待框,默认为true
					title: '正在加载...', //等待对话框上显示的提示内容
				}
			})
		},
		create(){
			// some jump
			this.edit(0);
			// JZL.openWindow('trade_rule.html', 'trade_rule.html')
		},
		loadData() {
			$.ajax({
				url: qlgUrl("app/note/index"),
				method: "GET",
				dataType: 'json',
				success: (res) => {
					if(res.status == 1){
						this.noteData = res.data;
						localStorage.setItem("LOCAL_NOTE", JSON.stringify(res.data));
					}else{
						mui.alert(res.msg);
					}
				},
				error: function(err){
					mui.alert("请求失败");
					self.back();
				}
			});
		},
	},
	created() {
		var localData = localStorage.getItem("LOCAL_NOTE");
		this.loadData();
		if(localData){
			try{
				JSON.parse(localData);
				this.noteData = JSON.parse(localData);
			} catch(e) {
				console.log(e);
				this.noteData = [];
			}
		}
	},
})