red-packet.vue 38 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518
  1. <!-- 红包任务页面 -->
  2. <template>
  3. <div class="content">
  4. <!-- open -->
  5. <div v-show="data.status == 'opened'" class="opened">
  6. <div class="header" :style="{ 'backgroundImage': `url(${require('@/assets/subject/001-back-head-top.svg')})` }">
  7. <div class="title">Awesome! You Will Get</div>
  8. <div class="money">
  9. <img :src="data.detail.currencyIconPath" alt />
  10. <!-- <span class="big">{{ data.money }}</span> -->
  11. <font-amount :amount="data.money" class="big" :fontSize="46"></font-amount>
  12. <!-- <span class="small">{{ data.detail.currencySymbol || '' }}</span> -->
  13. </div>
  14. </div>
  15. <div class="list">
  16. <div class="item" v-for="item, i in data.detail.taskCondition" v-bind:key="i">
  17. <template v-if="item.type == 1 && item.relatedUsers && item.relatedUsers.length > 0">
  18. <div class="item-content">
  19. <div class="item-follow-title">
  20. <img :src="require('@/assets/svg/icon-follow.svg')" alt />
  21. <div class="item-title">Follow</div>
  22. <img :src="require('@/assets/gif/red-right.gif')" alt class="red-right"
  23. v-show="!data.done.follow && data.done.follow_red" />
  24. <img v-if="data.done.follow" :src="require('@/assets/svg/icon-true.svg')" alt />
  25. <div v-else class="btn" @click="clickFollowAll(item.relatedUsers)">Follow All</div>
  26. </div>
  27. <div class="item-follow-area">
  28. <template v-for="item2, i in item.relatedUsers" v-bind:key="i">
  29. <div class="item-follow" v-if="item2.finished">
  30. <span :class="{ finished: item2.finished }">@{{ item2.name }}</span>
  31. <img :src="require('@/assets/svg/icon-true-ed.svg')" alt />
  32. </div>
  33. <div class="item-follow" v-else @click="clickFollowAll([{ name: item2.name }])">
  34. <span :class="{ finished: item2.finished }">@{{ item2.name }}</span>
  35. <img :src="require('@/assets/svg/icon-add.svg')" alt />
  36. </div>
  37. </template>
  38. </div>
  39. </div>
  40. </template>
  41. <template v-if="item.type == 2">
  42. <img :src="require('@/assets/svg/icon-like.svg')" alt />
  43. <div class="item-content">
  44. <div class="item-title">Like</div>
  45. </div>
  46. <img :src="require('@/assets/gif/red-right.gif')" alt class="red-right"
  47. v-show="!data.done.like && data.done.like_red" />
  48. <img v-if="data.done.like" :src="require('@/assets/svg/icon-true.svg')" alt />
  49. <div v-else class="btn" @click="clickLickBtn">Like</div>
  50. </template>
  51. <template v-if="item.type == 3">
  52. <img :src="require('@/assets/svg/icon-retweet.svg')" alt />
  53. <div class="item-content">
  54. <div class="item-title">Retweet</div>
  55. </div>
  56. <img :src="require('@/assets/gif/red-right.gif')" alt class="red-right"
  57. v-show="!data.done.retweet && data.done.retweet_red" />
  58. <img v-if="data.done.retweet" :src="require('@/assets/svg/icon-true.svg')" alt />
  59. <div v-else class="btn" @click="clickRetweetBtn">Retweet</div>
  60. </template>
  61. </div>
  62. </div>
  63. <div class="people" @click="clickRoad">
  64. <div class="txt">
  65. {{ data.detail.receiveCount || 0 }}/{{ data.detail.totalCount || 0 }} Get,{{
  66. data.detail.receiveAmountValue
  67. }}/{{ data.detail.amountValue }} {{ data.detail.currencySymbol }}</div>
  68. <div class="right" v-if="data.detail.allReceived">
  69. <template v-for="item, i in data.detail.allReceived.slice(0, 3)" v-bind:key="i">
  70. <img :src="item.simpleUserInfoVO.avatarUrl" alt :style="{ right: `${i * 16 + 14}px` }"
  71. v-if="item.simpleUserInfoVO.avatarUrl" />
  72. <img v-else :src="require('@/assets/svg/icon-twitter.svg')" alt :style="{ right: `${i * 16 + 14}px` }" />
  73. </template>
  74. <img :src="require('@/assets/svg/icon-right.svg')" alt class="road" />
  75. </div>
  76. </div>
  77. <div class="footer">
  78. <div class="first">
  79. <div class="validity">Validity</div>
  80. <div class="time">{{ data.detail.validity || '' }}</div>
  81. </div>
  82. <div class="btn" @click="clickGetGiveaways">Get Giveaways</div>
  83. </div>
  84. </div>
  85. <!-- success -->
  86. <div v-if="data.status == 'success'" class="success">
  87. <div class="header" :style="{ 'backgroundImage': `url(${require('@/assets/subject/001-back-head-top.svg')})` }">
  88. <div class="money">
  89. <img :src="data.detail.currencyIconPath" alt />
  90. <font-amount :amount="data.money" class="big" :fontSize="46"></font-amount>
  91. <!-- <span class="small">{{ data.detail.currencySymbol }}</span> -->
  92. </div>
  93. <div class="done" @click="clickDone">
  94. <img :src="require('@/assets/subject/001-icon-done.svg')" alt class="icon-done" />
  95. <span>Giveaways transferred to Wallet</span>
  96. <img :src="require('@/assets/svg/icon-right.svg')" alt class="icon-right" />
  97. </div>
  98. </div>
  99. <div class="luck-list-title">
  100. <div>{{ data.detail.receiveCount || 0 }}/{{ data.detail.totalCount || 0 }} Get</div>
  101. <div> {{ data.detail.receiveAmountValue }} / {{ data.detail.amountValue || '' }} {{
  102. data.detail.currencySymbol || ''
  103. }}</div>
  104. </div>
  105. <div class="luck-list" @scroll="handleScroll($event)">
  106. <div class="luck-item" v-for="item, i in data.detail.allReceived" v-bind:key="i">
  107. <img v-if="item.simpleUserInfoVO.avatarUrl" :src="item.simpleUserInfoVO.avatarUrl" alt />
  108. <img v-else :src="require('@/assets/svg/icon-twitter.svg')" alt />
  109. <div class="luck-content">
  110. <div class="luck-title" v-if="item.simpleUserInfoVO.nickName">{{ item.simpleUserInfoVO.nickName }}</div>
  111. <div class="luck-title" v-else>Twitter User</div>
  112. <div class="luck-time">{{ moment(item.receiveTimestamp).format('MM-DD hh:mm:ss') }}</div>
  113. </div>
  114. <div class="luck-money">
  115. <img :src="data.detail.currencyIconPath" alt />
  116. <div class="luck-money-txt">{{ showLastTwoPlace(item.amountValue) || 0 }}</div>
  117. </div>
  118. <div class="luck-king" v-if="item.maxAmount">
  119. <img :src="require('@/assets/svg/icon-king-hat.svg')" alt />
  120. <span>Luckiest Draw</span>
  121. </div>
  122. </div>
  123. </div>
  124. </div>
  125. <!-- no-open -->
  126. <div v-else-if="data.status == 'not-open'" class="not-open">
  127. <img :src="require('@/assets/subject/001-card.png')" alt="">
  128. <img class="open-gif" :src="require('@/assets/gif/001.gif')" />
  129. <img :src="require('@/assets/svg/icon-open.svg')" alt="" class="open" @click="clickOpenRedPacket">
  130. <div class="title" v-if="data.detail.postUserInfo">
  131. <img :src="data.detail.postUserInfo.avatarUrl" alt />
  132. <span>{{ data.detail.postUserInfo.nickName || 'FutureDoctor' }}</span>
  133. </div>
  134. <div class="money-area">
  135. <div class="txt">{{ data.detail.currencySymbol }} GIVEAWAY</div>
  136. <div class="coin">
  137. <img :src="data.detail.currencyIconPath" alt />
  138. <font-amount :amount="data.detail.amountValue"></font-amount>
  139. </div>
  140. <div class="people">{{ data.detail.totalCount }} WINNERS TO SHARE</div>
  141. </div>
  142. </div>
  143. <!-- 领取列表 -->
  144. <div v-else-if="data.status == 'luck-peopel-list'" class="luck-peopel-list">
  145. <div class="head">
  146. <img :src="require('@/assets/svg/icon-back.svg')" alt @click="clickBack" />
  147. </div>
  148. <div class="luck-list-title">
  149. <div>{{ data.detail.receiveCount || 0 }}/{{ data.detail.totalCount || 0 }} Get</div>
  150. <div> {{ data.detail.receiveAmountValue }} / {{ data.detail.amountValue || '' }} {{
  151. data.detail.currencySymbol || ''
  152. }}</div>
  153. </div>
  154. <div class="luck-list" @scroll="handleScroll">
  155. <div class="luck-item" v-for="item, i in data.detail.allReceived" v-bind:key="i">
  156. <img v-if="item.simpleUserInfoVO.avatarUrl" :src="item.simpleUserInfoVO.avatarUrl" alt />
  157. <img v-else :src="require('@/assets/svg/icon-twitter.svg')" alt />
  158. <div class="luck-content">
  159. <div class="luck-title" v-if="item.simpleUserInfoVO.nickName">{{ item.simpleUserInfoVO.nickName }}</div>
  160. <div class="luck-title" v-else>Twitter User</div>
  161. <div class="luck-time">{{ moment(item.receiveTimestamp).format('MM-DD hh:mm:ss') }}</div>
  162. </div>
  163. <div class="luck-money">
  164. <img :src="data.detail.currencyIconPath" alt />
  165. <div class="luck-money-txt">{{ showLastTwoPlace(item.amountValue) }}</div>
  166. </div>
  167. <div class="luck-king" v-if="item.maxAmount">
  168. <img :src="require('@/assets/svg/icon-king-hat.svg')" alt />
  169. <span>Luckiest Draw</span>
  170. </div>
  171. </div>
  172. </div>
  173. </div>
  174. <!-- 红包被领完了 -->
  175. <div v-else-if="data.status == 'close'" class="close">
  176. <div class="header" :style="{ 'backgroundImage': `url(${require('@/assets/subject/001-back-head-top.svg')})` }">
  177. <div class="close-title">{{ data.close_title }}</div>
  178. <div class="close-title" v-if="data.close_text">{{ data.close_text }}</div>
  179. </div>
  180. <div class="luck-list-title">
  181. <div>{{ data.detail.receiveCount || 0 }}/{{ data.detail.totalCount || 0 }} Get</div>
  182. <div> {{ data.detail.receiveAmountValue }} / {{ data.detail.amountValue || '' }} {{
  183. data.detail.currencySymbol || ''
  184. }}</div>
  185. </div>
  186. <div class="luck-list" @scroll="handleScroll">
  187. <div class="luck-item" v-for="item, i in data.detail.allReceived" v-bind:key="i">
  188. <img v-if="item.simpleUserInfoVO.avatarUrl" :src="item.simpleUserInfoVO.avatarUrl" alt />
  189. <img v-else :src="require('@/assets/svg/icon-twitter.svg')" alt />
  190. <div class="luck-content">
  191. <div class="luck-title" v-if="item.simpleUserInfoVO.nickName">{{ item.simpleUserInfoVO.nickName }}</div>
  192. <div class="luck-title" v-else>Twitter User</div>
  193. <div class="luck-time">{{ moment(item.receiveTimestamp).format('MM-DD HH:mm:ss') }}</div>
  194. </div>
  195. <div class="luck-money">
  196. <img :src="data.detail.currencyIconPath" alt />
  197. <div class="luck-money-txt">{{ showLastTwoPlace(item.amountValue) || 0 }}</div>
  198. </div>
  199. <div class="luck-king" v-if="item.maxAmount">
  200. <img :src="require('@/assets/svg/icon-king-hat.svg')" alt />
  201. <span>Luckiest Draw</span>
  202. </div>
  203. </div>
  204. </div>
  205. </div>
  206. <!-- error -->
  207. <div v-else-if="data.status == 'error'" class="error">
  208. <img :src="require('@/assets/svg/icon-error.svg')" alt />
  209. <div class="txt">
  210. {{ data.error_txt }}
  211. </div>
  212. <div class="retry" v-show="data.retry" @click="clickRetry">
  213. Retry
  214. </div>
  215. </div>
  216. <!-- loading -->
  217. <div v-show="data.loading_show" class="loading">
  218. <img :src="require('@/assets/svg/icon-loading.svg')" alt />
  219. </div>
  220. </div>
  221. </template>
  222. <script>
  223. export default {
  224. name: 'redPacket',
  225. }
  226. </script>
  227. <script setup>
  228. import { onMounted, reactive } from "vue";
  229. import { getPostDetail, getRedPacket, finishRedPacket, oneKeyLike, oneKeyReTweet, oneKeyFollow, getTaskDetail, getReceivedList } from '@/http/redPacket.js'
  230. import { getQueryString } from '@/uilts/help.js'
  231. import { message } from 'ant-design-vue';
  232. import FontAmount from '@/view/components/font-amount.vue'
  233. import { getChromeStorage } from '@/uilts/chromeExtension.js'
  234. var moment = require('moment');
  235. let data = reactive({
  236. status: '',
  237. loading_show: false,
  238. detail: {},
  239. luck_list_end: false,
  240. page_index: 1,
  241. page_size: 20,
  242. srcContentId: '',
  243. close_title: 'Better luck next time!',
  244. error_txt: `oops, new accounts cannot participate in this event,`,
  245. receiveAmount: 0,
  246. money: 0,
  247. // 状态
  248. done: {
  249. follow: false,
  250. like: false,
  251. retweet: false
  252. }
  253. })
  254. function clickRetry() {
  255. init()
  256. }
  257. async function clickLickBtn() {
  258. let _userInfo = await checkIsLogin()
  259. if (!_userInfo) {
  260. return
  261. }
  262. data.loading_show = true
  263. oneKeyLike({
  264. params: {
  265. tweetId: data.srcContentId
  266. }
  267. }).then((res) => {
  268. data.loading_show = false
  269. if (res.code == 0) {
  270. if (res.data.result) {
  271. data.done.like = true
  272. } else {
  273. data.done.like = false
  274. }
  275. } else {
  276. data.done.like = false
  277. console.log(res)
  278. }
  279. })
  280. }
  281. function clickDone() {
  282. window.open(`${chrome.runtime.getURL('/iframe/home.html')}`)
  283. }
  284. function handleScroll(e) {
  285. if (data.luck_list_end) {
  286. return
  287. }
  288. e = e.target
  289. if ((e.clientHeight + e.scrollTop) / e.scrollHeight > .8) {
  290. data.luck_list_end = true
  291. data.page_index++
  292. getReceivedList({
  293. params: {
  294. pageNum: data.page_index,
  295. pageSize: data.page_size,
  296. postId: data.postId
  297. }
  298. }).then((res) => {
  299. if (res.code == 0) {
  300. if (res.data.length > 0) {
  301. data.detail.allReceived = data.detail.allReceived.concat(res.data)
  302. data.luck_list_end = false
  303. } else {
  304. data.luck_list_end = true
  305. }
  306. } else {
  307. console.log('getReceivedList', res)
  308. }
  309. })
  310. }
  311. }
  312. async function clickRetweetBtn() {
  313. let _userInfo = await checkIsLogin()
  314. if (!_userInfo) {
  315. return
  316. }
  317. data.loading_show = true
  318. oneKeyReTweet({
  319. params: {
  320. tweetId: data.srcContentId
  321. }
  322. }).then((res) => {
  323. data.loading_show = false
  324. if (res.code == 0) {
  325. if (res.data.result) {
  326. data.done.retweet = true
  327. } else {
  328. data.done.retweet = false
  329. }
  330. } else {
  331. data.done.retweet = false
  332. console.log(res)
  333. }
  334. })
  335. }
  336. function getValidity() {
  337. let _d1, _d2, _d3, _h, _m, _s
  338. if (!data.detail.myReceived.taskEndTimestamp) {
  339. return
  340. }
  341. let timer = setInterval(() => {
  342. let _time = new Date().getTime()
  343. _d3 = data.detail.myReceived.taskEndTimestamp - _time
  344. if (_d3 > 0) {
  345. _d1 = moment(data.detail.myReceived.taskEndTimestamp)
  346. _d2 = moment(_time)
  347. _h = moment.duration(_d1.diff(_d2)).hours()
  348. if (_h < 10) {
  349. _h = '0' + _h
  350. }
  351. _m = moment.duration(_d1.diff(_d2)).minutes()
  352. if (_m < 10) {
  353. _m = '0' + _m
  354. }
  355. _s = moment.duration(_d1.diff(_d2)).seconds()
  356. if (_s < 10) {
  357. _s = '0' + _s
  358. }
  359. data.detail.validity = `${_h}:${_m}:${_s}`
  360. } else {
  361. data.detail.validity = `00:00:00`
  362. clearInterval(timer)
  363. }
  364. }, 1000)
  365. }
  366. async function clickFollowAll(item) {
  367. let _userInfo = await checkIsLogin()
  368. if (!_userInfo) {
  369. return
  370. }
  371. data.loading_show = true
  372. let arr_name = []
  373. for (let i in item) {
  374. arr_name.push(item[i].name)
  375. }
  376. oneKeyFollow({
  377. params: {
  378. names: arr_name
  379. }
  380. }).then((res) => {
  381. data.loading_show = false
  382. if (res.code == 0) {
  383. res.data.forEach((item1) => {
  384. data.detail.taskCondition[0].relatedUsers.forEach(item2 => {
  385. if (item1.name == item2.name) {
  386. item2.finished = true
  387. }
  388. });
  389. })
  390. let _len = data.detail.taskCondition[0].relatedUsers.filter((item) => { return item.finished == false }).length
  391. if (_len > 0) {
  392. data.done.follow = false
  393. } else {
  394. data.done.follow = true
  395. }
  396. } else {
  397. data.detail.taskCondition[0].relatedUsers.forEach(item => {
  398. item.finished = false
  399. });
  400. }
  401. })
  402. }
  403. // 我领取了的状态
  404. function myReceivedState() {
  405. data.status = 'opened'
  406. data.money = data.detail.myReceived.amountValue
  407. // 我的红包已经过期了 and 大红包可以领取
  408. if (data.detail.myReceived.taskFinishStatus == 2 && !data.detail.receiveTimeExpired) {
  409. data.status = 'not-open'
  410. // 任务已经被领完了
  411. if (data.detail.totalCount == data.detail.receiveCount) {
  412. data.status = 'close'
  413. data.close_title = 'Better luck next time!'
  414. }
  415. // 我领取未完成
  416. } else if (data.detail.myReceived.taskFinishStatus == 0 && data.detail.status == 1) {
  417. initTaskDetail()
  418. getValidity()
  419. data.detail.taskCondition = JSON.parse(data.detail.taskCondition)
  420. data.detail.amountValue = showLastTwoPlace(data.detail.amountValue)
  421. data.detail.receiveAmountValue = showLastTwoPlace(data.detail.receiveAmountValue)
  422. // 大红包不能领取了 and 我的红包过期了
  423. } else if (data.detail.receiveTimeExpired && data.detail.myReceived.taskFinishStatus == 2) {
  424. data.status = 'close'
  425. data.close_title = `This Giveaways`
  426. data.close_text = `expired on ${moment(data.detail.endTimestamp).format('MM-DD')}`
  427. // 我领取成功了
  428. } else if (data.detail.myReceived.taskFinishStatus == 1) {
  429. data.status = 'success'
  430. }
  431. }
  432. function showLastTwoPlace(n) {
  433. return n
  434. }
  435. function init() {
  436. getPostDetail({
  437. params: {
  438. postId: data.postId
  439. }
  440. }).then((res) => {
  441. data.loading_show = false
  442. if (res.code == 0) {
  443. data.srcContentId = res.data.srcContentId
  444. // if (data.tweetId != data.srcContentId) {
  445. // data.error_txt = 'Giveaways link Error'
  446. // data.status = 'error'
  447. // return
  448. // }
  449. data.detail = JSON.parse(res.data.postBizData)
  450. console.log(data.detail)
  451. // 红包未开始
  452. if (data.detail.status == 0) {
  453. data.status = 'not-open'
  454. // 任务进行中
  455. } else if (data.detail.status == 1) {
  456. data.status = 'not-open'
  457. // 我领取过的状态
  458. if (data.detail.myReceived) {
  459. myReceivedState()
  460. } else {
  461. // 大红包不可以领取了
  462. if (data.detail.receiveTimeExpired) {
  463. data.status = 'close'
  464. data.close_title = `This Giveaways`
  465. data.close_text = `expired on ${moment(data.detail.endTimestamp).format('MM-DD')}`
  466. }
  467. // 任务已经被领完了
  468. if (data.detail.totalCount == data.detail.receiveCount) {
  469. data.status = 'close'
  470. data.close_title = 'Better luck next time!'
  471. }
  472. }
  473. // 任务已经结束了
  474. } else if (data.detail.status == 2) {
  475. // 我领取过的状态
  476. if (data.detail.myReceived) {
  477. myReceivedState()
  478. } else {
  479. data.status = 'close'
  480. data.close_title = `This Giveaways`
  481. data.close_text = `expired on ${moment(data.detail.endTimestamp).format('MM-DD')}`
  482. }
  483. }
  484. } else {
  485. handleErrorCode(res)
  486. }
  487. })
  488. }
  489. function initTaskDetail() {
  490. // 任务详情
  491. getTaskDetail({
  492. params: {
  493. postId: data.postId
  494. }
  495. }).then((res) => {
  496. if (res.code.toString()) {
  497. for (let i in res.data) {
  498. switch (res.data[i].type) {
  499. case 1:
  500. data.done.follow = res.data[i].finished
  501. data.detail.taskCondition[0].relatedUsers = res.data[i].detail
  502. break
  503. case 2:
  504. data.done.like = res.data[i].finished
  505. break
  506. case 3:
  507. data.done.retweet = res.data[i].finished
  508. break
  509. }
  510. }
  511. } else {
  512. handleErrorCode(res)
  513. }
  514. })
  515. }
  516. onMounted(() => {
  517. data.postId = getQueryString('postId')
  518. data.tweetId = getQueryString('tweetId')
  519. init()
  520. // data.loading_show = true
  521. })
  522. // 点击领取
  523. function clickOpenRedPacket() {
  524. chrome.runtime.sendMessage({
  525. actionType: 'CONTENT_GET_PINED'
  526. }, res => {
  527. console.log(res);
  528. })
  529. handleRedPacket()
  530. }
  531. function handleRedPacket() {
  532. getRedPacket({
  533. params: {
  534. postId: data.postId
  535. }
  536. }).then((res) => {
  537. if (res.code == 0) {
  538. data.status = 'opened'
  539. data.money = res.data.receiveAmount
  540. init()
  541. } else {
  542. handleErrorCode(res)
  543. }
  544. })
  545. }
  546. chrome.storage.onChanged.addListener(changes => {
  547. if (changes.userInfo) {
  548. // let item = JSON.parse(changes.userInfo.newValue)
  549. data.loading_show = false
  550. init()
  551. }
  552. })
  553. // 校验是否封路
  554. function checkIsLogin() {
  555. return new Promise((resolve) => {
  556. getChromeStorage('userInfo', (_userInfo) => {
  557. if (!_userInfo) {
  558. data.loading_show = true
  559. setTimeout(() => {
  560. data.loading_show = false
  561. }, 3000)
  562. chrome.runtime.sendMessage(
  563. { method: "POPUP_LOGIN", data: "" },
  564. (response) => {
  565. console.log("res", response);
  566. }
  567. )
  568. resolve(_userInfo)
  569. } else {
  570. resolve(_userInfo)
  571. }
  572. })
  573. })
  574. }
  575. async function clickGetGiveaways() {
  576. let _userInfo = await checkIsLogin()
  577. if (_userInfo) {
  578. handleFinishRedPacket()
  579. }
  580. }
  581. function handleFinishRedPacket() {
  582. data.loading_show = true
  583. finishRedPacket({
  584. params: {
  585. postId: data.postId
  586. }
  587. }).then((res) => {
  588. if (res.code == 0) {
  589. data.loading_show = false
  590. if (res.data.finished) {
  591. data.status = 'success'
  592. data.receiveAmount = res.data.receiveAmount
  593. init()
  594. } else {
  595. let _data = res.data.conditionResult
  596. for (let i in _data) {
  597. switch (_data[i].type.toString()) {
  598. case '1':
  599. data.detail.taskCondition[0].relatedUsers = _data[i].detail
  600. if (_data[i].finished) {
  601. data.done.follow = true
  602. } else {
  603. // alert('Please complete the task: follow')
  604. data.done.follow_red = true
  605. }
  606. break
  607. case '2':
  608. if (_data[i].finished) {
  609. data.done.like = true
  610. } else {
  611. // alert('Please complete the task: like tweet')
  612. data.done.like_red = true
  613. }
  614. break
  615. case '3':
  616. if (_data[i].finished) {
  617. data.done.retweet = true
  618. } else {
  619. // alert('Please complete the task: Retweet')
  620. data.done.retweet_red = true
  621. }
  622. break
  623. }
  624. }
  625. }
  626. } else {
  627. handleErrorCode(res)
  628. }
  629. })
  630. }
  631. function handleErrorCode(res) {
  632. switch (res.code.toString()) {
  633. // 数据异常,请联系管理员
  634. case '-102':
  635. break
  636. //系统错误
  637. case '-101':
  638. break
  639. // 参数不对
  640. case '-103':
  641. break
  642. // 接口被限流
  643. case '-105':
  644. break
  645. // 访问凭证不存在
  646. case '-107':
  647. break
  648. // 重复操作过于频繁
  649. case '-106':
  650. message.error('Clicking too often, wait a moment and click again')
  651. this.loading_show =false
  652. break
  653. // 红包不存在
  654. case '2001':
  655. message.error(res.msg)
  656. break
  657. // 还未到红包领取时间
  658. case '2002':
  659. message.error(res.msg)
  660. break
  661. // 已超过红包领取时间
  662. case '2003':
  663. // data.status = 'close'
  664. // data.close_title = `This Giveaways`
  665. // data.close_text = `expired on ${moment(data.detail.endTimestamp).format('MM-DD')}`
  666. init()
  667. break
  668. // 红包支付状态异常 没有可提交的任务红包
  669. case '2004':
  670. data.status = 'not-open'
  671. break
  672. // 红包活动已结束
  673. case '2006':
  674. // data.status = 'close'
  675. // data.close_title = `This Giveaways`
  676. // data.close_text = `expired on ${moment(data.detail.endTimestamp).format('MM-DD')}`
  677. init()
  678. break
  679. // 红包金额已经被领取完了
  680. case '2007':
  681. message.error(res.msg)
  682. break
  683. // 红包个数已经被领取完了
  684. case '2008':
  685. message.error(res.msg)
  686. break
  687. // 该用户不满足领取条件
  688. case '2009':
  689. data.error_txt = `oops, new accounts cannot participate in this event,`
  690. data.status = 'error'
  691. data.retry = true
  692. break
  693. // 无法校验用户Twitter信息
  694. case '2010':
  695. message.error(res.msg)
  696. break
  697. // 用户已经领过该红包
  698. case '2011':
  699. message.error(res.msg)
  700. break
  701. // 推文不存在
  702. case '2022':
  703. message.error(res.msg)
  704. break
  705. // 推文未发布 and 不是红包任务的推文
  706. case '2023':
  707. message.error(res.msg)
  708. break
  709. // 没有可提交的任务红包
  710. case '2024':
  711. message.error(res.msg)
  712. break
  713. // 红包任务已完成
  714. case '2025':
  715. break
  716. // 任务已经过期
  717. case '2026':
  718. break
  719. // 任务未完成
  720. case '2027':
  721. break
  722. // 红包金额每人不足1分钱
  723. case '2028':
  724. break
  725. // 推文未发布
  726. case '2029':
  727. message.error('推文未发布')
  728. break
  729. // 不是红包任务的推文
  730. case '2030':
  731. break
  732. //用户没有领取过红包,无法重抽
  733. case '2031':
  734. break
  735. }
  736. }
  737. function clickBack() {
  738. data.status = 'opened'
  739. }
  740. function clickRoad() {
  741. data.status = 'luck-peopel-list'
  742. }
  743. </script>
  744. <style lang="scss">
  745. html,
  746. body {
  747. margin: 0;
  748. padding: 0;
  749. width: 375px;
  750. height: 500px;
  751. }
  752. .content {
  753. width: 375px;
  754. height: 500px;
  755. background: #fafafa;
  756. border-radius: 11px;
  757. font-family: "SF Pro Display";
  758. font-style: normal;
  759. .loading {
  760. background: #FFFFFF;
  761. opacity: 0.8;
  762. z-index: 222;
  763. text-align: center;
  764. width: 375px;
  765. height: 500px;
  766. position: fixed;
  767. top: 0;
  768. left: 0;
  769. img {
  770. margin-top: 216px;
  771. width: 70px;
  772. height: 70px;
  773. }
  774. }
  775. .error {
  776. width: 100%;
  777. height: 100%;
  778. text-align: center;
  779. position: relative;
  780. img {
  781. width: 100px;
  782. height: 100px;
  783. margin-top: 100px;
  784. }
  785. .txt {
  786. font-weight: 500;
  787. font-size: 22px;
  788. line-height: 26px;
  789. text-align: center;
  790. letter-spacing: 0.3px;
  791. color: #a8a8a8;
  792. margin: 34px 44px 0 44px;
  793. }
  794. .retry {
  795. position: absolute;
  796. bottom: 30px;
  797. left: 50%;
  798. margin-left: -167.5px;
  799. width: 335px;
  800. height: 46px;
  801. line-height: 46px;
  802. text-align: center;
  803. border-radius: 100px;
  804. border: 1px solid #1D9BF0;
  805. background: rgba(196, 196, 196, 0.01);
  806. color: #1D9BF0;
  807. font-size: 16px;
  808. font-weight: 500;
  809. cursor: pointer;
  810. }
  811. }
  812. .success,
  813. .close,
  814. .luck-peopel-list {
  815. filter: drop-shadow(0px 4px 94px rgba(0, 0, 0, 0.3));
  816. width: 100%;
  817. height: 100%;
  818. border-radius: 11px;
  819. background: #fff;
  820. overflow: hidden;
  821. display: flex;
  822. flex-direction: column;
  823. .close-title {
  824. width: 100%;
  825. font-weight: 600;
  826. font-size: 27px;
  827. line-height: 32px;
  828. text-align: center;
  829. letter-spacing: 0.3px;
  830. color: #ffffff;
  831. }
  832. .head {
  833. padding: 14px 16px;
  834. img {
  835. cursor: pointer;
  836. width: 24px;
  837. height: 24px;
  838. }
  839. }
  840. .header {
  841. text-align: center;
  842. height: 150px;
  843. width: 100%;
  844. background: #fff;
  845. // padding-top: 30px;
  846. background-size: 100% 100%;
  847. position: relative;
  848. display: flex;
  849. align-content: center;
  850. flex-wrap: wrap;
  851. .done {
  852. cursor: pointer;
  853. position: absolute;
  854. top: 107px;
  855. left: 50%;
  856. margin-left: -150px;
  857. width: 300px;
  858. height: 60px;
  859. display: flex;
  860. align-items: center;
  861. border-radius: 100px;
  862. background: #ffffff;
  863. box-shadow: 0px 2px 10px rgba(0, 0, 0, 0.1);
  864. span {
  865. color: #000000;
  866. font-size: 14px;
  867. }
  868. .icon-done {
  869. width: 24px;
  870. height: 24px;
  871. margin-left: 28px;
  872. margin-right: 10px;
  873. }
  874. .icon-right {
  875. margin-left: 5px;
  876. width: 7px;
  877. height: 14px;
  878. }
  879. }
  880. .title {
  881. margin-top: 30px;
  882. color: #fff7e4;
  883. opacity: 0.6;
  884. font-weight: 700;
  885. font-size: 18px;
  886. line-height: 21px;
  887. letter-spacing: -0.3px;
  888. }
  889. .money {
  890. margin-bottom: 30px;
  891. width: 100%;
  892. display: flex;
  893. justify-content: center;
  894. align-items: center;
  895. img {
  896. width: 40px;
  897. height: 40px;
  898. margin-right: 9px;
  899. }
  900. .big {
  901. font-weight: 700;
  902. font-size: 46px;
  903. line-height: 55px;
  904. /* identical to box height */
  905. letter-spacing: 0.3px;
  906. color: #fff8e6;
  907. }
  908. .small {
  909. margin-left: 4px;
  910. font-weight: 700;
  911. font-size: 13px;
  912. line-height: 16px;
  913. /* identical to box height */
  914. letter-spacing: 0.5px;
  915. color: #fff8e6;
  916. }
  917. }
  918. }
  919. .luck-list-title {
  920. /* margin-top: 47px;*/
  921. margin: 0 16px;
  922. padding: 14px 0 11px 0;
  923. background: #fff;
  924. display: flex;
  925. justify-content: space-between;
  926. color: #B0B0B0;
  927. border-bottom: 1px solid #D1D1D1;
  928. div:last-child{
  929. text-align: right;
  930. }
  931. }
  932. .luck-list {
  933. background: #fff;
  934. overflow: auto;
  935. .luck-item {
  936. display: flex;
  937. padding: 12px 0;
  938. margin: 0 16px;
  939. border-bottom: 1px solid #d1d1d1;
  940. justify-content: space-between;
  941. position: relative;
  942. img:first-child {
  943. border-radius: 50%;
  944. }
  945. .luck-king {
  946. position: absolute;
  947. top: 36px;
  948. right: 0px;
  949. display: flex;
  950. align-items: center;
  951. img {
  952. width: 22px;
  953. height: 19px;
  954. margin: 0;
  955. }
  956. span {
  957. font-weight: 500;
  958. font-size: 12px;
  959. line-height: 14px;
  960. letter-spacing: 0.3px;
  961. color: #f5b945;
  962. }
  963. }
  964. img {
  965. width: 42px;
  966. height: 42px;
  967. margin-right: 12px;
  968. }
  969. .luck-content {
  970. flex: auto;
  971. .luck-title {
  972. font-weight: 500;
  973. font-size: 16px;
  974. letter-spacing: 0.3px;
  975. color: #444444;
  976. }
  977. .luck-time {
  978. font-weight: 400;
  979. font-size: 12px;
  980. line-height: 14px;
  981. color: #9b9b9b;
  982. }
  983. }
  984. .luck-money {
  985. display: flex;
  986. height: 17px;
  987. align-items: center;
  988. height: 100%;
  989. img {
  990. width: 14px;
  991. height: 14px;
  992. margin-right: 6px;
  993. }
  994. .luck-money-txt {
  995. font-weight: 500;
  996. font-size: 14px;
  997. word-break: break-all;
  998. /* identical to box height */
  999. text-align: right;
  1000. letter-spacing: 0.3px;
  1001. color: #444444;
  1002. }
  1003. }
  1004. }
  1005. .luck-item:last-child {
  1006. border: 0;
  1007. }
  1008. }
  1009. }
  1010. .success {
  1011. .luck-list-title {
  1012. margin-top: 47px;
  1013. margin-bottom: 11px;
  1014. border-bottom: 1px solid #D1D1D1;
  1015. }
  1016. }
  1017. .opened {
  1018. filter: drop-shadow(0px 4px 94px rgba(0, 0, 0, 0.3));
  1019. width: 100%;
  1020. height: 100%;
  1021. display: flex;
  1022. flex-direction: column;
  1023. justify-content: space-between;
  1024. .header {
  1025. text-align: center;
  1026. height: 150px;
  1027. width: 100%;
  1028. background: #fff;
  1029. // padding-top: 30px;
  1030. background-size: 100% 100%;
  1031. display: flex;
  1032. flex-wrap: wrap;
  1033. align-content: center;
  1034. .title {
  1035. color: #fff7e4;
  1036. opacity: 0.6;
  1037. width: 100%;
  1038. font-weight: 700;
  1039. font-size: 18px;
  1040. line-height: 21px;
  1041. letter-spacing: -0.3px;
  1042. margin-bottom: 10px;
  1043. }
  1044. .money {
  1045. width: 100%;
  1046. display: flex;
  1047. justify-content: center;
  1048. align-items: center;
  1049. img {
  1050. margin-right: 9px;
  1051. width: 40px;
  1052. height: 40px;
  1053. }
  1054. .big {
  1055. font-weight: 700;
  1056. font-size: 46px;
  1057. line-height: 55px;
  1058. /* identical to box height */
  1059. letter-spacing: 0.3px;
  1060. color: #fff8e6;
  1061. }
  1062. .small {
  1063. margin-left: 4px;
  1064. font-weight: 700;
  1065. font-size: 13px;
  1066. line-height: 16px;
  1067. /* identical to box height */
  1068. letter-spacing: 0.5px;
  1069. color: #fff8e6;
  1070. }
  1071. }
  1072. }
  1073. .list {
  1074. padding: 0 16px 0 16px;
  1075. background: #ffffff;
  1076. flex: 1;
  1077. .item {
  1078. display: flex;
  1079. align-items: center;
  1080. min-height: 50px;
  1081. border-bottom: 1px solid #f0f0f0;
  1082. img {
  1083. width: 24px;
  1084. height: 24px;
  1085. }
  1086. .red-right {
  1087. width: 35px;
  1088. height: 24px;
  1089. }
  1090. .item-content {
  1091. width: 100%;
  1092. flex: 1;
  1093. .item-follow-title {
  1094. display: flex;
  1095. align-items: center;
  1096. margin-top: 20px;
  1097. margin-bottom: 11px;
  1098. position: relative;
  1099. .btn {
  1100. // position: absolute;
  1101. // right: 0;
  1102. }
  1103. }
  1104. .item-title {
  1105. flex: 1;
  1106. margin-left: 10px;
  1107. font-weight: 500;
  1108. font-size: 16px;
  1109. letter-spacing: 0.3px;
  1110. color: #000000;
  1111. }
  1112. .item-follow-area {
  1113. display: flex;
  1114. flex-wrap: wrap;
  1115. .item-follow {
  1116. cursor: pointer;
  1117. border: 1px solid #ebebeb;
  1118. border-radius: 1000px;
  1119. height: 26px;
  1120. margin-right: 5px;
  1121. margin-bottom: 5px;
  1122. display: flex;
  1123. align-items: center;
  1124. .finished {
  1125. text-decoration: line-through;
  1126. color: #949494;
  1127. }
  1128. span {
  1129. margin-left: 8px;
  1130. margin-right: 2px;
  1131. color: #1D9BF0;
  1132. opacity: 1;
  1133. }
  1134. img {
  1135. width: 16px;
  1136. height: 16px;
  1137. margin-right: 7px;
  1138. }
  1139. }
  1140. }
  1141. span {
  1142. font-weight: 400;
  1143. font-size: 11px;
  1144. line-height: 13px;
  1145. letter-spacing: 0.3px;
  1146. color: #000000;
  1147. opacity: 0.4;
  1148. }
  1149. }
  1150. .btn {
  1151. width: 90px;
  1152. height: 29px;
  1153. line-height: 29px;
  1154. background: rgba(56, 154, 255, 0.1);
  1155. border-radius: 500px;
  1156. text-align: center;
  1157. letter-spacing: 0.3px;
  1158. color: #1D9BF0;
  1159. cursor: pointer;
  1160. }
  1161. }
  1162. }
  1163. .people {
  1164. cursor: pointer;
  1165. padding-left: 16px;
  1166. height: 38px;
  1167. line-height: 38px;
  1168. background: #fff;
  1169. border-bottom: 1px solid #f0f0f0;
  1170. box-shadow: 0px 1px 0px #f2f2f2;
  1171. display: flex;
  1172. align-items: center;
  1173. justify-content: space-between;
  1174. .txt {
  1175. width: 90%;
  1176. font-weight: 400;
  1177. font-size: 12px;
  1178. line-height: 14px;
  1179. letter-spacing: 0.3px;
  1180. color: #000000;
  1181. opacity: 0.4;
  1182. }
  1183. .right {
  1184. flex: 1;
  1185. cursor: pointer;
  1186. margin-right: 22px;
  1187. display: flex;
  1188. align-items: center;
  1189. position: relative;
  1190. img {
  1191. position: absolute;
  1192. width: 22px;
  1193. height: 22px;
  1194. border: 2px solid #fff;
  1195. border-radius: 50%;
  1196. }
  1197. .road {
  1198. right: 0;
  1199. width: 7px;
  1200. height: 14px;
  1201. }
  1202. }
  1203. }
  1204. .footer {
  1205. background: #ffffff;
  1206. display: flex;
  1207. padding: 15px 22px 15px 17px;
  1208. .first {
  1209. flex: 1;
  1210. .validity {
  1211. font-weight: 400;
  1212. font-size: 12px;
  1213. line-height: 14px;
  1214. letter-spacing: 0.3px;
  1215. color: #000000;
  1216. opacity: 0.4;
  1217. margin: 2px 0 8px 0;
  1218. }
  1219. .time {
  1220. font-weight: 500;
  1221. font-size: 13px;
  1222. line-height: 16px;
  1223. /* identical to box height */
  1224. color: #000000;
  1225. }
  1226. }
  1227. .btn {
  1228. background: #1D9BF0;
  1229. border-radius: 100px;
  1230. color: #fff;
  1231. width: 258px;
  1232. height: 52px;
  1233. font-weight: 600;
  1234. font-size: 18px;
  1235. line-height: 52px;
  1236. text-align: center;
  1237. cursor: pointer;
  1238. }
  1239. }
  1240. }
  1241. .not-open {
  1242. width: 100%;
  1243. height: 100%;
  1244. filter: drop-shadow(0px 2px 20px rgba(0, 0, 0, 0.1));
  1245. position: relative;
  1246. overflow: hidden;
  1247. border-radius: 11px;
  1248. .money-area {
  1249. width: 100%;
  1250. position: absolute;
  1251. top: 65px;
  1252. display: flex;
  1253. flex-wrap: wrap;
  1254. align-items: center;
  1255. justify-content: center;
  1256. .txt {
  1257. font-weight: 800;
  1258. font-size: 16px;
  1259. text-align: center;
  1260. letter-spacing: 0.3px;
  1261. color: #FFFFFF;
  1262. }
  1263. .coin {
  1264. text-align: center;
  1265. margin-top: 6px;
  1266. margin-bottom: 7px;
  1267. display: flex;
  1268. justify-content: center;
  1269. align-items: center;
  1270. width:90%;
  1271. img {
  1272. width: 46px;
  1273. height: 46px;
  1274. border-radius: 50%;
  1275. border: 3px solid #FFFFFF;
  1276. }
  1277. span {
  1278. margin-left: 15px;
  1279. font-weight: 800;
  1280. font-size: 60px;
  1281. line-height: 76px;
  1282. color: #FFFFFF;
  1283. }
  1284. }
  1285. .people {
  1286. font-weight: 800;
  1287. font-size: 13px;
  1288. line-height: 16px;
  1289. letter-spacing: 0.05em;
  1290. text-align: center;
  1291. color: #FFFFFF;
  1292. }
  1293. }
  1294. .title {
  1295. position: absolute;
  1296. top: 15px;
  1297. left: 15px;
  1298. z-index: 3;
  1299. display: flex;
  1300. align-items: center;
  1301. img {
  1302. width: 24px;
  1303. height: 24px;
  1304. border: 2px solid #FFF4DB;
  1305. border-radius: 50%;
  1306. }
  1307. span {
  1308. margin-left: 10px;
  1309. font-weight: 600;
  1310. font-size: 16px;
  1311. letter-spacing: 0.3px;
  1312. color: #fff;
  1313. }
  1314. }
  1315. // .txt {
  1316. // width: 100%;
  1317. // position: absolute;
  1318. // font-style: normal;
  1319. // font-weight: 700;
  1320. // font-size: 42px;
  1321. // line-height: 50px;
  1322. // text-align: center;
  1323. // color: #FFF2D3;
  1324. // top: 90px;
  1325. // z-index: 3;
  1326. // }
  1327. img {
  1328. width: 100%;
  1329. }
  1330. .up {
  1331. position: absolute;
  1332. top: 0;
  1333. // box-shadow: 0px 4px 44px rgba(0, 0, 0, 0.1);
  1334. z-index: 1;
  1335. }
  1336. .down {
  1337. position: absolute;
  1338. top: 253px;
  1339. }
  1340. .open {
  1341. width: 335px;
  1342. height: 50px;
  1343. cursor: pointer;
  1344. position: absolute;
  1345. bottom: 28px;
  1346. left: 50%;
  1347. margin-left: -167.5px;
  1348. z-index: 4;
  1349. }
  1350. .open-gif {
  1351. width: 200px;
  1352. height: 200px;
  1353. text-align: center;
  1354. position: absolute;
  1355. bottom: 70px;
  1356. left: 50%;
  1357. margin-left: -100px;
  1358. z-index: 3;
  1359. }
  1360. }
  1361. }
  1362. </style>