userCard.vue 8.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321
  1. <template>
  2. <div class="user-card" :class="{ 'user-card--goods': props.type === 'goods' }">
  3. <div class="user-card__main">
  4. <div class="user-card__stat">
  5. <span class="user-card__label">剩余乐跑次数</span>
  6. <div class="user-card__stat-row">
  7. <a-statistic
  8. :value="userCount?.lepao_count ?? 0"
  9. :value-style="{ fontSize: '2rem', fontWeight: 700, color: 'var(--stat-color)' }"
  10. animation
  11. show-group-separator
  12. />
  13. <div class="vip-strip" :class="{ 'vip-strip--active': isVip }" @click="router.push('/ai/assistant')">
  14. <span class="vip-strip__badge">VIP</span>
  15. <span class="vip-strip__text">{{ vipText }}</span>
  16. <icon-right class="vip-strip__arrow" />
  17. </div>
  18. </div>
  19. </div>
  20. <div class="user-card__actions">
  21. <a-button
  22. v-if="props.type === 'lepao'"
  23. type="primary"
  24. size="large"
  25. class="action-btn action-btn--primary"
  26. @click="$router.push('/store/goodsList')"
  27. >
  28. <icon-fire /> 去购买
  29. </a-button>
  30. <a-button
  31. v-else
  32. type="primary"
  33. size="large"
  34. class="action-btn action-btn--primary"
  35. @click="$router.push('/lepao/accountList')"
  36. >
  37. <icon-thunderbolt />&nbsp;去乐跑
  38. </a-button>
  39. <a-button
  40. v-if="hasPermission('action.goods.sendCount')"
  41. size="large"
  42. class="action-btn"
  43. @click="SendCount"
  44. >
  45. <icon-gift />&nbsp;赠送
  46. </a-button>
  47. <a-button size="large" class="action-btn" @click="goCountLedger">
  48. <icon-list />&nbsp;明细
  49. </a-button>
  50. </div>
  51. </div>
  52. </div>
  53. <a-modal
  54. v-model:visible="visible"
  55. title="赠送乐跑次数"
  56. @cancel="handleCancel"
  57. @before-ok="handleBeforeOk"
  58. :ok-loading="ok_loading"
  59. unmount-on-close
  60. >
  61. <a-form :model="sendform" layout="vertical">
  62. <a-form-item field="username" label="接收人用户名">
  63. <a-input
  64. v-model="sendform.username"
  65. placeholder="如:用户adfg45g"
  66. :max-length="20"
  67. allow-clear
  68. />
  69. </a-form-item>
  70. <a-form-item field="count" label="赠送次数">
  71. <a-input-number v-model="sendform.count" :min="1" :max="9999" mode="button" />
  72. </a-form-item>
  73. </a-form>
  74. <div v-if="hasPermission('action.goods.sendCount')" class="send-modal-extra">
  75. <a-link @click="goSendCountRecords">
  76. <icon-list />&nbsp;赠送记录
  77. </a-link>
  78. </div>
  79. </a-modal>
  80. </template>
  81. <script setup>
  82. import { ref, reactive, onUnmounted, onMounted, computed } from 'vue'
  83. import { useRouter } from 'vue-router'
  84. import { getCount, sendCount } from '@/api/goods'
  85. import { Notification, Message } from '@arco-design/web-vue'
  86. import { hasPermission } from '@/utils/permission'
  87. const props = defineProps({
  88. type: { type: String, default: 'lepao' }
  89. })
  90. const userCount = ref({ lepao_count: 0 })
  91. const router = useRouter()
  92. const visible = ref(false)
  93. const ok_loading = ref(false)
  94. const sendform = reactive({ username: '', count: 1 })
  95. const isVip = computed(() => {
  96. const expire = Number(userCount.value?.vip_expire_time || 0)
  97. return expire > Date.now() || (Number(userCount.value?.vip || 0) === 1 && expire === 0)
  98. })
  99. const vipText = computed(() => {
  100. const expire = Number(userCount.value?.vip_expire_time || 0)
  101. if (!isVip.value) return '开通会员'
  102. if (!expire) return '永久会员'
  103. return `VIP 至 ${new Date(expire).toLocaleDateString('zh-CN')}`
  104. })
  105. const handleBeforeOk = async (done) => {
  106. if (!hasPermission('action.goods.sendCount')) {
  107. Notification.warning({ title: '无权限', content: '当前账号暂无赠送权限' })
  108. return false
  109. }
  110. try {
  111. ok_loading.value = true
  112. if (!sendform.username) {
  113. Message.error('请填写接收人用户名')
  114. return false
  115. }
  116. if (!sendform.count || sendform.count < 1 || sendform.count > 9999) {
  117. Notification.error({ title: '赠送失败', content: '赠送次数需在 1~9999 之间' })
  118. return false
  119. }
  120. const res = await sendCount({ username: sendform.username, count: sendform.count })
  121. if (!res || res.code !== 0) {
  122. Notification.error({ title: '赠送失败', content: res?.msg ?? '请稍后再试' })
  123. return false
  124. }
  125. Message.success(res.msg || '赠送成功')
  126. done()
  127. GetCount()
  128. } catch (error) {
  129. Notification.error({ title: '赠送失败', content: error.message || '请稍后再试' })
  130. return false
  131. } finally {
  132. ok_loading.value = false
  133. }
  134. }
  135. const handleCancel = () => {
  136. visible.value = false
  137. }
  138. const SendCount = () => {
  139. sendform.username = ''
  140. sendform.count = 1
  141. visible.value = true
  142. }
  143. const goCountLedger = () => router.push('/lepao/countLedger')
  144. const goSendCountRecords = () => {
  145. visible.value = false
  146. router.push('/store/sendCountRecords')
  147. }
  148. const GetCount = async () => {
  149. try {
  150. const res = await getCount()
  151. if (!res || res.code !== 0) return
  152. userCount.value = res.data
  153. } catch {
  154. /* 静默失败,避免轮询刷屏 */
  155. }
  156. }
  157. let timer = null
  158. const startPolling = () => {
  159. if (!timer) timer = setInterval(GetCount, 8000)
  160. }
  161. const stopPolling = () => {
  162. if (timer) {
  163. clearInterval(timer)
  164. timer = null
  165. }
  166. }
  167. onMounted(async () => {
  168. await GetCount()
  169. startPolling()
  170. })
  171. onUnmounted(stopPolling)
  172. </script>
  173. <style scoped lang="less">
  174. @import '@/styles/store-theme.less';
  175. .user-card {
  176. --stat-color: rgb(var(--primary-6));
  177. background: @store-card-bg;
  178. border: 1px solid @store-card-border;
  179. border-radius: @store-radius;
  180. box-shadow: @store-shadow;
  181. padding: 20px 24px;
  182. &--goods {
  183. background: linear-gradient(135deg, #f4faf6 0%, #e8f5ec 100%);
  184. --stat-color: @store-primary;
  185. }
  186. &__main {
  187. display: flex;
  188. flex-wrap: wrap;
  189. align-items: center;
  190. justify-content: space-between;
  191. gap: 20px;
  192. }
  193. &__label {
  194. display: block;
  195. font-size: 0.85rem;
  196. color: @store-text-muted;
  197. margin-bottom: 4px;
  198. }
  199. &__stat-row {
  200. display: flex;
  201. flex-wrap: wrap;
  202. align-items: baseline;
  203. gap: 10px;
  204. :deep(.arco-statistic) {
  205. flex: 0 0 auto;
  206. }
  207. }
  208. &__actions {
  209. display: flex;
  210. flex-wrap: wrap;
  211. gap: 10px;
  212. }
  213. }
  214. .vip-strip {
  215. display: inline-flex;
  216. align-items: center;
  217. align-self: center;
  218. gap: 6px;
  219. min-height: 28px;
  220. max-width: min(210px, 100%);
  221. padding: 4px 7px 4px 5px;
  222. border: 1px solid rgba(236, 133, 171, 0.18);
  223. border-radius: 999px;
  224. background: linear-gradient(135deg, rgba(255, 246, 250, 0.96), rgba(255, 250, 240, 0.92));
  225. color: #94465f;
  226. font-size: 12px;
  227. cursor: pointer;
  228. box-shadow: 0 8px 18px rgba(236, 133, 171, 0.08);
  229. transition: border-color 0.18s ease, box-shadow 0.18s ease, transform 0.18s ease;
  230. &:hover {
  231. border-color: rgba(236, 133, 171, 0.34);
  232. box-shadow: 0 10px 22px rgba(236, 133, 171, 0.12);
  233. transform: translateY(-1px);
  234. }
  235. &--active {
  236. border-color: rgba(249, 168, 212, 0.3);
  237. background: linear-gradient(135deg, rgba(255, 245, 248, 0.98), rgba(255, 247, 237, 0.96));
  238. color: #8f3f58;
  239. box-shadow: 0 8px 18px rgba(249, 168, 212, 0.1);
  240. }
  241. &__badge {
  242. display: inline-grid;
  243. place-items: center;
  244. height: 18px;
  245. min-width: 30px;
  246. padding: 0 6px;
  247. border-radius: 999px;
  248. background: linear-gradient(135deg, #f9a8d4, #8b5cf6);
  249. color: #fff;
  250. font-size: 10px;
  251. font-weight: 900;
  252. box-shadow: 0 6px 14px rgba(139, 92, 246, 0.18);
  253. }
  254. &__text {
  255. min-width: 0;
  256. overflow: hidden;
  257. text-overflow: ellipsis;
  258. white-space: nowrap;
  259. }
  260. &__arrow {
  261. flex: 0 0 auto;
  262. font-size: 11px;
  263. opacity: 0.56;
  264. }
  265. }
  266. .action-btn {
  267. border-radius: 999px;
  268. &--primary {
  269. background: @store-primary !important;
  270. border-color: @store-primary !important;
  271. }
  272. }
  273. .send-modal-extra {
  274. margin-top: 4px;
  275. text-align: center;
  276. }
  277. @media (max-width: 640px) {
  278. .user-card__stat-row {
  279. align-items: flex-start;
  280. gap: 8px;
  281. }
  282. .vip-strip {
  283. width: auto;
  284. max-width: 100%;
  285. justify-content: flex-start;
  286. }
  287. }
  288. </style>