const _Http = getApp().globalData.http;

Page({
	data: {
		sa_agentsid: null,
		tabsActive: 0,
		tabsList: [{
			label: "账户信息",
			icon: "icon-tabkaipiaoxinxi",
			model: "#Account"
		}, {
			label: "目标",
			icon: "icon-tabrenwu",
			model: '#Target'
		}]
	},
	onLoad(options) {
		this.data.sa_agentsid = options.id;
		this.getDetail()
	},
	getDetail() {
		_Http.basic({
			"classname": "webmanage.sale.agents.agents",
			"method": "query_agentMain",
			"content": {
				"nocache": true,
				"sa_agentsid": this.data.sa_agentsid
			},
		}).then(res => {
			console.log("经销商档案详情", res)
			let briefs = [{
				label: "企业名称",
				value: res.data.enterprisename
			}, {
				label: "企业等级",
				value: res.data.grade
			}, {
				label: "企业联系人",
				value: res.data.contact
			}, {
				label: "联系电话",
				value: res.data.phonenumber
			}, {
				label: "省市县",
				value: res.data.province ? res.data.province + res.data.city + res.data.county : ''
			}, {
				label: "详细地址",
				value: res.data.address
			}, {
				label: "可退货天数",
				value: res.data.limitreturnday
			}, {
				label: "授权经营",
				value: res.data.saleclassauth ? '是' : '否'
			}, {
				label: "统一码",
				value: res.data.taxno
			}];
			this.setData({
				detail: res.data,
				briefs
			})
			this.partialRenewal();
		})
	},
	//tabs 切换
	tabsChange({
		detail
	}) {
		this.setData({
			tabsActive: detail
		});
		this.partialRenewal();
	},
	//局部数据更新 tabs
	partialRenewal(init = false) {
		let model = this.data.tabsList[this.data.tabsActive].model;
		if (model) {
			let Component = this.selectComponent(model),
				{
					total,
					pageNumber,
					pageTotal
				} = Component.data.content,
				id = this.data.detail.sys_enterpriseid;
			if (total == null || init) {
				Component.getList(id, init);
			} else if (pageNumber <= pageTotal) {
				Component.getList(id, false);
			}
		}
	},
	onReachBottom() {
		this.partialRenewal();
	},
})