List.vue 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185
  1. <template>
  2. <div class="supply-system-list">
  3. <el-card>
  4. <div slot="header">
  5. <span>供应商体系管理</span>
  6. <el-button style="float: right" type="primary" size="small" @click="$router.push('/supply-system/create')">+ 新建体系</el-button>
  7. </div>
  8. <el-form :inline="true" style="margin-bottom: 15px;">
  9. <el-form-item>
  10. <el-input v-model="searchKeyword" placeholder="搜索体系名称" clearable @clear="loadData" @keyup.enter.native="loadData">
  11. <i slot="prefix" class="el-icon-search"></i>
  12. </el-input>
  13. </el-form-item>
  14. <el-form-item>
  15. <el-select v-model="searchStatus" placeholder="状态" clearable style="width: 120px" @change="loadData">
  16. <el-option label="启用" value="active"></el-option>
  17. <el-option label="停用" value="disabled"></el-option>
  18. </el-select>
  19. </el-form-item>
  20. <el-form-item>
  21. <el-button type="primary" @click="loadData" :loading="loading">查询</el-button>
  22. </el-form-item>
  23. </el-form>
  24. <el-table :data="systems" stripe v-loading="loading" :max-height="tableHeight">
  25. <el-table-column prop="id" label="ID" width="80">
  26. <template slot="header">
  27. <span class="sort-header" @click.stop="onSortClick('id', $event)">ID<span v-if="sortIndex('id') !== null" class="sort-index" :class="sortClass('id') === 'sort-asc' ? 'sort-asc-badge' : 'sort-desc-badge'">{{ sortIndex('id') }}</span>{{ sortIcon('id') }}</span>
  28. </template>
  29. </el-table-column>
  30. <el-table-column prop="name" label="体系名称" min-width="150">
  31. <template slot="header">
  32. <span class="sort-header" @click.stop="onSortClick('name', $event)">体系名称<span v-if="sortIndex('name') !== null" class="sort-index" :class="sortClass('name') === 'sort-asc' ? 'sort-asc-badge' : 'sort-desc-badge'">{{ sortIndex('name') }}</span>{{ sortIcon('name') }}</span>
  33. </template>
  34. </el-table-column>
  35. <el-table-column prop="settlementPeriodDays" label="账期(天)" width="100">
  36. <template slot="header">
  37. <span class="sort-header" @click.stop="onSortClick('settlementPeriodDays', $event)">账期(天)<span v-if="sortIndex('settlementPeriodDays') !== null" class="sort-index" :class="sortClass('settlementPeriodDays') === 'sort-asc' ? 'sort-asc-badge' : 'sort-desc-badge'">{{ sortIndex('settlementPeriodDays') }}</span>{{ sortIcon('settlementPeriodDays') }}</span>
  38. </template>
  39. </el-table-column>
  40. <el-table-column prop="platformProfitRate" label="平台留利" width="100">
  41. <template slot="header">
  42. <span class="sort-header" @click.stop="onSortClick('platformProfitRate', $event)">平台留利<span v-if="sortIndex('platformProfitRate') !== null" class="sort-index" :class="sortClass('platformProfitRate') === 'sort-asc' ? 'sort-asc-badge' : 'sort-desc-badge'">{{ sortIndex('platformProfitRate') }}</span>{{ sortIcon('platformProfitRate') }}</span>
  43. </template>
  44. <template slot-scope="scope">
  45. {{ scope.row.platformProfitRate ? (scope.row.platformProfitRate * 1).toFixed(2) + '%' : '-' }}
  46. </template>
  47. </el-table-column>
  48. <el-table-column prop="description" label="描述" min-width="200">
  49. <template slot="header">
  50. <span class="sort-header" @click.stop="onSortClick('description', $event)">描述<span v-if="sortIndex('description') !== null" class="sort-index" :class="sortClass('description') === 'sort-asc' ? 'sort-asc-badge' : 'sort-desc-badge'">{{ sortIndex('description') }}</span>{{ sortIcon('description') }}</span>
  51. </template>
  52. </el-table-column>
  53. <el-table-column prop="status" label="状态" width="100">
  54. <template slot="header">
  55. <span class="sort-header" @click.stop="onSortClick('status', $event)">状态<span v-if="sortIndex('status') !== null" class="sort-index" :class="sortClass('status') === 'sort-asc' ? 'sort-asc-badge' : 'sort-desc-badge'">{{ sortIndex('status') }}</span>{{ sortIcon('status') }}</span>
  56. </template>
  57. <template slot-scope="scope">
  58. <el-tag :type="scope.row.status === 'active' ? 'success' : 'danger'" size="small">
  59. {{ scope.row.status === 'active' ? '启用' : '停用' }}
  60. </el-tag>
  61. </template>
  62. </el-table-column>
  63. <el-table-column label="操作" width="220">
  64. <template slot-scope="scope">
  65. <el-button size="mini" type="primary" @click="$router.push('/supply-system/' + scope.row.id)">详情</el-button>
  66. <el-button size="mini" @click="$router.push('/supply-system/' + scope.row.id + '/edit')">编辑</el-button>
  67. <el-button size="mini" :type="scope.row.status === 'active' ? 'warning' : 'success'" @click="toggleStatus(scope.row)">
  68. {{ scope.row.status === 'active' ? '停用' : '启用' }}
  69. </el-button>
  70. </template>
  71. </el-table-column>
  72. </el-table>
  73. <el-pagination
  74. v-if="total > 0"
  75. style="margin-top: 15px; text-align: right"
  76. background
  77. layout="total, prev, pager, next"
  78. :total="total"
  79. :page-size="pageSize"
  80. :current-page="page"
  81. @current-change="handlePageChange">
  82. </el-pagination>
  83. </el-card>
  84. </div>
  85. </template>
  86. <script>
  87. import SortMixin from '@/mixins/SortMixin'
  88. import { getSupplySystemList, toggleSupplySystemStatus } from '@/api/admin'
  89. export default {
  90. name: 'SupplySystemList',
  91. mixins: [SortMixin],
  92. computed: {
  93. tableHeight() {
  94. return window.innerHeight - 300
  95. }
  96. },
  97. data() {
  98. return {
  99. systems: [],
  100. loading: false,
  101. sortableColumns: { id: 'ID', name: '体系名称', settlementPeriodDays: '账期(天)', platformProfitRate: '平台留利', description: '描述', status: '状态' },
  102. searchKeyword: '',
  103. searchStatus: '',
  104. page: 1,
  105. pageSize: 10,
  106. total: 0
  107. }
  108. },
  109. created() {
  110. this.loadData()
  111. },
  112. methods: {
  113. loadList() {
  114. this.loadData()
  115. },
  116. async loadData() {
  117. this.loading = true
  118. try {
  119. const params = {
  120. keyword: this.searchKeyword,
  121. status: this.searchStatus,
  122. page: this.page,
  123. size: this.pageSize
  124. }
  125. if (this.sortState.length > 0) params.sort = this.sortState
  126. const res = await getSupplySystemList(params)
  127. if (res.data) {
  128. this.systems = res.data.records || res.data.list || []
  129. this.total = res.data.total || 0
  130. }
  131. } catch (e) {
  132. this.$message.error('加载失败')
  133. } finally {
  134. this.loading = false
  135. }
  136. },
  137. handlePageChange(val) {
  138. this.page = val
  139. this.loadData()
  140. },
  141. async toggleStatus(row) {
  142. try {
  143. await toggleSupplySystemStatus(row.id)
  144. this.$message.success('状态已更新')
  145. this.loadData()
  146. } catch (e) {
  147. this.$message.error('操作失败')
  148. }
  149. }
  150. }
  151. }
  152. </script>
  153. <style scoped>
  154. .supply-system-list {
  155. padding: 20px;
  156. }
  157. .sort-header {
  158. cursor: pointer;
  159. user-select: none;
  160. font-weight: 500;
  161. font-size: 12px;
  162. }
  163. .sort-header:hover {
  164. color: #409eff;
  165. }
  166. .sort-index {
  167. color: #fff;
  168. border-radius: 8px;
  169. font-size: 10px;
  170. padding: 0 4px;
  171. margin: 0 2px;
  172. }
  173. .sort-asc-badge {
  174. background: #f56c6c;
  175. }
  176. .sort-desc-badge {
  177. background: #409eff;
  178. }
  179. </style>