VirtualTeamList.vue 8.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249
  1. <template>
  2. <div class="virtual-team-list admin-page">
  3. <el-card>
  4. <div slot="header">
  5. <span>虚拟服务商团队</span>
  6. <el-button style="float: right" type="primary" size="small" @click="handleCreate">+ 创建团队</el-button>
  7. </div>
  8. <div class="toolbar">
  9. <el-input
  10. v-model="searchKeyword"
  11. placeholder="搜索团队名称"
  12. prefix-icon="el-icon-search"
  13. size="small"
  14. style="width: 240px"
  15. clearable
  16. @clear="loadData"
  17. @keyup.enter.native="loadData"
  18. ></el-input>
  19. <el-button size="small" type="primary" @click="loadData">查询</el-button>
  20. </div>
  21. <el-table :max-height="tableHeight" :data="pagedData" stripe v-loading="loading">
  22. <el-table-column prop="id" label="ID" width="80"></el-table-column>
  23. <el-table-column prop="name" label="团队名称" width="160"></el-table-column>
  24. <el-table-column prop="description" label="描述" show-overflow-tooltip></el-table-column>
  25. <el-table-column prop="ownerId" label="负责人ID" width="100"></el-table-column>
  26. <el-table-column prop="profitRate" label="利润率" width="100">
  27. <template slot-scope="scope">
  28. {{ scope.row.profitRate != null ? (scope.row.profitRate + '%') : '-' }}
  29. </template>
  30. </el-table-column>
  31. <el-table-column prop="enabled" label="状态" width="80">
  32. <template slot-scope="scope">
  33. <el-tag :type="scope.row.enabled ? 'success' : 'info'" size="mini">
  34. {{ scope.row.enabled ? '启用' : '禁用' }}
  35. </el-tag>
  36. </template>
  37. </el-table-column>
  38. <el-table-column prop="createdAt" label="创建时间" width="170">
  39. <template slot-scope="scope">
  40. {{ formatDate(scope.row.createdAt) }}
  41. </template>
  42. </el-table-column>
  43. <el-table-column label="操作" width="200" fixed="right">
  44. <template slot-scope="{ row }">
  45. <el-button size="mini" type="primary" @click="handleEdit(row)">编辑</el-button>
  46. <el-dropdown trigger="hover" @command="(cmd) => handleActionCmd(row, cmd)">
  47. <el-button size="mini">
  48. 更多<i class="el-icon-arrow-down el-icon--right"></i>
  49. </el-button>
  50. <el-dropdown-menu slot="dropdown">
  51. <el-dropdown-item command="toggle" icon="el-icon-switch-button">{{ row.enabled ? '禁用' : '启用' }}</el-dropdown-item>
  52. <el-dropdown-item command="members" icon="el-icon-user">成员</el-dropdown-item>
  53. </el-dropdown-menu>
  54. </el-dropdown>
  55. </template>
  56. </el-table-column>
  57. </el-table>
  58. <el-pagination
  59. v-if="filteredData.length > pageSize"
  60. style="margin-top: 16px; text-align: right"
  61. background
  62. layout="prev, pager, next, total"
  63. :total="filteredData.length"
  64. :page-size="pageSize"
  65. :current-page.sync="currentPage"
  66. ></el-pagination>
  67. </el-card>
  68. <el-dialog :visible.sync="dialogVisible" :title="isEdit ? '编辑团队' : '创建团队'" width="500px" :close-on-click-modal="false">
  69. <el-form :model="form" :rules="formRules" ref="teamForm" label-width="80px">
  70. <el-form-item label="团队名称" prop="name">
  71. <el-input v-model="form.name" placeholder="请输入团队名称"></el-input>
  72. </el-form-item>
  73. <el-form-item label="描述" prop="description">
  74. <el-input v-model="form.description" type="textarea" :rows="3" placeholder="请输入团队描述"></el-input>
  75. </el-form-item>
  76. <el-form-item label="利润率" prop="profitRate">
  77. <el-input-number v-model="form.profitRate" :min="0" :max="100" :precision="1" :step="0.5" style="width: 200px"></el-input-number>
  78. <span style="margin-left: 8px; color: #909399">%</span>
  79. </el-form-item>
  80. </el-form>
  81. <div slot="footer">
  82. <el-button @click="dialogVisible = false">取消</el-button>
  83. <el-button type="primary" :loading="submitting" @click="handleSubmit">保存</el-button>
  84. </div>
  85. </el-dialog>
  86. <el-dialog title="操作成功" :visible.sync="successDialogVisible" width="400px" :close-on-click-modal="false">
  87. <div style="text-align:center;padding:10px 0">
  88. <i class="el-icon-success" style="color:#67C23A;font-size:32px"></i>
  89. <p style="margin:12px 0 0;font-size:16px;color:#303133">保存成功</p>
  90. </div>
  91. <div slot="footer">
  92. <el-button type="primary" @click="handleContinue">继续添加</el-button>
  93. <el-button @click="handleClose">关闭</el-button>
  94. </div>
  95. </el-dialog>
  96. </div>
  97. </template>
  98. <script>
  99. import {
  100. listVirtualTeams,
  101. createVirtualTeam,
  102. updateVirtualTeam,
  103. toggleVirtualTeam
  104. } from '@/api/admin'
  105. export default {
  106. name: 'VirtualTeamList',
  107. data() {
  108. return {
  109. teams: [],
  110. loading: false,
  111. submitting: false,
  112. searchKeyword: '',
  113. currentPage: 1,
  114. pageSize: 15,
  115. dialogVisible: false,
  116. successDialogVisible: false,
  117. isEdit: false,
  118. form: this.getEmptyForm(),
  119. formRules: {
  120. name: [{ required: true, message: '请输入团队名称', trigger: 'blur' }]
  121. }
  122. }
  123. },
  124. computed: {
  125. tableHeight() {
  126. return window.innerHeight - 300
  127. },
  128. filteredData() {
  129. if (!this.searchKeyword) return this.teams
  130. var kw = this.searchKeyword.toLowerCase()
  131. return this.teams.filter(function(t) {
  132. return t.name && t.name.toLowerCase().indexOf(kw) !== -1
  133. })
  134. },
  135. pagedData() {
  136. var start = (this.currentPage - 1) * this.pageSize
  137. return this.filteredData.slice(start, start + this.pageSize)
  138. }
  139. },
  140. created() {
  141. this.loadData()
  142. },
  143. methods: {
  144. getEmptyForm() {
  145. return { id: null, name: '', description: '', profitRate: 0 }
  146. },
  147. formatDate(val) {
  148. if (!val) return '-'
  149. return val.replace('T', ' ').substring(0, 19)
  150. },
  151. handleSearch() {
  152. this.loadData()
  153. },
  154. async loadData() {
  155. this.loading = true
  156. try {
  157. var res = await listVirtualTeams({})
  158. this.teams = res.data || []
  159. } catch (e) {
  160. console.error(e)
  161. } finally {
  162. this.loading = false
  163. }
  164. },
  165. handleCreate() {
  166. this.isEdit = false
  167. this.form = this.getEmptyForm()
  168. this.dialogVisible = true
  169. this.$nextTick(function() {
  170. if (this.$refs.teamForm) this.$refs.teamForm.clearValidate()
  171. }.bind(this))
  172. },
  173. handleEdit(row) {
  174. this.isEdit = true
  175. this.form = { id: row.id, name: row.name, description: row.description, profitRate: row.profitRate || 0 }
  176. this.dialogVisible = true
  177. this.$nextTick(function() {
  178. if (this.$refs.teamForm) this.$refs.teamForm.clearValidate()
  179. }.bind(this))
  180. },
  181. async handleToggle(row) {
  182. var action = row.enabled ? '禁用' : '启用'
  183. try {
  184. await this.$confirm('确定' + action + '团队"' + row.name + '"吗?', '提示', { type: 'warning' })
  185. await toggleVirtualTeam(row.id)
  186. this.$message.success(action + '成功')
  187. this.loadData()
  188. } catch (e) {
  189. if (e !== 'cancel') this.$message.error(action + '失败')
  190. }
  191. },
  192. handleActionCmd(row, cmd) {
  193. switch (cmd) {
  194. case 'toggle': this.handleToggle(row); break
  195. case 'members': this.viewMembers(row); break
  196. }
  197. },
  198. viewMembers(row) {
  199. this.$router.push('/virtual-team-detail/' + row.id)
  200. },
  201. async handleSubmit() {
  202. this.$refs.teamForm.validate(function(valid) {
  203. if (!valid) return
  204. }.bind(this))
  205. if (!this.form.name) return
  206. this.submitting = true
  207. try {
  208. if (this.isEdit) {
  209. await updateVirtualTeam(this.form)
  210. } else {
  211. await createVirtualTeam(this.form)
  212. }
  213. this.$message.success('保存成功')
  214. this.successDialogVisible = true
  215. } catch (e) {
  216. this.$message.error('保存失败')
  217. } finally {
  218. this.submitting = false
  219. }
  220. },
  221. handleContinue() {
  222. this.successDialogVisible = false
  223. this.isEdit = false
  224. this.form = this.getEmptyForm()
  225. this.dialogVisible = true
  226. this.$nextTick(function() {
  227. if (this.$refs.teamForm) this.$refs.teamForm.clearValidate()
  228. }.bind(this))
  229. },
  230. handleClose() {
  231. this.successDialogVisible = false
  232. this.dialogVisible = false
  233. this.loadData()
  234. }
  235. }
  236. }
  237. </script>
  238. <style scoped>
  239. .virtual-team-list { padding: 20px; }
  240. .toolbar { margin-bottom: 16px; display: flex; align-items: center; gap: 8px; }
  241. </style>