index.vue 8.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367
  1. <template>
  2. <div class="p-invite">
  3. <div class="p-top">
  4. <div class="award">
  5. <p class="award-name">Invite friends to get</p>
  6. <div class="award-worth">
  7. <span class="num">- ${{ couponAmount() }}</span>
  8. <span class="txt">COUPON</span>
  9. </div>
  10. <p class="award-instruction">PTC offline store use</p>
  11. </div>
  12. <div class="desc">
  13. <p class="desc-title"><i class="star"></i>Event Description</p>
  14. <p class="desc-content">
  15. Friends who share your link will get
  16. <strong>${{ couponAmount(true) }}</strong> coupon. If a friend buys a
  17. membership, you will get
  18. <strong>${{ couponAmount(true) }}</strong> coupon. after the purchase,
  19. which can be used for the next membership fee payment and electronic
  20. accessories products.
  21. </p>
  22. </div>
  23. <div class="methods">
  24. <div class="ptc-inner-md">
  25. <div class="method">
  26. <p class="method-title">Share your exclusive link with friends</p>
  27. <p class="ptc-comboinput">
  28. <input
  29. type="text"
  30. class="ptc-input"
  31. readonly
  32. :value="inviteUrl"
  33. />
  34. <button class="ptc-button" @click="copy(inviteUrl)">
  35. Copy Link
  36. </button>
  37. </p>
  38. </div>
  39. <div class="method">
  40. <p class="method-title">Email invitation</p>
  41. <textarea
  42. v-model="emails"
  43. placeholder="Enter email addresses, multiple mailboxes are separated by“ ,”"
  44. ></textarea>
  45. </div>
  46. <button class="ptc-button" @click="invite">Send invitation</button>
  47. </div>
  48. </div>
  49. </div>
  50. <div class="p-bottom">
  51. <template v-if="awards.length">
  52. <h3 class="ptc-title">My Reward ${{ totalAmount }}</h3>
  53. <div class="block records">
  54. <div class="ptc-inner-md">
  55. <ul>
  56. <li v-for="(award, index) of awards" :key="index" class="record">
  57. <span class="left">{{ award.title }}</span>
  58. <span class="center">{{ award.created_at }}</span>
  59. <span class="right">${{ award.gift_card_amount }}</span>
  60. </li>
  61. </ul>
  62. </div>
  63. </div>
  64. </template>
  65. <h3 class="ptc-title">Activity Details</h3>
  66. <div class="block details">
  67. <div class="ptc-inner-md">
  68. <p>
  69. After a friend places an order, you can get a corresponding coupon
  70. according to the amount of his first order, which can be used for
  71. the purchase of membership services and consumption at PTC's offline
  72. outlets.
  73. </p>
  74. <p class="mt48">1. The invitee is an unregistered new user;</p>
  75. <p class="mt48">
  76. 2. On the 10th of each month/at 23:00 every day, the invitation
  77. rewards will be settled, and the coupons will be issued to the
  78. personal account
  79. </p>
  80. </div>
  81. </div>
  82. </div>
  83. </div>
  84. </template>
  85. <script>
  86. import { defineComponent } from 'vue'
  87. import { string } from 'yup'
  88. import { inviteFriends, getInviteRewards } from '@/service/user'
  89. import Toast from '@/components/toast'
  90. import copy from '@/utils/clipboard'
  91. import { state } from '@/store'
  92. export default defineComponent({
  93. name: 'InviteFriends',
  94. async beforeRouteEnter(to, from, next) {
  95. const { results } = await getInviteRewards()
  96. next(vm => (vm.awards = results))
  97. },
  98. data() {
  99. return {
  100. emails: '',
  101. /** @type {any[]} */
  102. awards: [],
  103. inviteUrl:
  104. location.origin +
  105. '/fill-order?from=member&invitee=' +
  106. state.userInfo.id,
  107. }
  108. },
  109. computed: {
  110. totalAmount() {
  111. return this.awards.reduce(
  112. (sum, award) => sum + +award.gift_card_amount,
  113. 0
  114. )
  115. },
  116. },
  117. methods: {
  118. couponAmount(total = false) {
  119. const { coupon_amount, coupon_num } = state.coupon
  120. return coupon_amount
  121. ? total
  122. ? coupon_amount * coupon_num
  123. : coupon_amount
  124. : 'N/A'
  125. },
  126. async invite() {
  127. if (!this.emails) return Toast('Please enter email addresses')
  128. try {
  129. this.emails
  130. .split(',')
  131. .forEach(email =>
  132. string().email('Please check email addresses').validateSync(email)
  133. )
  134. await inviteFriends(this.emails)
  135. Toast('success')
  136. } catch (err) {
  137. Toast(err.message)
  138. }
  139. },
  140. copy(content) {
  141. copy(content)
  142. Toast('copy success')
  143. },
  144. },
  145. })
  146. </script>
  147. <style lang="scss">
  148. .p-invite {
  149. .p-top {
  150. display: flex;
  151. flex-wrap: wrap;
  152. justify-content: center;
  153. align-items: center;
  154. padding: 8px 0 48px;
  155. background: $primary-color;
  156. overflow: hidden;
  157. @include media-breakpoint-up(md) {
  158. padding: 40px 0 64px;
  159. }
  160. @include media-breakpoint-up(xl) {
  161. display: block;
  162. text-align: center;
  163. .award,
  164. .desc {
  165. display: inline-block;
  166. vertical-align: middle;
  167. }
  168. .methods {
  169. margin: 36px auto 0;
  170. }
  171. }
  172. }
  173. .p-bottom {
  174. margin: auto;
  175. @include media-breakpoint-up(lg) {
  176. width: 768px * 2;
  177. }
  178. @include media-breakpoint-up(xl) {
  179. width: 999px * 2;
  180. }
  181. }
  182. .award,
  183. .desc,
  184. .methods {
  185. width: 90%;
  186. }
  187. .award {
  188. @include icon('@img/coupon.png', 98%, 370px);
  189. text-align: center;
  190. overflow: hidden;
  191. @include media-breakpoint-up(md) {
  192. margin-left: -40px;
  193. height: 500px;
  194. width: 880px;
  195. }
  196. @include media-breakpoint-up(xl) {
  197. margin-right: 108px;
  198. width: 960px;
  199. }
  200. &-name {
  201. margin-top: 66px;
  202. font-weight: bold;
  203. font-size: 48px;
  204. color: #193059;
  205. }
  206. &-worth {
  207. margin: 32px 0 24px;
  208. line-height: 56px;
  209. font-weight: 500;
  210. color: #193059;
  211. .num {
  212. font-size: 56px;
  213. }
  214. .txt {
  215. margin-left: 20px;
  216. font-size: 40px;
  217. }
  218. }
  219. &-instruction {
  220. font-size: 28px;
  221. color: #9aa8c5;
  222. }
  223. @include media-breakpoint-up(md) {
  224. &-name {
  225. margin-top: 100px;
  226. font-size: 60px;
  227. }
  228. &-worth {
  229. margin: 54px 0 44px;
  230. .num {
  231. font-size: 80px;
  232. }
  233. .txt {
  234. font-size: 56px;
  235. }
  236. }
  237. &-instruction {
  238. font-size: 40px;
  239. }
  240. }
  241. }
  242. .desc {
  243. padding: 52px 26px 26px;
  244. border: 2px solid rgba(218, 225, 239, 0.25);
  245. color: #dae1ef;
  246. @include media-breakpoint-up(md) {
  247. // margin-left: 134px;
  248. width: 680px;
  249. }
  250. &-title {
  251. @include thin-border(bottom, rgba(218, 225, 239, 0.25));
  252. display: flex;
  253. align-items: center;
  254. justify-content: center;
  255. padding-bottom: 48px;
  256. font-size: 32px;
  257. font-weight: bold;
  258. .star {
  259. @include icon('@img/star.png', 40px);
  260. margin-right: 16px;
  261. }
  262. }
  263. &-content {
  264. margin-top: 26px;
  265. font-size: 28px;
  266. line-height: 40px;
  267. }
  268. strong {
  269. font-size: 32px;
  270. }
  271. }
  272. .methods {
  273. margin-top: 36px;
  274. padding: 64px 36px;
  275. background: #fff;
  276. border-radius: 16px;
  277. @include media-breakpoint-up(md) {
  278. border-radius: 0;
  279. }
  280. @include media-breakpoint-up(lg) {
  281. width: 768px * 2;
  282. }
  283. @include media-breakpoint-up(xl) {
  284. width: 999px * 2;
  285. }
  286. }
  287. .method {
  288. &:nth-child(1) {
  289. margin-bottom: 64px;
  290. }
  291. &:nth-child(2) {
  292. margin-bottom: 24px;
  293. }
  294. &-title {
  295. margin-bottom: 24px;
  296. font-size: 32px;
  297. font-weight: bold;
  298. color: #193059;
  299. }
  300. .ptc-input {
  301. height: 88px;
  302. font-size: 24px;
  303. @include media-breakpoint-up(md) {
  304. font-size: 28px;
  305. }
  306. }
  307. }
  308. textarea {
  309. display: block;
  310. padding: 24px;
  311. width: 100%;
  312. height: 182px;
  313. border-radius: 8px;
  314. border: 2px solid #d9d9d9;
  315. font-size: 28px;
  316. line-height: 40px;
  317. }
  318. .block {
  319. background: #fff;
  320. }
  321. .records {
  322. padding: 0 36px;
  323. }
  324. .record {
  325. display: flex;
  326. justify-content: space-between;
  327. align-items: center;
  328. padding: 36px 0;
  329. + .record {
  330. @include thin-border(top);
  331. }
  332. .left {
  333. font-weight: bold;
  334. font-size: 32px;
  335. color: #1a1a1a;
  336. }
  337. .center,
  338. .right {
  339. font-size: 28px;
  340. color: #666;
  341. }
  342. .center {
  343. padding-right: 50px;
  344. }
  345. }
  346. .details {
  347. padding: 36px;
  348. font-size: 32px;
  349. line-height: 44px;
  350. color: #666;
  351. }
  352. @include media-breakpoint-up(md) {
  353. .ptc-comboinput .ptc-button {
  354. width: 322px;
  355. }
  356. }
  357. }
  358. </style>