const vm = new Vue({
	el: "#app",
	data: {
		current_page: '1',
		page_size: '10',
		order_status_list: [],
		order_type_list: [],
		start_time: '',
		end_time: '',
		settlement_startday: '',
		settlement_endday: '',
		order_listinfo: [],
		no_info: "无查询结果",
		select_order_type: '',
		select_order_status: '',
		order_id: '',
		fx_uid : getPar('fx_uid'),
		pay_type : '3',
		recharge_listinfo:[],
		recharge_currentpage:'1'
	},
	//过滤器
	filters: {
		filterReplace: function(total_money){
			return `￥${total_money}`;
		}
	},
	//钩子函数
	mounted: function() {
		this.$nextTick(function() {
			this.httpBaseInfo();
			this.rechargeFirstHttpData();
		})
	},
	//方法
	methods: {
		//解决jquery日历插件的问题
		loadJqueryDate() {
			$(".form_date").datetimepicker({
				format: 'yyyy-mm-dd',
				autoclose: true,
				minView: 2,
				pickerPosition: "bottom-left"
			});
		},
		//配置页面参数基本信息
		httpBaseInfo() {
			let _this = this;
			this.$http.post(
				base_api + "order/order/get-initialize", {}, { emulateJSON: true }
			).then(res => {
					let res_data = res.body;
					let data = res_data.data;
					ZZLog('参数返回',data);
					this.order_status_list = data.order_status_list;
					this.order_type_list = data.order_type_list;
				},
				error => {
					ZZAlertInfo(infoApiError);
				})
			this.loadJqueryDate();
			this.httpFirstData();
		},
		//搜索按钮的点击事件
		searchDidClick() {
			this.httpFirstData();
		},
		//第一次查询数据 (搜索按钮的点击查询)
		httpFirstData() {
			this.start_time = $('#start_time').val();
			this.end_time = $('#end_time').val();
			this.settlement_startday = $('#settlement_startday').val();
			this.settlement_endday = $('#settlement_endday').val();
			this.current_page = '1';
			let order_id = this.order_id;
			let order_type_id = this.select_order_type;
			let start_time = this.start_time;
			let end_time = this.end_time;
			let order_status_id = this.select_order_status;
			let settlement_startday = this.settlement_startday;
			let settlement_endday = this.settlement_endday;
			let fx_uid = this.fx_uid;
			let pay_type = this.pay_type
			let data = {
				current_page: this.current_page,
				page_size: this.page_size,
				order_id,
				order_type_id,
				start_time,
				end_time,
				order_status_id,
				settlement_startday,
				settlement_endday,
				fx_uid,
				pay_type
			}
			ZZLog('第一次请求数据参数', data);
			let urlstr = base_api + 'order/order/get-order-list';
			this.$http.post(urlstr, data, { emulateJSON: true }).then(res => {
				let res_data = res.body;
				ZZLog('ttt',res_data);
				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) {
						$('#order_page').show();
					} else {
						$('#order_page').hide();
					}
				}
			}, error => {
				ZZAlertInfo(infoApiError);
			})
		},
		//创建分页控件
		createPage(currpage, totalpage) {
			$("#order_page").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();
			this.settlement_startday = $('#settlement_startday').val();
			this.settlement_endday = $('#settlement_endday').val();
			let _current_page = this.current_page;
			let order_id = this.order_id;
			let order_type_id = this.select_order_type;
			let start_time = this.start_time;
			let end_time = this.end_time;
//			this.start_time = $('#start_time').val();
//			this.end_time = $('#end_time').val();
			let order_status_id = this.select_order_status;
			let settlement_startday = this.settlement_startday;
			let settlement_endday = this.settlement_endday;
			let fx_uid = this.fx_uid;
			let pay_type = this.pay_type;			
			let data = {
				current_page: this.current_page,
				page_size: this.page_size,
				order_id,
				order_type_id,
				start_time,
				end_time,
				order_status_id,
				settlement_startday,
				settlement_endday,
				fx_uid,
				pay_type
			}
			let urlstr = base_api + 'order/order/get-order-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.order_id = '';
			this.select_order_type = '';
			this.select_order_status = '';
			this.settlement_startday = '';
			this.settlement_endday = '';
			this.start_time = '';
			this.end_time = '';
			$('#start_time').val('');
			$('#end_time').val('');
			$('#settlement_endday').val('');
			$('#settlement_startday').val('');
			this.httpFirstData();
		},
		//取消订单
		cancelDidClick(dict) {
			let urlstr = base_api + 'order/order/cancel';
			let data = { order_id: dict.order_id };
			ZZConfirm('确定取消当前订单？', () => {
				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 {
						this.httpData();
					}
				}, error => {
					ZZAlertInfo(infoApiError);
				})
			})
		},
		orderStatusChange() {
			this.start_time = $('#start_time').val();
			this.end_time = $('#end_time').val();
		},
		orderTypeChange() {
			this.start_time = $('#start_time').val();
			this.end_time = $('#end_time').val();
		},
		//充值列表第一次加载
		rechargeFirstHttpData() {
			let fx_uid = this.fx_uid;
			let data = {
				fx_uid
			};
			let urlstr = base_api + 'user/fx-user/get-amount-order';
			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;
					this.recharge_listinfo = data.order_list;
					$('#recharge_listinfo').show();
					let page = data.page;
					let totalpage = page.total_pages;
					this.rechargeCreatePage(this.recharge_currentpage, totalpage);
					if(page.total_pages > 0) {
						$('#recharge_div').show();
					} else {
						$('#recharge_div').hide();
					}
				}
			}, error => {
				ZZAlertInfo(infoApiError);
			})
		},
		//充值列表分页查询
		rechargeHttpData() {
			let fx_uid = this.fx_uid;
			let data = {fx_uid};
			let urlstr = base_api + 'user/fx-user/get-amount-order';
			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.recharge_listinfo = data.order_list;
					$('#recharge_listinfo').show();
				}
			}, error => {
				ZZAlertInfo(infoApiError);
			})
		},
		//充值列表创建分页
		rechargeCreatePage(currpage,totalpage) {
			$("#recharge_div").createPage({
				pageCount: totalpage, //总页数
				current: currpage, //当前页
				turndown: 'true', //是否显示跳转框，显示为true，不现实为false,一定记得加上引号...
				backFn: (p)=> {
					this.recharge_currentpage = p;
					this.rechargeHttpData();
				}
			})
		}
		
		
		
	}
})