category.vue 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  1. <template>
  2. <div class="app-container">
  3. <div class="filter-container">
  4. <router-link to="/goods/category/create"><el-button class="filter-item" type="primary" icon="el-icon-circle-plus-outline">添加分类</el-button></router-link>
  5. <el-button class="filter-item" type="primary" icon="el-icon-sort" @click="batchSaveSort">批量更新排序</el-button>
  6. </div>
  7. <el-table
  8. v-loading="listLoading"
  9. :data="list"
  10. element-loading-text="Loading"
  11. border
  12. fit
  13. highlight-current-row
  14. :header-cell-style="{background:'#eef1f6',color:'#606266'}"
  15. >
  16. <el-table-column align="center" label="序号" width="50px">
  17. <template slot-scope="scope">
  18. {{ scope.$index }}
  19. </template>
  20. </el-table-column>
  21. <el-table-column label="分类名称" align="center" prop="classifyName" />
  22. <el-table-column label="分类图标" align="center" prop="classifyImage">
  23. <template slot-scope="{row}">
  24. <img :src="row.classifyImage" alt="" width="50">
  25. </template>
  26. </el-table-column>
  27. <el-table-column label="排序值" align="center" prop="sort">
  28. <template slot-scope="{row}">
  29. <el-input v-model="row.sort" style="width:60px;" size="small" />
  30. </template>
  31. </el-table-column>
  32. <el-table-column class-name="status-col" label="状态" align="center" prop="status">
  33. <template slot-scope="{row}">
  34. <el-tooltip :content="row.status*1 === 1 ? '停用' : '启用'" placement="top">
  35. <el-switch
  36. v-model="row.status"
  37. active-value="1"
  38. inactive-value="0"
  39. @change="changeStatus(row.id)"
  40. />
  41. </el-tooltip>
  42. </template>
  43. </el-table-column>
  44. <el-table-column align="center" label="添加时间" prop="addTime">
  45. <template slot-scope="{row}">
  46. <i class="el-icon-time" />
  47. <span>{{ row.addTime | parseTime('{y}-{m}-{d} {h}:{i}') }}</span>
  48. </template>
  49. </el-table-column>
  50. <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
  51. <template slot-scope="{row}">
  52. <router-link :to="'/goods/category/edit/' + row.id "><el-button type="primary" size="small">编辑</el-button></router-link>
  53. </template>
  54. </el-table-column>
  55. </el-table>
  56. <pagination v-show="total>0" :total="total" :page.sync="listQuery.index" :limit.sync="listQuery.pageSize" @pagination="getList" />
  57. </div>
  58. </template>
  59. <script>
  60. import { getCategory, switchClassify, saveCategorySort } from '@/api/goods-classify'
  61. import Pagination from '@/components/Pagination'
  62. export default {
  63. components: { Pagination },
  64. filters: {
  65. statusFilter(status) {
  66. const statusMap = {
  67. 1: 'success',
  68. 0: 'danger'
  69. }
  70. return statusMap[status]
  71. }
  72. },
  73. data() {
  74. return {
  75. list: null,
  76. listLoading: true,
  77. total: 0,
  78. listQuery: {
  79. index: 1,
  80. pageSize: 20,
  81. organizeID: this.$store.getters.organizeID
  82. }
  83. }
  84. },
  85. computed: {
  86. organizeID() {
  87. return this.$store.getters.organizeID
  88. }
  89. },
  90. created() {
  91. this.getList()
  92. },
  93. methods: {
  94. getList() {
  95. this.listLoading = true
  96. getCategory(this.listQuery).then(response => {
  97. this.list = response.data.results
  98. this.total = response.data.totalRecord
  99. this.listLoading = false
  100. })
  101. },
  102. changeStatus(id) {
  103. switchClassify({ id: id }).then(() => {
  104. this.getList()
  105. }).catch(() => {
  106. this.getList()
  107. })
  108. },
  109. batchSaveSort() {
  110. const sorts = []
  111. this.list.map(item => {
  112. sorts.push(item.id + '-' + item.sort)
  113. })
  114. saveCategorySort({ newProducSorttList: sorts.join(',') }).then(() => {
  115. this.getList()
  116. }).catch(() => {
  117. this.getList()
  118. })
  119. }
  120. }
  121. }
  122. </script>