index.vue 6.6 KB

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