index.vue 8.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256
  1. <template>
  2. <div class="app-container">
  3. <!-- 查询和其他操作 -->
  4. <div class="filter-container">
  5. <el-select
  6. v-model="listQuery.shelveState" clearable size="mini" class="filter-item"
  7. style="width: 200px;"
  8. placeholder="请选择商品状态"
  9. >
  10. <el-option label="全部" value="" />
  11. <el-option label="已下架" :value="0" />
  12. <el-option label="已上架" :value="1" />
  13. <el-option label="待审核" :value="2" />
  14. <el-option label="审核失败" :value="3" />
  15. </el-select>
  16. <el-input
  17. v-model="listQuery.productId" clearable size="mini" class="filter-item"
  18. style="width: 200px;margin-left: 10px;" placeholder="请输入商品ID"
  19. />
  20. <el-input
  21. v-model="listQuery.productName" clearable size="mini" class="filter-item"
  22. style="width: 200px;margin-left: 10px;" placeholder="请输入商品名称"
  23. />
  24. <el-input
  25. v-model="listQuery.shopName" clearable size="mini" class="filter-item"
  26. style="width: 200px;margin-left: 10px;" placeholder="请输入商户名称"
  27. />
  28. <el-button
  29. size="mini" class="filter-item" type="primary" icon="el-icon-search"
  30. style="margin-left:10px;"
  31. @click="handleSearch"
  32. >
  33. 查找
  34. </el-button>
  35. <el-button size="mini" type="info" class="filter-item" @click="handleReset">
  36. 重置
  37. </el-button>
  38. <br />
  39. <el-button size="mini" type="primary" icon="el-icon-plus" @click="handleProductDataExport">
  40. 导出商品
  41. </el-button>
  42. </div>
  43. <!-- 查询结果 -->
  44. <div v-tableHeight>
  45. <el-table
  46. v-loading="listLoading" height="100%" element-loading-text="正在查询中。。。" :data="list"
  47. v-bind="{ stripe: true, size: 'small', border: true, fit: true, highlightCurrentRow: true }"
  48. >
  49. <el-table-column align="center" width="100" label="商品ID" prop="productId" fixed="left" />
  50. <el-table-column align="center" width="100" label="商品主图" prop="image">
  51. <template slot-scope="{ row }">
  52. <el-image
  53. v-if="row.image" lazy :src="common.seamingImgUrl(row.image)" style="width:40px; height:40px"
  54. fit="cover" :preview-src-list="[ common.seamingImgUrl(row.image) ]"
  55. />
  56. <span v-else>--</span>
  57. </template>
  58. </el-table-column>
  59. <el-table-column prop="productName" label="商品名称" width="180" />
  60. <el-table-column prop="shopName" label="商家名称" width="180" />
  61. <el-table-column prop="supplierName" label="供应商名称" width="180" />
  62. <el-table-column prop="classifyHierarchy" label="分类层级" width="180" />
  63. <el-table-column prop="sectionPrice" label="售价区间" show-overflow-tooltip />
  64. <!-- <el-table-column prop="memberSection" label="会员价" show-overflow-tooltip /> -->
  65. <el-table-column prop="stockNumber" label="库存" show-overflow-tooltip />
  66. <el-table-column prop="volume" label="实际销售" show-overflow-tooltip />
  67. <el-table-column prop="fictitiousNumber" label="虚拟销售" show-overflow-tooltip />
  68. <el-table-column align="center" width="150" label="创建时间" prop="createTime" />
  69. <el-table-column align="center" label="上架状态" prop="shelveState">
  70. <template slot-scope="{ row }">
  71. <el-tag v-if="row.shelveState === 0">已下架</el-tag>
  72. <el-tag v-else-if="row.shelveState === 1">已上架</el-tag>
  73. <el-tag v-else-if="row.shelveState === 2">待审核</el-tag>
  74. <el-tag v-else-if="row.shelveState === 3">审核失败</el-tag>
  75. <span v-else>--</span>
  76. </template>
  77. </el-table-column>
  78. <el-table-column align="center" label="操作" width="220" fixed="right" class-name="small-padding fixed-width">
  79. <template slot-scope="{ row }">
  80. <el-button v-if="row.shelveState === 1" type="text" @click="handleOffShelf(row)">
  81. 强制下架
  82. </el-button>
  83. <el-button
  84. v-if="row.shelveState === 1" type="text"
  85. @click="$refs.VirtualSales && $refs.VirtualSales.handleOpen(row)"
  86. >
  87. 虚拟销量
  88. </el-button>
  89. <el-button
  90. v-if="row.shelveState === 2" type="danger" size="mini"
  91. @click="$refs.ProductReview && $refs.ProductReview.handleOpen(row)"
  92. >
  93. 审核
  94. </el-button>
  95. <el-button type="warning" size="mini" @click="handleDetail(row)">
  96. 详情
  97. </el-button>
  98. <el-button
  99. v-if="row.shelveState === 1" type="danger" size="mini"
  100. @click="$refs.AddSelection && $refs.AddSelection.handleOpen(row)"
  101. >
  102. 加入选品
  103. </el-button>
  104. </template>
  105. </el-table-column>
  106. </el-table>
  107. </div>
  108. <div>
  109. <el-pagination
  110. :current-page="listQuery.page" :page-sizes="[10, 20, 50, 100]" :page-size="listQuery.pageSize"
  111. layout="total, sizes, prev, pager, next, jumper" :total="total"
  112. @size-change="(val) => ((listQuery.pageSize = val) && getList())"
  113. @current-change="(val) => ((listQuery.page = val) && getList())"
  114. />
  115. </div>
  116. <!-- 商品审核 -->
  117. <ProductReview ref="ProductReview" @success="getList" />
  118. <!-- 设置虚拟销量 -->
  119. <VirtualSales ref="VirtualSales" @success="getList" />
  120. <!-- 加入选品 -->
  121. <AddSelection ref="AddSelection" @success="getList" />
  122. <!-- 查看详情 -->
  123. <DetailModal ref="DetailModal" />
  124. </div>
  125. </template>
  126. <script>
  127. import {
  128. getClassifyGetAll,
  129. Forced,
  130. productExport
  131. } from '@/api/commodity'
  132. import ProductReview from './components/ProductReview'
  133. import VirtualSales from './components/VirtualSales'
  134. import AddSelection from './components/AddSelection'
  135. import DetailModal from './components/DetailModal'
  136. export default {
  137. name: 'CommoditySystem',
  138. components: {
  139. ProductReview,
  140. VirtualSales,
  141. AddSelection,
  142. DetailModal
  143. },
  144. data() {
  145. return {
  146. list: [],
  147. total: 0,
  148. listLoading: true,
  149. listQuery: {
  150. shelveState: '', // 商品状态 0-已下架 1-已上架 2-待审核 3-审核失败
  151. productName: '', // 商品名称
  152. productId: '', // 商品ID
  153. shopName: '', // 商户名称
  154. page: 1, // 当前页
  155. pageSize: 20
  156. }
  157. }
  158. },
  159. created() {
  160. this.getList()
  161. },
  162. methods: {
  163. async getList() {
  164. this.listLoading = true
  165. try {
  166. const res = await getClassifyGetAll(this.listQuery)
  167. this.list = res.data.list
  168. this.total = res.data.total
  169. } finally {
  170. this.listLoading = false
  171. }
  172. },
  173. handleSearch() {
  174. this.listQuery.page = 1
  175. this.getList()
  176. },
  177. handleReset() {
  178. this.listQuery = { shelveState: '', productName: '', productId: '', shopName: '', page: 1, pageSize: 5 }
  179. this.getList()
  180. },
  181. handleDetail(row) {
  182. this.$refs.DetailModal && this.$refs.DetailModal.handleOpen(row)
  183. },
  184. handleOffShelf(row) {
  185. this.$confirm('确定下架此商品吗?')
  186. .then(async () => {
  187. await Forced({ productId: row.productId })
  188. this.$message({ message: '下架成功!', type: 'success' })
  189. this.handleSearch()
  190. })
  191. .catch(() => { })
  192. },
  193. // 导出商品
  194. async handleProductDataExport() {
  195. this.$message({
  196. message: '数据导出中,请勿重复操作!',
  197. type: 'success'
  198. })
  199. const res = await productExport(this.listQuery)
  200. if (!res) {
  201. return
  202. }
  203. const blob = new Blob([ res ], { type: 'application/vnd.ms-excel' })
  204. const fileName = '商品数据明细表.xls'
  205. if ('download' in document.createElement('a')) {
  206. // 非IE下载
  207. const elink = document.createElement('a')
  208. elink.download = fileName
  209. elink.style.display = 'none'
  210. elink.href = URL.createObjectURL(blob)
  211. document.body.appendChild(elink)
  212. elink.click()
  213. URL.revokeObjectURL(elink.href) // 释放URL 对象
  214. document.body.removeChild(elink)
  215. } else {
  216. // IE10+下载
  217. navigator.msSaveBlob(blob, fileName)
  218. }
  219. }
  220. }
  221. }
  222. </script>
  223. <style lang="scss" scoped>
  224. .app-container {
  225. padding: 20px;
  226. display: flex;
  227. flex-direction: column;
  228. .filter-container {
  229. .filter-item {
  230. display: inline-block;
  231. vertical-align: middle;
  232. margin-bottom: 10px;
  233. }
  234. }
  235. .small-padding {
  236. .cell {
  237. padding-left: 5px;
  238. padding-right: 5px;
  239. }
  240. }
  241. .fixed-width {
  242. .el-button--mini {
  243. padding: 7px 10px;
  244. }
  245. }
  246. }
  247. </style>