inspector.vue 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218
  1. <template>
  2. <div>
  3. <div v-show="!inspectorEditState.show && !inspectorAddState.show" class="app-container">
  4. <el-row :gutter="20">
  5. <el-col :lg="4" :xs="24">
  6. <el-tree
  7. ref="deptTreeRef"
  8. class="mt-2"
  9. node-key="id"
  10. :data="deptOptions"
  11. :props="{ label: 'label', children: 'children' }"
  12. :expand-on-click-node="false"
  13. :filter-node-method="filterNode"
  14. highlight-current
  15. default-expand-all
  16. @node-click="handleNodeClick"
  17. />
  18. </el-col>
  19. <el-col :lg="20" :xs="24">
  20. <transition name="fade">
  21. <div v-show="showSearch">
  22. <el-form ref="queryFormRef" :model="queryParams">
  23. <el-row :gutter="20">
  24. <el-col :span="8">
  25. <el-form-item prop="nickName">
  26. <el-input v-model="queryParams.nickName" placeholder="请输入巡查人员" clearable />
  27. </el-form-item>
  28. </el-col>
  29. <el-col :span="8">
  30. <el-button type="primary" @click="handleQuery">搜索</el-button>
  31. <el-button @click="resetQuery">重置</el-button>
  32. </el-col>
  33. </el-row>
  34. </el-form>
  35. </div>
  36. </transition>
  37. <el-row :gutter="10">
  38. <el-col :span="1.5">
  39. <el-button type="primary" icon="Plus" @click="handleAdd()">新建</el-button>
  40. </el-col>
  41. <el-col :span="1.5">
  42. <el-button type="primary" plain icon="Top" @click="handleImport()"> 批量导入 </el-button>
  43. </el-col>
  44. <el-col :span="1.5">
  45. <el-button type="danger" plain :disabled="multiple" icon="Delete" @click="handleDelete(selectedRow)"> 删除 </el-button>
  46. </el-col>
  47. </el-row>
  48. <el-table ref="multipleTable" v-loading="loading" :data="tableData" @selection-change="handleSelectionChange">
  49. <el-table-column type="selection" width="55" align="center" />
  50. <el-table-column label="姓名" align="center" prop="nickName" />
  51. <el-table-column label="联系方式" align="center" prop="phone" />
  52. <el-table-column label="粤政易组织" align="center" prop="yzy_organization" />
  53. <el-table-column label="责任区划" align="center" prop="division_responsibility" />
  54. <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
  55. <template #default="scope">
  56. <el-text class="common-btn-text-primary" @click="handleUpdate(scope.row)">编辑</el-text>
  57. <el-text class="common-btn-text-danger" @click="handleDelete(scope.row)">删除</el-text>
  58. </template>
  59. </el-table-column>
  60. </el-table>
  61. <pagination
  62. v-show="total > 0"
  63. v-model:page="queryParams.page"
  64. v-model:limit="queryParams.pageSize"
  65. :total="total"
  66. @pagination="tableData"
  67. />
  68. </el-col>
  69. </el-row>
  70. </div>
  71. <InspectorEdit v-if="inspectorEditState.show" :event-id="inspectorEditState.eventId" @close="handleCancel" />
  72. <InspectorAdd v-if="inspectorAddState.show" @close="handleCancel" @refresh="fetchUserData" />
  73. </div>
  74. </template>
  75. <script setup lang="ts">
  76. import { onMounted, reactive, ref, watch } from 'vue';
  77. import { useRouter } from 'vue-router';
  78. import { deptList, inspectorList, inspectorDelete } from '@/api/inspectionWork/inspector';
  79. import InspectorEdit from './inspectorEdit.vue';
  80. import InspectorAdd from './inspectorAdd.vue';
  81. import { to } from 'await-to-js';
  82. const router = useRouter();
  83. const { proxy } = getCurrentInstance() as ComponentInternalInstance;
  84. const loading = ref(true);
  85. const showSearch = ref(true);
  86. const ids = ref<Array<number | string>>([]);
  87. const single = ref(true);
  88. const multiple = ref(true);
  89. const total = ref(0);
  90. const deptOptions = ref([]);
  91. const deptTreeRef = ref(null);
  92. const tableData = ref([]);
  93. const selectedRow = ref<InspectorVO | null>(null);
  94. const initFormData = reactive({
  95. nickName: '',
  96. phone: '',
  97. yzy_organization: '',
  98. division_responsibility: '',
  99. id: ''
  100. });
  101. export interface InspectorVO {
  102. phone: number;
  103. nickName: string;
  104. yzy_organization: string;
  105. division_responsibility: string;
  106. id: number;
  107. }
  108. const data = reactive({
  109. form: { ...initFormData },
  110. queryParams: {
  111. page: 1,
  112. pageSize: 10,
  113. nickName: '',
  114. deptId: ''
  115. }
  116. });
  117. const { queryParams, form } = toRefs(data);
  118. const filterNode = (value: string, data: any) => {
  119. if (!value) return true;
  120. return data.label.indexOf(value) !== -1;
  121. };
  122. const getTreeSelect = async () => {
  123. const res = await deptList();
  124. deptOptions.value = res.data; // 直接赋值给 deptOptions
  125. loading.value = false; // 加载完成后关闭加载提示
  126. };
  127. const fetchUserData = async () => {
  128. const res = await inspectorList(queryParams.value); // 调用 inspectorList 接口
  129. tableData.value = res.data.map((item) => ({
  130. id: item.id,
  131. nickName: item.nick_name,
  132. phone: item.phonenumber,
  133. yzy_organization: item.ancestors_names || '', // 如果 yzy_account 为空,则显示空字符串
  134. division_responsibility: item.area // 显示责任区划
  135. }));
  136. total.value = res.total;
  137. };
  138. // 监听查询参数变化并重新获取数据
  139. watch(queryParams, () => {
  140. fetchUserData();
  141. });
  142. let inspectorEditState = reactive({
  143. show: false,
  144. eventId: ''
  145. });
  146. let inspectorAddState = reactive({
  147. show: false
  148. });
  149. const handleCancel = () => {
  150. inspectorEditState.show = false;
  151. inspectorAddState.show = false;
  152. };
  153. const handleImport = () => {
  154. // 实现导入逻辑
  155. };
  156. const handleAdd = async () => {
  157. inspectorAddState.show = true;
  158. };
  159. const handleDelete = async (row) => {
  160. let id = [];
  161. if (row) {
  162. id = [row.id];
  163. } else {
  164. id = ids.value;
  165. }
  166. const [err] = await to(proxy?.$modal.confirm('是否确认删除选择的数据项?') as any);
  167. if (!err) {
  168. await inspectorDelete(id);
  169. proxy.$modal.msgSuccess('删除成功');
  170. fetchUserData();
  171. }
  172. };
  173. const handleUpdate = (row) => {
  174. if (row) {
  175. inspectorEditState.eventId = row.id; // 假设eventId是id字段
  176. inspectorEditState.show = true;
  177. }
  178. };
  179. const handleQuery = () => {
  180. queryParams.value.page = 1;
  181. fetchUserData();
  182. };
  183. /** 节点单击事件 */
  184. const handleNodeClick = (data: DeptVO) => {
  185. queryParams.value.deptId = data.id;
  186. handleQuery();
  187. };
  188. // 重置查询条件
  189. const resetQuery = () => {
  190. queryParams.value = { page: 1, pageSize: 10, nickName: '', deptId: '' };
  191. handleQuery();
  192. };
  193. const handleSelectionChange = (selection) => {
  194. ids.value = selection.map((item) => item.id);
  195. selectedRow.value = selection.length === 1 ? selection[0] : null;
  196. single.value = selection.length != 1;
  197. multiple.value = !selection.length;
  198. };
  199. onMounted(async () => {
  200. await getTreeSelect();
  201. fetchUserData();
  202. });
  203. </script>
  204. <style scoped>
  205. .mt-2 {
  206. max-width: 300px; /* 设置最大宽度 */
  207. max-height: 800px; /* 设置最大高度 */
  208. overflow-y: auto; /* 如果内容超出高度则显示滚动条 */
  209. }
  210. </style>