SubOrg.vue 7.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315
  1. <template>
  2. <div>
  3. <div class="tw-bg-white tw-p-5 tw-rounded-xl tw-mb-5">
  4. <RootOrgSelect v-if="store.isSuperAdmin" v-model:value="rootOrgId" />
  5. <a-input
  6. v-model:value="code"
  7. style="width: 178px"
  8. placeholder="机构代码"
  9. allowClear
  10. ></a-input>
  11. <span class="tw-mr-4"></span>
  12. <a-input
  13. v-model:value="name"
  14. class="tw-mr-4"
  15. style="width: 178px"
  16. placeholder="机构名称"
  17. allowClear
  18. ></a-input>
  19. <span class="tw-mr-4"></span>
  20. <StateSelect v-model:value="enable" />
  21. <span class="tw-mr-4"></span>
  22. <a-button @click="search">查询</a-button>
  23. <div class="tw-mt-4">
  24. <a-button @click="newOrg">新增</a-button>
  25. <a-button @click="importModalVisible = true">批量导入</a-button>
  26. <a-button @click="handleExport">批量导出</a-button>
  27. <a-button @click="handleToggleOrg(true, selectIds)">批量启用</a-button>
  28. <a-button @click="handleToggleOrg(false, selectIds)">批量禁用</a-button>
  29. <a-button @click="handleDelOrg(selectIds)">批量删除</a-button>
  30. </div>
  31. </div>
  32. <div class="tw-bg-white tw-p-5 tw-rounded-xl">
  33. <a-table
  34. row-key="id"
  35. :columns="columns"
  36. :data-source="data"
  37. :row-selection="rowSelection"
  38. :pagination="{
  39. pageSize: pageSize,
  40. current: pageNo,
  41. total: totalElements,
  42. showTotal: (total: number) => `总数:${total}`,
  43. onChange: (pageNoChanged: number, pageSizeChanged: number) => {
  44. pageNo = pageNoChanged;
  45. pageSize = pageSizeChanged;
  46. }
  47. }"
  48. >
  49. <template #enable="{ text }">
  50. <a>{{ $filters.booleanEnableDisableFilter(text) }}</a>
  51. </template>
  52. <template #action="{ record }">
  53. <span>
  54. <a-button @click="showModal(record)">编辑</a-button>
  55. <a-button @click="handleToggleOrg(!record.enable, [record.id])">{{
  56. record.enable ? "禁用" : "启用"
  57. }}</a-button>
  58. <a-button @click="handleDelOrg([record.id])">删除</a-button>
  59. </span>
  60. </template>
  61. </a-table>
  62. </div>
  63. <a-modal
  64. v-model:visible="visible"
  65. title="机构信息页"
  66. @ok="handleOk"
  67. ok-text="确定"
  68. cancel-text="取消"
  69. >
  70. <a-form>
  71. <a-form-item v-show="store.isSuperAdmin" label="顶级机构">
  72. <RootOrgSelect
  73. :disabled="!!orgObj.id"
  74. v-model:value="orgObj.rootOrgId"
  75. />
  76. </a-form-item>
  77. <a-form-item label="机构名称">
  78. <a-input v-model:value="orgObj.name"></a-input>
  79. </a-form-item>
  80. <a-form-item label="机构编码">
  81. <a-input
  82. :disabled="!!orgObj.id"
  83. v-model:value="orgObj.code"
  84. ></a-input>
  85. </a-form-item>
  86. <a-form-item label="状态">
  87. <a-radio-group v-model:value="orgObj.enable">
  88. <a-radio :value="true">启用</a-radio>
  89. <a-radio :value="false">禁用</a-radio>
  90. </a-radio-group>
  91. </a-form-item>
  92. </a-form>
  93. </a-modal>
  94. <a-modal
  95. v-model:visible="importModalVisible"
  96. title="批量机构导入"
  97. @ok="handleImport"
  98. ok-text="确定"
  99. cancel-text="取消"
  100. >
  101. <a-form>
  102. <a-form-item label="顶级机构">
  103. <RootOrgSelect
  104. v-show="store.isSuperAdmin"
  105. :disabled="!!orgObj.id"
  106. v-model:value="orgObj.rootOrgId"
  107. />
  108. </a-form-item>
  109. <a-form-item label="文件地址">
  110. <input id="file-input" :multiple="false" type="file" />
  111. </a-form-item>
  112. <a-form-item label="下载模板">
  113. <a-button @click="downloadTpl">下载模板</a-button>
  114. </a-form-item>
  115. </a-form>
  116. </a-modal>
  117. </div>
  118. </template>
  119. <script setup lang="ts">
  120. import {
  121. delOrgs,
  122. exportOrgs,
  123. getSubOrgList,
  124. importOrgs,
  125. toggleSubOrgs,
  126. updateSubOrg,
  127. } from "@/api/subOrgPage";
  128. import { useMainStore } from "@/store";
  129. import { downloadFileURL } from "@/utils/utils";
  130. import { message, Modal } from "ant-design-vue";
  131. import { watch, onMounted, ref, reactive, toRaw } from "vue-demi";
  132. const store = useMainStore();
  133. store.currentLocation = "基础管理 / 机构管理";
  134. let rootOrgId = $ref(undefined as unknown as number);
  135. let code = $ref("");
  136. let name = $ref("");
  137. let enable = $ref(undefined as undefined | boolean);
  138. let data = $ref([]);
  139. let pageSize = $ref(10);
  140. let pageNo = $ref(1);
  141. let totalElements = $ref(0);
  142. async function search() {
  143. await fetchData();
  144. }
  145. watch(() => [pageNo, pageSize], fetchData);
  146. async function fetchData() {
  147. const res = await getSubOrgList({
  148. code,
  149. name,
  150. enable,
  151. rootOrgId,
  152. pageSize,
  153. pageNo,
  154. });
  155. // console.log(res);
  156. data = res.data.content;
  157. pageNo = res.data.pageNo;
  158. pageSize = res.data.pageSize;
  159. totalElements = res.data.totalElements;
  160. }
  161. const columns = [
  162. {
  163. title: "顶级机构名称",
  164. dataIndex: "rootOrgName",
  165. width: 150,
  166. },
  167. {
  168. title: "机构代码",
  169. dataIndex: "code",
  170. width: 150,
  171. },
  172. {
  173. title: "机构名称",
  174. dataIndex: "name",
  175. width: 150,
  176. },
  177. {
  178. title: "状态",
  179. dataIndex: "enable",
  180. slots: { customRender: "enable" },
  181. },
  182. {
  183. title: "创建时间",
  184. dataIndex: "createTime",
  185. },
  186. {
  187. title: "创建人",
  188. dataIndex: "creator",
  189. },
  190. {
  191. title: "更新时间",
  192. dataIndex: "updateTime",
  193. },
  194. {
  195. title: "更新人",
  196. dataIndex: "updater",
  197. },
  198. {
  199. title: "Action",
  200. key: "action",
  201. slots: { customRender: "action" },
  202. },
  203. ];
  204. onMounted(async () => {
  205. rootOrgId = store.userInfo.rootOrgId;
  206. await search();
  207. });
  208. const visible = ref<boolean>(false);
  209. const showModal = (record: any) => {
  210. Object.assign(orgObj, record);
  211. visible.value = true;
  212. };
  213. const handleOk = async (e: MouseEvent) => {
  214. await updateSubOrg(toRaw(orgObj));
  215. visible.value = false;
  216. await search();
  217. };
  218. const orgObj = reactive({
  219. id: undefined,
  220. code: "",
  221. name: "",
  222. enable: true,
  223. rootOrgId: store.userInfo.rootOrgId,
  224. });
  225. const newOrg = async () => {
  226. Object.assign(orgObj, {
  227. id: undefined,
  228. code: "",
  229. name: "",
  230. enable: true,
  231. rootOrgId,
  232. });
  233. showModal(orgObj);
  234. };
  235. function checkEmpty(): boolean {
  236. if (selectIds && selectIds.length > 0) {
  237. return false;
  238. } else {
  239. message.warn({ content: "请先选择行" });
  240. return true;
  241. }
  242. }
  243. async function handleToggleOrg(enable: boolean, ids: number[]) {
  244. if (checkEmpty()) return;
  245. await toggleSubOrgs(enable, ids);
  246. await search();
  247. }
  248. async function handleDelOrg(ids: number[]) {
  249. if (checkEmpty()) return;
  250. Modal.confirm({
  251. title: "提示",
  252. content: "确认删除?",
  253. cancelText: "取消",
  254. okText: "确定",
  255. onOk: async () => {
  256. await delOrgs(ids);
  257. await search();
  258. },
  259. });
  260. }
  261. /** <handleImport> */
  262. let importModalVisible = ref<boolean>(false);
  263. async function handleImport() {
  264. const files = (document.querySelector("#file-input") as HTMLInputElement)
  265. .files;
  266. const fileToImport = files && files[0];
  267. if (!fileToImport) {
  268. message.warn({ content: "请选择文件" });
  269. return;
  270. }
  271. await importOrgs(rootOrgId, fileToImport);
  272. message.success({ content: "导入成功" });
  273. }
  274. /** </handleImport> */
  275. async function handleExport() {
  276. await exportOrgs({ rootOrgId, name, code, enable });
  277. message.success({ content: "导出成功" });
  278. }
  279. let selectIds = $ref<number[]>([]);
  280. const rowSelection = {
  281. onChange: (selectedRowKeys: (string | number)[]) => {
  282. console.log(`selectedRowKeys: ${selectedRowKeys}`);
  283. selectIds = selectedRowKeys as number[];
  284. },
  285. };
  286. async function downloadTpl() {
  287. downloadFileURL("/api/ess/org/template");
  288. }
  289. </script>