category.vue 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142
  1. <template>
  2. <div>
  3. <el-card shadow="never">
  4. <div>
  5. <el-button type="primary" @click="handleCreate">新建需求类别</el-button>
  6. <!-- <el-button type="primary" @click="handleUpdateServiceProvider"
  7. >服务商设置</el-button
  8. > -->
  9. </div>
  10. </el-card>
  11. <el-card shadow="never" class="mt-4">
  12. <div>
  13. <el-table :data="state.tableData" style="width: 100%">
  14. <el-table-column prop="name" label="类别名称"> </el-table-column>
  15. <el-table-column prop="name" label="是否启用">
  16. <template #default="{ row }">
  17. <el-switch
  18. v-model="row.status"
  19. :active-value="1"
  20. :inactive-value="0"
  21. @change="onChangeStatus(row)"
  22. >
  23. </el-switch>
  24. </template>
  25. </el-table-column>
  26. <el-table-column prop="sort" label="排序(数字越大越排在前)">
  27. <template #default="{ row }">
  28. <el-input
  29. v-model.number="row.sort"
  30. type="number"
  31. @blur="updateSort(row)"
  32. ></el-input>
  33. </template>
  34. </el-table-column>
  35. <el-table-column prop="" label="操作">
  36. <template #default="{ row }">
  37. <el-button type="primary" link @click="handleEdit(row)"
  38. >编辑</el-button
  39. >
  40. </template>
  41. </el-table-column>
  42. </el-table>
  43. <el-pagination
  44. class="mt-4 justify-end"
  45. background
  46. layout="prev, pager, next"
  47. :total="state.pagination.total"
  48. @current-change="changePage"
  49. />
  50. </div>
  51. </el-card>
  52. <ComponentUpdateCategory
  53. v-model:show="state.visible"
  54. :rowData="state.rowData"
  55. @success="getTableData"
  56. ></ComponentUpdateCategory>
  57. <ComponentDialogService
  58. v-model:show="state.visibleServiceProvider"
  59. ></ComponentDialogService>
  60. </div>
  61. </template>
  62. <script lang="ts" setup>
  63. import { request } from "@/utils";
  64. import { ElMessage, ElMessageBox } from "element-plus";
  65. import { ref, reactive } from "vue";
  66. import ComponentUpdateCategory from "./components/UpdateCategory.vue";
  67. import ComponentDialogService from "./components/DialogService.vue";
  68. const state = reactive({
  69. query: {
  70. page: 1,
  71. pageSize: 15
  72. },
  73. pagination: {
  74. total: 0
  75. },
  76. tableData: [],
  77. visible: false,
  78. rowData: {},
  79. visibleServiceProvider: false // 服务商设置
  80. });
  81. const init = () => {
  82. getTableData();
  83. };
  84. const getTableData = () => {
  85. request
  86. .get("/articleService/demand/category/paginate", {
  87. params: state.query
  88. })
  89. .then(resp => {
  90. console.log("获取的需求", resp);
  91. state.tableData = resp?.data.list;
  92. state.pagination.total = resp.data.total;
  93. });
  94. };
  95. const updateSort = async row => {
  96. let resp = await request.post("/articleService/demand/category/sort", {
  97. id: row.id,
  98. sort: row.sort
  99. });
  100. ElMessage.success(resp.message);
  101. getTableData();
  102. };
  103. const onChangeStatus = row => {
  104. ElMessageBox.confirm(
  105. row.status ? "确定要启用此类别吗?" : "确定要关闭此类别吗?",
  106. "",
  107. {
  108. distinguishCancelAndClose: true,
  109. confirmButtonText: "确定",
  110. cancelButtonText: "取消"
  111. }
  112. )
  113. .then(async () => {
  114. await request.post("/articleService/demand/category/status", row);
  115. ElMessage.success("操作成功");
  116. getTableData();
  117. })
  118. .catch(err => {
  119. row.status = row.status ? 0 : 1;
  120. });
  121. };
  122. const handleCreate = () => {
  123. state.visible = true;
  124. state.rowData = {};
  125. console.log("state.rowData", state.rowData);
  126. };
  127. const handleUpdateServiceProvider = () => {
  128. state.visibleServiceProvider = true;
  129. };
  130. const handleEdit = row => {
  131. state.visible = true;
  132. state.rowData = row;
  133. };
  134. const changePage = page => {
  135. state.query.page = page;
  136. getTableData();
  137. };
  138. init();
  139. </script>