AssessmentProducts.vue 8.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202
  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 :max-height="tableHeight">
  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. computed: {
  101. tableHeight() {
  102. return window.innerHeight - 300
  103. }
  104. },
  105. data() {
  106. return {
  107. list: [],
  108. loading: false,
  109. page: 1,
  110. size: 20,
  111. total: 0,
  112. filters: {
  113. keyword: '',
  114. status: ''
  115. },
  116. detail: null,
  117. detailVisible: false
  118. }
  119. },
  120. mounted() {
  121. this.loadList()
  122. },
  123. methods: {
  124. async loadList() {
  125. this.loading = true
  126. try {
  127. const res = await getProductList({
  128. page: this.page,
  129. size: this.size,
  130. productType: 'assessment',
  131. keyword: this.filters.keyword || undefined,
  132. status: this.filters.status || undefined
  133. })
  134. if (res.code === 200 && res.data) {
  135. this.list = res.data.records || []
  136. this.total = res.data.total || 0
  137. }
  138. } catch (e) {
  139. this.$message.error('加载失败')
  140. } finally {
  141. this.loading = false
  142. }
  143. },
  144. edit(id) {
  145. this.$router.push('/product-edit?id=' + id)
  146. },
  147. async handleReview(row, action) {
  148. try {
  149. await this.$confirm('确认' + (action === 'approve' ? '通过' : '拒绝') + '该商品审核?', '提示')
  150. await reviewProduct(row.id, { action })
  151. this.$message.success('操作成功')
  152. this.loadList()
  153. } catch (e) {
  154. if (e !== 'cancel') this.$message.error('操作失败')
  155. }
  156. },
  157. async handleShelve(row) {
  158. const action = row.status === 'on_shelf' ? '下架' : '上架'
  159. try {
  160. await this.$confirm('确认' + action + '该商品?', '提示')
  161. await shelveProduct(row.id, { shelve: row.status !== 'on_shelf' })
  162. this.$message.success(action + '成功')
  163. this.loadList()
  164. } catch (e) {
  165. if (e !== 'cancel') this.$message.error(action + '失败')
  166. }
  167. },
  168. previewImage(url) {
  169. this.detail = { coverImage: url }
  170. this.detailVisible = true
  171. },
  172. statusType(status) {
  173. const map = { pending: 'warning', approved: 'info', on_shelf: 'success', off_shelf: 'info', rejected: 'danger' }
  174. return map[status] || ''
  175. },
  176. statusLabel(status) {
  177. const map = { pending: '待审核', approved: '待上架', on_shelf: '已上架', off_shelf: '已下架', rejected: '已拒绝' }
  178. return map[status] || status
  179. },
  180. formatPriceWithSymbol(price) {
  181. if (price === 0) return '免费'
  182. return '¥' + (price / 100).toFixed(2)
  183. },
  184. handleSizeChange(val) { this.size = val; this.page = 1; this.loadList() },
  185. handlePageChange(val) { this.page = val; this.loadList() }
  186. }
  187. }
  188. </script>
  189. <style scoped>
  190. .assessment-products { padding: 20px; }
  191. .admin-page-header { display: flex; justify-content: space-between; align-items: center; }
  192. .admin-page-actions { display: flex; gap: 8px; align-items: center; }
  193. .header-search { width: 200px; }
  194. .product-thumb { width: 40px; height: 40px; object-fit: cover; border-radius: 4px; cursor: pointer; }
  195. .pagination-wrap { margin-top: 16px; text-align: right; }
  196. </style>