give-dialog.vue 51 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573
  1. <template>
  2. <div class="overlay" v-if="visible">
  3. <div class="content"
  4. :style="{
  5. height: dialogHeight + 'px',
  6. width: showComType != 'preview' ? '600px' : 'auto'}">
  7. <div class="pop-mask"
  8. v-show="showCurrencyPop"
  9. @click.stop="showCurrencyPop = false"></div>
  10. <!-- 头部 -->
  11. <div class="head">
  12. <div class="left">
  13. <!-- 关闭按钮 -->
  14. <div class="close-btn" @click="close">
  15. <img class="icon-close"
  16. :src="require('@/assets/svg/icon-close.svg')"
  17. v-if="showComType == 'default'"/>
  18. <img class="icon-close"
  19. :src="require('@/assets/svg/icon-back.svg')"
  20. v-else/>
  21. </div>
  22. <!-- 标题 -->
  23. <div class="title">
  24. {{ currentComData[showComType]["title"] }}
  25. </div>
  26. </div>
  27. <div class="right">
  28. <!-- 更多按钮 -->
  29. <img :src="require('@/assets/svg/icon-more-l.svg')"
  30. class="more"
  31. @click="showMoreOption = true">
  32. <div class="area-option"
  33. v-if="showMoreOption"
  34. @click="showMoreOption = false">
  35. <div class="option">
  36. <div class="item" @click="goTransactionsList()">
  37. <img :src="require('@/assets/svg/icon-menu.svg')">
  38. <span>Transaction History</span>
  39. </div>
  40. </div>
  41. </div>
  42. </div>
  43. </div>
  44. <!-- 内容 -->
  45. <div class="body">
  46. <img src="@/assets/gif/icon-guide-select.gif"
  47. class="icon-guide-select"
  48. v-if="!currentCurrencyInfo.currencyCode && showComType == 'default'">
  49. <!-- 充值组件 -->
  50. <top-up v-if="showComType == 'topUp'"
  51. :asyncIng="asyncIng"
  52. :currentCurrencyInfo="tempCurrentCurrencyInfo"
  53. @topUpDone="topUpDone"></top-up>
  54. <!-- 表单填写容器 -->
  55. <div class="body-content" v-if="showComType != 'topUp'">
  56. <!-- 货币列表 -->
  57. <div class="currency-pop" v-show="showCurrencyPop">
  58. <currency-list
  59. ref="currencyListDom"
  60. @selectCurrency="selectCurrency"
  61. @setCurrencyList="setCurrentCurrencyInfo"></currency-list>
  62. </div>
  63. <div class="left" v-if="showComType != 'preview'">
  64. <div class="gift-pack-wrapper">
  65. <img class="icon"
  66. :src="require('@/assets/svg/icon-gift-pack.svg')"/>
  67. </div>
  68. <div class="bottom">
  69. </div>
  70. </div>
  71. <div class="right"
  72. :class="{'fill-right': showComType == 'preview'}">
  73. <div class="form-wrapper" v-if="showComType == 'default'">
  74. <img
  75. class="img-mode"
  76. :src="require('@/assets/svg/img-mode.svg')"
  77. />
  78. <!-- 金额、数量 -->
  79. <div class="form-base">
  80. <div class="item currency-select-wrapper">
  81. <div
  82. class="label currency-select"
  83. :class="{'selected': currentCurrencyInfo.currencyCode}"
  84. @click="selectCurrencyPopHandle"
  85. >
  86. <img v-if="currentCurrencyInfo.iconPath"
  87. class="icon"
  88. :src="currentCurrencyInfo.iconPath"
  89. />
  90. <div class="text">
  91. {{currentCurrencyInfo.currencyCode == 'USD' ? 'USD' : currentCurrencyInfo.tokenSymbol || 'Select a reward'}}
  92. </div>
  93. <img
  94. class="arrow"
  95. :src="currentCurrencyInfo.currencyCode ?
  96. require('@/assets/svg/icon-form-arrow-down.svg') : require('@/assets/svg/icon-form-white-arrow-down.svg')
  97. "
  98. />
  99. </div>
  100. <input
  101. v-model="baseFormData.amountValue"
  102. placeholder="0"
  103. autofocus
  104. @input="onAmountInput"
  105. @blur="onAmountBlur"
  106. />
  107. </div>
  108. <div class="item">
  109. <div class="label">
  110. <img
  111. class="icon"
  112. :src="
  113. require('@/assets/svg/icon-winners.svg')
  114. "
  115. />
  116. Winners
  117. </div>
  118. <input
  119. v-model="baseFormData.totalCount"
  120. placeholder="0"
  121. @input="onCountInput"
  122. @blur="onCountBlur"
  123. />
  124. </div>
  125. </div>
  126. <!-- 刷新按钮、充值 -->
  127. <div class="form-base-help" v-show="currentCurrencyInfo.currencyCode">
  128. <div class="currency-operation">
  129. <div class="balance">
  130. <img
  131. :src="
  132. require('@/assets/svg/icon-balance.svg')
  133. "
  134. />
  135. Balance
  136. </div>
  137. <div class="amount">
  138. {{currentCurrencyInfo.balance}}
  139. <img
  140. :class="{ 'icon-refresh-rotate': refreshRotate }"
  141. @click="updateCurrencyBanlce"
  142. :src="
  143. require('@/assets/svg/icon-form-refresh.svg')
  144. "
  145. />
  146. </div>
  147. <div v-if="currentCurrencyInfo.currencyCode != 'USD'" class="top-up" @click="goTopUp">Deposit</div>
  148. </div>
  149. <div class="msg">
  150. Recommend winners 100~10000
  151. </div>
  152. </div>
  153. <div class="form-label">Tasks</div>
  154. <!-- 转推、like、关注 -->
  155. <div class="form-require">
  156. <div
  157. class="form-item"
  158. v-for="(item, index) in formList"
  159. :key="index"
  160. >
  161. <div class="label">
  162. <img
  163. class="icon"
  164. :src="item.icon"
  165. />
  166. {{ item.label }}
  167. </div>
  168. <div
  169. class="control"
  170. v-if="item.nodeType == 'textarea'"
  171. >
  172. <follow-input
  173. :isAddSelf="!isBack"
  174. :atUserList="atUserList"
  175. @addUser="addFollowUser"
  176. @setUser="setFollowUser"
  177. @delUser="delFollowUser"
  178. ></follow-input>
  179. </div>
  180. <el-switch
  181. v-if="item.type == 2"
  182. v-model="item.checked"
  183. />
  184. <img
  185. v-if="item.type == 3"
  186. :src="
  187. require('@/assets/svg/icon-option-checked.svg')
  188. "
  189. />
  190. </div>
  191. </div>
  192. <!-- 机器人 -->
  193. <!-- <div class="anti-bot-wrapper">
  194. <div class="label">
  195. <img
  196. :src="
  197. require('@/assets/svg/icon-anti-bot.svg')
  198. "
  199. class="icon-bot"
  200. />
  201. Anti Bot
  202. <img
  203. :src="
  204. require('@/assets/svg/icon-beta.svg')
  205. "
  206. class="icon-beta"
  207. />
  208. <img
  209. :src="
  210. require('@/assets/svg/icon-question.svg')
  211. "
  212. class="icon-question"
  213. />
  214. </div>
  215. <el-switch v-model="openAntiBot" />
  216. </div> -->
  217. <!-- 提示 -->
  218. <ul class="tips-wrapper">
  219. <li class="row">
  220. Rewards can only be claimed after the target user completes all tasks you set.
  221. </li>
  222. <li class="row">
  223. Each user can only receive a reward once per task.
  224. </li>
  225. <li class="row">
  226. The reward will expire in 7 days once issued. Please promote it as much as possible within this period. After the experiment, the remaining rewards will be returned to your DeNet Wallet.
  227. </li>
  228. </ul>
  229. <div class="submit-btn-wrapper">
  230. <div class="submit-btn"
  231. :class="{ 'disabled-submit': iptErrMsgTxt != '' && !depositGuide }"
  232. @click="confirm">
  233. <img
  234. class="icon-loading"
  235. v-if="submitIng"
  236. :src="
  237. require('@/assets/svg/icon-btn-loading.svg')
  238. "
  239. />
  240. {{iptErrMsgTxt ? iptErrMsgTxt : 'NEXT'}}
  241. </div>
  242. </div>
  243. </div>
  244. <!-- 预览 -->
  245. <template v-else-if="showComType == 'preview'">
  246. <preview-card
  247. :currentCurrencyInfo="currentCurrencyInfo"
  248. :postData="publishRes"
  249. :baseFormData="baseFormData"
  250. :amountFontSize="previewFontSize"
  251. ></preview-card>
  252. </template>
  253. <!-- paypal支付按钮 -->
  254. <div v-show="showComType == 'preview'">
  255. <paypal-button
  256. :finalAmountData="finalAmountData"
  257. :payConfig="{
  258. paypalClientId,
  259. feeDesc: payConfig.feeDesc,
  260. paypalHtml,
  261. amount: baseFormData.amountValue,
  262. postId
  263. }"
  264. :currentCurrencyInfo="currentCurrencyInfo"
  265. @payPalFinsh="payPalFinsh"
  266. ></paypal-button>
  267. </div>
  268. </div>
  269. </div>
  270. </div>
  271. </div>
  272. <!-- 提示 -->
  273. <message-box
  274. :dialogVisible="showMessageBox"
  275. :title="messageBoxData.title"
  276. :content="messageBoxData.content"
  277. @cancel="messageBoxCancel"
  278. @confirm="messageBoxConfirm"
  279. ></message-box>
  280. </div>
  281. </template>
  282. <script setup>
  283. import { ref, watch, reactive, defineProps, defineEmits, onMounted, nextTick } from "vue";
  284. import { postPublish, verifyPaypalResult, syncChainTokenRechargeRecord, getCurrencyInfoByCode } from "@/http/publishApi";
  285. import { payCalcFee, getPayConfig } from "@/http/pay";
  286. import { getFrontConfig } from "@/http/account";
  287. import {setChromeStorage, getChromeStorage} from "@/uilts/chromeExtension"
  288. import { throttle } from "@/uilts/help"
  289. import Report from "@/log-center/log"
  290. import { ElMessage, ElLoading } from "element-plus";
  291. import "element-plus/es/components/message/style/css";
  292. import {create, all} from "mathjs";
  293. import messageBox from "@/view/components/message-box.vue";
  294. import currencyList from "@/view/components/currency-list.vue";
  295. import previewCard from "@/view/iframe/publish/components/preview-card";
  296. import followInput from "@/view/iframe/publish/components/follow-input";
  297. import paypalButton from "@/view/iframe/publish/components/paypal-button";
  298. import topUp from "@/view/iframe/publish/components/top-up.vue";
  299. const config = {
  300. number: 'BigNumber',
  301. }
  302. const math = create(all, config);
  303. //临时货币信息
  304. let tempCurrentCurrencyInfo = ref({});
  305. let paypalClientId = ref("");
  306. let payConfig = ref({});
  307. let paypalHtml = ref("");
  308. // 发布后返回的结果
  309. let publishRes = reactive({});
  310. //弹窗是否展示
  311. let visible = ref(false);
  312. //弹窗高度
  313. let dialogHeight = ref(680);
  314. // 当前展示组件内容 default(表单) preview(预览) topUp(充值)
  315. let showComType = ref("default");
  316. let currentComData = {
  317. default: {
  318. title: "Giveaway",
  319. },
  320. preview: {
  321. title: "Preview",
  322. },
  323. topUp: {
  324. title: "Deposit",
  325. },
  326. };
  327. // 机器人开关
  328. let openAntiBot = ref(false);
  329. // 是否正在提交
  330. let submitIng = ref(false);
  331. // 艾特关注人列表
  332. let atUserList = ref([]);
  333. // 表单错误提示
  334. let iptErrMsgTxt = ref("Select a reward");
  335. // 是否返回
  336. let isBack = ref(false);
  337. // 展示消息提示
  338. let showMessageBox = ref(false);
  339. // 展示货币列表pop
  340. let showCurrencyPop = ref(false);
  341. // 展示更多按钮下的选项
  342. let showMoreOption = ref(false);
  343. // 货币列表的dom
  344. let currencyListDom = ref('');
  345. // 刷新按钮旋转
  346. let refreshRotate = ref(false);
  347. // 预览字体大小
  348. let previewFontSize = ref(56);
  349. let postId = ref('');
  350. // 余额是否同步中
  351. let asyncIng = ref(false);
  352. // 提交按钮-充值引导提示
  353. let depositGuide = ref(false);
  354. let messageBoxData = ref({
  355. title: "",
  356. content: "",
  357. });
  358. // 真实支付金额数据
  359. let finalAmountData = ref({
  360. currencyCode: '',
  361. feeAmountValue: 0,
  362. finalAmountValue: 0,
  363. requestAmountValue: 0,
  364. });
  365. // 表单数据
  366. let baseFormData = reactive({
  367. amountCurrencyCode: '',
  368. amountValue: "",
  369. totalCount: "",
  370. });
  371. // 当前选择的货币信息
  372. let currentCurrencyInfo = ref({
  373. currencyCode: "",
  374. currencyName: "",
  375. balance: "",
  376. currencyType: "",
  377. iconPath: "",
  378. minAmount: "",
  379. tokenChain: "",
  380. tokenSymbol: "",
  381. usdEstimateBalance: ""
  382. });
  383. let formList = reactive([
  384. {
  385. label: "Follow",
  386. icon: require("@/assets/svg/icon-follow.svg"),
  387. nodeType: "textarea",
  388. type: 1,
  389. text: [],
  390. checked: true,
  391. },
  392. {
  393. label: "Retweet",
  394. icon: require("@/assets/svg/icon-retweet.svg"),
  395. nodeType: "div",
  396. type: 3,
  397. checked: true,
  398. },
  399. {
  400. label: "Like Tweet",
  401. icon: require("@/assets/svg/icon-like.svg"),
  402. nodeType: "div",
  403. type: 2,
  404. checked: true,
  405. },
  406. ]);
  407. const props = defineProps({
  408. dialogVisible: {
  409. type: Boolean,
  410. default: false,
  411. },
  412. });
  413. watch(
  414. () => props.dialogVisible,
  415. (newVal) => {
  416. console.log("watch", newVal);
  417. visible.value = newVal;
  418. if (newVal) {
  419. Report.reportLog({
  420. pageSource: Report.pageSource.publisherDialog,
  421. businessType: Report.businessType.pageView,
  422. });
  423. getLocalCurrencyInfoByCode();
  424. setTimeout(() => {
  425. setDialogHeight();
  426. }, 300);
  427. }
  428. }
  429. );
  430. const emits = defineEmits(["close", "confirm", "payPalFinsh"]);
  431. const close = () => {
  432. if (showComType.value != "default") {
  433. showComType.value = "default";
  434. calcDomZoom();
  435. isBack.value = true;
  436. } else {
  437. initParams();
  438. emits("close", false);
  439. }
  440. };
  441. /**
  442. * 设置弹窗高度
  443. */
  444. const setDialogHeight = (resize = false) => {
  445. nextTick(() => {
  446. let clientHeight = window.innerHeight;
  447. let gapSafe = 40;
  448. console.log('resize',resize)
  449. if (dialogHeight.value > clientHeight - gapSafe) {
  450. dialogHeight.value = clientHeight - gapSafe;
  451. } else {
  452. if(resize) {
  453. dialogHeight.value = 680;
  454. }
  455. }
  456. })
  457. };
  458. const selectCurrencyPopHandle = () => {
  459. Report.reportLog({
  460. pageSource: Report.pageSource.currencySelectorPage,
  461. businessType: Report.businessType.pageView,
  462. });
  463. showCurrencyPop.value = true;
  464. nextTick(() => {
  465. if(currencyListDom.value) {
  466. currencyListDom.value.getCurrencyInfoList && currencyListDom.value.getCurrencyInfoList();
  467. }
  468. })
  469. }
  470. /**
  471. * 获取实际支付金额
  472. */
  473. const getPayAmount = async (amountValue) => {
  474. let res = await payCalcFee({
  475. params: {
  476. amountValue,
  477. currencyCode: currentCurrencyInfo.value.currencyCode,
  478. payChannel: 'paypal',
  479. },
  480. });
  481. if (res.code == 0) {
  482. let { finalAmountValue, feeDesc } = res.data;
  483. payConfig.value.feeDesc = feeDesc;
  484. if (finalAmountValue > 0) {
  485. finalAmountData.value = res.data;
  486. }
  487. }
  488. return res.data;
  489. };
  490. const confirm = () => {
  491. if(depositGuide.value) { //余额不够去充值
  492. goTopUp();
  493. return;
  494. }
  495. if (submitIng.value || iptErrMsgTxt.value) {
  496. return;
  497. }
  498. let { totalCount = 0 } = baseFormData;
  499. if (!totalCount) {
  500. return;
  501. }
  502. submitRequest();
  503. };
  504. /**
  505. * 货币列表-选中货币
  506. */
  507. const selectCurrency = (params) => {
  508. tempCurrentCurrencyInfo.value = params;
  509. depositGuide.value = false;
  510. if(params.currencyCode != "USD" && params.balance < params.minAmount) {
  511. let tokenSymbol = params.currencyCode == 'USD' ? 'USD' : params.tokenSymbol;
  512. messageBoxBlock({
  513. title: `Whether to deposit ${tokenSymbol}`,
  514. content: `Insufficient ${tokenSymbol} balance`,
  515. });
  516. } else {
  517. currentCurrencyInfo.value = params;
  518. setLocalSelectCurrencyInfo(currentCurrencyInfo.value);
  519. showCurrencyPop.value = false;
  520. finalAmountData.value.currencyCode = currentCurrencyInfo.value.currencyCode;
  521. calcDomZoom();
  522. resetFormIpt();
  523. onIptSetErrorTxt();
  524. }
  525. };
  526. const calcDomZoom = () => {
  527. nextTick(() => {
  528. let maxWidth = 68;
  529. var textWidth = document.querySelector('.text').offsetWidth;
  530. if(textWidth > 68) {
  531. var scale = maxWidth / textWidth;
  532. document.querySelector('.text').style.zoom = scale;
  533. }
  534. })
  535. }
  536. const resetFormIpt = () => {
  537. baseFormData.amountValue = "";
  538. baseFormData.totalCount = "";
  539. }
  540. const setLocalSelectCurrencyInfo = (params = {}) => {
  541. setChromeStorage({ selectCurrencyInfo : JSON.stringify(params)})
  542. }
  543. /**
  544. * 获取完货币列表
  545. */
  546. const setCurrentCurrencyInfo = (params) => {
  547. }
  548. const messageBoxBlock = ({ title = "", content = "" }) => {
  549. showMessageBox.value = true;
  550. messageBoxData.value.title = title;
  551. messageBoxData.value.content = content;
  552. };
  553. /**
  554. * 确定
  555. */
  556. const messageBoxConfirm = () => {
  557. showMessageBox.value = false;
  558. goTopUp();
  559. };
  560. /**
  561. * 取消
  562. */
  563. const messageBoxCancel = () => {
  564. currentCurrencyInfo.value = tempCurrentCurrencyInfo.value;
  565. setLocalSelectCurrencyInfo(currentCurrencyInfo.value);
  566. showMessageBox.value = false;
  567. showCurrencyPop.value = false;
  568. calcDomZoom();
  569. resetFormIpt();
  570. onIptSetErrorTxt();
  571. };
  572. /**
  573. * 去充值
  574. */
  575. const goTopUp = () => {
  576. Report.reportLog({
  577. pageSource: Report.pageSource.rechargePage,
  578. businessType: Report.businessType.pageView,
  579. });
  580. showComType.value = 'topUp';
  581. }
  582. /**
  583. * 充值done事件
  584. */
  585. const topUpDone = () => {
  586. currentCurrencyInfo.value = tempCurrentCurrencyInfo.value;
  587. asyncIng.value = true;
  588. depositGuide.value = false;
  589. asyncIng.value = false;
  590. showCurrencyPop.value = false;
  591. showComType.value = 'default';
  592. calcDomZoom();
  593. onIptSetErrorTxt()
  594. asyncTokenRechRecord((res) => {
  595. if(res.code == 0 && res.data && res.data.length) {
  596. let currencyInfo = res.data[0];
  597. if(currencyInfo.currencyCode == currentCurrencyInfo.value.currencyCode) {
  598. currentCurrencyInfo.value.balance = currencyInfo.balance;
  599. onIptSetErrorTxt()
  600. }
  601. }
  602. })
  603. }
  604. /**
  605. * 更新货币余额
  606. */
  607. const updateCurrencyBanlce = () => {
  608. if(!refreshRotate.value) {
  609. refreshRotate.value = true;
  610. setTimeout(() => {
  611. refreshRotate.value = false;
  612. }, 1000)
  613. }
  614. asyncTokenRechRecord((res) => {
  615. if(res.code == 0 && res.data && res.data.length) {
  616. let currencyInfo = res.data[0];
  617. if(currencyInfo.currencyCode == currentCurrencyInfo.value.currencyCode) {
  618. currentCurrencyInfo.value.balance = currencyInfo.balance;
  619. }
  620. }
  621. })
  622. }
  623. /**
  624. * 同步链上交易
  625. */
  626. const asyncTokenRechRecord = (cb) => {
  627. syncChainTokenRechargeRecord({
  628. params: {
  629. currencyCode: currentCurrencyInfo.value.currencyCode
  630. }
  631. }).then(res => {
  632. cb && cb(res)
  633. })
  634. }
  635. /**
  636. * 提交表单请求
  637. */
  638. const submitRequest = async () => {
  639. let { amountValue = 0, totalCount = 0 } = baseFormData;
  640. baseFormData.amountCurrencyCode = currentCurrencyInfo.value.currencyCode;
  641. // 组装提交参数
  642. formList[0]["text"] = atUserList.value;
  643. let finishConditions = [];
  644. for (let i = 0; i < formList.length; i++) {
  645. let item = {};
  646. item.type = formList[i]["type"];
  647. if (item.type == 1 && formList[i]["text"]) {
  648. // follow 参数
  649. let relatedUsers = formList[i]["text"];
  650. item.relatedUsers = relatedUsers;
  651. finishConditions.push(item);
  652. } else if (formList[i]["checked"]) {
  653. finishConditions.push(item);
  654. }
  655. }
  656. let receiveConditions = openAntiBot.value ? "" : [];
  657. // 提交参数
  658. let formData = {
  659. amountCurrencyCode: baseFormData.amountCurrencyCode,
  660. amountValue,
  661. totalCount,
  662. finishConditions,
  663. receiveConditions,
  664. payAmountValue: amountValue
  665. };
  666. submitIng.value = true;
  667. // 法币支付需要计算费率
  668. if(formData.amountCurrencyCode == "USD") {
  669. let payAmountRes = await getPayAmount(amountValue);
  670. formData["payAmountValue"] = payAmountRes.finalAmountValue;
  671. }
  672. let data = {
  673. params: {
  674. postBizData: JSON.stringify(formData),
  675. postSrc: 1, //1 twitter
  676. postType: 1, //1 红包
  677. },
  678. };
  679. postPublish(data).then((res) => {
  680. submitIng.value = false;
  681. if (res.code == 0) {
  682. publishRes = res.data;
  683. postId.value = res.data.postId;
  684. Report.reportLog({
  685. pageSource: Report.pageSource.previewPage,
  686. businessType: Report.businessType.pageView,
  687. });
  688. showComType.value = "preview";
  689. previewFontSize.value = calcFontSize(baseFormData.amountValue, 238, 56);
  690. isBack.value = false;
  691. } else {
  692. console.log(res);
  693. }
  694. })
  695. .catch((err) => {
  696. console.log(err);
  697. });
  698. };
  699. const calcFontSize = (str, domWidth, maxSize) => {
  700. let lenstr = str.length;
  701. let num = parseInt(domWidth / lenstr);
  702. let fontSize = num < maxSize ? num : maxSize
  703. return fontSize;
  704. }
  705. /**
  706. * 初始化提交参数
  707. */
  708. const initParams = () => {
  709. resetFormIpt();
  710. formList[0].text = [];
  711. atUserList.value = [];
  712. submitIng.value = false;
  713. isBack.value = false;
  714. showCurrencyPop.value = false;
  715. openAntiBot.value = false;
  716. tempCurrentCurrencyInfo.value = {};
  717. currentCurrencyInfo.value = {};
  718. };
  719. /**
  720. * 支付完成回调
  721. */
  722. const payPalFinsh = (params) => {
  723. let {payNetwork, payStatus} = params;
  724. // token 支付
  725. if(payNetwork == 'bsc') {
  726. payStatusHandle(payStatus);
  727. } else {
  728. // 法币支付
  729. let transaction = params.transaction;
  730. let loadingInstance = ElLoading.service({
  731. background: "rgba(0,0,0,.3)",
  732. });
  733. verifyPaypalResult({
  734. params: {
  735. paypalTransactionId: transaction.id,
  736. postId: publishRes.postId,
  737. paypalClientId: paypalClientId.value,
  738. },
  739. }).then((res) => {
  740. loadingInstance.close();
  741. if (res.code == 0) {
  742. if (res.data) {
  743. payStatusHandle(res.data.payStatus)
  744. }
  745. }
  746. })
  747. .catch(() => {
  748. loadingInstance.close();
  749. });
  750. }
  751. };
  752. const payStatusHandle = (payStatus) => {
  753. //支付状态 0:未支付,1:支付成功,2:支付失败,3:已关闭,4:已退款
  754. switch (payStatus) {
  755. case 1:
  756. emits("payPalFinsh", { publishRes });
  757. showComType.value = "default";
  758. initParams();
  759. break;
  760. case 2:
  761. // ElMessage({
  762. // message: "Pay Fail",
  763. // type: "warning",
  764. // });
  765. break;
  766. case 3:
  767. // ElMessage({
  768. // message: "Pay Exceptions",
  769. // type: "warning",
  770. // });
  771. break;
  772. case 4:
  773. // ElMessage({
  774. // message: "Pay Exceptions",
  775. // type: "warning",
  776. // });
  777. break;
  778. }
  779. }
  780. /**
  781. * follow组件触发新增关注人
  782. */
  783. const addFollowUser = (params) => {
  784. atUserList.value.push(params);
  785. };
  786. const setFollowUser = (params) => {
  787. atUserList.value[params.index]["name"] = params.name;
  788. };
  789. const delFollowUser = (params) => {
  790. atUserList.value.splice(params.index, 1);
  791. };
  792. const onAmountInput = () => {
  793. let val = baseFormData.amountValue;
  794. // val = val.replace(/[^\d^\.]+/g, "");
  795. val = val.replace(/^\D*(\d*(?:\.\d{0,18})?).*$/g, '$1');
  796. if(val == '00') {
  797. val = '0'
  798. }
  799. if(val.indexOf('.') > -1){ //校验 例:00.12 => 0.12
  800. let arr = val.split('.');
  801. if(arr[0].startsWith('0')) {
  802. let num = +arr[0];
  803. val = num + '.' + arr[1];
  804. }
  805. }
  806. baseFormData.amountValue = val;
  807. setInputErrorMsg({from: 'amount', type:'input'});
  808. return val;
  809. };
  810. const onCountInput = () => {
  811. let val = baseFormData.totalCount;
  812. if (val == 0) {
  813. val = "";
  814. }
  815. // val = val.replace(/[^\d]/g, "");
  816. val = val.replace(/^\D*(\d*(?:\.\d{0,18})?).*$/g, '$1');
  817. baseFormData.totalCount = val;
  818. setInputErrorMsg({from: 'count', type:'input'});
  819. return val;
  820. };
  821. /**
  822. * 金额输入失焦
  823. */
  824. const onAmountBlur = () => {
  825. setInputErrorMsg({from: 'amount', type:'blur'});
  826. };
  827. /**
  828. * count失焦,校验输入结果
  829. */
  830. const onCountBlur = () => {
  831. setInputErrorMsg({from: 'count', type:'blur'});
  832. };
  833. /**
  834. * 输入结果金额和数量 (金额/数量)是否小于最小货币单位
  835. */
  836. const calcIptValue = (cb) => {
  837. let amountValue = baseFormData.amountValue;
  838. let totalCount = baseFormData.totalCount;
  839. let flag = true;
  840. if (!amountValue || !totalCount) {
  841. return {
  842. flag
  843. };
  844. }
  845. // let num = amountValue, scale = 1;
  846. // if(amountValue.indexOf('.') > -1) {
  847. // num = amountValue.toString();
  848. // let obj = scaleNumber(num);
  849. // num = obj.val;
  850. // scale = obj.scale;
  851. // }
  852. // let minAmount = currentCurrencyInfo.value.minAmount;
  853. // // 输入的token数量或者法币金额,平均分到每个红包,是否小于最小单位
  854. // if (num / totalCount < minAmount * scale) {
  855. // flag = false;
  856. // }
  857. // return {
  858. // flag,
  859. // count: Math.floor((num / minAmount * scale)/ (scale * scale))
  860. // };
  861. // console.log('baseFormData',`${baseFormData.amountValue} / ${baseFormData.totalCount}`)
  862. if (math.format(math.evaluate(`${baseFormData.amountValue} / ${baseFormData.totalCount}`)) < +currentCurrencyInfo.value.minAmount) {
  863. flag = false;
  864. }
  865. return {
  866. flag,
  867. count: Math.floor(math.format(math.evaluate(`${baseFormData.amountValue} / ${currentCurrencyInfo.value.minAmount}`)))
  868. }
  869. };
  870. /**
  871. * 设置输入提示语
  872. */
  873. const setInputErrorMsg = (params) => {
  874. // let amountValue = baseFormData.amountValue;
  875. // let num = amountValue, scale = 1;
  876. // if(amountValue.indexOf('.') > -1) {
  877. // num = amountValue.toString();
  878. // let obj = scaleNumber(num);
  879. // num = obj.val;
  880. // scale = obj.scale;
  881. // }
  882. onIptSetErrorTxt(params);
  883. };
  884. /**
  885. * 输入时 检测设置错误信息
  886. */
  887. const onIptSetErrorTxt = (params) => {
  888. depositGuide.value = false;
  889. if(!currentCurrencyInfo.value.currencyCode) {
  890. iptErrMsgTxt.value = "Select a reward"
  891. } else if (!baseFormData.amountValue || baseFormData.amountValue == '0') {
  892. iptErrMsgTxt.value = "Enter an amount";
  893. } else if (!baseFormData.totalCount || baseFormData.totalCount == '0') {
  894. iptErrMsgTxt.value = "Enter the number of winners";
  895. } else if(+baseFormData.amountValue <= +currentCurrencyInfo.value.balance) {
  896. let res = calcIptValue();
  897. if (!res.flag) {
  898. iptErrMsgTxt.value = `${baseFormData.amountValue} ${currentCurrencyInfo.value.tokenSymbol} Can send up to ${res.count} winners`;
  899. } else {
  900. iptErrMsgTxt.value = "";
  901. }
  902. } else if(currentCurrencyInfo.value.currencyCode != 'USD') {
  903. depositGuide.value = true;
  904. iptErrMsgTxt.value = `Insufficient ${currentCurrencyInfo.value.tokenSymbol} balance, please deposit`;
  905. }
  906. }
  907. /**
  908. * 获取支付配置(paypalClientId)
  909. */
  910. const setPayConfig = () => {
  911. getPayConfig({
  912. params: {},
  913. }).then((res) => {
  914. if (res.code == 0) {
  915. payConfig.value = res.data;
  916. paypalClientId.value = res.data.paypalClientId;
  917. }
  918. });
  919. };
  920. /**
  921. * 获取配置
  922. */
  923. const setFrontConfig = () => {
  924. getFrontConfig({
  925. params: {},
  926. }).then((res) => {
  927. if (res.code == 0) {
  928. paypalHtml.value = res.data.paypalHtml;
  929. }
  930. });
  931. };
  932. const goTransactionsList = () => {
  933. window.open(`${chrome.runtime.getURL('/iframe/home.html#/transactions')}`)
  934. }
  935. /**
  936. * 默认获取上次选中的货币信息
  937. */
  938. const getLocalCurrencyInfoByCode = () => {
  939. if(!currentCurrencyInfo.value.currencyCode) {
  940. getChromeStorage('selectCurrencyInfo', (res) => {
  941. if(res && res.currencyCode) {
  942. getCurrencyInfoByCode({
  943. params: {
  944. currencyCode: res.currencyCode
  945. }
  946. }).then(res => {
  947. if(res.code == 0 && res.data) {
  948. currentCurrencyInfo.value = res.data;
  949. tempCurrentCurrencyInfo.value = res.data;
  950. onIptSetErrorTxt();
  951. }
  952. });
  953. }
  954. })
  955. }
  956. }
  957. onMounted(() => {
  958. setFrontConfig();
  959. setPayConfig();
  960. getLocalCurrencyInfoByCode();
  961. document.onkeydown = function (e) {
  962. var keyNum = window.event ? e.keyCode : e.which;
  963. let escKey = 27;
  964. if (keyNum == escKey) {
  965. if (visible.value) {
  966. // close();
  967. }
  968. }
  969. };
  970. window.addEventListener('resize', function () {
  971. setDialogHeight(true);
  972. })
  973. });
  974. </script>
  975. <style lang="scss" scoped>
  976. .overlay {
  977. position: fixed;
  978. top: 0;
  979. right: 0;
  980. bottom: 0;
  981. left: 0;
  982. z-index: 2000;
  983. height: 100%;
  984. background-color: rgba(0, 0, 0, 0.5);
  985. overflow: auto;
  986. .content {
  987. height: 620px;
  988. background: #ffffff;
  989. border-radius: 20px;
  990. position: absolute;
  991. left: 50%;
  992. top: 50%;
  993. transform: translate(-50%, -50%);
  994. box-sizing: border-box;
  995. .pop-mask {
  996. width: 100%;
  997. height:100%;
  998. position: absolute;
  999. z-index:900;
  1000. }
  1001. .head {
  1002. border-bottom: 1px solid #ececec;
  1003. height: 48px;
  1004. box-sizing: border-box;
  1005. display: flex;
  1006. align-items: center;
  1007. justify-content: space-between;
  1008. padding: 0 14px;
  1009. .left {
  1010. display: flex;
  1011. align-items: center;
  1012. .title {
  1013. font-size: 16px;
  1014. font-weight: 500;
  1015. }
  1016. .close-btn {
  1017. display: flex;
  1018. align-items: center;
  1019. width: max-content;
  1020. margin-right: 12px;
  1021. cursor: pointer;
  1022. }
  1023. }
  1024. .right {
  1025. .more {
  1026. cursor: pointer;
  1027. }
  1028. .area-option {
  1029. width: 100%;
  1030. height: 100%;
  1031. position: absolute;
  1032. top: 0;
  1033. left: 0;
  1034. z-index: 111;
  1035. .option {
  1036. position: absolute;
  1037. top: 43px;
  1038. right: 15px;
  1039. background: #fff;
  1040. filter: drop-shadow(0px 3px 20px rgba(0, 0, 0, 0.2));
  1041. width: 240px;
  1042. border-radius: 15px;
  1043. overflow: hidden;
  1044. .item {
  1045. width: 100%;
  1046. height: 50px;
  1047. display: flex;
  1048. align-items: center;
  1049. cursor: pointer;
  1050. border-top: 1px solid #E9E9E9;
  1051. img {
  1052. margin-left: 15px;
  1053. width: 30px;
  1054. height: 30px;
  1055. margin-right: 6px;
  1056. }
  1057. span {
  1058. font-weight: 500;
  1059. font-size: 14px;
  1060. }
  1061. }
  1062. .item:first-child {
  1063. border-top: 0;
  1064. }
  1065. .item:hover {
  1066. background: #F5F5F5;
  1067. }
  1068. }
  1069. }
  1070. }
  1071. }
  1072. .body {
  1073. box-sizing: border-box;
  1074. height: calc(100% - 48px);
  1075. display: flex;
  1076. position: relative;
  1077. .icon-guide-select {
  1078. width: 40px;
  1079. position: absolute;
  1080. top: 78px;
  1081. left: 25px;
  1082. z-index: 1000;
  1083. }
  1084. .body-content {
  1085. display:flex;
  1086. width:100%;
  1087. }
  1088. .currency-pop {
  1089. position: absolute;
  1090. width: 375px;
  1091. height: 480px;
  1092. top: 85px;
  1093. left: 88px;
  1094. z-index: 1000;
  1095. box-shadow: 0px 4px 30px rgba(0, 0, 0, 0.3);
  1096. background-color: #fff;
  1097. border-radius: 20px;
  1098. overflow-y: scroll;
  1099. }
  1100. .left,
  1101. .right {
  1102. height: 100%;
  1103. }
  1104. .left {
  1105. width: 50px;
  1106. display: flex;
  1107. flex-direction: column;
  1108. justify-content: space-between;
  1109. align-items: center;
  1110. .gift-pack-wrapper {
  1111. width: 100%;
  1112. height: 55px;
  1113. background: #f5f5f5;
  1114. display: flex;
  1115. align-items: center;
  1116. justify-content: center;
  1117. }
  1118. .bottom {
  1119. .icon {
  1120. display: block;
  1121. margin-bottom: 26px;
  1122. }
  1123. }
  1124. }
  1125. .right {
  1126. width: calc(100% - 50px);
  1127. box-sizing: border-box;
  1128. position: relative;
  1129. border-left: 1px solid #ececec;
  1130. .form-wrapper {
  1131. padding: 0px 18px 18px 18px;
  1132. height: calc(100% - 80px);
  1133. overflow-y: scroll;
  1134. overflow-x: hidden;
  1135. box-sizing: border-box;
  1136. .img-mode {
  1137. margin-left: -18px;
  1138. }
  1139. .form-base-help {
  1140. display: flex;
  1141. justify-content: space-between;
  1142. margin-top: 10px;
  1143. .currency-operation:before{
  1144. box-sizing: content-box;
  1145. width: 0px;
  1146. height: 0px;
  1147. position: absolute;
  1148. top: -16px;;
  1149. left:46px;
  1150. padding:0;
  1151. border-bottom:8px solid #FFFFFF;
  1152. border-top:8px solid transparent;
  1153. border-left:8px solid transparent;
  1154. border-right:8px solid transparent;
  1155. display: block;
  1156. content:'';
  1157. z-index: 12;
  1158. }
  1159. .currency-operation:after{
  1160. box-sizing: content-box;
  1161. width: 0px;
  1162. height: 0px;
  1163. position: absolute;
  1164. top: -18px;;
  1165. left:45px;
  1166. padding:0;
  1167. border-bottom:9px solid #EAEAEA;
  1168. border-top:9px solid transparent;
  1169. border-left:9px solid transparent;
  1170. border-right:9px solid transparent;
  1171. display: block;
  1172. content:'';
  1173. z-index:10
  1174. }
  1175. .currency-operation {
  1176. position: relative;
  1177. height: 36px;
  1178. border: 1px solid #EAEAEA;
  1179. box-sizing: border-box;
  1180. padding: 10px;
  1181. display: flex;
  1182. align-items: center;
  1183. border-radius: 100px;
  1184. .balance,
  1185. .amount {
  1186. display: flex;
  1187. align-items: center;
  1188. }
  1189. .balance {
  1190. font-weight: 400;
  1191. font-size: 13px;
  1192. img {
  1193. width: 16px;
  1194. height: 16px;
  1195. margin-right: 3px;
  1196. }
  1197. }
  1198. .amount {
  1199. font-weight: 500;
  1200. font-size: 13px;
  1201. color: #4e4e4e;
  1202. margin-left: 5px;
  1203. img {
  1204. margin-left: 5px;
  1205. cursor: pointer;
  1206. }
  1207. }
  1208. .top-up {
  1209. font-weight: 500;
  1210. font-size: 12px;
  1211. color: #ff9839;
  1212. cursor: pointer;
  1213. margin-left: 8px;
  1214. }
  1215. .icon-refresh-rotate {
  1216. transform: rotate(360deg);
  1217. transition-duration: 1s;
  1218. }
  1219. }
  1220. .msg {
  1221. font-weight: 400;
  1222. font-size: 12px;
  1223. color: #acacac;
  1224. }
  1225. }
  1226. .form-base {
  1227. display: flex;
  1228. justify-content: space-between;
  1229. align-items: center;
  1230. margin-top: 14px;
  1231. .item {
  1232. width: 250px;
  1233. height: 50px;
  1234. box-sizing: border-box;
  1235. border-radius: 14px;
  1236. border: 1px solid #D1D9DD;
  1237. display: flex;
  1238. align-items: center;
  1239. justify-content: space-between;
  1240. padding: 16px 14px;
  1241. input {
  1242. width: 102px;
  1243. text-align: right;
  1244. font-weight: 500;
  1245. font-size: 18px;
  1246. border: none;
  1247. outline: none;
  1248. box-sizing: border-box;
  1249. }
  1250. input::placeholder {
  1251. color: #c5c5c5;
  1252. }
  1253. .label {
  1254. font-weight: 500;
  1255. font-size: 15px;
  1256. display: flex;
  1257. align-items: center;
  1258. .icon {
  1259. width: 20px;
  1260. height: 20px;
  1261. margin-right: 8px;
  1262. }
  1263. }
  1264. }
  1265. .item:first-child {
  1266. margin-right: 14px
  1267. }
  1268. .currency-select-wrapper {
  1269. padding: 0 !important;
  1270. input {
  1271. padding-right: 14px;
  1272. }
  1273. .currency-select {
  1274. max-width: 136px;
  1275. cursor: pointer;
  1276. background: #1D9BF0;
  1277. margin-left: 6px;
  1278. padding: 6px 10px;
  1279. border-radius: 12px;
  1280. color: #fff;
  1281. .text {
  1282. white-space: nowrap;
  1283. zoom: 0.85;
  1284. }
  1285. .arrow {
  1286. margin-left: 5px;
  1287. }
  1288. }
  1289. .selected {
  1290. background: #F4F4F4 !important;
  1291. color: #000 !important;
  1292. }
  1293. }
  1294. }
  1295. .form-label {
  1296. margin-top: 14px;
  1297. margin-bottom: 10px;
  1298. font-weight: 500;
  1299. font-size: 14px;
  1300. }
  1301. .form-require {
  1302. box-sizing: border-box;
  1303. border-radius: 15px;
  1304. margin-top: 12px;
  1305. border: 1px solid #D1D9DD;
  1306. .form-item {
  1307. min-height: 50px;
  1308. display: flex;
  1309. align-items: center;
  1310. justify-content: space-between;
  1311. margin: 0 16px;
  1312. border-bottom: 1px solid #ececec;
  1313. .label {
  1314. min-width: 88px;
  1315. display: flex;
  1316. align-items: center;
  1317. font-size: 15px;
  1318. font-weight: 500;
  1319. .icon {
  1320. margin-right: 10px;
  1321. }
  1322. }
  1323. .control {
  1324. width: 100%;
  1325. min-height: 50px;
  1326. margin-left: 18px;
  1327. box-sizing: border-box;
  1328. }
  1329. }
  1330. .form-item:last-child {
  1331. border-bottom: none !important;
  1332. }
  1333. }
  1334. }
  1335. .anti-bot-wrapper {
  1336. width: 100%;
  1337. height: 50px;
  1338. display: flex;
  1339. align-items: center;
  1340. justify-content: space-between;
  1341. box-sizing: border-box;
  1342. border-radius: 15px;
  1343. padding: 0 18px;
  1344. margin-top: 14px;
  1345. border: 1px solid #D1D9DD;
  1346. .label {
  1347. display: flex;
  1348. align-items: center;
  1349. font-size: 15px;
  1350. font-weight: 500;
  1351. .icon-bot {
  1352. margin-right: 8px;
  1353. }
  1354. .icon-beta {
  1355. margin-left: 5px;
  1356. margin-right: 8px;
  1357. }
  1358. .icon-question {
  1359. cursor: pointer;
  1360. }
  1361. }
  1362. }
  1363. .tips-wrapper {
  1364. margin: 16px 0 0 12px !important;
  1365. padding: 0px !important;
  1366. .title,
  1367. .row {
  1368. font-weight: 400;
  1369. font-size: 12px;
  1370. color: #A39F9F;
  1371. }
  1372. .row {
  1373. box-sizing: border-box;
  1374. line-height: 16px;
  1375. }
  1376. .more {
  1377. color: #1D9BF0;
  1378. font-size: 13px;
  1379. padding-left: 4px;
  1380. cursor: pointer;
  1381. }
  1382. }
  1383. .submit-btn-wrapper {
  1384. width: 100%;
  1385. background: #fff;
  1386. position: absolute;
  1387. bottom: 18px;
  1388. left: 0;
  1389. box-sizing: border-box;
  1390. padding: 16px 18px 0 18px;
  1391. .submit-btn {
  1392. width: 100%;
  1393. height: 46px;
  1394. text-align: center;
  1395. background: #4a99e9;
  1396. border-radius: 100px;
  1397. color: #fff;
  1398. display: flex;
  1399. align-items: center;
  1400. justify-content: center;
  1401. font-size: 16px;
  1402. font-weight: 500;
  1403. cursor: pointer;
  1404. .icon-loading {
  1405. width: 20px;
  1406. height: 20px;
  1407. margin-right: 3px;
  1408. }
  1409. }
  1410. .disabled-submit {
  1411. background-color: #D9D9D9;
  1412. }
  1413. }
  1414. }
  1415. .fill-right {
  1416. width: 100% !important;
  1417. border-bottom-left-radius: 16px;
  1418. }
  1419. }
  1420. }
  1421. }
  1422. </style>