index.vue 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201
  1. <template>
  2. <div class="tabManage app-container">
  3. <div class="search">
  4. <el-button class="add-btn" type="primary" size="small" @click="handleAdd"
  5. >添加</el-button
  6. >
  7. </div>
  8. <el-table
  9. :data="tableData"
  10. tooltip-effect="dark"
  11. border
  12. v-loading="loading"
  13. style="width: 100%"
  14. >
  15. <el-table-column
  16. align="center"
  17. label="ID"
  18. prop="id"
  19. show-overflow-tooltip
  20. >
  21. </el-table-column>
  22. <el-table-column
  23. align="center"
  24. label="社区标签名称"
  25. prop="communityName"
  26. show-overflow-tooltip
  27. >
  28. </el-table-column>
  29. <el-table-column align="center" label="操作">
  30. <template slot-scope="scope">
  31. <el-button type="text" size="small" @click="handleEdit(scope.row)"
  32. >编辑</el-button
  33. >
  34. <el-button type="text" size="small" @click="handleDel(scope.row.id)"
  35. >删除</el-button
  36. >
  37. </template>
  38. </el-table-column>
  39. </el-table>
  40. <div class="page-box">
  41. <el-pagination
  42. @size-change="handleSizeChange"
  43. @current-change="handleCurrentChange"
  44. background
  45. :current-page="query.currentPage"
  46. :page-sizes="[10, 20, 30, 40]"
  47. :page-size="query.pageSize"
  48. layout="total, sizes, prev, pager, next, jumper"
  49. :total="total"
  50. >
  51. </el-pagination>
  52. </div>
  53. <el-dialog :title="title" width="550px" :visible.sync="dialogFormVisible">
  54. <el-form label-width="130px" :model="setQuery"
  55. ref="setQuery"
  56. :rules="rules">
  57. <el-form-item label="标签名称" prop="communityName">
  58. <el-input
  59. v-model.number="setQuery.communityName"
  60. class="item-width-300"
  61. ></el-input>
  62. </el-form-item>
  63. </el-form>
  64. <div slot="footer" class="dialog-footer">
  65. <el-button @click="dialogFormVisible = false">取 消</el-button>
  66. <el-button type="primary" :loading="btnLoading" @click="save">确 定</el-button>
  67. </div>
  68. </el-dialog>
  69. </div>
  70. </template>
  71. <script>
  72. import { debounce } from "@/utils/index";
  73. import { getTabList,delTab,addOrUpdateTab } from "@/api/study";
  74. export default {
  75. name: "tabManage",
  76. data() {
  77. return {
  78. title:'',
  79. tableData: [],
  80. loading: false,
  81. btnLoading: false,
  82. dialogFormVisible: false,
  83. query: {
  84. currentPage: 1,
  85. pageSize: 10,
  86. },
  87. total: 0,
  88. setQuery:{
  89. communityName:''
  90. },
  91. rules:{
  92. communityName: [{ required: true, message: "请输入社区标签", trigger: "blur" }],
  93. }
  94. };
  95. },
  96. watch: {
  97. query: {
  98. handler: debounce(function (val) {
  99. this.getTabList()
  100. }),
  101. deep: true,
  102. },
  103. },
  104. methods: {
  105. handleEdit(row){
  106. this.title = '编辑标签'
  107. this.dialogFormVisible = true
  108. this.setQuery = JSON.parse(JSON.stringify(row))
  109. },
  110. handleAdd() {
  111. this.title = '添加标签'
  112. this.dialogFormVisible = true
  113. this.setQuery = {
  114. communityName:''
  115. }
  116. },
  117. // 删除
  118. handleDel(id) {
  119. this.$confirm(`此操作将删除该数据, 是否继续?`, '提示', {
  120. confirmButtonText: '确定',
  121. cancelButtonText: '取消',
  122. type: 'warning'
  123. }).then(() => {
  124. delTab({id}).then(res=>{
  125. if(res.state == 'Success'){
  126. this.$notify({
  127. title: '成功',
  128. message: '操作成功',
  129. type: 'success'
  130. });
  131. this.getTabList()
  132. }
  133. })
  134. })
  135. },
  136. handleSizeChange(val) {
  137. this.query.currentPage = 1;
  138. this.query.pageSize = val;
  139. this.getTabList();
  140. },
  141. handleCurrentChange(val) {
  142. this.query.currentPage = val;
  143. this.getTabList();
  144. },
  145. search() {
  146. this.query.currentPage = 1;
  147. this.getTabList();
  148. },
  149. getTabList() {
  150. this.loading = true
  151. getTabList(this.query).then((res) => {
  152. this.loading = false
  153. if (res.state == "Success") {
  154. this.tableData = res.content.records;
  155. this.total = res.content.total
  156. }
  157. });
  158. },
  159. save(){
  160. this.$refs.setQuery.validate((v) => {
  161. if (v) {
  162. this.btnLoading = true
  163. addOrUpdateTab(this.setQuery).then(res=>{
  164. this.btnLoading = false
  165. if(res.state == 'Success'){
  166. this.dialogFormVisible = false
  167. this.$notify({
  168. title: '成功',
  169. message: '操作成功',
  170. type: 'success'
  171. });
  172. this.query.currentPage = 1
  173. this.getTabList();
  174. }
  175. })
  176. }
  177. });
  178. }
  179. },
  180. created() {
  181. this.getTabList();
  182. },
  183. };
  184. </script>
  185. <style lang="scss" >
  186. .tabManage {
  187. }
  188. </style>