AssessmentProducts.vue 7.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197
  1. <template>
  2. <div class="assessment-products admin-page">
  3. <el-card>
  4. <div slot="header" class="admin-page-header">
  5. <span class="admin-page-title">测评商品管理</span>
  6. <div class="admin-page-actions">
  7. <el-input
  8. v-model="filters.keyword"
  9. placeholder="搜索商品名称"
  10. prefix-icon="el-icon-search"
  11. clearable
  12. class="header-search"
  13. @clear="loadList"
  14. @keyup.enter.native="loadList"
  15. />
  16. <el-select v-model="filters.status" placeholder="商品状态" @change="loadList" clearable>
  17. <el-option label="全部状态" value="" />
  18. <el-option label="待审核" value="pending" />
  19. <el-option label="待上架" value="approved" />
  20. <el-option label="已上架" value="on_shelf" />
  21. <el-option label="已下架" value="off_shelf" />
  22. <el-option label="已拒绝" value="rejected" />
  23. </el-select>
  24. <el-button type="primary" size="mini" @click="loadList">查询</el-button>
  25. <el-button type="success" size="mini" icon="el-icon-plus" @click="$router.push('/product-edit')">新增测评商品</el-button>
  26. </div>
  27. </div>
  28. <el-table :data="list" v-loading="loading" border stripe>
  29. <el-table-column prop="id" label="ID" width="70" />
  30. <el-table-column label="商品图片" width="80">
  31. <template slot-scope="{ row }">
  32. <img v-if="row.coverImage" :src="row.coverImage" class="product-thumb"
  33. @click="previewImage(row.coverImage)" />
  34. <span v-else style="color:#999">-</span>
  35. </template>
  36. </el-table-column>
  37. <el-table-column prop="name" label="商品名称" min-width="160" show-overflow-tooltip />
  38. <el-table-column label="测评类型" width="90">
  39. <template slot-scope="{ row }">
  40. <el-tag :type="row.assessmentType === 'bundle' ? 'warning' : 'primary'" size="mini">
  41. {{ row.assessmentType === 'bundle' ? '组合' : '单包' }}
  42. </el-tag>
  43. </template>
  44. </el-table-column>
  45. <el-table-column label="次数" width="70" prop="totalSessions" />
  46. <el-table-column label="有效期(天)" width="90" prop="validityDays" />
  47. <el-table-column label="售价(元)" width="90">
  48. <template slot-scope="{ row }">
  49. {{ formatPriceWithSymbol(row.price || 0) }}
  50. </template>
  51. </el-table-column>
  52. <el-table-column label="状态" width="90">
  53. <template slot-scope="{ row }">
  54. <el-tag :type="statusType(row.status)" size="mini">{{ statusLabel(row.status) }}</el-tag>
  55. </template>
  56. </el-table-column>
  57. <el-table-column label="操作" width="160" fixed="right">
  58. <template slot-scope="{ row }">
  59. <el-button type="text" size="mini" @click="edit(row.id)">编辑</el-button>
  60. <el-button v-if="row.status === 'pending'" type="text" size="mini" @click="handleReview(row, 'approve')">审核通过</el-button>
  61. <el-button v-if="row.status === 'on_shelf' || row.status === 'off_shelf'" type="text" size="mini" @click="handleShelve(row)">
  62. {{ row.status === 'on_shelf' ? '下架' : '上架' }}
  63. </el-button>
  64. </template>
  65. </el-table-column>
  66. </el-table>
  67. <div class="pagination-wrap">
  68. <el-pagination
  69. @size-change="handleSizeChange"
  70. @current-change="handlePageChange"
  71. :current-page="page"
  72. :page-sizes="[10, 20, 50]"
  73. :page-size="size"
  74. layout="total, sizes, prev, pager, next, jumper"
  75. :total="total"
  76. />
  77. </div>
  78. </el-card>
  79. <el-dialog title="商品详情" :visible.sync="detailVisible" width="600px">
  80. <el-descriptions v-if="detail" :column="2" border>
  81. <el-descriptions-item label="商品ID">{{ detail.id }}</el-descriptions-item>
  82. <el-descriptions-item label="商品名称">{{ detail.name }}</el-descriptions-item>
  83. <el-descriptions-item label="商品类型">{{ detail.productType }}</el-descriptions-item>
  84. <el-descriptions-item label="测评类型">{{ detail.assessmentType === 'bundle' ? '组合' : '单包' }}</el-descriptions-item>
  85. <el-descriptions-item label="测评次数">{{ detail.totalSessions }}</el-descriptions-item>
  86. <el-descriptions-item label="有效期(天)">{{ detail.validityDays }}</el-descriptions-item>
  87. <el-descriptions-item label="规划师范围">{{ detail.guideScope }}</el-descriptions-item>
  88. <el-descriptions-item label="价格(元)">{{ formatPriceWithSymbol(detail.price || 0) }}</el-descriptions-item>
  89. <el-descriptions-item label="状态">
  90. <el-tag :type="statusType(detail.status)" size="mini">{{ statusLabel(detail.status) }}</el-tag>
  91. </el-descriptions-item>
  92. </el-descriptions>
  93. </el-dialog>
  94. </div>
  95. </template>
  96. <script>
  97. import { getProductList, reviewProduct, shelveProduct } from '@/api/admin'
  98. export default {
  99. name: 'AssessmentProducts',
  100. data() {
  101. return {
  102. list: [],
  103. loading: false,
  104. page: 1,
  105. size: 20,
  106. total: 0,
  107. filters: {
  108. keyword: '',
  109. status: ''
  110. },
  111. detail: null,
  112. detailVisible: false
  113. }
  114. },
  115. mounted() {
  116. this.loadList()
  117. },
  118. methods: {
  119. async loadList() {
  120. this.loading = true
  121. try {
  122. const res = await getProductList({
  123. page: this.page,
  124. size: this.size,
  125. productType: 'assessment',
  126. keyword: this.filters.keyword || undefined,
  127. status: this.filters.status || undefined
  128. })
  129. if (res.code === 200 && res.data) {
  130. this.list = res.data.records || []
  131. this.total = res.data.total || 0
  132. }
  133. } catch (e) {
  134. this.$message.error('加载失败')
  135. } finally {
  136. this.loading = false
  137. }
  138. },
  139. edit(id) {
  140. this.$router.push('/product-edit?id=' + id)
  141. },
  142. async handleReview(row, action) {
  143. try {
  144. await this.$confirm('确认' + (action === 'approve' ? '通过' : '拒绝') + '该商品审核?', '提示')
  145. await reviewProduct(row.id, { action })
  146. this.$message.success('操作成功')
  147. this.loadList()
  148. } catch (e) {
  149. if (e !== 'cancel') this.$message.error('操作失败')
  150. }
  151. },
  152. async handleShelve(row) {
  153. const action = row.status === 'on_shelf' ? '下架' : '上架'
  154. try {
  155. await this.$confirm('确认' + action + '该商品?', '提示')
  156. await shelveProduct(row.id, { shelve: row.status !== 'on_shelf' })
  157. this.$message.success(action + '成功')
  158. this.loadList()
  159. } catch (e) {
  160. if (e !== 'cancel') this.$message.error(action + '失败')
  161. }
  162. },
  163. previewImage(url) {
  164. this.detail = { coverImage: url }
  165. this.detailVisible = true
  166. },
  167. statusType(status) {
  168. const map = { pending: 'warning', approved: 'info', on_shelf: 'success', off_shelf: 'info', rejected: 'danger' }
  169. return map[status] || ''
  170. },
  171. statusLabel(status) {
  172. const map = { pending: '待审核', approved: '待上架', on_shelf: '已上架', off_shelf: '已下架', rejected: '已拒绝' }
  173. return map[status] || status
  174. },
  175. formatPriceWithSymbol(price) {
  176. if (price === 0) return '免费'
  177. return '¥' + (price / 100).toFixed(2)
  178. },
  179. handleSizeChange(val) { this.size = val; this.loadList() },
  180. handlePageChange(val) { this.page = val; this.loadList() }
  181. }
  182. }
  183. </script>
  184. <style scoped>
  185. .assessment-products { padding: 20px; }
  186. .admin-page-header { display: flex; justify-content: space-between; align-items: center; }
  187. .admin-page-actions { display: flex; gap: 8px; align-items: center; }
  188. .header-search { width: 200px; }
  189. .product-thumb { width: 40px; height: 40px; object-fit: cover; border-radius: 4px; cursor: pointer; }
  190. .pagination-wrap { margin-top: 16px; text-align: right; }
  191. </style>