share.vue 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373
  1. <template>
  2. <view class="share-page">
  3. <!-- Background -->
  4. <image src="/packet/static/share/bg.png" class="bg-image" mode="widthFix"></image>
  5. <!-- Main Content -->
  6. <view class="content-wrapper">
  7. <!-- Loop through share list -->
  8. <view class="card" v-for="(item, index) in shareList" :key="index">
  9. <!-- Header -->
  10. <view class="card-header">
  11. <text class="card-title">邀请好友同享最高可得{{ item.shareSumPrice }}元红包</text>
  12. <text class="card-time">截止时间:{{ item.shareRedBagExpire }}</text>
  13. </view>
  14. <!-- Progress Section -->
  15. <view class="progress-section">
  16. <!-- Left Icon -->
  17. <image src="/packet/static/share/invite-text.png" class="left-icon" mode="heightFix"></image>
  18. <!-- Center Content -->
  19. <view class="center-content">
  20. <!-- Progress Bubble -->
  21. <view class="progress-bubble">
  22. <text>已领{{ item.shareGetNum || 0 }}元,最高还可得{{ (item.shareSumPrice || 0) - (item.shareGetNum || 0) }}元</text>
  23. </view>
  24. <!-- Progress Bar -->
  25. <view class="progress-bar-container">
  26. <view class="progress-line"></view>
  27. <view class="progress-dot" :style="{ left: getProgressPercent(item) + '%' }"></view>
  28. </view>
  29. <!-- Progress Labels -->
  30. <view class="progress-labels">
  31. <text class="label">邀请好友</text>
  32. <text class="label">好友领取</text>
  33. <text class="label">获得红包</text>
  34. </view>
  35. </view>
  36. <!-- Right Packet Icon -->
  37. <image src="/packet/static/share/red-packet.png" class="right-packet" mode="heightFix"></image>
  38. </view>
  39. <!-- Share/Detail Button -->
  40. <button class="btn-wrapper" open-type="share" :data-index="index" @getuserinfo="handleShare">
  41. <text class="btn-text">立即分享</text>
  42. </button>
  43. </view>
  44. <view class="empty-wrap" v-if="listLoaded && shareList.length === 0">
  45. <u-empty text="暂无可分享的红包" mode="list" margin-top="80"></u-empty>
  46. <text class="empty-tip">领取红包并成功发起分享后,会出现在此列表</text>
  47. </view>
  48. </view>
  49. </view>
  50. </template>
  51. <script>
  52. export default {
  53. data() {
  54. return {
  55. shareList: [],
  56. listLoaded: false,
  57. useMock: false
  58. }
  59. },
  60. onLoad(options) {
  61. this.useMock = options && options.mock === '1';
  62. if (this.useMock) {
  63. this.shareList = [{
  64. bianhao: 'preview-mock',
  65. shareSumPrice: 10,
  66. shareGetNum: 3,
  67. shareNum: 10,
  68. shareRedBagExpire: '2026-12-31 23:59:59'
  69. }];
  70. this.listLoaded = true;
  71. return;
  72. }
  73. this.getShareList();
  74. },
  75. onShow() {
  76. if (!this.useMock) {
  77. this.getShareList();
  78. }
  79. },
  80. onShareAppMessage(options) {
  81. console.log(options);
  82. // 从 options 中获取卡片索引
  83. const index = options?.target?.dataset?.index || 0;
  84. const item = this.shareList[index] || this.shareList[0];
  85. // 设置分享内容 - 使用对应卡片的数据
  86. return {
  87. title: '邀请好友同享最高可得' + (item?.shareSumPrice) + '元红包',
  88. path: '/packet/pages/index?bianhao=' + item.bianhao,
  89. imageUrl: '../static/index/share.png' // 使用默认分享图
  90. };
  91. },
  92. methods: {
  93. // 获取分享列表
  94. async getShareList() {
  95. try {
  96. const res = await this.$u.api.getShareRedBagListAjax();
  97. if (res.code === 200 || res.code === 0) {
  98. const data = res.data;
  99. this.shareList = Array.isArray(data) ? data : (data && (data.list || data.rows) || []);
  100. } else {
  101. uni.showToast({
  102. title: res.msg || '获取分享列表失败',
  103. icon: 'none'
  104. });
  105. }
  106. } catch (e) {
  107. console.error('获取分享列表失败:', e);
  108. uni.showToast({
  109. title: '网络错误',
  110. icon: 'none'
  111. });
  112. } finally {
  113. this.listLoaded = true;
  114. }
  115. },
  116. // 计算进度百分比
  117. getProgressPercent(item) {
  118. if (!item.shareNum || item.shareNum === 0) {
  119. return 0;
  120. }
  121. return (item.shareGetNum / item.shareNum) * 100;
  122. },
  123. // 格式化过期时间
  124. formatExpireTime(timeStr) {
  125. if (!timeStr) {
  126. return this.formatTime(new Date());
  127. }
  128. const date = new Date(timeStr);
  129. return this.formatTime(date);
  130. },
  131. // 格式化时间
  132. formatTime(date) {
  133. const year = date.getFullYear();
  134. const month = String(date.getMonth() + 1).padStart(2, '0');
  135. const day = String(date.getDate()).padStart(2, '0');
  136. const hours = String(date.getHours()).padStart(2, '0');
  137. const minutes = String(date.getMinutes()).padStart(2, '0');
  138. const seconds = String(date.getSeconds()).padStart(2, '0');
  139. return `${year}-${month}-${day} ${hours}:${minutes}:${seconds}`;
  140. },
  141. handleShare() {
  142. // 分享逻辑
  143. uni.showToast({
  144. title: '分享成功',
  145. icon: 'success'
  146. });
  147. },
  148. handleViewDetail() {
  149. // 查看详情逻辑
  150. uni.showToast({
  151. title: '查看详情',
  152. icon: 'none'
  153. });
  154. }
  155. }
  156. }
  157. </script>
  158. <style lang="scss" scoped>
  159. .share-page {
  160. height: 100vh;
  161. position: relative;
  162. display: flex;
  163. flex-direction: column;
  164. align-items: center;
  165. padding: 40rpx 30rpx;
  166. box-sizing: border-box;
  167. padding-top: 0;
  168. .bg-image {
  169. position: fixed;
  170. top: 0;
  171. left: 0;
  172. width: 100%;
  173. height: 100%;
  174. z-index: 0;
  175. }
  176. .content-wrapper {
  177. position: relative;
  178. z-index: 1;
  179. width: 100%;
  180. max-width: 700rpx;
  181. padding: 60rpx 0;
  182. margin-top: 350rpx;
  183. .empty-wrap {
  184. background: rgba(255, 255, 255, 0.95);
  185. border-radius: 24rpx;
  186. padding: 40rpx 30rpx 60rpx;
  187. text-align: center;
  188. .empty-tip {
  189. display: block;
  190. margin-top: 16rpx;
  191. font-size: 24rpx;
  192. color: #666;
  193. line-height: 1.6;
  194. }
  195. }
  196. .card {
  197. background: #fff;
  198. border-radius: 24rpx;
  199. overflow: hidden;
  200. margin-bottom: 40rpx;
  201. .card-header {
  202. background: #03A65F;
  203. padding: 24rpx 30rpx;
  204. display: flex;
  205. justify-content: space-between;
  206. align-items: center;
  207. height: 79rpx;
  208. box-sizing: border-box;
  209. .card-title {
  210. font-size: 28rpx;
  211. font-weight: 600;
  212. color: #fff;
  213. flex: 1;
  214. }
  215. .card-time {
  216. font-size: 22rpx;
  217. color: rgba(255, 255, 255, 0.9);
  218. white-space: nowrap;
  219. margin-left: 20rpx;
  220. }
  221. }
  222. .progress-section {
  223. padding: 30rpx 50rpx;
  224. display: flex;
  225. align-items: center;
  226. gap: 20rpx;
  227. position: relative;
  228. .left-icon {
  229. width: 80rpx;
  230. height: 80rpx;
  231. flex-shrink: 0;
  232. position: absolute;
  233. top: 20%;
  234. left: 40rpx;
  235. }
  236. .center-content {
  237. flex: 1;
  238. display: flex;
  239. flex-direction: column;
  240. align-items: center;
  241. margin-top: 40rpx;
  242. .progress-bubble {
  243. background: #18B94E;
  244. padding: 12rpx 28rpx;
  245. border-radius: 30rpx;
  246. margin-bottom: 30rpx;
  247. margin-left: 10rpx;
  248. text {
  249. font-size: 24rpx;
  250. color: #fff;
  251. font-weight: 500;
  252. }
  253. }
  254. .progress-bar-container {
  255. position: relative;
  256. width: 100%;
  257. height: 15rpx;
  258. background: #BDFAAD;
  259. border-radius: 6rpx;
  260. margin-bottom: 16rpx;
  261. .progress-line {
  262. position: absolute;
  263. left: 0;
  264. top: 0;
  265. height: 100%;
  266. background: linear-gradient(90deg, #4CAF50 0%, #8BC34A 100%);
  267. border-radius: 6rpx;
  268. }
  269. .progress-dot {
  270. position: absolute;
  271. top: 50%;
  272. transform: translate(-50%, -50%);
  273. width: 32rpx;
  274. height: 32rpx;
  275. background: #fff;
  276. border-radius: 50%;
  277. box-shadow: 0 2rpx 8rpx rgba(76, 175, 80, 0.3);
  278. display: flex;
  279. align-items: center;
  280. justify-content: center;
  281. &::after {
  282. content: '';
  283. width: 24rpx;
  284. height: 24rpx;
  285. background: linear-gradient(135deg, #4CAF50 0%, #66BB6A 100%);
  286. border-radius: 50%;
  287. }
  288. }
  289. }
  290. .progress-labels {
  291. display: flex;
  292. justify-content: space-between;
  293. width: 100%;
  294. .label {
  295. font-size: 26rpx;
  296. color: #333;
  297. text-align: center;
  298. font-weight: 600;
  299. flex: 1;
  300. }
  301. }
  302. }
  303. .right-packet {
  304. width: 60rpx;
  305. height: 80rpx;
  306. flex-shrink: 0;
  307. position: absolute;
  308. top: 20%;
  309. right: 40rpx;
  310. }
  311. }
  312. .btn-wrapper {
  313. position: relative;
  314. width: 300rpx;
  315. height: 90rpx;
  316. margin: 0 auto 30rpx;
  317. background: url('/packet/static/share/share-btn.png') no-repeat center center;
  318. background-size: 100% 100%;
  319. display: flex;
  320. align-items: center;
  321. justify-content: center;
  322. border: none;
  323. padding: 0;
  324. line-height: normal;
  325. font-size: 0;
  326. &::after {
  327. border: none;
  328. }
  329. .btn-text {
  330. font-family: Adobe Heiti Std;
  331. font-size: 42rpx;
  332. color: #FFFFFF;
  333. text-align: center;
  334. }
  335. }
  336. }
  337. }
  338. }
  339. </style>