give-dialog.vue 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719
  1. <template>
  2. <div class="overlay" v-if="visible">
  3. <div class="content"
  4. :style="{height: showPreview ? previewDialogHeight + 'px' : 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 :finalAmountData="finalAmountData" @payPalFinsh="payPalFinsh"></paypal-button>
  125. </div>
  126. </div>
  127. </div>
  128. </div>
  129. </div>
  130. </template>
  131. <script setup>
  132. import { ref, watch, reactive, defineProps, defineEmits, onMounted } from "vue";
  133. import {postPublish, verifyPaypalResult} from "../../http/publishApi"
  134. import {payCalcFee} from "../../http/pay"
  135. import { ElMessage } from 'element-plus';
  136. import 'element-plus/es/components/message/style/css'
  137. import previewCard from "./preview-card";
  138. import paypalButton from "./paypal-button";
  139. import followInput from "./follow-input";
  140. const paypalClientId = 'ASn7k0zqyS5AWYikVSfmamR-RFpjyU_QFJWSxOHHoWE04-RgHNO6nahn0GyHUaUAEBxj-aKgtSrq4O4G';
  141. let publishRes = reactive({})
  142. let visible = ref(false);
  143. let showPreview = ref(false);
  144. let openAntiBot = ref(false);
  145. let dialogHeight = ref(680);
  146. let previewDialogHeight = ref(680);
  147. let submitIng = ref(false);
  148. let atUserList = ref([]);
  149. let iptErrMsgTxt = ref('');
  150. let isBack = ref(false);
  151. let finalAmountData = ref({
  152. currencyCode: "USD",
  153. feeAmountValue: 0,
  154. finalAmountValue: 0,
  155. requestAmountValue: 0
  156. })
  157. let baseFormData = reactive({
  158. amountCurrencyCode: "USD",
  159. amountValue: "",
  160. totalCount: "",
  161. });
  162. let formList = reactive([
  163. {
  164. label: "Follow",
  165. icon: require('../../assets/svg/icon-follow.svg'),
  166. nodeType: 'textarea',
  167. type: 1,
  168. text: [],
  169. checked: true
  170. },
  171. {
  172. label: "Retweet",
  173. icon: require('../../assets/svg/icon-retweet.svg'),
  174. nodeType: 'div',
  175. type: 3,
  176. checked: true
  177. },
  178. {
  179. label: "Like tweet",
  180. icon: require('../../assets/svg/icon-like.svg'),
  181. nodeType: 'div',
  182. type: 2,
  183. checked: true
  184. },
  185. ]);
  186. const props = defineProps({
  187. dialogVisible: {
  188. type: Boolean,
  189. default: false,
  190. },
  191. });
  192. watch(
  193. () => props.dialogVisible,
  194. (newVal) => {
  195. console.log("watch", newVal);
  196. visible.value = newVal;
  197. }
  198. );
  199. const emits = defineEmits(["close", "confirm", "payPalFinsh"]);
  200. const close = () => {
  201. if (showPreview.value) {
  202. showPreview.value = false;
  203. isBack.value = true;
  204. } else {
  205. initParams();
  206. emits("close", false);
  207. }
  208. };
  209. const setPreviewDialogHeight = () => {
  210. let clientHeight = document.documentElement.clientHeight;
  211. let gapSafe = 40;
  212. if(previewDialogHeight.value > clientHeight - gapSafe) {
  213. previewDialogHeight.value = clientHeight - gapSafe;
  214. }
  215. };
  216. const getPayAmount = (amountValue, cb) => {
  217. payCalcFee({
  218. params : {
  219. amountValue,
  220. currencyCode: "USD",
  221. payChannel: 1
  222. }
  223. }).then(res => {
  224. if(res.code == 0) {
  225. cb && cb(res.data);
  226. let {finalAmountValue} = res.data;
  227. if(finalAmountValue >= 100) {
  228. res.data.finalAmountValue = finalAmountValue / 100;
  229. finalAmountData.value = res.data
  230. }
  231. }
  232. })
  233. }
  234. const confirm = () => {
  235. if(submitIng.value) {
  236. return;
  237. }
  238. let {amountValue = 0, totalCount = 0, amountCurrencyCode} = baseFormData;
  239. if(!totalCount) {
  240. return;
  241. }
  242. amountValue = amountValue * 100; // 元转分
  243. formList[0]['text'] = atUserList.value;
  244. let finishConditions = [];
  245. for(let i = 0; i < formList.length; i++) {
  246. let item = {};
  247. item.type = formList[i]['type'];
  248. if(item.type == 1 && formList[i]['text']) { // follow 参数
  249. let relatedUsers = formList[i]['text'];
  250. item.relatedUsers = relatedUsers;
  251. finishConditions.push(item);
  252. } else if(formList[i]['checked']){
  253. finishConditions.push(item);
  254. }
  255. }
  256. let receiveConditions = openAntiBot.value ? '' : [];
  257. console.log('finishConditions', finishConditions);
  258. let formData = {
  259. amountCurrencyCode,
  260. amountValue,
  261. totalCount,
  262. finishConditions,
  263. receiveConditions
  264. }
  265. if(!calcIptValue()) {
  266. return;
  267. }
  268. submitIng.value = true;
  269. getPayAmount(amountValue, (res) => {
  270. formData['payAmountValue'] = res.finalAmountValue;
  271. let data = {
  272. params: {
  273. postBizData: JSON.stringify(formData),
  274. postSrc: 1, //1 twitter
  275. postType: 1, //1 红包
  276. }
  277. }
  278. postPublish(data).then((res) => {
  279. submitIng.value = false;
  280. if(res.code == 0) {
  281. publishRes = res.data;
  282. // setPreviewDialogHeight();
  283. showPreview.value = true;
  284. isBack.value = false;
  285. } else {
  286. console.log(res);
  287. }
  288. }).catch(err => {
  289. console.log(err);
  290. })
  291. });
  292. };
  293. const calcIptValue = (cb) => {
  294. let amountValue = baseFormData.amountValue;
  295. let totalCount = baseFormData.totalCount;
  296. let flag = true;
  297. if(!amountValue || !totalCount) {
  298. return flag;
  299. }
  300. //每人平均要分到大于 0.01美元(1美分)
  301. if(amountValue / totalCount < 1) {
  302. flag = false;
  303. }
  304. cb && cb(flag);
  305. return flag
  306. }
  307. const initParams = () => {
  308. baseFormData.amountValue = '';
  309. baseFormData.totalCount = '';
  310. formList[0].text = [];
  311. atUserList.value = [];
  312. }
  313. const payPalFinsh = (params) => {
  314. let transaction = params.transaction;
  315. console.log('transaction', transaction)
  316. verifyPaypalResult({
  317. params: {
  318. paypalTransactionId: transaction.id,
  319. postId: publishRes.postId,
  320. paypalClientId: paypalClientId
  321. }
  322. }).then((res) => {
  323. if(res.code == 0) {
  324. //支付状态 0:未支付,1:支付成功,2:支付失败,3:已关闭,4:已退款
  325. if(res.data && res.data.payStatus == 1) {
  326. emits("payPalFinsh", {publishRes});
  327. showPreview.value = false;
  328. initParams();
  329. } else {
  330. ElMessage({
  331. message: 'pay error',
  332. type: 'warning',
  333. })
  334. }
  335. }
  336. })
  337. }
  338. const addFollowUser = (params) => {
  339. atUserList.value.push(params)
  340. }
  341. const setFollowUser = (params) => {
  342. atUserList.value[params.index]['name'] = params.name;
  343. }
  344. const delFollowUser = (params) => {
  345. atUserList.value.splice(params.index, 1);
  346. }
  347. const onUsdInput = (val) => {
  348. val = val.replace(/[^\d]/g,'');
  349. baseFormData.amountValue = val;
  350. setIptAmountErrorMsg();
  351. return val;
  352. }
  353. const onCountInput = (val) => {
  354. if(val == 0) {
  355. val = ''
  356. }
  357. val = val.replace(/[^\d]/g,'');
  358. if(val > 9999) {
  359. val = 9999;
  360. }
  361. baseFormData.totalCount = val;
  362. setIptAmountErrorMsg();
  363. return val;
  364. }
  365. const onUsdBlur = () => {
  366. if(!baseFormData.amountValue) {
  367. iptErrMsgTxt.value = 'Please enter the giveaways amount in USD input box.';
  368. } else {
  369. setIptAmountErrorMsg((res) => {
  370. if(res) {
  371. iptErrMsgTxt.value = '';
  372. }
  373. })
  374. }
  375. }
  376. const onCountBlur = () => {
  377. if(!baseFormData.amountValue) {
  378. iptErrMsgTxt.value = 'Please enter the number of giveaways in Quantity input box.';
  379. } else {
  380. setIptAmountErrorMsg((res) => {
  381. if(res) {
  382. iptErrMsgTxt.value = '';
  383. }
  384. })
  385. }
  386. }
  387. const setIptAmountErrorMsg = (cb) => {
  388. let res = calcIptValue();
  389. if(!res) {
  390. iptErrMsgTxt.value = 'If you wish to send {100} red packets, please send USD amount > {$1.00}';
  391. } else {
  392. iptErrMsgTxt.value = '';
  393. }
  394. cb && cb(res);
  395. }
  396. onMounted(() => {
  397. setPreviewDialogHeight();
  398. document.onkeydown = function(e){
  399. var keyNum=window.event ? e.keyCode :e.which;
  400. let escKey = 27;
  401. if(keyNum == escKey) {
  402. if(visible.value) {
  403. close();
  404. }
  405. }
  406. console.log(keyNum)
  407. }
  408. })
  409. </script>
  410. <style lang="scss" scoped>
  411. .ql-container {
  412. height: 100px;
  413. }
  414. .overlay {
  415. position: fixed;
  416. top: 0;
  417. right: 0;
  418. bottom: 0;
  419. left: 0;
  420. z-index: 1000;
  421. height: 100%;
  422. background-color: rgba(0, 0, 0, 0.5);
  423. overflow: auto;
  424. .content {
  425. width: 650px;
  426. height: 620px;
  427. background: #ffffff;
  428. border-radius: 20px;
  429. position: absolute;
  430. left: 50%;
  431. top: 50%;
  432. transform: translate(-50%, -50%);
  433. box-sizing: border-box;
  434. .head {
  435. border-bottom: 1px solid #ececec;
  436. height: 48px;
  437. box-sizing: border-box;
  438. display: flex;
  439. align-items: center;
  440. justify-content: space-between;
  441. padding: 0 14px;
  442. .left {
  443. display: flex;
  444. .title {
  445. font-size: 16px;
  446. font-weight: 500;
  447. }
  448. .close-btn {
  449. display: flex;
  450. align-items: center;
  451. width: max-content;
  452. margin-right: 12px;
  453. cursor: pointer;
  454. }
  455. }
  456. .icon-question {
  457. cursor: pointer;
  458. }
  459. }
  460. .body {
  461. box-sizing: border-box;
  462. height: calc(100% - 48px);
  463. display: flex;
  464. .left,
  465. .right {
  466. height: 100%;
  467. }
  468. .left {
  469. width: 50px;
  470. display: flex;
  471. flex-direction: column;
  472. justify-content: space-between;
  473. align-items: center;
  474. .gift-pack-wrapper {
  475. width: 100%;
  476. height: 54px;
  477. background: #F5F5F5;
  478. display: flex;
  479. align-items: center;
  480. justify-content: center;
  481. }
  482. .bottom {
  483. .icon {
  484. display: block;
  485. margin-bottom: 26px;
  486. }
  487. }
  488. }
  489. .right {
  490. width: calc(100% - 50px);
  491. box-sizing: border-box;
  492. position: relative;
  493. border-left: 1px solid #ececec;
  494. .form-wrapper {
  495. padding: 8px 18px 26px 18px;
  496. height: calc(100% - 80px);
  497. overflow-y: scroll;
  498. box-sizing: border-box;
  499. .error-msg {
  500. font-size: 12px;
  501. color: #FF0000;
  502. margin-bottom: 8px;
  503. height: 16px;
  504. }
  505. .form-base {
  506. display: flex;
  507. justify-content: space-between;
  508. align-items: center;
  509. .item {
  510. width: 270px;
  511. height: 60px;
  512. box-sizing: border-box;
  513. border-radius: 15px;
  514. display: flex;
  515. align-items: center;
  516. justify-content: space-between;
  517. padding: 16px 14px;
  518. box-shadow: 0px 3px 27px 0px #0000001A;
  519. .label {
  520. font-weight: 500;
  521. font-size: 15px;
  522. display: flex;
  523. align-items: center;
  524. .icon {
  525. width: 20px;
  526. height: 20px;
  527. margin-right: 8px;
  528. }
  529. }
  530. }
  531. }
  532. .form-label {
  533. color: rgba(0, 0, 0, 0.4);
  534. margin-top: 23px;
  535. margin-bottom: 10px;
  536. font-weight: 500;
  537. font-size: 15px;
  538. }
  539. .form-require {
  540. box-sizing: border-box;
  541. border-radius: 15px;
  542. margin-top: 12px;
  543. box-shadow: 0px 3px 27px 0px #0000001A;
  544. .form-item {
  545. min-height: 60px;
  546. display: flex;
  547. align-items: center;
  548. justify-content: space-between;
  549. margin: 0 16px;
  550. border-bottom: 1px solid #ececec;
  551. .label {
  552. min-width: 88px;
  553. display: flex;
  554. align-items: center;
  555. font-size: 15px;
  556. font-weight: 500;
  557. .icon {
  558. margin-right: 10px;
  559. }
  560. }
  561. .control {
  562. width: 100%;
  563. min-height: 60px;
  564. margin-left: 18px;
  565. padding: 4px 0;
  566. box-sizing: border-box;
  567. }
  568. }
  569. }
  570. }
  571. .anti-bot-wrapper {
  572. width: 100%;
  573. height: 60px;
  574. display: flex;
  575. align-items: center;
  576. justify-content: space-between;
  577. box-sizing: border-box;
  578. border-radius: 15px;
  579. padding: 0 18px;
  580. margin-top: 14px;
  581. box-shadow: 0px 3px 27px 0px #0000001A;
  582. .label {
  583. display: flex;
  584. align-items: center ;
  585. font-size: 15px;
  586. font-weight: 500;
  587. .icon-bot {
  588. margin-right: 8px;
  589. }
  590. .icon-beta {
  591. margin-left: 5px;
  592. margin-right: 8px;
  593. }
  594. .icon-question {
  595. cursor: pointer;
  596. }
  597. }
  598. }
  599. .tips-wrapper {
  600. margin-top: 23px;
  601. .title, .row {
  602. font-weight: 400;
  603. font-size: 13px;
  604. color: rgba(0, 0, 0, 0.3);
  605. }
  606. .row {
  607. box-sizing: border-box;
  608. padding-left: 4px;
  609. }
  610. .more {
  611. color: #389AFF;
  612. font-size: 13px;
  613. padding-left: 4px;
  614. cursor: pointer;
  615. }
  616. }
  617. .submit-btn-wrapper {
  618. width: 100%;
  619. background: #fff;
  620. position: absolute;
  621. bottom: 32px;
  622. left: 0;
  623. box-sizing: border-box;
  624. padding-top: 16px;
  625. .submit-btn {
  626. width: calc(100% - 36px);
  627. height: 46px;
  628. text-align: center;
  629. line-height: 46px;
  630. background: #4a99e9;
  631. border-radius: 100px;
  632. color: #fff;
  633. margin-left: 18px;
  634. display: flex;
  635. align-items: center;
  636. justify-content: center;
  637. font-size: 16px;
  638. font-weight: 500;
  639. cursor: pointer;
  640. .icon-loading {
  641. width: 20px;
  642. height: 20px;
  643. margin-right: 3px;
  644. }
  645. }
  646. }
  647. }
  648. }
  649. }
  650. }
  651. </style>