// 表单校验规则由 schema2code 生成，不建议直接修改校验规则，而建议通过 schema2code 生成, 详情: https://uniapp.dcloud.net.cn/uniCloud/schema


const validator = {
	"createBy": {
		"rules": [{
			"format": "string"
		}],
		"title": "创建人",
		"label": "创建人"
	},
	"updateBy": {
		"rules": [{
			"format": "string"
		}],
		"title": "更新人",
		"label": "更新人"
	},
	"meterID": {
		"rules": [{
			"format": "string"
		}],
		"title": "计量点编号",
		"label": "计量点编号"
	},
	"dFlowCalbz": {
		"rules": [{
			"format": "string"
		}],
		"title": "流量计算标准",
		"label": "流量计算标准"
	},
	"dZcalbz": {
		"rules": [{
			"format": "string"
		}],
		"title": "压缩因子计算标准",
		"label": "压缩因子计算标准"
	},
	"dCbtj": {
		"rules": [{
			"format": "string"
		}],
		"title": "计量参比条件压力",
		"label": "计量参比条件压力"
	},
	"dPb_M": {
		"rules": [{
			"format": "string"
		}],
		"title": "计量参比条件压力",
		"label": "计量参比条件压力"
	},
	"dTb_M": {
		"rules": [{
			"format": "string"
		}],
		"title": "计量参比条件温度",
		"label": "计量参比条件温度"
	},
	"dPb_E": {
		"rules": [{
			"format": "string"
		}],
		"title": "燃烧参比条件压力",
		"label": "燃烧参比条件压力"
	},
	"dTb_E": {
		"rules": [{
			"format": "string"
		}],
		"title": "燃烧参比条件温度",
		"label": "燃烧参比条件温度"
	},
	"dPatm": {
		"rules": [{
			"format": "string",
			"required": true,
			"errorMessage": '大气压未输入'
		}],
		"title": "当地大气压",
		"label": "当地大气压"
	},
	"dPatmUnit": {
		"rules": [{
			"format": "string"
		}],
		"title": "当地大气压单位",
		"label": "当地大气压单位"
	},
	"dNG_Compents": {
		"rules": [{
			"format": "string"
		}],
		"title": "天然气组分",
		"label": "天然气组分"
	},
	"dMeterType": {
		"rules": [{
			"format": "string"
		}],
		"title": "流量计类别",
		"label": "流量计类别"
	},
	"dCoreType": {
		"rules": [{
			"format": "string"
		}],
		"title": "节流装置类型",
		"label": "节流装置类型"
	},
	"dPtmode": {
		"rules": [{
			"format": "string"
		}],
		"title": "取压方式",
		"label": "取压方式"
	},
	"dPipeType": {
		"rules": [{
			"format": "string"
		}],
		"title": "管道类型",
		"label": "管道类型"
	},
	"dPipeD": {
		"rules": [{
			"format": "string",
			"required": true,
			"errorMessage": '管径未输入'
		}],
		"title": "管道内径",
		"label": "管道内径"
	},
	"dLenUnit": {
		"rules": [{
			"format": "string"
		}],
		"title": "长度单位",
		"label": "长度单位"
	},
	"dPipeDtemp": {
		"rules": [{
			"format": "string"
		}],
		"title": "管道内径参考温度",
		"label": "管道内径参考温度"
	},
	"dPileDtempU": {
		"rules": [{
			"format": "string"
		}],
		"title": "温度单位",
		"label": "温度单位"
	},
	"dPipeMaterial": {
		"rules": [{
			"format": "string"
		}],
		"title": "管道材料",
		"label": "管道材料"
	},
	"dOrificeD": {
		"rules": [{
			"format": "string",
			"required": true,
			"errorMessage": '孔径未输入'
		}],
		"title": "孔板孔径",
		"label": "孔板孔径"
	},
	"dOrificeUnit": {
		"rules": [{
			"format": "string"
		}],
		"title": "长度单位",
		"label": "长度单位"
	},
	"dOrificeDtemp": {
		"rules": [{
			"format": "string"
		}],
		"title": "孔板内径参考温度",
		"label": "孔板内径参考温度"
	},
	"dOrificeDtempUnit": {
		"rules": [{
			"format": "string"
		}],
		"title": "温度单位",
		"label": "温度单位"
	},
	"dOrificeMaterial": {
		"rules": [{
			"format": "string"
		}],
		"title": "孔板材料",
		"label": "孔板材料"
	},
	"dOrificeSharpness": {
		"rules": [{
			"format": "string"
		}],
		"title": "锐利度系数计算方法",
		"label": "锐利度系数计算方法"
	},
	"dOrificeRk": {
		"rules": [{
			"format": "string"
		}],
		"title": "孔板入口圆弧半径",
		"label": "孔板入口圆弧半径"
	},
	"dOrificeRkLenU": {
		"rules": [{
			"format": "string"
		}],
		"title": "长度单位",
		"label": "长度单位"
	},
	"dPf": {
		"rules": [{
			"format": "string",
			"required": true,
			"errorMessage": '工况压力未输入'
		}],
		"title": "输入压力",
		"label": "输入压力"
	},
	"dPfUnit": {
		"rules": [{
			"format": "string"
		}],
		"title": "压力单位",
		"label": "压力单位"
	},
	"dPfType": {
		"rules": [{
			"format": "string"
		}],
		"title": "压力类型",
		"label": "压力类型"
	},
	"dTf": {
		"rules": [{
			"format": "string",
			"required": true,
			"errorMessage": '工况温度未输入'
		}],
		"title": "输入温度",
		"label": "输入温度"
	},
	"dTfUnit": {
		"rules": [{
			"format": "string"
		}],
		"title": "温度单位",
		"label": "温度单位"
	},
	"dDp": {
		"rules": [{
			"format": "string",
			"required": true,
			"errorMessage": '差压未输入'
		}],
		"title": "输入差压",
		"label": "输入差压"
	},
	"dDpUnit": {
		"rules": [{
			"format": "string"
		}],
		"title": "压力单位",
		"label": "压力单位"
	},
	"dVFlowUnit": {
		"rules": [{
			"format": "string"
		}],
		"title": "体积流量单位",
		"label": "体积流量单位"
	},
	"dMFlowUnit": {
		"rules": [{
			"format": "string"
		}],
		"title": "质量流量单位",
		"label": "质量流量单位"
	},
	"dEFlowUnit": {
		"rules": [{
			"format": "string"
		}],
		"title": "能量流量单位",
		"label": "能量流量单位"
	},
	 
	"dCdCalMethod": {
		"rules": [{
			"format": "string"
		}],
		"title": "流出系数计算方法",
		"label": "流出系数计算方法"
	},
	"dMeterFactor": {
		"rules": [{
			"format": "string",
			"required": true,
			"errorMessage": '仪表系数未输入'
		}],
		"title": "仪表系数",
		"label": "仪表系数"
	},
	"dPulseNum": {
		"rules": [{
			"format": "string",
			"required": true,
			"errorMessage": '脉冲数未输入'
		}],
		"title": "脉冲数",
		"label": "脉冲数"
	},
	"dVFlowMax": {
		"rules": [{
			"format": "string"
		}],
		"title": "最大体积流量",
		"label": "最大体积流量"
	},
	"dVFlowMin": {
		"rules": [{
			"format": "string"
		}],
		"title": "最小体积流量",
		"label": "最小体积流量"
	},
	"dVFlowCon": {
		"rules": [{
			"format": "string"
		}],
		"title": "常用流量",
		"label": "常用流量"
	},
	"dPfRangeMin": {
		"rules": [{
			"format": "string"
		}],
		"title": "压力量程",
		"label": "压力量程"
	},
	"dPfRangeMax": {
		"rules": [{
			"format": "string"
		}],
		"title": "压力量程",
		"label": "压力量程"
	},
	"dDpRangeMin": {
		"rules": [{
			"format": "string"
		}],
		"title": "差压量程",
		"label": "差压量程"
	},
	"dDpRangeMax": {
		"rules": [{
			"format": "string"
		}],
		"title": "差压量程",
		"label": "差压量程"
	},
	"dTfRangeMin": {
		"rules": [{
			"format": "string"
		}],
		"title": "温度计量程",
		"label": "温度计量程"
	},
	"dTfRangeMax": {
		"rules": [{
			"format": "string"
		}],
		"title": "温度计量程",
		"label": "温度计量程"
	},
	 
	"updateTime": {
		"rules": [{
			"format": "datetime"
		}],
		"title": "更新时间",
		"label": "更新时间"
	},
	"createTime": {
		"rules": [{
			"format": "datetime"
		}],
		"title": "创建时间",
		"label": "创建时间"
	}
}

const enumConverter = {}

function filterToWhere(filter, command) {
	let where = {}
	for (let field in filter) {
		let {
			type,
			value
		} = filter[field]
		switch (type) {
			case "search":
				if (typeof value === 'string' && value.length) {
					where[field] = new RegExp(value)
				}
				break;
			case "select":
				if (value.length) {
					let selectValue = []
					for (let s of value) {
						selectValue.push(command.eq(s))
					}
					where[field] = command.or(selectValue)
				}
				break;
			case "range":
				if (value.length) {
					let gt = value[0]
					let lt = value[1]
					where[field] = command.and([command.gte(gt), command.lte(lt)])
				}
				break;
			case "date":
				if (value.length) {
					let [s, e] = value
					let startDate = new Date(s)
					let endDate = new Date(e)
					where[field] = command.and([command.gte(startDate), command.lte(endDate)])
				}
				break;
			case "timestamp":
				if (value.length) {
					let [startDate, endDate] = value
					where[field] = command.and([command.gte(startDate), command.lte(endDate)])
				}
				break;
		}
	}
	return where
}

export {
	validator,
	enumConverter,
	filterToWhere
}