| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647 |
- // module/user/components/field-picker/field-picker.ts
- Component({
- behaviors: ['wx://form-field'],
- lifetimes: {},
- properties: {
- title: { type: String, value: '' },
- options: { type: Array, value: [] },
- optionsColumns: { type: Number, value: 3 },
- itemHeight: { type: Number, value: 64 },
- multiple: { type: Boolean, value: true },
- closeOnOverlayClick: { type: Boolean, value: true },
- },
- data: {
- visible: false,
- value: [],
- selected: [] as Option[],
- },
- observers: {
- 'value, options'(values: Option[] | Option | string, options: Option[]) {
- const selected = new Set<Option>();
- if (options.length) {
- const _values = Array.isArray(values) ? values : values ? [values] : [];
- for (const item of _values) {
- const value = typeof item === 'object' ? item?.value : item;
- const [v,l] = value.split(':');
- const option = options.find(item => item.value === v)
- if (option) selected.add({...option, label: l ?? option.label});
- }
- }
- this.setData({ selected: [...selected] });
- },
- },
- methods: {
- onShow() {
- this.setData({ visible: true });
- },
- onPickerConfirm(event: any) {
- const { options } = event.detail;
- console.log(event.detail, '123-->');
-
- this.setData({ value: options })
- },
- onPickerClose() {
- this.setData({ visible: false })
- }
- }
- })
|