const vm = new Vue({
	el: "#app",
	data: {
		current_page: '1',
		page_size: '10',
		no_info: "无查询结果",
        start_time: '',
        end_time: '',
        user_name:'',
        title:'',
        resource_id: '',
        order_listinfo:[]
	},
	//过滤器
	filters: {
		filterReplace: function(total_money){
			return `￥${total_money}`;
		}
	},
	//钩子函数
	mounted: function() {
		this.$nextTick(function() {
			this.httpBaseInfo();
		})
	},
	//方法
	methods: {
		//解决jquery日历插件的问题
		loadJqueryDate() {
			$(".form_date").datetimepicker({
				format: 'yyyy-mm-dd',
				autoclose: true,
				minView: 2,
				pickerPosition: "bottom-left"
			});
		},
		//配置页面参数基本信息
		httpBaseInfo() {
			let _this = this;
			this.loadJqueryDate();
			this.httpFirstData();
		},
		//搜索按钮的点击事件
		searchDidClick() {
			this.httpFirstData();
		},
		//第一次查询数据 (搜索按钮的点击查询)
		httpFirstData() {
			this.start_time = $('#start_time').val();
			this.end_time = $('#end_time').val();
			this.current_page = '1';
			let user_name = this.user_name;
			let title = this.title;
			let start_time = this.start_time;
			let end_time = this.end_time;
			let resource_id = this.resource_id;
			let data = {
				current_page: this.current_page,
				page_size: this.page_size,
                user_name,
                title,
				start_time,
				end_time,
                resource_id
			}
			ZZLog('第一次请求数据参数', data);
			let urlstr = base_api + 'user/log/get-list';
			this.$http.post(urlstr, data, { emulateJSON: true }).then(res => {
				let res_data = res.body;
				if(res_data.flag == false) {
					ZZAlertInfo(res_data.msg, () => {
						ifLogin(res_data);
					});
				} else {
					let data = res_data.data;
					let page = data.page;
					this.order_listinfo = data.order_list;
					let totalpage = page.total_pages;
					$('#body_list').show();
					this.createPage(this.current_page, totalpage);
					if(page.total_pages > 0) {
						$('.pageDiv').show();
					} else {
						$('.pageDiv').hide();
					}
				}
			}, error => {
				ZZAlertInfo(infoApiError);
			})
		},
		//创建分页控件
		createPage(currpage, totalpage) {
			$(".pageDiv").createPage({
				pageCount: totalpage, //总页数
				current: currpage, //当前页
				turndown: 'true', //是否显示跳转框，显示为true，不现实为false,一定记得加上引号...
				backFn: (p)=> {
					this.current_page = p;
					this.httpData();
				}
			})
		},
		//分页查询数据
		httpData() {
            this.start_time = $('#start_time').val();
            this.end_time = $('#end_time').val();
            let user_name = this.user_name;
            let title = this.title;
            let start_time = this.start_time;
            let end_time = this.end_time;
            let resource_id = this.resource_id;
            let data = {
                current_page: this.current_page,
                page_size: this.page_size,
                user_name,
                title,
                start_time,
                end_time,
                resource_id
            }
			let urlstr = base_api + 'user/log/get-list';
			ZZLog('分页数据参数', data);
			this.$http.post(urlstr, data, { emulateJSON: true }).then(res => {
				let res_data = res.body;
				if(res_data.flag == false) {
					ZZAlertInfo(res_data.msg, () => {
						ifLogin(res_data);
					});
				} else {
					let data = res_data.data;
					let page = data.page;
					this.order_listinfo = data.order_list;
					$('#body_list').show();
				}
			}, error => {
				ZZAlertInfo(infoApiError);
			})
		},
		//重置按钮
		resetDidClick() {
			this.user_name = '';
			this.title = '';
			this.start_time = '';
			this.end_time = '';
            this.resource_id='';
			$('#start_time').val('');
			$('#end_time').val('');
			this.httpFirstData();
		}
	}
})