field-cascader.ts 730 B

1234567891011121314151617181920212223242526272829
  1. // module/user/components/field-cascader/field-cascader.ts
  2. Component({
  3. behaviors: ['wx://form-field'],
  4. lifetimes: {},
  5. properties: {
  6. title: { type: String, value: '' },
  7. closeOnOverlayClick: { type: Boolean, value: true },
  8. },
  9. data: {
  10. visible: false,
  11. value: [] as { code: string; name: string; }[],
  12. },
  13. observers: {
  14. },
  15. methods: {
  16. onShow() {
  17. this.setData({ visible: true });
  18. },
  19. onConfirm(event: { detail: { value: string[]; code: string[] } }) {
  20. const { value, code } = event.detail;
  21. const gather = value.map((name, index) => ({ name, code: code[index] }))
  22. this.setData({ value: gather });
  23. },
  24. onClose() {
  25. this.setData({ visible: false })
  26. }
  27. }
  28. })