message-customer-service.vue 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. <template>
  2. <div class="custom">
  3. <div v-if="payload.src === CUSTOM_MESSAGE_SRC.BRANCH || payload.src === CUSTOM_MESSAGE_SRC.BRANCH_NUMBER">
  4. <MessageBranch
  5. :payload="payload"
  6. @sendMessage="sendTextMessage"
  7. />
  8. </div>
  9. <div v-if="payload.src === CUSTOM_MESSAGE_SRC.FROM_INPUT">
  10. <MessageForm
  11. :payload="payload"
  12. @sendMessage="sendTextMessage"
  13. />
  14. </div>
  15. <div v-if="payload.src === CUSTOM_MESSAGE_SRC.PRODUCT_CARD">
  16. <MessageProductCard :payload="payload" />
  17. </div>
  18. </div>
  19. </template>
  20. <script lang="ts">
  21. import vue from '../adapter-vue';
  22. import { JSONToObject } from '../utils/index';
  23. import { CUSTOM_MESSAGE_SRC } from '../constant';
  24. import { customerServicePayloadType, IMessageModel } from '../interface';
  25. import MessageBranch from './message-branch.vue';
  26. import MessageForm from './message-form/index.vue';
  27. import MessageProductCard from './message-product-card.vue';
  28. const { computed } = vue;
  29. interface Props {
  30. message: IMessageModel;
  31. }
  32. export default {
  33. components: {
  34. MessageBranch,
  35. MessageForm,
  36. MessageProductCard,
  37. },
  38. props: {
  39. message: {
  40. type: Object as () => IMessageModel,
  41. default: () => ({}),
  42. },
  43. },
  44. emits: ['sendMessage'],
  45. setup(props: Props, { emit }) {
  46. const payload = computed<customerServicePayloadType>(() => {
  47. return props.message && JSONToObject(props.message?.payload?.data);
  48. });
  49. const sendTextMessage = (text: string) => {
  50. emit('sendMessage', text);
  51. };
  52. return {
  53. payload,
  54. sendTextMessage,
  55. CUSTOM_MESSAGE_SRC,
  56. };
  57. },
  58. };
  59. </script>