give-dialog.vue 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515
  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 id="editor" class=""></div>
  30. <div class="form-wrapper">
  31. <div class="form-base">
  32. <div class="item">
  33. <div class="label">
  34. <img class="icon"
  35. :src="require('../../assets/svg/icon-usd.svg')" />
  36. USD
  37. </div>
  38. <el-input
  39. v-model="baseFormData.amountValue"
  40. placeholder="$0.00"
  41. oninput = "value=value.replace(/[^\d]/g,'')"
  42. :input-style="{ 'box-shadow': 'none' }"/>
  43. </div>
  44. <div class="item">
  45. <div class="label">
  46. <img class="icon"
  47. :src="require('../../assets/svg/icon-quantity.svg')" />
  48. Quantity
  49. </div>
  50. <el-input
  51. v-model="baseFormData.totalCount"
  52. placeholder="Enter quantity"
  53. oninput = "value=value.replace(/[^\d]/g,'')"
  54. :input-style="{ 'box-shadow': 'none' }"/>
  55. </div>
  56. </div>
  57. <div class="form-require">
  58. <div class="bar">
  59. <div class="label">
  60. <img class="icon"
  61. :src="require('../../assets/svg/icon-require.svg')" />
  62. Require
  63. </div>
  64. </div>
  65. <div
  66. class="form-item"
  67. v-for="(item, index) in formList"
  68. :key="index">
  69. <div class="label">
  70. <img class="icon"
  71. :src="item.icon" />
  72. {{ item.label }}
  73. </div>
  74. <div class="control">
  75. <el-input
  76. :type="item.nodeType"
  77. rows="2"
  78. resize="none"
  79. v-model="item.text"
  80. v-if="item.nodeType == 'textarea'"
  81. placeholder="Enter account number"
  82. :input-style="{
  83. 'box-shadow': 'none',
  84. 'padding': '1px',
  85. 'line-height': '1'
  86. }"/>
  87. </div>
  88. <el-switch v-model="item.checked" />
  89. </div>
  90. </div>
  91. <div class="submit-btn" @click="confirm">NEXT</div>
  92. </div>
  93. </template>
  94. <template v-if="showPreview">
  95. <preview-card :postData="publishRes"></preview-card>
  96. </template>
  97. <div v-show="showPreview">
  98. <paypal-button :amount="baseFormData.amountValue" @payPalFinsh="payPalFinsh"></paypal-button>
  99. </div>
  100. </div>
  101. </div>
  102. </div>
  103. </div>
  104. </template>
  105. <script setup>
  106. import { ref, watch, reactive, defineProps, defineEmits, onMounted } from "vue";
  107. import {postPublish, verifyPaypalResult} from "../../http/publishApi"
  108. // import Quill from 'quill';
  109. // import 'quill/dist/quill.snow.css'
  110. // const quillOptions = {
  111. // placeholder: 'Compose an epic...',
  112. // };
  113. import previewCard from "./preview-card";
  114. import paypalButton from "./paypal-button";
  115. const paypalClientId = 'ASn7k0zqyS5AWYikVSfmamR-RFpjyU_QFJWSxOHHoWE04-RgHNO6nahn0GyHUaUAEBxj-aKgtSrq4O4G';
  116. let publishRes = reactive({})
  117. let visible = ref(false);
  118. let showPreview = ref(false);
  119. let dialogHeight = ref(620);
  120. let previewDialogHeight = ref(880)
  121. let baseFormData = reactive({
  122. amountCurrencyCode: "USD",
  123. amountValue: "",
  124. totalCount: "",
  125. });
  126. let formList = reactive([
  127. {
  128. label: "Follow",
  129. icon: require('../../assets/svg/icon-follow.svg'),
  130. nodeType: 'textarea',
  131. type: 1,
  132. text: '',
  133. checked: true
  134. },
  135. {
  136. label: "Like",
  137. icon: require('../../assets/svg/icon-like.svg'),
  138. nodeType: 'div',
  139. type: 2,
  140. checked: true
  141. },
  142. {
  143. label: "Retweet",
  144. icon: require('../../assets/svg/icon-retweet.svg'),
  145. nodeType: 'div',
  146. type: 3,
  147. checked: true
  148. },
  149. ]);
  150. const props = defineProps({
  151. dialogVisible: {
  152. type: Boolean,
  153. default: false,
  154. },
  155. });
  156. watch(
  157. () => props.dialogVisible,
  158. (newVal) => {
  159. console.log("watch", newVal);
  160. visible.value = newVal;
  161. if(newVal) {
  162. // initQuill();
  163. }
  164. }
  165. );
  166. const emits = defineEmits(["close", "confirm", "payPalFinsh"]);
  167. const close = () => {
  168. if (showPreview.value) {
  169. showPreview.value = false;
  170. } else {
  171. initParams();
  172. emits("close", false);
  173. }
  174. };
  175. const setPreviewDialogHeight = () => {
  176. let clientHeight = document.documentElement.clientHeight;
  177. let gapSafe = 80;
  178. if(previewDialogHeight.value > clientHeight - gapSafe) {
  179. previewDialogHeight.value = clientHeight - gapSafe;
  180. }
  181. };
  182. const confirm = () => {
  183. let {amountValue = 0, totalCount = 0, amountCurrencyCode} = baseFormData;
  184. if(!amountValue || !totalCount) {
  185. return;
  186. }
  187. amountValue = amountValue * 100; // 元转分
  188. let finishConditions = [];
  189. for(let i = 0; i < formList.length; i++) {
  190. let item = {};
  191. item.type = formList[i]['type'];
  192. if(item.type == 1 && formList[i]['checked'] && formList[i]['text']) { // follow 参数
  193. let relatedUsers = [];
  194. let text = formList[i]['text'].replace(/\s*/g,""); // 删除空格
  195. let textList = text.split('@');
  196. for(let i = 0; i < textList.length; i++) {
  197. let item = textList[i];
  198. if(item) {
  199. relatedUsers.push({name: item});
  200. }
  201. }
  202. item.relatedUsers = relatedUsers;
  203. finishConditions.push(item);
  204. } else if(formList[i]['checked']){
  205. finishConditions.push(item);
  206. }
  207. }
  208. console.log('finishConditions', finishConditions);
  209. let formData = {
  210. amountCurrencyCode,
  211. amountValue,
  212. totalCount,
  213. finishConditions
  214. }
  215. let data = {
  216. params: {
  217. postBizData: JSON.stringify(formData),
  218. postSrc: 1, //1 twitter
  219. postType: 1, //1 红包
  220. }
  221. }
  222. postPublish(data).then((res) => {
  223. if(res.code == 0) {
  224. publishRes = res.data;
  225. setPreviewDialogHeight();
  226. showPreview.value = true;
  227. }
  228. })
  229. };
  230. const initParams = () => {
  231. baseFormData.amountValue = '';
  232. baseFormData.totalCount = '';
  233. formList[0].text = '';
  234. }
  235. const payPalFinsh = (params) => {
  236. let transaction = params.transaction;
  237. console.log('transaction', transaction)
  238. verifyPaypalResult({
  239. params: {
  240. paypalTransactionId: transaction.id,
  241. postId: publishRes.postId,
  242. paypalClientId: paypalClientId
  243. }
  244. }).then((res) => {
  245. if(res.code == 0) {
  246. //支付状态 0:未支付,1:支付成功,2:支付失败,3:已关闭,4:已退款
  247. if(res.data && res.data.payStatus == 1) {
  248. emits("payPalFinsh", {publishRes});
  249. showPreview.value = false;
  250. initParams();
  251. }
  252. }
  253. })
  254. }
  255. // const initQuill = () => {
  256. // let container = document.getElementById('editor');
  257. // let editor = new Quill(container, quillOptions);
  258. // editor.on('text-change', () => {
  259. // if(editor.getText()) {
  260. // /**
  261. // * quill.insertText(5, 'Quill', {
  262. // 'color': '#ffff00',
  263. // 'italic': true
  264. // });
  265. // */
  266. // // editor.setContents([
  267. // // { insert: 'World!', attributes: { color: 'blue' } },
  268. // // ]);
  269. // }
  270. // console.log(editor.getText())
  271. // });
  272. // }
  273. onMounted(() => {
  274. setPreviewDialogHeight();
  275. // initQuill();
  276. })
  277. </script>
  278. <style lang="scss" scoped>
  279. .ql-container {
  280. height: 100px;
  281. }
  282. .overlay {
  283. position: fixed;
  284. top: 0;
  285. right: 0;
  286. bottom: 0;
  287. left: 0;
  288. z-index: 2000;
  289. height: 100%;
  290. background-color: rgba(0, 0, 0, 0.5);
  291. overflow: auto;
  292. .content {
  293. width: 650px;
  294. height: 620px;
  295. background: #ffffff;
  296. border-radius: 16px;
  297. position: absolute;
  298. left: 50%;
  299. top: 50%;
  300. transform: translate(-50%, -50%);
  301. box-sizing: border-box;
  302. .head {
  303. border-bottom: 1px solid #ececec;
  304. height: 48px;
  305. box-sizing: border-box;
  306. display: flex;
  307. align-items: center;
  308. justify-content: space-between;
  309. padding: 0 14px;
  310. .left {
  311. display: flex;
  312. .close-btn {
  313. display: flex;
  314. align-items: center;
  315. width: max-content;
  316. margin-right: 12px;
  317. cursor: pointer;
  318. }
  319. }
  320. .icon-question {
  321. cursor: pointer;
  322. }
  323. }
  324. .body {
  325. box-sizing: border-box;
  326. height: calc(100% - 48px);
  327. display: flex;
  328. .left,
  329. .right {
  330. height: 100%;
  331. }
  332. .left {
  333. width: 50px;
  334. display: flex;
  335. flex-direction: column;
  336. justify-content: space-between;
  337. align-items: center;
  338. .gift-pack-wrapper {
  339. width: 100%;
  340. height: 54px;
  341. background: #F5F5F5;
  342. display: flex;
  343. align-items: center;
  344. justify-content: center;
  345. }
  346. .bottom {
  347. .icon {
  348. display: block;
  349. margin-bottom: 26px;
  350. }
  351. }
  352. }
  353. .right {
  354. width: calc(100% - 50px);
  355. box-sizing: border-box;
  356. position: relative;
  357. border-left: 1px solid #ececec;
  358. .form-wrapper {
  359. padding: 26px 18px;
  360. box-sizing: border-box;
  361. .form-base {
  362. display: flex;
  363. justify-content: space-between;
  364. align-items: center;
  365. .item {
  366. width: 250px;
  367. height: 60px;
  368. border: 1px solid #e1e1e1;
  369. box-sizing: border-box;
  370. border-radius: 15px;
  371. display: flex;
  372. align-items: center;
  373. justify-content: space-between;
  374. padding: 16px 14px;
  375. .label {
  376. font-weight: 500;
  377. font-size: 15px;
  378. display: flex;
  379. align-items: center;
  380. .icon {
  381. width: 20px;
  382. height: 20px;
  383. margin-right: 8px;
  384. }
  385. }
  386. }
  387. }
  388. .form-require {
  389. border: 1px solid #e1e1e1;
  390. box-sizing: border-box;
  391. border-radius: 15px;
  392. margin-top: 12px;
  393. .bar {
  394. padding: 2px 10px 0 10px;
  395. box-sizing: border-box;
  396. display: flex;
  397. align-items: center;
  398. justify-content: space-between;
  399. line-height: 50px;
  400. .label {
  401. display: flex;
  402. .icon {
  403. margin-right: 8px;
  404. }
  405. }
  406. .icon-button {
  407. width: 28px;
  408. height: 28px;
  409. cursor: pointer;
  410. }
  411. }
  412. .form-item {
  413. height: 50px;
  414. display: flex;
  415. align-items: center;
  416. justify-content: space-between;
  417. margin: 0 16px;
  418. border-bottom: 1px solid #ececec;
  419. .label {
  420. width: 100px;
  421. color: rgba(0, 0, 0, 0.6);
  422. display: flex;
  423. align-items: center;
  424. .icon {
  425. margin-right: 10px;
  426. }
  427. }
  428. .control {
  429. width: 264px;
  430. height: 50px;
  431. line-height: 50px;
  432. cursor: pointer;
  433. .inner {
  434. width: 100%;
  435. height: 100%;
  436. box-sizing: border-box;
  437. display: flex;
  438. align-items: center;
  439. }
  440. }
  441. .icon-remove-button {
  442. cursor: pointer;
  443. }
  444. }
  445. }
  446. }
  447. .submit-btn {
  448. width: calc(100% - 36px);
  449. height: 60px;
  450. text-align: center;
  451. line-height: 60px;
  452. background: #4a99e9;
  453. border-radius: 15px;
  454. color: #fff;
  455. position: absolute;
  456. bottom: 32px;
  457. left: 18px;
  458. cursor: pointer;
  459. }
  460. }
  461. }
  462. }
  463. }
  464. </style>