index.vue 18 KB

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