TotastUtils.js 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  1. /* eslint-disable no-use-before-define */
  2. /* eslint-disable no-console */
  3. import React from 'react';
  4. import { Modal } from '@ant-design/react-native';
  5. import { Text } from 'react-native-magnus';
  6. import * as Linking from 'expo-linking';
  7. import i18n from '../i18n';
  8. import { navigate } from '../navigation/RootNavigation';
  9. export function alert(title, content, submitEvent) {
  10. Modal.alert(
  11. <Text textAlign="center" fontWeight="bold">
  12. {title || i18n.t('ti-shi')}
  13. </Text>,
  14. <Text fontSize="sm" color="red500" textAlign="center">
  15. {content}
  16. </Text>,
  17. [
  18. {
  19. text: i18n.t('qu-xiao'),
  20. onPress: () => console.log('cancel'),
  21. style: { color: '#000', fontSize: 12, lineHeight: 30 },
  22. },
  23. {
  24. text: i18n.t('que-ding'),
  25. onPress: () => {
  26. if (submitEvent) {
  27. submitEvent();
  28. }
  29. },
  30. style: { color: '#FFC21C', fontSize: 12, lineHeight: 30 },
  31. },
  32. ],
  33. () => true
  34. );
  35. }
  36. export function alertWithoutCancel(title, content, isError, submitEvent) {
  37. Modal.alert(
  38. !!title && (
  39. <Text textAlign="center" fontWeight="bold">
  40. {title || ''}
  41. </Text>
  42. ),
  43. <Text
  44. fontSize="sm"
  45. color={isError ? 'red500' : 'gray600'}
  46. textAlign="center"
  47. >
  48. {content}
  49. </Text>,
  50. [
  51. {
  52. text: i18n.t('que-ding'),
  53. onPress: () => {
  54. if (submitEvent) {
  55. submitEvent();
  56. }
  57. },
  58. style: { color: '#FFC21C', fontSize: 12, lineHeight: 30 },
  59. },
  60. ],
  61. () => true
  62. );
  63. }
  64. export function operation() {
  65. Modal.operation([
  66. { text: '标为未读', onPress: () => console.log('标为未读被点击了') },
  67. { text: '置顶聊天', onPress: () => console.log('置顶聊天被点击了') },
  68. ]);
  69. }
  70. export function connectKefu(orderId, canConnect) {
  71. Modal.alert(
  72. '',
  73. <Text style={{ marginHorizontal: 15 }} more>
  74. {i18n.t('tips9')}
  75. </Text>,
  76. canConnect
  77. ? [
  78. {
  79. text: i18n.t('ke-fu-dian-hua'),
  80. onPress: connectKefuOn,
  81. style: { color: '#000', fontSize: 12, lineHeight: 30 },
  82. },
  83. {
  84. text: i18n.t('wo-yao-tou-su'),
  85. onPress: () => {
  86. navigate('Complaint', { orderId });
  87. },
  88. style: { color: '#FFC21C', fontSize: 12, lineHeight: 30 },
  89. },
  90. ]
  91. : [
  92. {
  93. text: i18n.t('qu-xiao'),
  94. onPress: () => console.log('cancel'),
  95. style: { color: '#000', fontSize: 12, lineHeight: 30 },
  96. },
  97. {
  98. text: '拨打电话',
  99. onPress: connectKefuOn,
  100. style: { color: '#FFC21C', fontSize: 12, lineHeight: 30 },
  101. },
  102. ],
  103. () => true
  104. );
  105. }
  106. export function connectKefuOn() {
  107. Linking.openURL('tel:+123456789');
  108. }
  109. export function prompt(title, plac, defaultValue, callBack) {
  110. Modal.prompt(
  111. title || '',
  112. '',
  113. (val) => {
  114. if (callBack) callBack(val);
  115. },
  116. 'default',
  117. defaultValue || '',
  118. [plac || ''],
  119. () => true
  120. );
  121. }