index.vue 8.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259
  1. <template>
  2. <div class="auxiliary-external-citizen-container layout-padding">
  3. <div class="layout-padding-auto layout-padding-view pd20">
  4. <el-form :model="state.queryParams" ref="ruleFormRef" inline @submit.native.prevent>
  5. <el-form-item label="市民姓名" prop="Name">
  6. <el-input v-model="state.queryParams.Name" placeholder="请填写市民姓名" clearable @keyup.enter="handleQuery" class="keyword-input" />
  7. </el-form-item>
  8. <el-form-item label="联系电话" prop="PhoneNum">
  9. <el-input
  10. v-model="state.queryParams.PhoneNum"
  11. placeholder="请填写市民联系电话"
  12. clearable
  13. @keyup.enter="handleQuery"
  14. class="keyword-input"
  15. />
  16. </el-form-item>
  17. <el-form-item>
  18. <el-button type="primary" @click="handleQuery" :loading="state.loading"> <SvgIcon name="ele-Search" class="mr5" />查询 </el-button>
  19. <el-button @click="resetQuery(ruleFormRef)" class="default-button" :loading="state.loading"> <SvgIcon name="ele-Refresh" class="mr5" />重置 </el-button>
  20. </el-form-item>
  21. </el-form>
  22. <vxe-toolbar
  23. ref="toolbarRef"
  24. :loading="state.loading"
  25. custom
  26. :refresh="{
  27. queryMethod: handleQuery
  28. }"
  29. >
  30. <template #buttons>
  31. <el-upload
  32. v-model:file-list="fileList"
  33. action="#"
  34. :multiple="false"
  35. ref="uploadListRef"
  36. name="file"
  37. :http-request="onImport"
  38. :show-file-list="false"
  39. class="upload-demo"
  40. :disabled="state.loading"
  41. >
  42. <el-button type="primary" v-auth="'auxiliary:externalCitizen:import'" :loading="state.loading"> <SvgIcon name="ele-Upload" class="mr5" /> 导入市民 </el-button>
  43. </el-upload>
  44. <el-button type="primary" @click="onDownload" v-auth="'auxiliary:externalCitizen:download'" :loading="state.loading">
  45. <SvgIcon name="ele-Download" class="mr5" /> 模板下载
  46. </el-button>
  47. <el-button type="danger" @click="onDelete" :disabled="isChecked" :loading="state.loading" v-auth="'auxiliary:externalCitizen:delete'"
  48. ><SvgIcon name="ele-Delete" class="mr5" />删除
  49. </el-button>
  50. </template>
  51. </vxe-toolbar>
  52. <div style="overflow: hidden; width: 100%; height: 100%; flex: 1">
  53. <vxe-table
  54. border
  55. :loading="state.loading"
  56. :data="state.tableData"
  57. :column-config="{ resizable: true }"
  58. :row-config="{ isCurrent: true, isHover: true, height: 30,useKey: true }"
  59. ref="tableRef"
  60. @checkbox-all="selectAllChangeEvent"
  61. @checkbox-change="selectChangeEvent"
  62. height="auto"
  63. auto-resize
  64. show-overflow
  65. :scrollY="{ enabled: true, gt: 20, mode: 'wheel' }"
  66. id="auxiliaryExternalCitizen"
  67. :custom-config="{ storage: true }"
  68. showHeaderOverflow
  69. >
  70. <vxe-column type="checkbox" width="50" align="center"></vxe-column>
  71. <vxe-column field="name" title="市民姓名" ></vxe-column>
  72. <vxe-column field="phoneNum" title="联系电话"></vxe-column>
  73. <vxe-column field="creationTime" title="创建时间" width="160">
  74. <template #default="{ row }">
  75. {{ formatDate(row.creationTime, 'YYYY-mm-dd HH:MM:SS') }}
  76. </template>
  77. </vxe-column>
  78. <vxe-column title="操作" fixed="right" width="90" align="center">
  79. <template #default="{ row }">
  80. <el-button link type="primary" @click="onEdit(row)" title="编辑市民信息" v-auth="'auxiliary:externalCitizen:edit'"> 修改 </el-button>
  81. </template>
  82. </vxe-column>
  83. </vxe-table>
  84. </div>
  85. <pagination
  86. @pagination="queryList"
  87. :total="state.total"
  88. v-model:current-page="state.queryParams.PageIndex"
  89. v-model:page-size="state.queryParams.PageSize"
  90. :disabled="state.loading"
  91. />
  92. </div>
  93. <!-- 编辑 -->
  94. <edit-info ref="editInfoRef" @updateList="queryList" />
  95. </div>
  96. </template>
  97. <script lang="tsx" setup name="auxiliaryExternalCitizen">
  98. import { computed, defineAsyncComponent, onMounted, reactive, ref } from 'vue';
  99. import { ElMessage, ElMessageBox, ElNotification, FormInstance } from 'element-plus';
  100. import { externalCitizenDelete, externalCitizenImport, externalCitizenList, externalCitizenTemplate } from '@/api/auxiliary/externalCitizen';
  101. import { downloadFileByStream } from '@/utils/tools';
  102. import { formatDate } from '@/utils/formatTime';
  103. // 引入组件
  104. const EditInfo = defineAsyncComponent(() => import('@/views/auxiliary/externalCitizen/components/Edit.vue')); // 标签编辑
  105. const pagination = defineAsyncComponent(() => import('@/components/ProTable/components/Pagination.vue')); // 分页
  106. // 定义变量内容
  107. const state = reactive({
  108. loading: false, // 加载状态
  109. queryParams: {
  110. // 查询参数
  111. PageIndex: 1,
  112. PageSize: 2,
  113. PhoneNum: null,
  114. Name: null,
  115. },
  116. total: 0, // 总条数
  117. tableData: [], // 表格数据
  118. });
  119. const ruleFormRef = ref<RefType>(null); // 表单ref
  120. /** 搜索按钮操作 */
  121. const handleQuery = () => {
  122. state.queryParams.PageIndex = 1;
  123. queryList();
  124. };
  125. // 获取列表
  126. const queryList = () => {
  127. state.loading = true;
  128. externalCitizenList(state.queryParams)
  129. .then((res) => {
  130. state.loading = false;
  131. state.tableData = res.result.items ?? [];
  132. state.total = res.result.total ?? 0;
  133. tableRef.value.clearCheckboxRow();
  134. checkTable.value = [];
  135. })
  136. .finally(() => {
  137. state.loading = false;
  138. tableRef.value.clearCheckboxRow();
  139. checkTable.value = [];
  140. });
  141. };
  142. // 重置表单
  143. const resetQuery = (formEl: FormInstance | undefined) => {
  144. if (!formEl) return;
  145. formEl.resetFields();
  146. queryList();
  147. };
  148. // 导入
  149. const fileList = ref<EmptyArrayType>([]);
  150. const uploadListRef = ref<RefType>(); // 上传组件ref
  151. const onImport = async (file: any) => {
  152. state.loading = true;
  153. let fileObj = file.file; // 相当于input里取得的files
  154. let fd = new FormData(); // FormData 对象
  155. fd.append('file', fileObj); // 文件对象
  156. try {
  157. const { result } = await externalCitizenImport(fd);
  158. ElNotification({
  159. title: '导入完成',
  160. message: `总条数:${result.count}条,新增:${result.addCount}条,失败:${result.errorCount}条`,
  161. type: 'success',
  162. })
  163. queryList();
  164. state.loading = false;
  165. } catch (e) {
  166. console.log(e);
  167. state.loading = false;
  168. }
  169. };
  170. // 模板下载
  171. const onDownload = () => {
  172. ElMessageBox.confirm(`您确定下载外部市民导入模板,是否继续?`, '提示', {
  173. confirmButtonText: '确认',
  174. cancelButtonText: '取消',
  175. type: 'warning',
  176. draggable: true,
  177. cancelButtonClass: 'default-button',
  178. autofocus: false,
  179. })
  180. .then(() => {
  181. state.loading = true;
  182. externalCitizenTemplate()
  183. .then((res: any) => {
  184. state.loading = false;
  185. downloadFileByStream(res);
  186. })
  187. .catch(() => {
  188. state.loading = false;
  189. });
  190. })
  191. .catch(() => {});
  192. };
  193. // 删除
  194. const onDelete = () => {
  195. const ids = checkTable.value.map((item: any) => item.id);
  196. ElMessageBox.confirm(`您确定删除选中的外部市民,是否继续?`, '提示', {
  197. confirmButtonText: '确认',
  198. cancelButtonText: '取消',
  199. type: 'warning',
  200. draggable: true,
  201. cancelButtonClass: 'default-button',
  202. autofocus: false,
  203. })
  204. .then(() => {
  205. state.loading = true;
  206. externalCitizenDelete(ids).then(()=>{
  207. ElMessage.success('删除成功');
  208. queryList();
  209. }).catch(()=>{
  210. state.loading = false;
  211. })
  212. }).catch(() => {
  213. state.loading = false;
  214. });
  215. }
  216. // 修改
  217. const editInfoRef = ref<RefType>();
  218. const onEdit = (row: any) => {
  219. editInfoRef.value.openDialog(row);
  220. };
  221. const tableRef = ref<RefType>();
  222. const checkTable = ref<EmptyArrayType>([]);
  223. const selectAllChangeEvent = ({ checked }) => {
  224. if (tableRef.value) {
  225. const records = tableRef.value.getCheckboxRecords();
  226. checkTable.value = records;
  227. console.log(checked ? '所有勾选事件' : '所有取消事件', records);
  228. }
  229. };
  230. const selectChangeEvent = ({ checked }) => {
  231. if (tableRef.value) {
  232. const records = tableRef.value.getCheckboxRecords();
  233. checkTable.value = records;
  234. console.log(checked ? '勾选事件' : '取消事件', records);
  235. }
  236. };
  237. const isChecked = computed(() => {
  238. return !Boolean(checkTable.value.length);
  239. });
  240. const toolbarRef = ref<RefType>();
  241. // 页面加载时
  242. onMounted(() => {
  243. queryList();
  244. if (tableRef.value && toolbarRef.value) {
  245. tableRef.value.connect(toolbarRef.value);
  246. }
  247. });
  248. </script>
  249. <style scoped lang="scss">
  250. .upload-demo {
  251. display: inline-flex;
  252. vertical-align: middle;
  253. margin-right: 12px;
  254. }
  255. </style>