const vm = new Vue({
	el: "#app",
	data: {
		current_page: '1',
		page_size: '10',
		order_type_list: [],
		order_status_list: [],
		select_order_type: "",
		select_status: "",
		prod_list: [],
		order_id: "",
		date1Val: "",
		date2Val: "",
		date3Val: "",
		date4Val: "",
		detail_list: [],
		no_info: "无查询结果"
	},
	//过滤器
	filters: {

	},
	//钩子函数
	mounted: function() {
		this.$nextTick(function() {
			this.httpLoadInfo();
		})
	},
	methods: {
		loadJqueryDate() {
			$(".form_date_start").datetimepicker({
				format: 'yyyy-mm-dd',
				autoclose: true,
				minView: 2,
				pickerPosition: "bottom-left"
			});
			$(".form_date_end").datetimepicker({
				format: 'yyyy-mm-dd',
				autoclose: true,
				minView: 2,
				pickerPosition: "bottom-left"
			});
		},
		httpLoadInfo() {
			let _this = this;
			let fx_uid = getPar('fx_uid');
			if(fx_uid==""){
				ZZAlertInfo('缺少参数,请返回上一个页面重试');
				return;
			}
			this.$http.post(
				base_api + "order/order/get-initialize", {}, { emulateJSON: true }
			).then(function(res) {
				let res_data = res['body'];
				let data = res_data['data'];
				ZZLog(res_data);
				this.order_type_list = data['order_type_list'];
				this.order_status_list = data['order_status_list'];
				this.btn_search();
			}, function() {
				ZZAlertInfo(infoApiError);
			});
			this.loadJqueryDate();
			this.httpFirstInfo();
		},
		order_type_change() {
			this.date1Val = $('#date1').val();
			this.date2Val = $('#date2').val();
			this.date3Val = $('#date3').val();
			this.date4Val = $('#date4').val();
		},
		order_status_change() {
			this.date1Val = $('#date1').val();
			this.date2Val = $('#date2').val();
			this.date3Val = $('#date3').val();
			this.date4Val = $('#date4').val();
		},
		httpFirstInfo() {
			this.current_page = 1;
			let fx_uid = getPar('fx_uid');
			let order_id = this.order_id;
			let order_type_id = this.select_order_type;
			let order_status_id = this.select_status;
			let create_order_start_date = $('#date1').val();
			this.date1Val = $('#date1').val();
			let create_order_end_date = $('#date2').val();
			this.date2Val = $('#date2').val();
			let settlement_start_date = $('#date3').val();
			this.date3Val = $('#date3').val();
			let settlement_end_date = $('#date4').val();
			this.date4Val = $('#date4').val();
			let data = {
				current_page: this.current_page,
				page_size: this.page_size,
				fx_uid,
				order_id,
				order_type_id,
				order_status_id,
				create_order_start_date,
				create_order_end_date,
				settlement_start_date,
				settlement_end_date
			};

			ZZLog(base_api + "order/order/get-commission-list", JSON.stringify(data));
			this.$http.post(
				base_api + "order/order/get-commission-list", data, { emulateJSON: true }
			).then(function(res) {
				let res_data = res['body'];
				ZZLog(res_data);
				$('#commission_table').show();
				if(res_data['flag'] == false) {
					ZZAlertInfo(res_data['msg'], function() {
						ifLogin(res_data);
					});
				} else {
					let data = res_data['data'];
					let page = data['page'];
					let prod_list = data['prod_list'];
					this.prod_list = prod_list;
					//分页控件
					$(".pageDiv").createPage({
						pageCount: page['total_pages'], //总页数
						current: this.current_page, //当前页
						turndown: 'true', //是否显示跳转框，显示为true，不现实为false,一定记得加上引号...
						backFn: (p) => {
							this.current_page = p;
							this.httpData();
						}
					});
					if(page['total_pages'] > 0) {
						$('.pageDiv').show();
					} else {
						$('.pageDiv').hide();
					}
				}

			}, function() {
				ZZAlertInfo(infoApiError);
			});
		},
		httpData() {
			let fx_uid = getPar('fx_uid');
			let order_id = this.order_id;
			let order_type_id = this.select_order_type;
			let order_status_id = this.select_status;
			let create_order_start_date = $('#date1').val();
			this.date1Val = $('#date1').val();
			let create_order_end_date = $('#date2').val();
			this.date2Val = $('#date2').val();
			let settlement_start_date = $('#date3').val();
			this.date3Val = $('#date3').val();
			let settlement_end_date = $('#date4').val();
			this.date4Val = $('#date4').val();
			let data = {
				current_page: this.current_page,
				page_size: this.page_size,
				fx_uid,
				order_id,
				order_type_id,
				order_status_id,
				create_order_start_date,
				create_order_end_date,
				settlement_start_date,
				settlement_end_date
			};

			ZZLog(base_api + "order/order/get-commission-list", JSON.stringify(data));
			this.$http.post(
				base_api + "order/order/get-commission-list", data, { emulateJSON: true }
			).then(function(res) {
				let res_data = res['body'];
				ZZLog(res_data);
				$('#commission_table').show();
				if(res_data['flag'] == false) {
					ZZAlertInfo(res_data['msg'], function() {
						ifLogin(res_data);
					});
				} else {
					let data = res_data['data'];
					let page = data['page'];
					let prod_list = data['prod_list'];
					this.prod_list = prod_list;
				}

			}, function() {
				ZZAlertInfo(infoApiError);
			});
		},
		btn_search() {
			this.httpFirstInfo();
//			this.loadJqueryDate();
		},
		btn_reset() {
			this.date1Val = "";
			this.date2Val = "";
			this.date3Val = "";
			this.date4Val = "";
			this.order_id = "";
			this.select_order_type = "";
			this.select_status = "";
			$('#date1').val('');
			$('#date2').val('');
			$('#date3').val('');
			$('#date4').val('');
			this.httpFirstInfo();

		},
		clickDetail(item) {
			let order_id = item['order_id'];
			let data = { order_id };
			ZZLog(base_api + 'order/order/get-commission-detail', JSON.stringify(data));
			this.$http.post(
				base_api + 'order/order/get-commission-detail', data, { emulateJSON: true }
			).then(res=> {
				let res_data = res.body;
				ZZLog(res_data);
				if(false == res_data['flag']) {
					ZZAlertInfo(res_data['msg']);
				} else {
					let data = res_data['data'];
					this.detail_list = data['detail'];
				}
			}, error=> {
				ZZAlertInfo(infoApiError);
			});
			
		}

	}
})