purchaseProduct.vue 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680
  1. <template>
  2. <div class="me-purchase-product">
  3. <div class="product-header">
  4. <h2 class="product-title">我的产品({{ productsNum }})</h2>
  5. <div class="product-filters">
  6. <el-input
  7. v-model="queryParams.product_name"
  8. placeholder="请输入产品名称"
  9. clearable
  10. class="filter-item"
  11. @clear="handleSearch"
  12. @keyup.enter.native="handleSearch"
  13. ></el-input>
  14. <el-select
  15. v-model="queryParams.status"
  16. placeholder="状态"
  17. clearable
  18. class="filter-item"
  19. @change="handleSearch"
  20. >
  21. <el-option label="有效" :value="1" />
  22. <el-option label="已过期" :value="2" />
  23. <el-option label="已用完" :value="3" />
  24. </el-select>
  25. <el-button type="primary" @click="handleSearch">搜索</el-button>
  26. </div>
  27. </div>
  28. <div class="product-content">
  29. <el-empty v-if="products.length === 0" description="暂无产品">
  30. <el-button type="primary" @click="gotoBuy">去购买</el-button>
  31. </el-empty>
  32. <div v-else>
  33. <div class="product-grid">
  34. <div
  35. v-for="item in products"
  36. :key="item.usage_id"
  37. class="product-card"
  38. :class="{ expired: item.status !== 1 }"
  39. @click="handleProductClick(item)"
  40. >
  41. <!-- 状态标签 -->
  42. <div class="status-badge" :class="getStatusClass(item.status)">
  43. {{ getStatusText(item.status) }}
  44. </div>
  45. <!-- 产品图片 -->
  46. <div class="product-image-wrapper">
  47. <img :src="item.image" :alt="item.product_name" />
  48. <div class="product-type-badge" :class="item.product_type === 1 ? 'web' : 'software'">
  49. <el-icon v-if="item.product_type == 1">
  50. <Link />
  51. </el-icon>
  52. <el-icon v-else>
  53. <Monitor />
  54. </el-icon>
  55. <span>{{ item.product_type == 1 ? '网页' : '软件' }}</span>
  56. </div>
  57. </div>
  58. <!-- 产品信息 -->
  59. <div class="product-info">
  60. <div class="product-main">
  61. <!-- 左侧:产品基本信息 -->
  62. <div class="product-main-left">
  63. <div class="product-name" :title="item.product_name">
  64. {{ item.product_name }}
  65. </div>
  66. <!-- 套餐信息 -->
  67. <div class="package-info">
  68. <el-tag size="small" type="primary" effect="plain">
  69. {{ item.package_type_text }}
  70. </el-tag>
  71. <el-tag size="small" type="warning" effect="plain">
  72. {{ item.card_type_text }}
  73. </el-tag>
  74. </div>
  75. <!-- 使用情况 -->
  76. <div class="usage-info">
  77. <!-- 次卡显示剩余次数 -->
  78. <div v-if="item.card_type == 1" class="usage-item">
  79. <el-icon>
  80. <Tickets />
  81. </el-icon>
  82. <span>剩余次数: <strong>{{ item.remaining_times }}</strong></span>
  83. </div>
  84. <!-- 积分卡显示剩余积分 -->
  85. <div v-if="item.card_type == 2" class="usage-item">
  86. <el-icon>
  87. <Coin />
  88. </el-icon>
  89. <span>剩余积分: <strong>{{ item.remaining_points }}</strong></span>
  90. </div>
  91. <!-- 日期卡显示到期时间 -->
  92. <div v-if="[3, 4, 5, 6, 7].includes(item.card_type)" class="usage-item">
  93. <el-icon>
  94. <Calendar />
  95. </el-icon>
  96. <span>{{ item.display_info }}</span>
  97. </div>
  98. </div>
  99. </div>
  100. <!-- 右侧:席位信息(企业套餐)- 仅日期卡显示 -->
  101. <div
  102. v-if="item.package_type == 2 && item.total_seats && [3, 4, 5, 6, 7].includes(item.card_type)"
  103. class="product-main-right"
  104. >
  105. <div class="seats-info">
  106. <div class="seats-row">
  107. <div class="seats-label">席位</div>
  108. <div class="seats-value">
  109. <span class="seats-number strong">{{ item.assigned_seats || 0 }}</span>
  110. <span class="seats-split">/</span>
  111. <span class="seats-number">{{ item.total_seats }}</span>
  112. </div>
  113. </div>
  114. </div>
  115. </div>
  116. </div>
  117. <!-- 底部信息 -->
  118. <div class="product-footer">
  119. <div class="buy-info">
  120. <el-icon>
  121. <ShoppingCart />
  122. </el-icon>
  123. <span>{{ formatDate(item.buy_time) }}</span>
  124. </div>
  125. <div v-if="item.is_allocated == 1" class="allocated-badge">
  126. <el-icon>
  127. <Share />
  128. </el-icon>
  129. <span>已分配</span>
  130. </div>
  131. </div>
  132. </div>
  133. </div>
  134. </div>
  135. <div class="product-pagination">
  136. <el-pagination
  137. v-model:current-page="queryParams.page"
  138. v-model:page-size="queryParams.pageSize"
  139. :page-sizes="[6, 12, 24, 48]"
  140. :total="productsNum || 0"
  141. layout="total, sizes, prev, pager, next, jumper"
  142. @size-change="handleSizeChange"
  143. @current-change="handleCurrentChange"
  144. />
  145. </div>
  146. </div>
  147. </div>
  148. </div>
  149. </template>
  150. <script setup lang="ts">
  151. import { onMounted, ref } from 'vue'
  152. import { purchasedList } from '/@/api/frontend/me'
  153. import { useRouter } from 'vue-router'
  154. import { ElMessage } from 'element-plus'
  155. import {
  156. Link,
  157. Monitor,
  158. Tickets,
  159. Coin,
  160. Calendar,
  161. ShoppingCart,
  162. Share
  163. } from '@element-plus/icons-vue'
  164. defineOptions({ name: 'MePurchaseProduct' })
  165. const router = useRouter()
  166. type ProductItem = {
  167. product_id: number
  168. product_name: string
  169. product_type: 1 | 2 // 1=网页,2=软件
  170. product_link: string
  171. image: string
  172. package_spec: string
  173. package_type: 1 | 2 // 1=个人套餐,2=企业套餐
  174. package_type_text: string
  175. card_type: 1 | 2 | 3 | 4 | 5 | 6 | 7 // 1=次卡,2=积分卡,3=日卡,4=周卡,5=季卡,6=月卡,7=年卡
  176. card_type_text: string
  177. total_quantity: number
  178. effective_end_time: string | null
  179. remaining_times: number
  180. remaining_points: number
  181. display_info: string
  182. usage_id: number
  183. start_time: string
  184. last_use_time: string | null
  185. status: 1 | 2 | 3 // 1=有效,2=已过期,3=已用完
  186. buy_time: string
  187. is_allocated: 0 | 1 // 0=未分配,1=已分配
  188. company_id: number | null
  189. allocation_id: number | null
  190. total_seats: number | null
  191. assigned_seats: number | null
  192. available_seats: number | null
  193. }
  194. type CompanyInfo = {
  195. company_id: number
  196. company_name: string
  197. is_creator: boolean
  198. }
  199. // 产品列表
  200. const products = ref<ProductItem[]>([])
  201. // 企业信息
  202. const companyInfo = ref<CompanyInfo | null>(null)
  203. // 产品数量
  204. const productsNum = ref<number>(0)
  205. // 查询与分页参数
  206. const queryParams = ref<{
  207. page: number
  208. pageSize: number
  209. product_name: string
  210. status: number | undefined
  211. }>({
  212. page: 1,
  213. pageSize: 6,
  214. product_name: '',
  215. status: undefined
  216. })
  217. // 获取列表
  218. const getList = async () => {
  219. try {
  220. const params: any = {
  221. page: queryParams.value.page,
  222. pageSize: queryParams.value.pageSize
  223. }
  224. if (queryParams.value.product_name) {
  225. params.product_name = queryParams.value.product_name
  226. }
  227. if (queryParams.value.status) {
  228. params.status = queryParams.value.status
  229. }
  230. const res = await purchasedList(params)
  231. products.value = res.data.products || []
  232. companyInfo.value = res.data.company_info || null
  233. productsNum.value = res.data.total || 0
  234. } catch (error) {
  235. ElMessage.error('获取产品列表失败')
  236. }
  237. }
  238. // 搜索
  239. const handleSearch = () => {
  240. queryParams.value.page = 1
  241. getList()
  242. }
  243. // 分页大小变更
  244. const handleSizeChange = (size: number) => {
  245. queryParams.value.pageSize = size
  246. queryParams.value.page = 1
  247. getList()
  248. }
  249. // 当前页变更
  250. const handleCurrentChange = (page: number) => {
  251. queryParams.value.page = page
  252. getList()
  253. }
  254. // 跳转购买
  255. const gotoBuy = () => {
  256. router.push('/')
  257. }
  258. // 获取状态文本
  259. const getStatusText = (status: number) => {
  260. const statusMap: Record<number, string> = {
  261. 1: '有效',
  262. 2: '已过期',
  263. 3: '已用完'
  264. }
  265. return statusMap[status] || '未知'
  266. }
  267. // 获取状态样式类
  268. const getStatusClass = (status: number) => {
  269. const classMap: Record<number, string> = {
  270. 1: 'status-active',
  271. 2: 'status-expired',
  272. 3: 'status-used-up'
  273. }
  274. return classMap[status] || ''
  275. }
  276. // 格式化日期
  277. const formatDate = (dateStr: string) => {
  278. if (!dateStr) return ''
  279. const date = new Date(dateStr)
  280. const now = new Date()
  281. const diff = now.getTime() - date.getTime()
  282. const days = Math.floor(diff / (1000 * 60 * 60 * 24))
  283. if (days == 0) return '今天'
  284. if (days == 1) return '昨天'
  285. if (days < 7) return `${days}天前`
  286. if (days < 30) return `${Math.floor(days / 7)}周前`
  287. if (days < 365) return `${Math.floor(days / 30)}个月前`
  288. return dateStr.split(' ')[0]
  289. }
  290. // 点击产品卡片
  291. const handleProductClick = (item: ProductItem) => {
  292. // 如果已过期或已用完,提示用户
  293. if (item.status == 2) {
  294. ElMessage.warning('该产品已过期')
  295. return
  296. }
  297. if (item.status == 3) {
  298. ElMessage.warning('该产品已用完')
  299. return
  300. }
  301. if (!item.product_link) {
  302. ElMessage.warning('产品链接不存在')
  303. return
  304. }
  305. // 软件类型,触发下载
  306. if (item.product_type == 2) {
  307. const a = document.createElement('a')
  308. a.href = item.product_link
  309. a.target = '_blank'
  310. a.rel = 'noopener noreferrer'
  311. a.download = ''
  312. document.body.appendChild(a)
  313. a.click()
  314. document.body.removeChild(a)
  315. return
  316. }
  317. // 网页类型,打开新窗口
  318. window.open(item.product_link, '_blank', 'noopener,noreferrer')
  319. }
  320. onMounted(() => {
  321. getList()
  322. })
  323. </script>
  324. <style scoped lang="scss">
  325. .me-purchase-product {
  326. width: 100%;
  327. .product-header {
  328. display: flex;
  329. justify-content: space-between;
  330. align-items: center;
  331. margin-bottom: 24px;
  332. padding-bottom: 16px;
  333. border-bottom: 2px solid #e4e7ed;
  334. .product-title {
  335. margin: 0;
  336. font-size: 24px;
  337. font-weight: bold;
  338. color: #303133;
  339. }
  340. .product-filters {
  341. display: flex;
  342. align-items: center;
  343. gap: 12px;
  344. .filter-item {
  345. width: 200px;
  346. }
  347. }
  348. .company-info {
  349. display: flex;
  350. align-items: center;
  351. gap: 8px;
  352. padding: 8px 16px;
  353. background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  354. border-radius: 20px;
  355. color: #fff;
  356. font-size: 14px;
  357. .el-icon {
  358. font-size: 16px;
  359. }
  360. }
  361. }
  362. .product-content {
  363. padding: 20px 0;
  364. .product-grid {
  365. display: grid;
  366. grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  367. gap: 24px;
  368. }
  369. .product-pagination {
  370. margin-top: 24px;
  371. display: flex;
  372. justify-content: flex-end;
  373. }
  374. .product-card {
  375. position: relative;
  376. cursor: pointer;
  377. background: #fff;
  378. border-radius: 12px;
  379. border: 1px solid #e4e7ed;
  380. transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
  381. overflow: hidden;
  382. &:hover {
  383. border-color: #409eff;
  384. box-shadow: 0 8px 24px rgba(64, 158, 255, 0.2);
  385. transform: translateY(-4px);
  386. }
  387. &.expired {
  388. opacity: 0.7;
  389. &:hover {
  390. border-color: #909399;
  391. box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
  392. }
  393. }
  394. }
  395. .status-badge {
  396. position: absolute;
  397. top: 12px;
  398. right: 12px;
  399. padding: 4px 12px;
  400. border-radius: 12px;
  401. font-size: 12px;
  402. font-weight: 600;
  403. z-index: 2;
  404. backdrop-filter: blur(8px);
  405. &.status-active {
  406. background: rgba(103, 194, 58, 0.9);
  407. color: #fff;
  408. }
  409. &.status-expired {
  410. background: rgba(245, 108, 108, 0.9);
  411. color: #fff;
  412. }
  413. &.status-used-up {
  414. background: rgba(144, 147, 153, 0.9);
  415. color: #fff;
  416. }
  417. }
  418. .product-image-wrapper {
  419. position: relative;
  420. padding: 16px 16px 0;
  421. img {
  422. display: block;
  423. width: 100%;
  424. height: 180px;
  425. border-radius: 8px;
  426. object-fit: cover;
  427. }
  428. .product-type-badge {
  429. position: absolute;
  430. bottom: 8px;
  431. left: 24px;
  432. display: flex;
  433. align-items: center;
  434. gap: 4px;
  435. padding: 6px 12px;
  436. border-radius: 16px;
  437. font-size: 12px;
  438. font-weight: 600;
  439. backdrop-filter: blur(8px);
  440. &.web {
  441. background: rgba(64, 158, 255, 0.9);
  442. color: #fff;
  443. }
  444. &.software {
  445. background: rgba(103, 194, 58, 0.9);
  446. color: #fff;
  447. }
  448. .el-icon {
  449. font-size: 14px;
  450. }
  451. }
  452. }
  453. .product-info {
  454. padding: 16px;
  455. display: flex;
  456. flex-direction: column;
  457. gap: 12px;
  458. }
  459. .product-main {
  460. display: flex;
  461. gap: 12px;
  462. align-items: flex-end;
  463. }
  464. .product-main-left {
  465. flex: 1.3;
  466. min-width: 0;
  467. display: flex;
  468. flex-direction: column;
  469. gap: 10px;
  470. }
  471. .product-main-right {
  472. flex: 1;
  473. display: flex;
  474. align-items: center;
  475. justify-content: flex-end;
  476. min-width: 150px;
  477. }
  478. .product-name {
  479. font-size: 16px;
  480. font-weight: 600;
  481. color: #303133;
  482. overflow: hidden;
  483. text-overflow: ellipsis;
  484. white-space: nowrap;
  485. }
  486. .package-info {
  487. display: flex;
  488. gap: 8px;
  489. flex-wrap: wrap;
  490. }
  491. .package-spec {
  492. font-size: 13px;
  493. color: #606266;
  494. line-height: 1.5;
  495. padding: 8px 12px;
  496. background: #f5f7fa;
  497. border-radius: 6px;
  498. border-left: 3px solid #409eff;
  499. }
  500. .usage-info {
  501. display: flex;
  502. flex-direction: column;
  503. gap: 8px;
  504. .usage-item {
  505. display: flex;
  506. align-items: center;
  507. gap: 6px;
  508. font-size: 13px;
  509. color: #606266;
  510. padding: 6px 10px;
  511. background: linear-gradient(135deg, #f5f7fa 0%, #e8eef5 100%);
  512. border-radius: 6px;
  513. .el-icon {
  514. font-size: 16px;
  515. color: #409eff;
  516. }
  517. strong {
  518. color: #409eff;
  519. font-weight: 600;
  520. }
  521. }
  522. }
  523. .seats-info {
  524. width: 100%;
  525. padding: 8px 12px;
  526. background: #f5f7fa;
  527. border-radius: 8px;
  528. border: 1px solid #e0e6f1;
  529. display: flex;
  530. flex-direction: column;
  531. .seats-row {
  532. display: flex;
  533. justify-content: space-between;
  534. align-items: center;
  535. font-size: 12px;
  536. color: #606266;
  537. }
  538. .seats-label {
  539. color: #909399;
  540. }
  541. .seats-value {
  542. display: flex;
  543. align-items: center;
  544. font-size: 12px;
  545. color: #606266;
  546. }
  547. .seats-number {
  548. font-weight: 500;
  549. color: #303133;
  550. &.strong {
  551. color: #409eff;
  552. font-weight: 600;
  553. }
  554. }
  555. .seats-split {
  556. margin: 0 4px;
  557. color: #c0c4cc;
  558. }
  559. .seats-text {
  560. margin-left: 6px;
  561. font-size: 12px;
  562. color: #909399;
  563. }
  564. }
  565. .product-footer {
  566. display: flex;
  567. justify-content: space-between;
  568. align-items: center;
  569. padding-top: 12px;
  570. border-top: 1px solid #e4e7ed;
  571. .buy-info {
  572. display: flex;
  573. align-items: center;
  574. gap: 6px;
  575. font-size: 12px;
  576. color: #909399;
  577. .el-icon {
  578. font-size: 14px;
  579. }
  580. }
  581. .allocated-badge {
  582. display: flex;
  583. align-items: center;
  584. gap: 4px;
  585. padding: 4px 10px;
  586. background: #e6f7ff;
  587. border-radius: 12px;
  588. font-size: 12px;
  589. color: #1890ff;
  590. .el-icon {
  591. font-size: 14px;
  592. }
  593. }
  594. }
  595. }
  596. }
  597. </style>