index.vue 9.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266
  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. <el-button type="text" @click="copyShelf(row)">
  105. 复制商品
  106. </el-button>
  107. </template>
  108. </el-table-column>
  109. </el-table>
  110. </div>
  111. <div>
  112. <el-pagination
  113. :current-page="listQuery.page" :page-sizes="[10, 20, 50, 100]" :page-size="listQuery.pageSize"
  114. layout="total, sizes, prev, pager, next, jumper" :total="total"
  115. @size-change="(val) => ((listQuery.pageSize = val) && getList())"
  116. @current-change="(val) => ((listQuery.page = val) && getList())"
  117. />
  118. </div>
  119. <!-- 商品审核 -->
  120. <ProductReview ref="ProductReview" @success="getList" />
  121. <!-- 设置虚拟销量 -->
  122. <VirtualSales ref="VirtualSales" @success="getList" />
  123. <!-- 加入选品 -->
  124. <AddSelection ref="AddSelection" :is-copy="isCopy" @success="getList" @changeIsCopy="isCopy = false" />
  125. <!-- 查看详情 -->
  126. <DetailModal ref="DetailModal" />
  127. </div>
  128. </template>
  129. <script>
  130. import {
  131. getClassifyGetAll,
  132. Forced,
  133. productExport
  134. } from '@/api/commodity'
  135. import ProductReview from './components/ProductReview'
  136. import VirtualSales from './components/VirtualSales'
  137. import AddSelection from './components/AddSelection'
  138. import DetailModal from './components/DetailModal'
  139. export default {
  140. name: 'CommoditySystem',
  141. components: {
  142. ProductReview,
  143. VirtualSales,
  144. AddSelection,
  145. DetailModal
  146. },
  147. data() {
  148. return {
  149. list: [],
  150. total: 0,
  151. listLoading: true,
  152. listQuery: {
  153. shelveState: '', // 商品状态 0-已下架 1-已上架 2-待审核 3-审核失败
  154. productName: '', // 商品名称
  155. productId: '', // 商品ID
  156. shopName: '', // 商户名称
  157. page: 1, // 当前页
  158. pageSize: 20
  159. },
  160. // 控制是否是复制商品
  161. isCopy: false
  162. }
  163. },
  164. created() {
  165. this.getList()
  166. },
  167. methods: {
  168. async getList() {
  169. this.listLoading = true
  170. try {
  171. const res = await getClassifyGetAll(this.listQuery)
  172. this.list = res.data.list
  173. this.total = res.data.total
  174. } finally {
  175. this.listLoading = false
  176. }
  177. },
  178. handleSearch() {
  179. this.listQuery.page = 1
  180. this.getList()
  181. },
  182. handleReset() {
  183. this.listQuery = { shelveState: '', productName: '', productId: '', shopName: '', page: 1, pageSize: 20 }
  184. this.getList()
  185. },
  186. handleDetail(row) {
  187. this.$refs.DetailModal && this.$refs.DetailModal.handleOpen(row)
  188. },
  189. handleOffShelf(row) {
  190. this.$confirm('确定下架此商品吗?')
  191. .then(async () => {
  192. await Forced({ productId: row.productId })
  193. this.$message({ message: '下架成功!', type: 'success' })
  194. this.handleSearch()
  195. })
  196. .catch(() => { })
  197. },
  198. // 复制商品
  199. copyShelf(row) {
  200. this.$refs.AddSelection && this.$refs.AddSelection.handleOpen(row)
  201. this.isCopy = true
  202. },
  203. // 导出商品
  204. async handleProductDataExport() {
  205. this.$message({
  206. message: '数据导出中,请勿重复操作!',
  207. type: 'success'
  208. })
  209. const res = await productExport(this.listQuery)
  210. if (!res) {
  211. return
  212. }
  213. const blob = new Blob([ res ], { type: 'application/vnd.ms-excel' })
  214. const fileName = '商品数据明细表.xls'
  215. if ('download' in document.createElement('a')) {
  216. // 非IE下载
  217. const elink = document.createElement('a')
  218. elink.download = fileName
  219. elink.style.display = 'none'
  220. elink.href = URL.createObjectURL(blob)
  221. document.body.appendChild(elink)
  222. elink.click()
  223. URL.revokeObjectURL(elink.href) // 释放URL 对象
  224. document.body.removeChild(elink)
  225. } else {
  226. // IE10+下载
  227. navigator.msSaveBlob(blob, fileName)
  228. }
  229. }
  230. }
  231. }
  232. </script>
  233. <style lang="scss" scoped>
  234. .app-container {
  235. padding: 20px;
  236. display: flex;
  237. flex-direction: column;
  238. .filter-container {
  239. .filter-item {
  240. display: inline-block;
  241. vertical-align: middle;
  242. margin-bottom: 10px;
  243. }
  244. }
  245. .small-padding {
  246. .cell {
  247. padding-left: 5px;
  248. padding-right: 5px;
  249. }
  250. }
  251. .fixed-width {
  252. .el-button--mini {
  253. padding: 7px 10px;
  254. }
  255. }
  256. }
  257. </style>