import md5 from 'js-md5'
import qs from 'qs'
const appKey = "3721zhkj"
// 生成签名
function alphabeticalSort(a, b) {
	return a.toUpperCase().localeCompare(b.toUpperCase());
}
function filterFunc(prefix, value) {
	if (prefix === "dishOtherOrderItems" || prefix === "template"|| prefix==='productItems') {
		const rel = value.map(item =>
			`{${
			  qs.stringify(item, {
				sort: alphabeticalSort,
				delimiter: ",",
				encode: false
			  })
			}}`
		);
		return `[${rel.join(",")}]`
	}
	return value;
}
export const signGen = function(data) {
	const str = qs.stringify(data, {
		sort: alphabeticalSort,
		encode: false,
		filter: filterFunc
	}) + '&key=' + appKey
	let sign = md5(str).toUpperCase();
	return Object.assign({
		sign
	}, data)
}