export default (preURL, columns, pager, gridDicts, vm) => {
	let countIdList = [];
	for (let column of columns) {
		if (column.cellRendererParams && column.cellRendererParams.asyncTranslate) {
			countIdList.push({
				type: 'queryMap',
				colId: column.colId,
				key: column.field,
				dataKey: column.field,
				url: column.cellRendererParams.asyncTranslate
			});
		}
		if (column.cellRendererParams && column.cellRendererParams.asyncTranslateByPager) {
			countIdList.push({
				type: 'pager',
				colId: column.colId,
				key: column.field,
				url: column.cellRendererParams.asyncTranslateByPager.url,
				dataName: column.cellRendererParams.asyncTranslateByPager.name,
				dataKey: column.cellRendererParams.asyncTranslateByPager.key
			});
		}
	}

	Promise.all(countIdList.map(config => {
		return vm.$http.post(preURL, Object.assign({
			countIdList: ['distinct', config.key]
		}, Object.assign({}, pager, { exhibitDatas: [] })))
	}))
		.then(list => {
			for (let index in list) {
				const config = countIdList[index];
				let dictList = list[index].filter(item => item && item[config.key]);
				let dict = gridDicts[config.colId];
				if (!dict) {
					dict = {}
					vm.$set(gridDicts, config.colId, dict)
				}
				if (config.type === 'pager' && dictList.length > 0) {
					vm.$http
						.getByPager(config.url, {
							pageSize: 64999,
							fastQueryParameters: [{
								columnId: config.dataKey,
								fastQueryType: 'in',
								dataType: 'list',
								value: dictList.map(item => item[config.dataKey])
							}]
						})
						.then(({ exhibitDatas: data }) => {
							for (let item of data) {
								vm.$set(dict, item[config.dataKey], item[config.dataName]);
							}
						})
						.catch(error => {
							console.error(error)
						})
				} else if (config.type = 'queryMap' && dictList.length > 0) {
					vm.$http
						.post(config.url, dictList.map(item => item[config.dataKey]))
						.then((dict) => {
							vm.$set(gridDicts, config.colId, dict)
						})
						.catch(error => {
							console.error(error)
						})
				}
			}
		})
		.catch(error => {
			console.error(error)
		})
};
