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

const app2 = new Vue({
	el: '#app2',
	data() {
		return {
			creditData: [
			],
		}
	},
	methods: {
		triggerDelete(index) {
			this.$set(this.creditData[index], 'currentDelete', true)
		},
		cancelDelete(index){
			this.$set(this.creditData[index], 'currentDelete', false)
		},
		confirmDelete(index){
			$.ajax({
				url: qlgUrl("app/note/creditDelete"),
				method: "POST",
				data: {
					id: this.creditData[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: "credit_edit.html",
				id: "credit_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/creditIndex"),
				method: "GET",
				dataType: 'json',
				success: (res) => {
					if(res.status == 1){
						this.creditData = res.data;
						localStorage.setItem("LOCAL_CREDIT", JSON.stringify(res.data));
					}else{
						mui.alert(res.msg);
					}
				},
				error: function(err){
					mui.alert("请求失败");
					self.back();
				}
			});
		},
	},
	created() {
		var localData = localStorage.getItem("LOCAL_CREDIT");
		this.loadData();
		if(localData){
			try{
				JSON.parse(localData);
				this.noteData = JSON.parse(localData);
			} catch(e) {
				this.noteData = [];
			}
		}
	},
})