SupplierProductManage.vue 7.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241
  1. <template>
  2. <div class="supplier-product-manage 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="approved" />
  19. <el-option label="已上架" value="on_shelf" />
  20. <el-option label="已下架" value="off_shelf" />
  21. </el-select>
  22. <el-button type="primary" size="mini" @click="loadList">查询</el-button>
  23. <el-button type="success" size="mini" icon="el-icon-plus" @click="handleAdd">新增商品</el-button>
  24. </div>
  25. </div>
  26. <div class="table-scroll-wrap-sm">
  27. <div style="overflow:auto;max-height:calc(100vh - 300px);">
  28. <el-table style="max-height:calc(100vh - 300px);" :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
  33. v-if="row.coverImage"
  34. :src="row.coverImage"
  35. class="product-thumb"
  36. @click="previewImage(row.coverImage)"
  37. />
  38. <span v-else style="color:#999">-</span>
  39. </template>
  40. </el-table-column>
  41. <el-table-column prop="name" label="商品名称" min-width="150" show-overflow-tooltip />
  42. <el-table-column label="类型" width="90">
  43. <template slot-scope="{ row }">
  44. {{ typeLabel(row.productType) }}
  45. </template>
  46. </el-table-column>
  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 prop="stock" label="库存" width="80">
  53. <template slot-scope="{ row }">
  54. <span :class="{ 'stock-warning': row.stock !== null && row.stock < 10 }">
  55. {{ row.stock }}
  56. </span>
  57. </template>
  58. </el-table-column>
  59. <el-table-column prop="salesCount" label="销量" width="70" />
  60. <el-table-column label="状态" width="90">
  61. <template slot-scope="{ row }">
  62. <el-tag :type="statusType(row.status)" size="mini">{{ statusLabel(row.status) }}</el-tag>
  63. </template>
  64. </el-table-column>
  65. <el-table-column prop="createdAt" label="创建时间" width="160">
  66. <template slot-scope="{ row }">
  67. {{ formatTime(row.createdAt) }}
  68. </template>
  69. </el-table-column>
  70. <el-table-column label="操作" width="200" fixed="right">
  71. <template slot-scope="{ row }">
  72. <el-button size="mini" type="primary" @click="handleEdit(row)">编辑</el-button>
  73. <el-dropdown trigger="hover" @command="(cmd) => handleActionCmd(row, cmd)">
  74. <el-button size="mini">
  75. 更多<i class="el-icon-arrow-down el-icon--right"></i>
  76. </el-button>
  77. <el-dropdown-menu slot="dropdown">
  78. <el-dropdown-item v-if="row.status === 'on_shelf'" command="offShelf" icon="el-icon-download">下架</el-dropdown-item>
  79. <el-dropdown-item v-if="row.status === 'off_shelf'" command="onShelf" icon="el-icon-upload2">上架</el-dropdown-item>
  80. </el-dropdown-menu>
  81. </el-dropdown>
  82. </template>
  83. </el-table-column>
  84. </el-table>
  85. </div>
  86. </div>
  87. <el-pagination
  88. @size-change="handleSizeChange"
  89. @current-change="handlePageChange"
  90. :current-page="pagination.page"
  91. :page-sizes="[10, 20, 50]"
  92. :page-size="pagination.size"
  93. :total="pagination.total"
  94. layout="total, sizes, prev, pager, next, jumper"
  95. class="pagination-wrap"
  96. />
  97. </el-card>
  98. </div>
  99. </template>
  100. <script>
  101. import { getSupplierProductList, shelveSupplierProduct } from '@/api/admin'
  102. export default {
  103. name: 'SupplierProductManage',
  104. data() {
  105. return {
  106. list: [],
  107. loading: false,
  108. filters: {
  109. keyword: '',
  110. status: ''
  111. },
  112. pagination: {
  113. page: 1,
  114. size: 20,
  115. total: 0
  116. }
  117. }
  118. },
  119. mounted() {
  120. this.loadList()
  121. },
  122. methods: {
  123. async loadList() {
  124. this.loading = true
  125. try {
  126. const params = {
  127. page: this.pagination.page,
  128. size: this.pagination.size,
  129. status: this.filters.status || null,
  130. keyword: this.filters.keyword || null
  131. }
  132. const res = await getSupplierProductList(params)
  133. if (res.code === 200) {
  134. this.list = res.data.records || []
  135. this.pagination.total = res.data.total || 0
  136. }
  137. } catch (e) {
  138. this.$message.error('加载失败')
  139. } finally {
  140. this.loading = false
  141. }
  142. },
  143. handleSizeChange(size) {
  144. this.pagination.size = size
  145. this.pagination.page = 1
  146. this.loadList()
  147. },
  148. handlePageChange(page) {
  149. this.pagination.page = page
  150. this.loadList()
  151. },
  152. statusType(status) {
  153. const map = {
  154. approved: 'info',
  155. on_shelf: 'success',
  156. off_shelf: 'warning'
  157. }
  158. return map[status] || 'info'
  159. },
  160. statusLabel(status) {
  161. const map = {
  162. approved: '待上架',
  163. on_shelf: '已上架',
  164. off_shelf: '已下架'
  165. }
  166. return map[status] || status
  167. },
  168. typeLabel(type) {
  169. const map = {
  170. physical: '实物商品',
  171. virtual: '虚拟商品',
  172. coupon: '优惠券',
  173. assessment: '测评商品'
  174. }
  175. return map[type] || type
  176. },
  177. formatTime(t) {
  178. if (!t) return '-'
  179. return t.replace ? t.replace('T', ' ').substring(0, 19) : t
  180. },
  181. formatPriceWithSymbol(price) {
  182. if (price === 0) return '免费'
  183. return '¥' + (price / 100).toFixed(2)
  184. },
  185. previewImage(url) {
  186. if (!url) return
  187. this.$alert('<img src="' + url + '" style="max-width:100%;" />', '商品图片', {
  188. dangerouslyUseHTMLString: true,
  189. closeOnClickModal: true
  190. })
  191. },
  192. handleAdd() {
  193. // 新增商品 - 默认进入编辑页,无需指定ID
  194. this.$router.push('/product-edit')
  195. },
  196. handleEdit(row) {
  197. this.$router.push('/product-edit?id=' + row.id)
  198. },
  199. async handleShelve(row, shelve) {
  200. try {
  201. await this.$confirm('确认' + (shelve ? '上架' : '下架') + '该商品?', '提示')
  202. await shelveSupplierProduct(row.id, { shelve })
  203. this.$message.success('操作成功')
  204. this.loadList()
  205. } catch (e) {
  206. if (e !== 'cancel') this.$message.error('操作失败')
  207. }
  208. },
  209. handleActionCmd(row, cmd) {
  210. switch (cmd) {
  211. case 'offShelf': this.handleShelve(row, false); break;
  212. case 'onShelf': this.handleShelve(row, true); break;
  213. }
  214. }
  215. }
  216. }
  217. </script>
  218. <style scoped>
  219. .supplier-product-manage {
  220. padding: 20px;
  221. }
  222. .product-thumb {
  223. width: 50px;
  224. height: 50px;
  225. object-fit: cover;
  226. border-radius: 4px;
  227. cursor: pointer;
  228. }
  229. .stock-warning {
  230. color: #f56c6c;
  231. font-weight: bold;
  232. }
  233. .header-search {
  234. width: 180px;
  235. }
  236. </style>