index.vue 8.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350
  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 a
  16. <strong>${{ couponAmount }}</strong> coupon. If a friend buys a
  17. membership, you will get a
  18. <strong>${{ couponAmount }}</strong> coupon. after the purchase, which
  19. 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. couponAmount() {
  117. return state.coupon.coupon_amount || 'N/A'
  118. },
  119. },
  120. methods: {
  121. async invite() {
  122. if (!this.emails) return Toast('Please enter email addresses')
  123. try {
  124. this.emails
  125. .split(',')
  126. .forEach(email =>
  127. string().email('Please check email addresses').validateSync(email)
  128. )
  129. await inviteFriends(this.emails)
  130. Toast('success')
  131. } catch (err) {
  132. Toast(err.message)
  133. }
  134. },
  135. copy(content) {
  136. copy(content)
  137. Toast('copy success')
  138. },
  139. },
  140. })
  141. </script>
  142. <style lang="scss">
  143. .p-invite {
  144. .p-top {
  145. display: flex;
  146. flex-wrap: wrap;
  147. justify-content: center;
  148. align-items: center;
  149. padding: 8px 0 48px;
  150. background: $primary-color;
  151. overflow: hidden;
  152. @include media-breakpoint-up(md) {
  153. padding: 40px 0 64px;
  154. }
  155. }
  156. .p-bottom {
  157. margin: auto;
  158. @include media-breakpoint-up(lg) {
  159. width: 768px * 2;
  160. }
  161. @include media-breakpoint-up(xl) {
  162. width: 999px * 2;
  163. }
  164. }
  165. .award,
  166. .desc,
  167. .methods {
  168. width: 90%;
  169. }
  170. .award {
  171. @include icon('@img/coupon.png', 98%, 370px);
  172. text-align: center;
  173. overflow: hidden;
  174. @include media-breakpoint-up(md) {
  175. margin-left: -40px;
  176. height: 500px;
  177. width: 880px;
  178. }
  179. @include media-breakpoint-up(xl) {
  180. margin-right: 108px;
  181. width: 960px;
  182. }
  183. &-name {
  184. margin-top: 66px;
  185. font-weight: bold;
  186. font-size: 48px;
  187. color: #193059;
  188. }
  189. &-worth {
  190. margin: 32px 0 24px;
  191. line-height: 56px;
  192. font-weight: 500;
  193. color: #193059;
  194. .num {
  195. font-size: 56px;
  196. }
  197. .txt {
  198. margin-left: 20px;
  199. font-size: 40px;
  200. }
  201. }
  202. &-instruction {
  203. font-size: 28px;
  204. color: #9aa8c5;
  205. }
  206. @include media-breakpoint-up(md) {
  207. &-name {
  208. margin-top: 100px;
  209. font-size: 60px;
  210. }
  211. &-worth {
  212. margin: 54px 0 44px;
  213. .num {
  214. font-size: 80px;
  215. }
  216. .txt {
  217. font-size: 56px;
  218. }
  219. }
  220. &-instruction {
  221. font-size: 40px;
  222. }
  223. }
  224. }
  225. .desc {
  226. padding: 52px 26px 26px;
  227. border: 2px solid rgba(218, 225, 239, 0.25);
  228. color: #dae1ef;
  229. @include media-breakpoint-up(md) {
  230. // margin-left: 134px;
  231. width: 680px;
  232. }
  233. &-title {
  234. @include thin-border(bottom, rgba(218, 225, 239, 0.25));
  235. display: flex;
  236. align-items: center;
  237. justify-content: center;
  238. padding-bottom: 48px;
  239. font-size: 32px;
  240. font-weight: bold;
  241. .star {
  242. @include icon('@img/star.png', 40px);
  243. margin-right: 16px;
  244. }
  245. }
  246. &-content {
  247. margin-top: 26px;
  248. font-size: 28px;
  249. line-height: 40px;
  250. }
  251. strong {
  252. font-size: 32px;
  253. }
  254. }
  255. .methods {
  256. margin-top: 36px;
  257. padding: 64px 36px;
  258. background: #fff;
  259. border-radius: 16px;
  260. @include media-breakpoint-up(md) {
  261. border-radius: 0;
  262. }
  263. @include media-breakpoint-up(lg) {
  264. width: 768px * 2;
  265. }
  266. @include media-breakpoint-up(xl) {
  267. width: 999px * 2;
  268. }
  269. }
  270. .method {
  271. &:nth-child(1) {
  272. margin-bottom: 64px;
  273. }
  274. &:nth-child(2) {
  275. margin-bottom: 24px;
  276. }
  277. &-title {
  278. margin-bottom: 24px;
  279. font-size: 32px;
  280. font-weight: bold;
  281. color: #193059;
  282. }
  283. .ptc-input {
  284. height: 88px;
  285. font-size: 24px;
  286. @include media-breakpoint-up(md) {
  287. font-size: 28px;
  288. }
  289. }
  290. }
  291. textarea {
  292. display: block;
  293. padding: 24px;
  294. width: 100%;
  295. height: 182px;
  296. border-radius: 8px;
  297. border: 2px solid #d9d9d9;
  298. font-size: 28px;
  299. line-height: 40px;
  300. }
  301. .block {
  302. background: #fff;
  303. }
  304. .records {
  305. padding: 0 36px;
  306. }
  307. .record {
  308. display: flex;
  309. justify-content: space-between;
  310. align-items: center;
  311. padding: 36px 0;
  312. + .record {
  313. @include thin-border(top);
  314. }
  315. .left {
  316. font-weight: bold;
  317. font-size: 32px;
  318. color: #1a1a1a;
  319. }
  320. .center,
  321. .right {
  322. font-size: 28px;
  323. color: #666;
  324. }
  325. .center {
  326. padding-right: 50px;
  327. }
  328. }
  329. .details {
  330. padding: 36px;
  331. font-size: 32px;
  332. line-height: 44px;
  333. color: #666;
  334. }
  335. @include media-breakpoint-up(md) {
  336. .ptc-comboinput .ptc-button {
  337. width: 322px;
  338. }
  339. }
  340. }
  341. </style>