select-send.tsx 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  1. import MSticky from '@/components/m-sticky';
  2. import { useRect } from '@vant/use';
  3. import { Button, Tab, Tabs } from 'vant';
  4. import { defineComponent, onMounted, reactive, watch } from 'vue';
  5. import styles from './index.module.less';
  6. import MHeader from '@/components/m-header';
  7. import GroupChat from './components/group-chat';
  8. import Contacts from './components/contacts';
  9. export default defineComponent({
  10. name: 'select-send',
  11. props: {
  12. selectObject: {
  13. type: Object,
  14. default: () => ({})
  15. },
  16. selectStatus: {
  17. type: Boolean,
  18. default: false
  19. }
  20. },
  21. emits: ['close', 'update:selectObject', 'confirm'],
  22. setup(props, { emit }) {
  23. const state = reactive({
  24. headerHeight: 0,
  25. height: 0,
  26. bottomHeight: 0,
  27. tabValue: 'groupChat',
  28. selectGroupChat: [] as any,
  29. selectContacts: [] as any
  30. });
  31. const onSubmit = async () => {
  32. const params = {
  33. groupChat: state.selectGroupChat,
  34. contacts: state.selectContacts
  35. };
  36. emit('close');
  37. console.log(params, 'selectSend');
  38. emit('update:selectObject', params);
  39. emit('confirm', params);
  40. };
  41. watch(
  42. () => props.selectObject,
  43. () => {
  44. resetSelectItems();
  45. },
  46. { deep: true }
  47. );
  48. const resetSelectItems = () => {
  49. const list = props.selectObject || {};
  50. state.selectGroupChat = list.groupChat || [];
  51. state.selectContacts = list.contacts || [];
  52. };
  53. onMounted(() => {
  54. const { height } = useRect(
  55. document.querySelector('.van-tab') as HTMLElement
  56. );
  57. state.height = height;
  58. resetSelectItems();
  59. console.log(state, 'select');
  60. });
  61. return () => (
  62. <div class={styles['select-send']}>
  63. <MSticky
  64. onBarHeight={(height: number) => {
  65. state.headerHeight = height;
  66. }}>
  67. <MHeader title="发送对象" />
  68. </MSticky>
  69. <Tabs
  70. sticky
  71. lineWidth={20}
  72. lineHeight={4}
  73. v-model:active={state.tabValue}
  74. offsetTop={state.headerHeight}>
  75. <Tab title="群聊" name="groupChat">
  76. <GroupChat
  77. height={state.height}
  78. headerHeight={state.headerHeight}
  79. bottomHeight={state.bottomHeight}
  80. v-model:selectItem={state.selectGroupChat}
  81. />
  82. </Tab>
  83. <Tab title="联系人" name="contacts">
  84. <Contacts
  85. height={state.height}
  86. headerHeight={state.headerHeight}
  87. bottomHeight={state.bottomHeight}
  88. v-model:selectItem={state.selectContacts}
  89. />
  90. </Tab>
  91. </Tabs>
  92. <MSticky
  93. position="bottom"
  94. onBarHeight={(height: any) => {
  95. state.bottomHeight = height;
  96. }}>
  97. <div class={'btnGroupFixed'}>
  98. <Button round block type="primary" onClick={onSubmit}>
  99. 确认
  100. </Button>
  101. </div>
  102. </MSticky>
  103. </div>
  104. );
  105. }
  106. });