AssessmentProducts.vue 8.3 KB

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