ProductManage.vue 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321
  1. <template>
  2. <div class="product-manage admin-page">
  3. <div class="header">
  4. <h2>商品管理</h2>
  5. <div class="filters">
  6. <el-input
  7. v-model="filters.keyword"
  8. placeholder="搜索商品名称"
  9. prefix-icon="el-icon-search"
  10. clearable
  11. style="width: 180px;"
  12. @clear="loadList"
  13. @keyup.enter.native="loadList"
  14. />
  15. <el-select v-model="filters.status" placeholder="商品状态" @change="loadList" style="width: 130px;" clearable>
  16. <el-option label="全部" value="" />
  17. <el-option label="待审核" value="pending" />
  18. <el-option label="待上架" value="approved" />
  19. <el-option label="已上架" value="on_shelf" />
  20. <el-option label="已下架" value="off_shelf" />
  21. <el-option label="已拒绝" value="rejected" />
  22. </el-select>
  23. <el-select v-model="filters.productType" placeholder="商品类型" @change="loadList" style="width: 140px;" clearable>
  24. <el-option label="全部类型" value="" />
  25. <el-option label="实物商品" value="physical" />
  26. <el-option label="虚拟商品" value="virtual" />
  27. <el-option label="优惠券" value="coupon" />
  28. </el-select>
  29. <el-button type="primary" size="mini" @click="loadList">查询</el-button>
  30. <el-button type="success" size="mini" icon="el-icon-plus" @click="$router.push('/product-edit')">新增商品</el-button>
  31. </div>
  32. </div>
  33. <div style="overflow:auto;max-height:calc(100vh - 300px);">
  34. <el-table :data="list" v-loading="loading" border stripe style="max-height:calc(100vh - 300px);">
  35. <el-table-column prop="id" label="ID" width="70" />
  36. <el-table-column label="商品图片" width="80">
  37. <template slot-scope="{ row }">
  38. <img
  39. v-if="row.coverImage"
  40. :src="row.coverImage"
  41. class="product-thumb"
  42. @click="previewImage(row.coverImage)"
  43. />
  44. <span v-else style="color:#999">-</span>
  45. </template>
  46. </el-table-column>
  47. <el-table-column prop="name" label="商品名称" min-width="150" show-overflow-tooltip />
  48. <el-table-column label="类型" width="90">
  49. <template slot-scope="{ row }">
  50. {{ typeLabel(row.productType) }}
  51. </template>
  52. </el-table-column>
  53. <el-table-column label="售价(元)" width="90">
  54. <template slot-scope="{ row }">
  55. {{ formatPriceWithSymbol(row.price || 0) }}
  56. </template>
  57. </el-table-column>
  58. <el-table-column prop="stock" label="库存" width="80">
  59. <template slot-scope="{ row }">
  60. <span :class="{ 'stock-warning': row.stock !== null && row.stock < 10 }">
  61. {{ row.stock }}
  62. </span>
  63. </template>
  64. </el-table-column>
  65. <el-table-column prop="salesCount" label="销量" width="70" />
  66. <el-table-column label="供应商" width="120" show-overflow-tooltip>
  67. <template slot-scope="{ row }">
  68. {{ row.vendorName || '-' }}
  69. </template>
  70. </el-table-column>
  71. <el-table-column label="状态" width="90">
  72. <template slot-scope="{ row }">
  73. <el-tag :type="statusType(row.status)" size="mini">{{ statusLabel(row.status) }}</el-tag>
  74. </template>
  75. </el-table-column>
  76. <el-table-column prop="createdAt" label="创建时间" width="160">
  77. <template slot-scope="{ row }">
  78. {{ formatTime(row.createdAt) }}
  79. </template>
  80. </el-table-column>
  81. <el-table-column label="操作" width="200" fixed="right">
  82. <template slot-scope="{ row }">
  83. <el-button size="mini" type="primary" @click="$router.push('/product-edit?id=' + row.id)">编辑</el-button>
  84. <el-dropdown trigger="hover" @command="(cmd) => handleActionCmd(row, cmd)">
  85. <el-button size="mini">
  86. 更多<i class="el-icon-arrow-down el-icon--right"></i>
  87. </el-button>
  88. <el-dropdown-menu slot="dropdown">
  89. <el-dropdown-item v-if="row.status === 'pending'" command="approve" icon="el-icon-circle-check">通过</el-dropdown-item>
  90. <el-dropdown-item v-if="row.status === 'pending'" command="reject" icon="el-icon-circle-close">拒绝</el-dropdown-item>
  91. <el-dropdown-item v-if="row.status === 'on_shelf'" command="offShelf" icon="el-icon-download">下架</el-dropdown-item>
  92. <el-dropdown-item v-if="row.status === 'off_shelf'" command="onShelf" icon="el-icon-upload2">上架</el-dropdown-item>
  93. </el-dropdown-menu>
  94. </el-dropdown>
  95. </template>
  96. </el-table-column>
  97. </el-table>
  98. </div>
  99. <el-pagination
  100. @size-change="handleSizeChange"
  101. @current-change="handlePageChange"
  102. :current-page="pagination.page"
  103. :page-sizes="[10, 20, 50]"
  104. :page-size="pagination.size"
  105. :total="pagination.total"
  106. layout="total, sizes, prev, pager, next, jumper"
  107. style="margin-top: 16px; text-align: right;"
  108. />
  109. <el-dialog title="拒绝原因" :visible.sync="rejectDialogVisible" width="420px">
  110. <el-input v-model="rejectReason" type="textarea" :rows="3" placeholder="请输入拒绝原因" />
  111. <span slot="footer">
  112. <el-button @click="rejectDialogVisible = false">取消</el-button>
  113. <el-button type="danger" @click="confirmReject">确认拒绝</el-button>
  114. </span>
  115. </el-dialog>
  116. <el-dialog title="商品详情" :visible.sync="detailDialogVisible" width="600px">
  117. <el-descriptions :column="2" border v-if="detail">
  118. <el-descriptions-item label="商品名称">{{ detail.name }}</el-descriptions-item>
  119. <el-descriptions-item label="商品类型">{{ typeLabel(detail.productType) }}</el-descriptions-item>
  120. <el-descriptions-item label="售价">{{ formatPriceWithSymbol(detail.price || 0) }}</el-descriptions-item>
  121. <el-descriptions-item label="会员价">{{ detail.memberPrice ? formatPriceWithSymbol(detail.memberPrice) : '-' }}</el-descriptions-item>
  122. <el-descriptions-item label="库存">{{ detail.stock }}</el-descriptions-item>
  123. <el-descriptions-item label="销量">{{ detail.salesCount || 0 }}</el-descriptions-item>
  124. <el-descriptions-item label="供应商">{{ detail.vendorName || '-' }}</el-descriptions-item>
  125. <el-descriptions-item label="状态">
  126. <el-tag :type="statusType(detail.status)" size="mini">{{ statusLabel(detail.status) }}</el-tag>
  127. </el-descriptions-item>
  128. <el-descriptions-item label="拒绝原因" v-if="detail.rejectReason">{{ detail.rejectReason }}</el-descriptions-item>
  129. <el-descriptions-item label="商品描述" :span="2">{{ detail.description || '-' }}</el-descriptions-item>
  130. <el-descriptions-item label="创建时间" :span="2">{{ formatTime(detail.createdAt) }}</el-descriptions-item>
  131. </el-descriptions>
  132. <div v-else style="text-align:center;color:#999;">加载中...</div>
  133. </el-dialog>
  134. </div>
  135. </template>
  136. <script>
  137. import { getProductList, reviewProduct, shelveProduct } from '@/api/admin'
  138. export default {
  139. name: 'ProductManage',
  140. data() {
  141. return {
  142. list: [],
  143. loading: false,
  144. filters: {
  145. keyword: '',
  146. status: '',
  147. productType: ''
  148. },
  149. pagination: {
  150. page: 1,
  151. size: 20,
  152. total: 0
  153. },
  154. rejectDialogVisible: false,
  155. rejectTarget: null,
  156. rejectReason: '',
  157. detailDialogVisible: false,
  158. detail: null
  159. }
  160. },
  161. mounted() {
  162. this.loadList()
  163. },
  164. methods: {
  165. async loadList() {
  166. this.loading = true
  167. try {
  168. const params = {
  169. page: this.pagination.page,
  170. size: this.pagination.size,
  171. status: this.filters.status || null,
  172. productType: this.filters.productType || null,
  173. keyword: this.filters.keyword || null
  174. }
  175. const res = await getProductList(params)
  176. this.list = res.data.records || []
  177. this.pagination.total = res.data.total || 0
  178. } catch (e) {
  179. this.$message.error('加载失败')
  180. } finally {
  181. this.loading = false
  182. }
  183. },
  184. handleSizeChange(size) {
  185. this.pagination.size = size
  186. this.pagination.page = 1
  187. this.loadList()
  188. },
  189. handlePageChange(page) {
  190. this.pagination.page = page
  191. this.loadList()
  192. },
  193. statusType(status) {
  194. const map = {
  195. pending: 'warning',
  196. approved: 'success',
  197. on_shelf: 'success',
  198. off_shelf: 'info',
  199. rejected: 'danger'
  200. }
  201. return map[status] || 'info'
  202. },
  203. statusLabel(status) {
  204. const map = {
  205. pending: '待审核',
  206. approved: '待上架',
  207. on_shelf: '已上架',
  208. off_shelf: '已下架',
  209. rejected: '已拒绝'
  210. }
  211. return map[status] || status
  212. },
  213. typeLabel(type) {
  214. const map = { physical: '实物商品', virtual: '虚拟商品', coupon: '优惠券' }
  215. return map[type] || type
  216. },
  217. formatTime(time) {
  218. if (!time) return '-'
  219. return new Date(time).toLocaleString()
  220. },
  221. formatPriceWithSymbol(price) {
  222. if (price === 0) return '免费'
  223. return '¥' + (price / 100).toFixed(2)
  224. },
  225. async handleReview(row, action) {
  226. try {
  227. await this.$confirm('确认通过该商品审核?', '提示')
  228. await reviewProduct(row.id, { action })
  229. this.$message.success('操作成功')
  230. this.loadList()
  231. } catch (e) {
  232. if (e !== 'cancel') this.$message.error('操作失败')
  233. }
  234. },
  235. showRejectDialog(row) {
  236. this.rejectTarget = row
  237. this.rejectReason = ''
  238. this.rejectDialogVisible = true
  239. },
  240. async confirmReject() {
  241. if (!this.rejectReason.trim()) {
  242. return this.$message.warning('请填写拒绝原因')
  243. }
  244. try {
  245. await reviewProduct(this.rejectTarget.id, { action: 'reject', reason: this.rejectReason })
  246. this.$message.success('已拒绝')
  247. this.rejectDialogVisible = false
  248. this.loadList()
  249. } catch (e) {
  250. this.$message.error('操作失败')
  251. }
  252. },
  253. async handleShelve(row, shelve) {
  254. try {
  255. await this.$confirm('确认' + (shelve ? '上架' : '下架') + '该商品?', '提示')
  256. await shelveProduct(row.id, { shelve })
  257. this.$message.success('操作成功')
  258. this.loadList()
  259. } catch (e) {
  260. if (e !== 'cancel') this.$message.error('操作失败')
  261. }
  262. },
  263. previewImage(url) {
  264. if (!url) return
  265. this.$alert('<img src="' + url + '" style="max-width:100%;" />', '商品图片', {
  266. dangerouslyUseHTMLString: true,
  267. closeOnClickModal: true
  268. })
  269. },
  270. handleActionCmd(row, cmd) {
  271. switch (cmd) {
  272. case 'approve': this.handleReview(row, 'approve'); break;
  273. case 'reject': this.showRejectDialog(row); break;
  274. case 'offShelf': this.handleShelve(row, false); break;
  275. case 'onShelf': this.handleShelve(row, true); break;
  276. }
  277. }
  278. }
  279. }
  280. </script>
  281. <style scoped>
  282. .product-manage {
  283. padding: 20px;
  284. }
  285. .header {
  286. display: flex;
  287. justify-content: space-between;
  288. align-items: center;
  289. margin-bottom: 20px;
  290. flex-wrap: wrap;
  291. gap: 12px;
  292. }
  293. .header h2 {
  294. margin: 0;
  295. font-size: 18px;
  296. }
  297. .filters {
  298. display: flex;
  299. gap: 8px;
  300. flex-wrap: wrap;
  301. align-items: center;
  302. }
  303. .product-thumb {
  304. width: 50px;
  305. height: 50px;
  306. object-fit: cover;
  307. border-radius: 4px;
  308. cursor: pointer;
  309. }
  310. .stock-warning {
  311. color: #f56c6c;
  312. font-weight: bold;
  313. }
  314. </style>