give-dialog.vue 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774
  1. <template>
  2. <div class="overlay" v-if="visible">
  3. <div class="content"
  4. :style="{height: dialogHeight +'px' }">
  5. <div class="head">
  6. <div class="left">
  7. <div class="close-btn" @click="close">
  8. <img class="icon-close" v-if="!showPreview" :src="require('../../assets/svg/icon-close.svg')" />
  9. <img class="icon-close" v-else :src="require('../../assets/svg/icon-back.svg')" />
  10. </div>
  11. <div class="title">
  12. Giveaways
  13. </div>
  14. </div>
  15. <!-- <img class="icon-question" :src="require('../../assets/svg/icon-question.svg')"> -->
  16. </div>
  17. <div class="body">
  18. <div class="left">
  19. <div class="gift-pack-wrapper">
  20. <img class="icon" :src="require('../../assets/svg/icon-gift-pack.svg')">
  21. </div>
  22. <div class="bottom">
  23. <!-- <img class="icon" :src="require('../../assets/svg/icon-wallet.svg')">
  24. <img class="icon" :src="require('../../assets/svg/icon-setting.svg')"> -->
  25. </div>
  26. </div>
  27. <div class="right">
  28. <template v-if="!showPreview">
  29. <div class="form-wrapper">
  30. <div class="error-msg">
  31. {{iptErrMsgTxt}}
  32. </div>
  33. <div class="form-base">
  34. <div class="item">
  35. <div class="label">
  36. <img class="icon"
  37. :src="require('../../assets/svg/icon-usd.svg')" />
  38. USD
  39. </div>
  40. <el-input
  41. v-model="baseFormData.amountValue"
  42. placeholder="Amount entered"
  43. autofocus
  44. @input = "onUsdInput"
  45. @blur = "onUsdBlur"
  46. :input-style="{ 'box-shadow': 'none','padding': '1px', 'width': '110px', 'text-align': 'right', 'font-size' : '15px', 'color': '#000' }"/>
  47. </div>
  48. <div class="item">
  49. <div class="label">
  50. <img class="icon"
  51. :src="require('../../assets/svg/icon-quantity.svg')" />
  52. Quantity
  53. </div>
  54. <el-input
  55. v-model="baseFormData.totalCount"
  56. placeholder="Quantity entered"
  57. @input = "onCountInput"
  58. @blur = "onCountBlur"
  59. :input-style="{ 'box-shadow': 'none','padding': '1px', 'width': '120px',
  60. 'text-align': 'right', 'font-size' : '15px', 'color': '#000'}"/>
  61. </div>
  62. </div>
  63. <div class="form-label">
  64. Requirement
  65. </div>
  66. <div class="form-require">
  67. <div
  68. class="form-item"
  69. v-for="(item, index) in formList"
  70. :key="index">
  71. <div class="label">
  72. <img class="icon"
  73. :src="item.icon" />
  74. {{ item.label }}
  75. </div>
  76. <div class="control" v-if="item.nodeType == 'textarea'">
  77. <follow-input
  78. :isAddSelf="!isBack"
  79. :atUserList="atUserList"
  80. @addUser="addFollowUser" @setUser="setFollowUser"
  81. @delUser="delFollowUser"></follow-input>
  82. </div>
  83. <el-switch v-if="item.type == 2" v-model="item.checked" />
  84. </div>
  85. </div>
  86. <div class="anti-bot-wrapper">
  87. <div class="label">
  88. <img :src="require('../../assets/svg/icon-anti-bot.svg')" class="icon-bot">
  89. Anti Bot
  90. <img :src="require('../../assets/svg/icon-beta.svg')" class="icon-beta">
  91. <img :src="require('../../assets/svg/icon-question.svg')" class="icon-question">
  92. </div>
  93. <el-switch v-model="openAntiBot" />
  94. </div>
  95. <div class="tips-wrapper">
  96. <div class="title">
  97. TIPS
  98. </div>
  99. <div class="row">
  100. 1. Only after the user completes the tasks you set, they can claim your red envelopes
  101. </div>
  102. <div class="row">
  103. 2. Each user can only receive one red envelope
  104. </div>
  105. <div class="row">
  106. 3. The red envelope issued is valid for 7 days. Please promote your red envelope as much as possible within the validity period. After the red envelope expires, the red envelope will be returned to your DeNet wallet.
  107. </div>
  108. <div class="more">
  109. More
  110. </div>
  111. </div>
  112. <div class="submit-btn-wrapper">
  113. <div class="submit-btn" @click="confirm">
  114. <img class="icon-loading" v-if="submitIng" :src="require('../../assets/svg/icon-btn-loading.svg')" />
  115. NEXT
  116. </div>
  117. </div>
  118. </div>
  119. </template>
  120. <template v-if="showPreview">
  121. <preview-card :postData="publishRes" :baseFormData="baseFormData"></preview-card>
  122. </template>
  123. <div v-show="showPreview">
  124. <paypal-button
  125. :finalAmountData="finalAmountData"
  126. :payConfig="{
  127. paypalClientId,
  128. paypalHtml
  129. }"
  130. @payPalFinsh="payPalFinsh"></paypal-button>
  131. </div>
  132. </div>
  133. </div>
  134. </div>
  135. </div>
  136. </template>
  137. <script setup>
  138. import { ref, watch, reactive, defineProps, defineEmits, onMounted } from "vue";
  139. import {postPublish, verifyPaypalResult} from "../../http/publishApi"
  140. import {payCalcFee, getPayConfig} from "../../http/pay"
  141. import {getFrontConfig} from "../../http/account"
  142. import { ElMessage, ElLoading} from 'element-plus';
  143. import 'element-plus/es/components/message/style/css'
  144. import previewCard from "./preview-card";
  145. import paypalButton from "./paypal-button";
  146. import followInput from "./follow-input";
  147. let paypalClientId = ref('');
  148. let paypalHtml = ref('');
  149. let publishRes = reactive({})
  150. let visible = ref(false);
  151. let showPreview = ref(false);
  152. let openAntiBot = ref(false);
  153. let dialogHeight = ref(680);
  154. let submitIng = ref(false);
  155. let atUserList = ref([]);
  156. let iptErrMsgTxt = ref('');
  157. let isBack = ref(false);
  158. let finalAmountData = ref({
  159. currencyCode: "USD",
  160. feeAmountValue: 0,
  161. finalAmountValue: 0,
  162. requestAmountValue: 0
  163. })
  164. let baseFormData = reactive({
  165. amountCurrencyCode: "USD",
  166. amountValue: "",
  167. totalCount: "",
  168. });
  169. let formList = reactive([
  170. {
  171. label: "Follow",
  172. icon: require('../../assets/svg/icon-follow.svg'),
  173. nodeType: 'textarea',
  174. type: 1,
  175. text: [],
  176. checked: true
  177. },
  178. {
  179. label: "Retweet",
  180. icon: require('../../assets/svg/icon-retweet.svg'),
  181. nodeType: 'div',
  182. type: 3,
  183. checked: true
  184. },
  185. {
  186. label: "Like tweet",
  187. icon: require('../../assets/svg/icon-like.svg'),
  188. nodeType: 'div',
  189. type: 2,
  190. checked: true
  191. },
  192. ]);
  193. const props = defineProps({
  194. dialogVisible: {
  195. type: Boolean,
  196. default: false,
  197. },
  198. });
  199. watch(
  200. () => props.dialogVisible,
  201. (newVal) => {
  202. console.log("watch", newVal);
  203. visible.value = newVal;
  204. }
  205. );
  206. const emits = defineEmits(["close", "confirm", "payPalFinsh"]);
  207. const close = () => {
  208. if (showPreview.value) {
  209. showPreview.value = false;
  210. isBack.value = true;
  211. } else {
  212. initParams();
  213. emits("close", false);
  214. }
  215. };
  216. const setDialogHeight = () => {
  217. let clientHeight = document.documentElement.clientHeight;
  218. let gapSafe = 40;
  219. if(dialogHeight.value > clientHeight - gapSafe) {
  220. dialogHeight.value = clientHeight - gapSafe;
  221. }
  222. };
  223. const getPayAmount = (amountValue, cb) => {
  224. payCalcFee({
  225. params : {
  226. amountValue,
  227. currencyCode: "USD",
  228. payChannel: 1
  229. }
  230. }).then(res => {
  231. if(res.code == 0) {
  232. cb && cb(res.data);
  233. let {finalAmountValue} = res.data;
  234. if(finalAmountValue >= 100) {
  235. res.data.finalAmountValue = finalAmountValue / 100;
  236. finalAmountData.value = res.data
  237. }
  238. }
  239. })
  240. }
  241. const confirm = () => {
  242. if(submitIng.value) {
  243. return;
  244. }
  245. let {amountValue = 0, totalCount = 0, amountCurrencyCode} = baseFormData;
  246. if(!totalCount) {
  247. return;
  248. }
  249. amountValue = amountValue * 100; // 元转分
  250. formList[0]['text'] = atUserList.value;
  251. let finishConditions = [];
  252. for(let i = 0; i < formList.length; i++) {
  253. let item = {};
  254. item.type = formList[i]['type'];
  255. if(item.type == 1 && formList[i]['text']) { // follow 参数
  256. let relatedUsers = formList[i]['text'];
  257. item.relatedUsers = relatedUsers;
  258. finishConditions.push(item);
  259. } else if(formList[i]['checked']){
  260. finishConditions.push(item);
  261. }
  262. }
  263. let receiveConditions = openAntiBot.value ? '' : [];
  264. console.log('finishConditions', finishConditions);
  265. let formData = {
  266. amountCurrencyCode,
  267. amountValue,
  268. totalCount,
  269. finishConditions,
  270. receiveConditions
  271. }
  272. if(!calcIptValue()) {
  273. return;
  274. }
  275. submitIng.value = true;
  276. getPayAmount(amountValue, (res) => {
  277. formData['payAmountValue'] = res.finalAmountValue;
  278. let data = {
  279. params: {
  280. postBizData: JSON.stringify(formData),
  281. postSrc: 1, //1 twitter
  282. postType: 1, //1 红包
  283. }
  284. }
  285. postPublish(data).then((res) => {
  286. submitIng.value = false;
  287. if(res.code == 0) {
  288. publishRes = res.data;
  289. // setPreviewDialogHeight();
  290. showPreview.value = true;
  291. isBack.value = false;
  292. } else {
  293. console.log(res);
  294. }
  295. }).catch(err => {
  296. console.log(err);
  297. })
  298. });
  299. };
  300. const calcIptValue = (cb) => {
  301. let amountValue = baseFormData.amountValue;
  302. let totalCount = baseFormData.totalCount;
  303. let flag = true;
  304. if(!amountValue || !totalCount) {
  305. return flag;
  306. }
  307. //每人平均要分到大于 0.01美元(1美分)
  308. if(amountValue / totalCount < 1) {
  309. flag = false;
  310. }
  311. cb && cb(flag);
  312. return flag
  313. }
  314. const initParams = () => {
  315. baseFormData.amountValue = '';
  316. baseFormData.totalCount = '';
  317. formList[0].text = [];
  318. atUserList.value = [];
  319. submitIng.value = false;
  320. isBack.value = false;
  321. }
  322. const payPalFinsh = (params) => {
  323. let transaction = params.transaction;
  324. console.log('transaction', transaction)
  325. let loadingInstance = ElLoading.service({
  326. background: 'rgba(0,0,0,.3)'
  327. })
  328. verifyPaypalResult({
  329. params: {
  330. paypalTransactionId: transaction.id,
  331. postId: publishRes.postId,
  332. paypalClientId: paypalClientId.value
  333. }
  334. }).then((res) => {
  335. loadingInstance.close();
  336. if(res.code == 0) {
  337. //支付状态 0:未支付,1:支付成功,2:支付失败,3:已关闭,4:已退款
  338. if(res.data) {
  339. let payStatus = res.data.payStatus;
  340. switch (payStatus) {
  341. case 1:
  342. emits("payPalFinsh", {publishRes});
  343. showPreview.value = false;
  344. initParams();
  345. break;
  346. case 2:
  347. ElMessage({
  348. message: 'Pay Fail',
  349. type: 'warning',
  350. })
  351. break;
  352. case 3:
  353. ElMessage({
  354. message: 'Pay Exceptions',
  355. type: 'warning',
  356. })
  357. break;
  358. case 4:
  359. ElMessage({
  360. message: 'Pay Exceptions',
  361. type: 'warning',
  362. })
  363. break;
  364. }
  365. }
  366. }
  367. }).catch(() => {
  368. loadingInstance.close();
  369. })
  370. }
  371. const addFollowUser = (params) => {
  372. atUserList.value.push(params)
  373. }
  374. const setFollowUser = (params) => {
  375. atUserList.value[params.index]['name'] = params.name;
  376. }
  377. const delFollowUser = (params) => {
  378. atUserList.value.splice(params.index, 1);
  379. }
  380. const onUsdInput = (val) => {
  381. val = val.replace(/[^\d]/g,'');
  382. baseFormData.amountValue = val;
  383. setIptAmountErrorMsg();
  384. return val;
  385. }
  386. const onCountInput = (val) => {
  387. if(val == 0) {
  388. val = ''
  389. }
  390. val = val.replace(/[^\d]/g,'');
  391. if(val > 9999) {
  392. val = 9999;
  393. }
  394. baseFormData.totalCount = val;
  395. setIptAmountErrorMsg();
  396. return val;
  397. }
  398. const onUsdBlur = () => {
  399. if(!baseFormData.amountValue) {
  400. iptErrMsgTxt.value = 'Please enter the giveaways amount in USD input box.';
  401. } else {
  402. setIptAmountErrorMsg((res) => {
  403. if(res) {
  404. iptErrMsgTxt.value = '';
  405. }
  406. })
  407. }
  408. }
  409. const onCountBlur = () => {
  410. if(!baseFormData.amountValue) {
  411. iptErrMsgTxt.value = 'Please enter the number of giveaways in Quantity input box.';
  412. } else {
  413. setIptAmountErrorMsg((res) => {
  414. if(res) {
  415. iptErrMsgTxt.value = '';
  416. }
  417. })
  418. }
  419. }
  420. const setIptAmountErrorMsg = (cb) => {
  421. let res = calcIptValue();
  422. if(!res) {
  423. iptErrMsgTxt.value = 'If you wish to send {100} red packets, please send USD amount > {$1.00}';
  424. } else {
  425. iptErrMsgTxt.value = '';
  426. }
  427. cb && cb(res);
  428. }
  429. const setPayConfig = () => {
  430. getPayConfig({
  431. params: {}
  432. }).then(res => {
  433. if(res.code ==0) {
  434. paypalClientId.value = res.data.paypalClientId
  435. }
  436. })
  437. }
  438. const setFrontConfig = () => {
  439. getFrontConfig({
  440. params : {}
  441. }).then(res => {
  442. if(res.code == 0) {
  443. paypalHtml.value = res.data.paypalHtml
  444. }
  445. })
  446. }
  447. onMounted(() => {
  448. setFrontConfig();
  449. setDialogHeight();
  450. setPayConfig();
  451. document.onkeydown = function(e){
  452. var keyNum=window.event ? e.keyCode :e.which;
  453. let escKey = 27;
  454. if(keyNum == escKey) {
  455. if(visible.value) {
  456. close();
  457. }
  458. }
  459. console.log(keyNum)
  460. }
  461. })
  462. </script>
  463. <style lang="scss" scoped>
  464. .ql-container {
  465. height: 100px;
  466. }
  467. .overlay {
  468. position: fixed;
  469. top: 0;
  470. right: 0;
  471. bottom: 0;
  472. left: 0;
  473. z-index: 1000;
  474. height: 100%;
  475. background-color: rgba(0, 0, 0, 0.5);
  476. overflow: auto;
  477. .content {
  478. width: 650px;
  479. height: 620px;
  480. background: #ffffff;
  481. border-radius: 20px;
  482. position: absolute;
  483. left: 50%;
  484. top: 50%;
  485. transform: translate(-50%, -50%);
  486. box-sizing: border-box;
  487. .head {
  488. border-bottom: 1px solid #ececec;
  489. height: 48px;
  490. box-sizing: border-box;
  491. display: flex;
  492. align-items: center;
  493. justify-content: space-between;
  494. padding: 0 14px;
  495. .left {
  496. display: flex;
  497. .title {
  498. font-size: 16px;
  499. font-weight: 500;
  500. }
  501. .close-btn {
  502. display: flex;
  503. align-items: center;
  504. width: max-content;
  505. margin-right: 12px;
  506. cursor: pointer;
  507. }
  508. }
  509. .icon-question {
  510. cursor: pointer;
  511. }
  512. }
  513. .body {
  514. box-sizing: border-box;
  515. height: calc(100% - 48px);
  516. display: flex;
  517. .left,
  518. .right {
  519. height: 100%;
  520. }
  521. .left {
  522. width: 50px;
  523. display: flex;
  524. flex-direction: column;
  525. justify-content: space-between;
  526. align-items: center;
  527. .gift-pack-wrapper {
  528. width: 100%;
  529. height: 54px;
  530. background: #F5F5F5;
  531. display: flex;
  532. align-items: center;
  533. justify-content: center;
  534. }
  535. .bottom {
  536. .icon {
  537. display: block;
  538. margin-bottom: 26px;
  539. }
  540. }
  541. }
  542. .right {
  543. width: calc(100% - 50px);
  544. box-sizing: border-box;
  545. position: relative;
  546. border-left: 1px solid #ececec;
  547. .form-wrapper {
  548. padding: 8px 18px 26px 18px;
  549. height: calc(100% - 80px);
  550. overflow-y: scroll;
  551. box-sizing: border-box;
  552. .error-msg {
  553. font-size: 12px;
  554. color: #FF0000;
  555. margin-bottom: 8px;
  556. height: 16px;
  557. }
  558. .form-base {
  559. display: flex;
  560. justify-content: space-between;
  561. align-items: center;
  562. .item {
  563. width: 270px;
  564. height: 60px;
  565. box-sizing: border-box;
  566. border-radius: 15px;
  567. display: flex;
  568. align-items: center;
  569. justify-content: space-between;
  570. padding: 16px 14px;
  571. box-shadow: 0px 3px 27px 0px #0000001A;
  572. .label {
  573. font-weight: 500;
  574. font-size: 15px;
  575. display: flex;
  576. align-items: center;
  577. .icon {
  578. width: 20px;
  579. height: 20px;
  580. margin-right: 8px;
  581. }
  582. }
  583. }
  584. }
  585. .form-label {
  586. color: rgba(0, 0, 0, 0.4);
  587. margin-top: 23px;
  588. margin-bottom: 10px;
  589. font-weight: 500;
  590. font-size: 15px;
  591. }
  592. .form-require {
  593. box-sizing: border-box;
  594. border-radius: 15px;
  595. margin-top: 12px;
  596. box-shadow: 0px 3px 27px 0px #0000001A;
  597. .form-item {
  598. min-height: 60px;
  599. display: flex;
  600. align-items: center;
  601. justify-content: space-between;
  602. margin: 0 16px;
  603. border-bottom: 1px solid #ececec;
  604. .label {
  605. min-width: 88px;
  606. display: flex;
  607. align-items: center;
  608. font-size: 15px;
  609. font-weight: 500;
  610. .icon {
  611. margin-right: 10px;
  612. }
  613. }
  614. .control {
  615. width: 100%;
  616. min-height: 60px;
  617. margin-left: 18px;
  618. padding: 4px 0;
  619. box-sizing: border-box;
  620. }
  621. }
  622. }
  623. }
  624. .anti-bot-wrapper {
  625. width: 100%;
  626. height: 60px;
  627. display: flex;
  628. align-items: center;
  629. justify-content: space-between;
  630. box-sizing: border-box;
  631. border-radius: 15px;
  632. padding: 0 18px;
  633. margin-top: 14px;
  634. box-shadow: 0px 3px 27px 0px #0000001A;
  635. .label {
  636. display: flex;
  637. align-items: center ;
  638. font-size: 15px;
  639. font-weight: 500;
  640. .icon-bot {
  641. margin-right: 8px;
  642. }
  643. .icon-beta {
  644. margin-left: 5px;
  645. margin-right: 8px;
  646. }
  647. .icon-question {
  648. cursor: pointer;
  649. }
  650. }
  651. }
  652. .tips-wrapper {
  653. margin-top: 23px;
  654. .title, .row {
  655. font-weight: 400;
  656. font-size: 13px;
  657. color: rgba(0, 0, 0, 0.3);
  658. }
  659. .row {
  660. box-sizing: border-box;
  661. padding-left: 4px;
  662. }
  663. .more {
  664. color: #389AFF;
  665. font-size: 13px;
  666. padding-left: 4px;
  667. cursor: pointer;
  668. }
  669. }
  670. .submit-btn-wrapper {
  671. width: 100%;
  672. background: #fff;
  673. position: absolute;
  674. bottom: 32px;
  675. left: 0;
  676. box-sizing: border-box;
  677. padding-top: 16px;
  678. .submit-btn {
  679. width: calc(100% - 36px);
  680. height: 46px;
  681. text-align: center;
  682. line-height: 46px;
  683. background: #4a99e9;
  684. border-radius: 100px;
  685. color: #fff;
  686. margin-left: 18px;
  687. display: flex;
  688. align-items: center;
  689. justify-content: center;
  690. font-size: 16px;
  691. font-weight: 500;
  692. cursor: pointer;
  693. .icon-loading {
  694. width: 20px;
  695. height: 20px;
  696. margin-right: 3px;
  697. }
  698. }
  699. }
  700. }
  701. }
  702. }
  703. }
  704. </style>