const _Http = getApp().globalData.http;

Page({
	data: {
		loading: true,
		active: 0,
		"content": {
			nocache: true,
			"pageNumber": 1,
			"pageTotal": 1,
			"pageSize": 20,
			total: 0,
			"where": {
				"condition": "",
			},
			sort: []
		}
	},
	onLoad(options) {
		this.getList(true)
	},
	getList(init = false) {
		if (init.detail != undefined) init = init.detail;
		let content = this.data.content;
		if (init) content.pageNumber = 1;
		if (content.pageNumber > content.pageTotal) return;
		_Http.basic({
			"id": wx.getStorageSync('userrole') == '业务员' ? 20221122132804 : 20230111141104,
			content
		}).then(res => {
			console.log("订单列表", res)
			if(res.msg!='成功')return wx.showToast({
				title: res.msg,
				icon:"none"
			})
			this.selectComponent('#ListBox').RefreshToComplete();
			this.setData({
				list: res.pageNumber == 1 ? res.data : this.data.list.concat(res.data),
				"content.pageNumber": res.pageNumber + 1,
				"content.pageTotal": res.pageTotal,
				"content.sort": res.sort,
				"content.total": res.total,
				loading: false
			})
		})
	},
	/* 搜索 */
	onSearch({
		detail
	}) {
		this.setData({
			"content.where.condition": detail
		});
		this.getList(true)
	},
	/* 切换tabs */
	tabsChange(e) {
		let status = "";
		switch (e.detail.title) {
			case '待收货':
				status = "审核";
				break;
			case '已收货':
				status = "收货";
				break;
		}
		this.setData({
			active: e.detail.index,
			"content.where.status": status
		});
		this.getList(true);
	},
	onReady() {
		this.setListHeight()
	},
	/* 设置页面高度 */
	setListHeight() {
		this.selectComponent("#ListBox").setHeight(".total", this);
	},
})