// module/user/components/field-cascader/field-cascader.ts
Component({
  behaviors: ['wx://form-field'],
  lifetimes: {},
  properties: {
    title: { type: String, value: '' },
    closeOnOverlayClick: { type: Boolean, value: true },
  },
  data: {
    visible: false,
    value: [] as { code: string; name: string; }[],
  },
  observers: {

  },
  methods: {
    onShow() {
      this.setData({ visible: true });
    },
    onConfirm(event: { detail: { value: string[]; code: string[] } }) {
      const { value, code } = event.detail;
      const gather = value.map((name, index) => ({ name, code: code[index] }))
      this.setData({ value: gather });
    },
    onClose() {
      this.setData({ visible: false })
    }
  }
})