import Helper, { Options } from 'bsl-core/components/Form/Helper'; import BSL from 'bsl-core/typings'; import Event from 'bsl-mp/typings/event'; import{ dispatchUpdate } from 'bsl-mp/app/Form/Helper'; export interface RegionValue { code: string; value: string; } class PickerHelper extends Helper { constructor(options?: Options) { super(options); this.value = options?.defaultValue || []; } public value: Value[]; public state: BSL.RequestState = 'undefined'; public onChange = (value: Value[], state?: BSL.RequestState) => { const isEmpty = value.length === 0 || !value; this.state = isEmpty && this.required ? 'empty' : 'complete'; this.value = value; dispatchUpdate(this); return this.state === 'complete'; } public clear = () => { this.onChange([], 'undefined'); } /** 将城市数据转换成数组 */ public transformRegion = (value: Event.PickerDetail['region']): RegionValue[] => { const data: RegionValue[] = []; for (let i = 0; i < value.value.length; i++) { data.push({ code: value.code[i], value: value.value[i] }); } return data; } } export default PickerHelper;