No Description

index.tsx 7.1KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234
  1. import React, { PureComponent } from "react";
  2. import classnames from "classnames";
  3. import iconAlipay from "../assets/kcxq_popovers_icon_alipay@2x.png";
  4. import iconWechatpay from "../assets/kcxq_popovers_icon_wechatpay@2x.png";
  5. import iconPaypal from "../assets/kcxq_popovers_icon_paypal@2x.png";
  6. import mobileIconAlipay from "../assets/payment_btn_pay_alipay@2x.png";
  7. import mobileIconWechatpay from "../assets/payment_btn_pay_wechatpay@2x.png";
  8. import mobileIconPaypal from "../assets/payment_btn_pay_paypal@2x.png";
  9. import styles from "./PayPlatformOptions.less";
  10. import { exportStyleSizeClass } from "../../Utils/utils";
  11. type PAY_CHANNEL_VALUE =
  12. | "PAYPAL_PAYPAL"
  13. | "ALI_WEB"
  14. | "ALI_WAP"
  15. | "WX_WAP"
  16. | "WX_NATIVE";
  17. interface PAY_CHANNEL_TYPE {
  18. PAYPAL: PAY_CHANNEL_VALUE;
  19. ALI_WEB: PAY_CHANNEL_VALUE;
  20. ALI_WAP: PAY_CHANNEL_VALUE;
  21. WX_WAP: PAY_CHANNEL_VALUE;
  22. WX_NATIVE: PAY_CHANNEL_VALUE;
  23. }
  24. interface Props {
  25. payitem: PAY_CHANNEL_VALUE;
  26. onPayItemChange: (value: PAY_CHANNEL_VALUE) => void;
  27. isMobile: boolean;
  28. size: "small" | "normal" | "large";
  29. withTitle: boolean;
  30. titleTxt?: string;
  31. locale: "zh" | "en";
  32. }
  33. export const PAY_CHANNEL: PAY_CHANNEL_TYPE = {
  34. PAYPAL: "PAYPAL_PAYPAL", // PAYPAL_LIVE
  35. ALI_WEB: "ALI_WEB",
  36. ALI_WAP: "ALI_WAP",
  37. WX_WAP: "WX_WAP",
  38. WX_NATIVE: "WX_NATIVE"
  39. };
  40. class PayPlatformOptions extends PureComponent<Props, {}> {
  41. render() {
  42. const {
  43. payitem,
  44. onPayItemChange,
  45. isMobile = false,
  46. size = "normal",
  47. withTitle = true,
  48. titleTxt,
  49. locale = "zh"
  50. } = this.props;
  51. let titleDOM = null;
  52. if (withTitle) {
  53. const titleResult = titleTxt || locale === 'zh' ? '支付方式' : 'Payment';
  54. titleDOM = (
  55. <div className={styles.label}>
  56. {titleResult}
  57. </div>
  58. );
  59. }
  60. if (isMobile) {
  61. return (
  62. <div>
  63. {titleDOM}
  64. <div
  65. className={classnames(styles["payment-method-box"], {
  66. [styles.mobile]: isMobile
  67. })}
  68. >
  69. <div className={styles.flexContainer}>
  70. <div className={styles.flexItem}>
  71. <div
  72. className={classnames(
  73. {
  74. [styles.payitem]: true,
  75. [styles.active]: payitem === PAY_CHANNEL.ALI_WEB,
  76. ...exportStyleSizeClass(styles, size),
  77. },
  78. styles[locale]
  79. )}
  80. onClick={() => {
  81. onPayItemChange(PAY_CHANNEL.ALI_WEB);
  82. }}
  83. >
  84. <img
  85. src={mobileIconAlipay}
  86. alt="alipay"
  87. className={styles["payment-method"]}
  88. />
  89. <div className={styles.platformName}>
  90. 支付宝
  91. </div>
  92. </div>
  93. </div>
  94. <div className={styles.flexItem}>
  95. <div
  96. className={classnames(
  97. {
  98. [styles.payitem]: true,
  99. [styles.active]: payitem === PAY_CHANNEL.WX_NATIVE,
  100. ...exportStyleSizeClass(styles, size),
  101. },
  102. styles[locale]
  103. )}
  104. onClick={() => {
  105. onPayItemChange(PAY_CHANNEL.WX_NATIVE);
  106. }}
  107. >
  108. <img
  109. src={mobileIconWechatpay}
  110. alt="wechatpay"
  111. className={styles["payment-method"]}
  112. />
  113. <div className={styles.platformName}>
  114. 微信
  115. </div>
  116. </div>
  117. </div>
  118. <div className={styles.flexItem}>
  119. <div
  120. className={classnames(
  121. {
  122. [styles.payitem]: true,
  123. [styles.active]: payitem === PAY_CHANNEL.PAYPAL,
  124. ...exportStyleSizeClass(styles, size),
  125. },
  126. styles[locale]
  127. )}
  128. onClick={() => {
  129. onPayItemChange(PAY_CHANNEL.PAYPAL);
  130. }}
  131. >
  132. <img
  133. src={mobileIconPaypal}
  134. alt="paypal"
  135. className={styles["payment-method"]}
  136. />
  137. <div className={styles.platformName}>
  138. Paypal
  139. </div>
  140. </div>
  141. </div>
  142. </div>
  143. </div>
  144. </div>
  145. );
  146. }
  147. return (
  148. <div>
  149. {titleDOM}
  150. <div className={styles["payment-method-box"]}>
  151. <div className={styles.flexContainer}>
  152. <div className={styles.flexItem}>
  153. <div
  154. className={classnames(
  155. {
  156. [styles.payitem]: true,
  157. [styles.active]: payitem === PAY_CHANNEL.ALI_WEB,
  158. ...exportStyleSizeClass(styles, size),
  159. },
  160. styles[locale]
  161. )}
  162. onClick={() => {
  163. onPayItemChange(PAY_CHANNEL.ALI_WEB);
  164. }}
  165. >
  166. <span className={styles["payment-method-before"]} />
  167. <img
  168. src={iconAlipay}
  169. alt="alipay"
  170. className={styles["payment-method"]}
  171. />
  172. </div>
  173. </div>
  174. <div className={styles.flexItem}>
  175. <div
  176. className={classnames(
  177. {
  178. [styles.payitem]: true,
  179. [styles.active]: payitem === PAY_CHANNEL.WX_NATIVE,
  180. ...exportStyleSizeClass(styles, size),
  181. },
  182. styles[locale]
  183. )}
  184. onClick={() => {
  185. onPayItemChange(PAY_CHANNEL.WX_NATIVE);
  186. }}
  187. >
  188. <span className={styles["payment-method-before"]} />
  189. <img
  190. src={iconWechatpay}
  191. alt="wechatpay"
  192. className={styles["payment-method"]}
  193. />
  194. </div>
  195. </div>
  196. <div className={styles.flexItem}>
  197. <div
  198. className={classnames(
  199. {
  200. [styles.payitem]: true,
  201. [styles.active]: payitem === PAY_CHANNEL.PAYPAL,
  202. ...exportStyleSizeClass(styles, size),
  203. },
  204. styles[locale]
  205. )}
  206. onClick={() => {
  207. onPayItemChange(PAY_CHANNEL.PAYPAL);
  208. }}
  209. >
  210. <span className={styles["payment-method-before"]} />
  211. <img
  212. src={iconPaypal}
  213. alt="paypal"
  214. className={styles["payment-method"]}
  215. />
  216. </div>
  217. </div>
  218. </div>
  219. </div>
  220. </div>
  221. );
  222. }
  223. }
  224. export default PayPlatformOptions;