index.vue 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629
  1. <template>
  2. <v-container class="invite-user" fluid :class="`bg-${type}`">
  3. <activity-invite-user-box class="box1">
  4. <template #title>参与步骤</template>
  5. <v-img
  6. v-if="type === 1"
  7. class="cybz-content"
  8. src="~/assets/image/activity/invite-user/cybz-content@2x.png"
  9. />
  10. <v-img
  11. v-else-if="type === 2"
  12. class="cybz-content"
  13. src="~/assets/image/activity/invite-user/cybz-content-2@2x.png"
  14. />
  15. <div class="cybz-content-text">
  16. <div class="cybz-content-text-item">分享好友</div>
  17. <div class="cybz-content-text-item">邀请购买云机</div>
  18. <div class="cybz-content-text-item">
  19. <template v-if="type === 1">返星币换现金</template>
  20. <template v-else-if="type === 2">返云手机时长</template>
  21. </div>
  22. </div>
  23. <v-btn class="share-button" rounded @click="share()">
  24. <template v-if="!($userAgent.isSzx || $userAgent.isSzxBrowser)"
  25. >复制链接</template
  26. >分享好友
  27. </v-btn>
  28. <!-- <button @click="share()">邀请</button> -->
  29. </activity-invite-user-box>
  30. <activity-invite-user-box class="ox box2">
  31. <template #title>收益明细</template>
  32. <div class="grid grid-cols-2 gap-x-4 gap-y-8">
  33. <div
  34. v-for="(item, index) in dataList"
  35. :key="index"
  36. :class="{
  37. 'col-span-2': index === 6,
  38. }"
  39. >
  40. <div class="label text-sm">
  41. <span>{{ item.label }}</span>
  42. </div>
  43. <div class="value text-2xl font-bold">
  44. <span>{{ item.value | formatNumber }}</span>
  45. </div>
  46. </div>
  47. </div>
  48. </activity-invite-user-box>
  49. <activity-invite-user-box v-if="type === 2" class="box3">
  50. <template #title>激活码明细</template>
  51. <div class="code-table">
  52. <div class="table-header">
  53. <table class="w-full">
  54. <colgroup>
  55. <col class="time-col" />
  56. <col class="code-col" />
  57. <col class="status-col" />
  58. </colgroup>
  59. <thead class="text-left text-sm whitespace-nowrap break-normal">
  60. <tr>
  61. <th class="">获得的时间</th>
  62. <th>激活码编号</th>
  63. <th class="">使用状态</th>
  64. </tr>
  65. </thead>
  66. </table>
  67. </div>
  68. <div class="table-body">
  69. <table class="w-full">
  70. <colgroup>
  71. <col class="time-col" />
  72. <col class="code-col" />
  73. <col class="status-col" />
  74. </colgroup>
  75. <tbody class="text-xs">
  76. <tr v-for="(item, index) in myActivationCode" :key="index">
  77. <td class="whitespace-nowrap break-normal">
  78. {{ item.createTime | formatDate('MM月DD日 HH:mm:ss') }}
  79. </td>
  80. <td class="whitespace-nowrap break-normal">
  81. <div class="flex">
  82. <span class="font-mono"
  83. >{{ item.activationCode | activationCodeMask }} </span
  84. ><span class="mx-1">|</span
  85. ><v-btn
  86. text
  87. small
  88. color="#991AD2"
  89. class="copy-btn"
  90. @click="copyCode(item)"
  91. >复制</v-btn
  92. >
  93. </div>
  94. </td>
  95. <td class="whitespace-nowrap break-normal text-right">
  96. <span v-if="item.activationUse" style="color: #dd1b0d"
  97. >已使用</span
  98. >
  99. <span v-else>未使用</span>
  100. </td>
  101. </tr>
  102. </tbody>
  103. </table>
  104. <div
  105. v-if="myActivationCode.length"
  106. v-intersect.quiet="codeLoadMoreIntersect"
  107. class="flex item-center justify-center"
  108. >
  109. <!-- <v-progress-circular indeterminate ></v-progress-circular> -->
  110. <v-btn :loading="codeIsLoading" text small>
  111. <template v-if="codeIsLoading">加载中</template>
  112. <template v-else-if="codeHasMore">加载更多</template>
  113. <template v-else>没有更多</template>
  114. </v-btn>
  115. </div>
  116. </div>
  117. </div>
  118. <!-- <div class="code-list">
  119. <div
  120. v-for="(item, index) in 10"
  121. :key="index"
  122. class="code-item"
  123. ></div>
  124. </div> -->
  125. </activity-invite-user-box>
  126. <activity-invite-user-box class="box4">
  127. <template #title>活动规则</template>
  128. <!-- eslint-disable-next-line vue/no-v-html -->
  129. <div class="text-sm" v-html="activityRules"></div>
  130. </activity-invite-user-box>
  131. <!-- <div class="">invite-user</div> -->
  132. <!-- <button>刷新数据</button> -->
  133. <!-- <div class="">{{ data }}</div> -->
  134. <!-- <div class="text-center">
  135. <span>分享好友购买云机套餐<br />返星币换现金</span>
  136. </div>
  137. <div class="text-center mt-4">
  138. <van-button type="primary" @click="share()">邀请好友</van-button>
  139. </div>
  140. <van-icon name="chat-o" />
  141. <van-icon name="shape-plus" class-prefix="mdi" />
  142. <van-button @click="$fetch()">刷新</van-button>
  143. <div class="ccc">{{ 36666666.123456 | formatNumber }}</div>
  144. <div class="ccc">{{ '2020-01-01' | formatDate }}</div> -->
  145. </v-container>
  146. </template>
  147. <script>
  148. // import qs from 'qs';
  149. // import clipboard from 'clipboardy/browser';
  150. // import * as clipboard from 'clipboard-polyfill/text';
  151. // console.log("🚀 ~ file: index.vue ~ line 176 ~ clipboard", clipboard)
  152. // import { getStarCoinOverview } from '~/api/activity/invite-user.js';
  153. // import { getContentByType } from '~/api/public/agreement.js';
  154. export default {
  155. // auth: false,
  156. name: 'InviteUser',
  157. filters: {
  158. activationCodeMask(value) {
  159. // 微信环境不支持零宽断言
  160. // return value.replace(/(?<=^.{4})(.*)(?=.{4}$)/, '***');
  161. return value.replace(/(.{4})(.*)(.{4}$)/, '$1***$3');
  162. },
  163. },
  164. // async asyncData({ $axios }) {
  165. // // 页面初始化前触发
  166. // const res = await $axios.$get(
  167. // '/activity/v1/inviteUser/orderRelation/starCoinOverview',
  168. // );
  169. // res.data.type = 2;
  170. // return {
  171. // data: res.data,
  172. // };
  173. // },
  174. data() {
  175. return {
  176. data: {
  177. todayIncomeStarCoin: 0,
  178. totalIncomeStarCoin: 0,
  179. todayBuyOrderCount: 0,
  180. totalBuyOrderCount: 0,
  181. todayBuyOrderSuccessCount: 0,
  182. totalBuyOrderSuccessCount: 0,
  183. withdrawStarCoinNum: 0,
  184. inviteUserName: null,
  185. activityId: null,
  186. status: 0,
  187. type: 0,
  188. },
  189. activityRules: '',
  190. myActivationCode: [],
  191. myCodeFrom: {
  192. activityId: null,
  193. pageNum: 1,
  194. pageSize: 8,
  195. },
  196. codeTotal: -1,
  197. codeIsLoading: false,
  198. };
  199. },
  200. async fetch() {
  201. // 页面初始化后触发
  202. try {
  203. await this.getActiveInfo();
  204. this.$native.setShareInfo(this.shareInfo);
  205. await Promise.all([
  206. this.getActivityRules(),
  207. this.type === 2 && this.getMyActivationCode(this.myCodeFrom),
  208. ]);
  209. } catch (error) {
  210. this.$toast.error(error.message);
  211. }
  212. },
  213. head: {
  214. title: '邀请好友',
  215. // share: {
  216. // title: '标题',
  217. // content: '内容',
  218. // gotoUrl: 'http://localhost',
  219. // shareImg: 'http://localhost',
  220. // },
  221. },
  222. computed: {
  223. codeHasMore() {
  224. return (
  225. this.codeTotal < 0 ||
  226. this.myCodeFrom.pageNum * this.myCodeFrom.pageSize < this.codeTotal
  227. );
  228. },
  229. dataList() {
  230. switch (this.type) {
  231. case 1: {
  232. return [
  233. { label: '今日收益(星币)', value: this.data.todayIncomeStarCoin },
  234. { label: '总收益(星币)', value: this.data.totalIncomeStarCoin },
  235. {
  236. label: '今日购买订单数',
  237. value: this.data.todayBuyOrderSuccessCount,
  238. },
  239. { label: '累计推广订单', value: this.data.totalBuyOrderCount },
  240. {
  241. label: '今日购买成功客户',
  242. value: this.data.todayBuyOrderSuccessCount,
  243. },
  244. {
  245. label: '累计购买成功客户',
  246. value: this.data.totalBuyOrderSuccessCount,
  247. },
  248. // { label: '可提现星币数量', value: this.data.withdrawStarCoinNum },
  249. ];
  250. }
  251. case 2: {
  252. return [
  253. {
  254. label: '今日获取的激活码',
  255. value: this.data.todayIncomeActivationCode,
  256. },
  257. { label: '总激活码', value: this.data.totalIncomeActivationCode },
  258. {
  259. label: '今日购买订单数',
  260. value: this.data.todayBuyOrderSuccessCount,
  261. },
  262. { label: '累计推广订单', value: this.data.totalBuyOrderCount },
  263. {
  264. label: '今日购买成功客户',
  265. value: this.data.todayBuyOrderSuccessCount,
  266. },
  267. {
  268. label: '累计购买成功客户',
  269. value: this.data.totalBuyOrderSuccessCount,
  270. },
  271. // { label: '可提现星币数量', value: this.data.withdrawStarCoinNum },
  272. ];
  273. }
  274. default: {
  275. return [];
  276. }
  277. }
  278. },
  279. type() {
  280. return this.data.type;
  281. },
  282. shareUrl() {
  283. return (
  284. location.origin +
  285. this.$router.resolve({
  286. path: '/activity/invite-user/register',
  287. query: {
  288. invitationUserName: this.data.inviteUserName,
  289. activityId: this.data.activityId,
  290. type: this.type,
  291. },
  292. }).href
  293. );
  294. },
  295. shareInfo() {
  296. if (this.$userAgent.isMiniProgram) {
  297. return {
  298. title: '双子星APP',
  299. path: '/pages/home/home',
  300. imgUrl: location.origin + require('~/assets/image/logo.png'),
  301. };
  302. }
  303. return {
  304. title: '双子星APP',
  305. desc: '分享好友购买云机套餐,返星币换现金',
  306. link: this.shareUrl,
  307. imgUrl: location.origin + require('~/assets/image/logo.png'),
  308. };
  309. },
  310. },
  311. mounted() {
  312. // this.$userAgent.isMiniProgram &&
  313. // this.$wx.miniProgram.postMessage({
  314. // data: {
  315. // action: 'updateAppMessageShareData',
  316. // params: {
  317. // title: '双子星云手机',
  318. // path: '/pages/home/home',
  319. // imageUrl:
  320. // location.origin +
  321. // require('~/assets/image/activity/invite-user/bg@2x.png'),
  322. // // promise: null,
  323. // },
  324. // },
  325. // });
  326. },
  327. methods: {
  328. async getActiveInfo() {
  329. const res = await this.$axios.$get(
  330. '/activity/v1/inviteUser/orderRelation/starCoinOverview',
  331. );
  332. // res.data.type = 2;
  333. this.data = res.data;
  334. this.myCodeFrom.activityId = res.data.activityId;
  335. },
  336. async getMyActivationCode(params) {
  337. try {
  338. this.codeIsLoading = true;
  339. const res = await this.$axios.$get(
  340. '/activity/v1/inviteUser/orderRelation/myActivationCode',
  341. {
  342. params,
  343. },
  344. );
  345. this.codeTotal = res.data.total;
  346. this.myActivationCode.push(
  347. ...(res.data.list ?? []),
  348. // ...Array.from({ length: 8 }).fill({
  349. // createTime: '2022-08-01 14:33:11',
  350. // activationCode: 'XXXXXXXXXXXXXXXXXXX',
  351. // activationUse: 1,
  352. // }),
  353. );
  354. this.myCodeFrom = params;
  355. } finally {
  356. this.codeIsLoading = false;
  357. }
  358. },
  359. async share() {
  360. // console.log(this);
  361. if (this.data.status !== 1) {
  362. if (this.data.status === 0) {
  363. throw new Error('当前活动已过期');
  364. }
  365. if (this.data.status === 2) {
  366. throw new Error('当前活动未开启');
  367. }
  368. if (this.data.status === 3) {
  369. throw new Error('当前活动已结束');
  370. }
  371. throw new Error('未知活动状态');
  372. }
  373. this.$tongji.trackEvent('活动', '分享', '', 0);
  374. // if (this.$userAgent.isMiniProgram) {
  375. // // 小程序环境
  376. // await clipboard.writeText(`${this.shareInfo.gotoUrl} 唔即云手机`);
  377. // this.$toast.success('链接复制成功');
  378. // } else
  379. if (this.$userAgent.isSzx || this.$userAgent.isSzxBrowser) {
  380. // app环境
  381. this.$native.share(this.shareInfo);
  382. } else {
  383. // 浏览器环境
  384. await this.$native.clipboard.writeText(`${this.shareUrl} 双子星云手机`);
  385. // throw new Error('1231');
  386. this.$toast.success('链接复制成功');
  387. }
  388. },
  389. async getActivityRules() {
  390. const agreementCoding = { 1: 'iuserrules01', 2: 'iuserrules02' }[
  391. this.type
  392. ];
  393. if (agreementCoding) {
  394. const res = await this.$axios.$get(
  395. '/public/v5/agreementApi/content/getContentByType',
  396. {
  397. params: {
  398. agreementCoding,
  399. type: 1,
  400. },
  401. },
  402. );
  403. this.activityRules = res.data.content
  404. .replace(/[\d\D]*<body>([\d\D]+)<\/body>[\d\D]*/i, '$1')
  405. .replace(/<div class="phone-container">([\d\D]+)<\/div>/g, '$1');
  406. }
  407. },
  408. async copyCode(item) {
  409. await this.$native.clipboard.writeText(item.activationCode);
  410. this.$toast.success('复制成功');
  411. },
  412. codeLoadMoreIntersect(event) {
  413. if (event[0].isIntersecting && this.codeHasMore && !this.codeIsLoading) {
  414. this.getMyActivationCode({
  415. ...this.myCodeFrom,
  416. pageNum: this.myCodeFrom.pageNum + 1,
  417. });
  418. }
  419. },
  420. },
  421. };
  422. </script>
  423. <style lang="scss" scoped>
  424. .invite-user {
  425. color: #333;
  426. // background-image: url('~/assets/image/activity/invite-user/bg@2x.png');
  427. background-size: 100% auto;
  428. // background-position-y: -44px;
  429. overflow: hidden;
  430. padding: 0;
  431. // padding-bottom: 30px;
  432. padding-bottom: env(safe-area-inset-bottom, 30px);
  433. background-color: #9525e3;
  434. &.bg-1 {
  435. background-image: url('~/assets/image/activity/invite-user/bg@2x.png');
  436. }
  437. &.bg-2 {
  438. background-image: url('~/assets/image/activity/invite-user/bg-2@2x.png');
  439. }
  440. }
  441. // .box {
  442. // width: 373px;
  443. // box-sizing: border-box;
  444. // margin: auto;
  445. // // border-image-width: 200px;
  446. // // border-image-slice: 200%;
  447. // // border-width: 1px;
  448. // position: relative;
  449. // z-index: 0;
  450. // + .box {
  451. // margin-top: 30px;
  452. // }
  453. // .box-header {
  454. // // position: absolute;
  455. // position: relative;
  456. // // top: -30px;
  457. // z-index: 1;
  458. // // left: 141px;
  459. // // left: 0;
  460. // // right: 0;
  461. // margin-bottom: -34px;
  462. // // text-align: center;
  463. // // padding: 0 130px;
  464. // display: flex;
  465. // align-items: center;
  466. // justify-content: center;
  467. // flex-direction: column;
  468. // .box-header-content {
  469. // color: #fff;
  470. // border-image-source: url('~/assets/image/activity/invite-user/box-title@2x.png');
  471. // border-image-slice: 0 140 fill;
  472. // border-width: 0 70px 0;
  473. // border-style: solid;
  474. // height: 38px;
  475. // display: flex;
  476. // align-items: center;
  477. // justify-content: center;
  478. // flex-direction: column;
  479. // // width: auto;
  480. // }
  481. // }
  482. // .box-main {
  483. // z-index: 0;
  484. // // padding: 30px 15px 20px;
  485. // border-image-source: url('~/assets/image/activity/invite-user/box-bg@2x.png');
  486. // border-image-slice: 50 60 80 fill;
  487. // border-image-width: 30px 30px 40px;
  488. // border-width: 50px 20px 40px;
  489. // border-style: solid;
  490. // // padding-top: 30px;
  491. // }
  492. // }
  493. .box1 {
  494. margin-top: 275px;
  495. // ::v-deep .box-main {
  496. // // padding: 30px 15px 20px;
  497. // padding-left: 0;
  498. // padding-right: 0;
  499. // }
  500. .cybz-content {
  501. width: 305px;
  502. height: 75px;
  503. margin: auto;
  504. display: block;
  505. // margin-top: 30px;
  506. }
  507. .cybz-content-text {
  508. // display: flex;
  509. display: grid;
  510. // width: 305px;
  511. // padding: 0 28px;
  512. // align-items: center;
  513. // margin: auto;
  514. // justify-content: space-between;
  515. grid-template-columns: 1fr 1fr 1fr;
  516. font-size: 12px;
  517. color: #333;
  518. .cybz-content-text-item {
  519. // width: 0;
  520. // flex: auto;
  521. text-align: center;
  522. }
  523. }
  524. .share-button {
  525. display: block;
  526. margin: auto;
  527. width: 302px !important;
  528. height: 62px !important;
  529. background-image: url('~/assets/image/activity/invite-user/share-button@2x.png');
  530. background-size: 100% 100%;
  531. margin-top: 24px;
  532. // margin-bottom: 24px;
  533. color: #dd1b0d;
  534. font-size: 22px;
  535. font-weight: bold;
  536. }
  537. }
  538. .box2 {
  539. .label {
  540. // font-size: 14px;
  541. }
  542. .value {
  543. color: #ff6600;
  544. // font-size: 24px;
  545. }
  546. ::v-deep .box-main {
  547. padding-left: 20px;
  548. padding-right: 20px;
  549. }
  550. }
  551. .box3 {
  552. ::v-deep .box-main {
  553. // padding-left: 20px;
  554. // padding-top: 0;
  555. padding-left: 10px;
  556. padding-right: 10px;
  557. }
  558. }
  559. .code-table {
  560. .table-body {
  561. max-height: 30px * 8;
  562. overflow-y: auto;
  563. }
  564. .time-col {
  565. width: 120px;
  566. }
  567. .status-col {
  568. width: 60px;
  569. }
  570. // width: 100%;
  571. tr {
  572. height: 30px;
  573. color: #666;
  574. }
  575. td {
  576. height: 30px;
  577. color: #333;
  578. }
  579. // tbody {
  580. // // max-height: 200px;
  581. // // overflow-y: auto;
  582. // // display: block;
  583. // }
  584. .copy-btn {
  585. min-width: 0 !important;
  586. height: auto !important;
  587. padding: 0 !important;
  588. }
  589. }
  590. .box4::v-deep .box-main {
  591. padding-left: 10px;
  592. padding-right: 10px;
  593. }
  594. </style>