index.vue 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442
  1. <template>
  2. <div class="dept">
  3. <div class="tree">
  4. <treeList :data="treeListData" v-model="sourceList.pagination.tenantId" node-key="id" @change="treeChange"> </treeList>
  5. </div>
  6. <div class="content">
  7. <byTable
  8. :hideTable="true"
  9. :hidePagination="true"
  10. :config="config"
  11. :loading="loading"
  12. highlight-current-row
  13. :selectConfig="selectConfig"
  14. :table-events="{
  15. //element talbe事件都能传
  16. select: select,
  17. }"
  18. :action-list="[
  19. {
  20. text: $t('dept.addDept'),
  21. action: () => openModal('add'),
  22. disabled: !sourceList.pagination.tenantId,
  23. },
  24. ]"
  25. @get-list="getList">
  26. <template #slotName="{ item }">
  27. {{ item.createTime }}
  28. </template>
  29. </byTable>
  30. <el-table
  31. v-loading="loading"
  32. :data="sourceList.data"
  33. row-key="deptId"
  34. style="padding: 0 20px; box-sizing: border-box"
  35. :tree-props="{
  36. children: 'children',
  37. hasChildren: 'hasChildren',
  38. }">
  39. <el-table-column prop="deptName" :label="$t('dept.deptName')" width="260"></el-table-column>
  40. <el-table-column prop="orderNum" :label="$t('common.serialNumber')" width="100"></el-table-column>
  41. <el-table-column prop="type" :label="$t('dept.deptType')" width="100" :formatter="(row) => showType(row.type)"> </el-table-column>
  42. <el-table-column :label="$t('common.createTime')" align="center" prop="createTime" width="200">
  43. <template #default="scope">
  44. <span>{{ parseTime(scope.row.createTime) }}</span>
  45. </template>
  46. </el-table-column>
  47. <el-table-column :label="$t('common.operation')" align="center" class-name="small-padding fixed-width">
  48. <template #default="scope">
  49. <el-button link type="primary" @click="getDtl(scope.row)">{{$t('common.edit')}}</el-button>
  50. <el-button link type="primary" @click="handleAdd(scope.row)">{{$t('common.add')}}</el-button>
  51. <el-button v-if="scope.row.parentId != 0" link type="primary" @click="listDelete(scope.row)">{{$t('common.delete')}}</el-button>
  52. </template>
  53. </el-table-column>
  54. </el-table>
  55. </div>
  56. <el-dialog :title="modalType == 'add' ? $t('common.add') : $t('common.edit')" v-if="dialogVisible" v-model="dialogVisible" width="500" v-loading="loading">
  57. <byForm :formConfig="formConfig" :formOption="formOption" v-model="formData.data" :rules="rules" ref="byform">
  58. <template #account>
  59. <el-input style="width: 150px; margin-right: 10px" v-model="formData.data.userName" :placeholder="$t('dept.pleaseEnterTheUsername')"></el-input>
  60. <el-input style="width: 150px; margin-right: 10px" v-model="formData.data.password" :placeholder="$t('dept.pleaseEnterThePassword')"></el-input>
  61. <span style="color: #409eff; cursor: pointer" @click="newPassword">{{$t('dept.randomGeneration')}}</span>
  62. </template>
  63. </byForm>
  64. <template #footer>
  65. <el-button @click="dialogVisible = false" size="large">{{$t('common.cancel')}}</el-button>
  66. <el-button type="primary" v-no-double-click="submitForm" size="large" :loading="submitLoading">{{$t('common.confirm')}}</el-button>
  67. </template>
  68. </el-dialog>
  69. <el-dialog title="修改密码" v-model="roomDialogVisible" width="500" :before-close="handleClose" v-loading="loading">
  70. <template #footer>
  71. <el-button @click="roomDialogVisible = false" size="large">{{$t('common.cancel')}}</el-button>
  72. <el-button type="primary" @click="submitTree('byform')" size="large" :loading="submitLoading">{{$t('common.confirm')}}</el-button>
  73. </template>
  74. </el-dialog>
  75. </div>
  76. </template>
  77. <script setup>
  78. /* eslint-disable vue/no-unused-components */
  79. import { ElMessage, ElMessageBox } from "element-plus";
  80. import byTable from "@/components/byTable/index";
  81. import byForm from "@/components/byForm/index";
  82. import treeList from "@/components/treeList/index";
  83. import { computed, defineComponent, ref } from "vue";
  84. const loading = ref(false);
  85. const submitLoading = ref(false);
  86. const sourceList = ref({
  87. data: [],
  88. pagination: {
  89. total: 3,
  90. pageNum: 1,
  91. pageSize: 10,
  92. },
  93. });
  94. const { proxy } = getCurrentInstance();
  95. let dialogVisible = ref(false);
  96. let modalType = ref("add");
  97. let rules = ref({
  98. parentId: [{ required: true, message: proxy.t('dept.pleaseSelectTheParentDept'), trigger: "blur" }],
  99. orderNum: [{ required: true, message: proxy.t('dept.serialNumberCannotBeEmpty'), trigger: "blur" }],
  100. deptName: [{ required: true, message: proxy.t('dept.deptNameCannotBeEmpty'), trigger: "blur" }],
  101. type: [{ required: true, message: proxy.t('dept.deptTypeCannotBeEmpty'), trigger: "change" }],
  102. });
  103. const selectConfig = computed(() => {
  104. return [];
  105. });
  106. const config = computed(() => {
  107. return [
  108. {
  109. attrs: {
  110. label: proxy.t('dept.deptName'),
  111. prop: "deptName",
  112. },
  113. },
  114. {
  115. attrs: {
  116. label: proxy.t('dept.deptType'),
  117. prop: "type",
  118. align: "left",
  119. },
  120. render(type) {
  121. return type == 0 ? "公司" : type == 1 ? "业务中心" : type == 2 ? "部门" : "组";
  122. },
  123. },
  124. {
  125. attrs: {
  126. label: proxy.t('common.serialNumber'),
  127. prop: "nickName",
  128. },
  129. },
  130. {
  131. attrs: {
  132. label: proxy.t('common.createTime'),
  133. prop: "createTime",
  134. },
  135. },
  136. {
  137. attrs: {
  138. label: proxy.t('common.operation'),
  139. width: "200",
  140. align: "right",
  141. },
  142. // 渲染 el-button,一般用在最后一列。
  143. renderHTML(row) {
  144. return [
  145. {
  146. attrs: {
  147. label: proxy.t('common.edit'),
  148. type: "primary",
  149. text: true,
  150. },
  151. el: "button",
  152. click() {
  153. getDtl(row);
  154. },
  155. },
  156. {
  157. attrs: {
  158. label: proxy.t('common.delete'),
  159. type: "danger",
  160. text: true,
  161. },
  162. el: "button",
  163. click() {},
  164. },
  165. ];
  166. },
  167. },
  168. ];
  169. });
  170. let formData = reactive({
  171. data: {
  172. orderNum: 1,
  173. },
  174. });
  175. const formOption = reactive({
  176. inline: true,
  177. labelWidth: 100,
  178. itemWidth: 100,
  179. rules: [],
  180. });
  181. const byform = ref(null);
  182. const treeListData = ref([]);
  183. const formConfig = computed(() => {
  184. return [
  185. {
  186. type: "treeSelect",
  187. prop: "parentId",
  188. label: proxy.t('dept.parentDept'),
  189. data: [],
  190. },
  191. {
  192. type: "input",
  193. prop: "deptName",
  194. label: proxy.t('dept.deptName'),
  195. required: true,
  196. itemWidth: 50,
  197. //disabled:true,
  198. itemType: "text",
  199. },
  200. {
  201. type: "select",
  202. prop: "type",
  203. label: proxy.t('dept.deptType'),
  204. required: true,
  205. data: [
  206. {
  207. label: proxy.t('dept.company'),
  208. value: 1,
  209. },
  210. {
  211. label: proxy.t('dept.businessCenter'),
  212. value: 2,
  213. },
  214. {
  215. label: proxy.t('dept.department'),
  216. value: 3,
  217. },
  218. {
  219. label: proxy.t('dept.group'),
  220. value: 4,
  221. },
  222. ],
  223. },
  224. {
  225. type: "select",
  226. label: proxy.t('dept.deptManager'),
  227. prop: "leaderId",
  228. itemWidth: 50,
  229. clearable: true,
  230. data: [],
  231. },
  232. {
  233. type: "select",
  234. label: proxy.t('dept.deptDirector'),
  235. prop: "directorId",
  236. clearable: true,
  237. itemWidth: 50,
  238. data: [],
  239. },
  240. {
  241. type: "input",
  242. prop: "orderNum",
  243. label: proxy.t('common.serialNumber'),
  244. required: true,
  245. itemWidth: 50,
  246. //disabled:true,
  247. itemType: "number",
  248. },
  249. ];
  250. });
  251. const newPassword = () => {
  252. formData.data.password = generatePassword();
  253. };
  254. const generatePassword = () => {
  255. var length = 12,
  256. charset = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789",
  257. password = "";
  258. for (var i = 0, n = charset.length; i < length; ++i) {
  259. password += charset.charAt(Math.floor(Math.random() * n));
  260. }
  261. return password;
  262. };
  263. const getTreeList = () => {
  264. proxy.post("/tenantInfo/list").then((message) => {
  265. message.map((item) => {
  266. item.label = item.enterpriseName;
  267. item.id = item.tenantId;
  268. item.children = [];
  269. });
  270. treeListData.value = message;
  271. console.log(treeListData.value);
  272. });
  273. };
  274. const getList = async (req) => {
  275. if (req) {
  276. req.deptName = req.keyword;
  277. }
  278. sourceList.value.pagination = { ...sourceList.value.pagination, ...req };
  279. loading.value = true;
  280. proxy.get("/tenantDept/list", sourceList.value.pagination).then((message) => {
  281. recursive(message.data);
  282. sourceList.value.data = proxy.handleTree(message.data, "deptId");
  283. console.log(sourceList.value);
  284. formConfig.value[0].data = proxy.handleTree(message.data, "deptId");
  285. console.log(formConfig.value[0].data);
  286. setTimeout(() => {
  287. loading.value = false;
  288. }, 200);
  289. });
  290. };
  291. const treeChange = (e) => {
  292. sourceList.value.pagination.tenantId = e.id;
  293. getList({ tenantId: e.id });
  294. };
  295. const handleAdd = (row) => {
  296. dialogVisible.value = true;
  297. modalType.value = "add";
  298. console.log(row);
  299. formData.data = {
  300. parentId: row.deptId,
  301. tenantId: row.tenantId,
  302. };
  303. };
  304. const openModal = () => {
  305. dialogVisible.value = true;
  306. modalType.value = "add";
  307. formData.data = {
  308. orderNum: 1,
  309. };
  310. getUserList();
  311. };
  312. const TreetenantId = ref("");
  313. const selection = ref({
  314. data: [],
  315. });
  316. const select = (_selection, row) => {
  317. selection.value.data = _selection;
  318. console.log(_selection.length);
  319. };
  320. const tree = ref(null);
  321. const submitForm = () => {
  322. byform.value.handleSubmit((valid) => {
  323. const method = modalType.value == "add" ? "POST" : "PUT";
  324. console.log(method);
  325. if (!formData.data.parentId) formData.data.parentId = 0;
  326. formData.data.leaderId = formData.data.leaderId ? formData.data.leaderId : '-1';
  327. formData.data.directorId = formData.data.directorId ? formData.data.directorId : '-1';
  328. proxy
  329. .post(
  330. "/tenantDept",
  331. {
  332. ...formData.data,
  333. tenantId: formData.data.tenantId ? formData.data.tenantId : sourceList.value.pagination.tenantId,
  334. },
  335. method
  336. )
  337. .then((res) => {
  338. ElMessage({
  339. message: modalType.value == "add" ? proxy.t('common.addSuccess') : proxy.t('common.editSuccess'),
  340. type: "success",
  341. });
  342. dialogVisible.value = false;
  343. getList();
  344. });
  345. });
  346. };
  347. const recursive = (data) => {
  348. data.map((item) => {
  349. item.label = item.deptName;
  350. item.id = item.deptId;
  351. if (item.children) {
  352. recursive(item.children);
  353. } else {
  354. item.children = [];
  355. }
  356. });
  357. };
  358. const listDelete = (row) => {
  359. // 弹窗提示是否删除
  360. ElMessageBox.confirm(proxy.t('common.thisOperationWillPermanentlyDeleteTheData'),proxy.t('common.prompt'), {
  361. confirmButtonText: proxy.t('common.confirm'),
  362. cancelButtonText: proxy.t('common.cancel'),
  363. type: "warning",
  364. }).then(() => {
  365. // 删除
  366. proxy.post("/tenantDept/" + row.deptId, {}, "delete").then((res) => {
  367. ElMessage({
  368. message: proxy.t('common.deleteSuccess'),
  369. type: "success",
  370. });
  371. getList();
  372. });
  373. });
  374. };
  375. const showType = (type) => {
  376. return type == 0 ?
  377. proxy.t('dept.company') : type == 1 ?
  378. proxy.t('dept.businessCenter') : type == 2 ?
  379. proxy.t('dept.department') :
  380. proxy.t('dept.group');
  381. };
  382. const getDtl = (row) => {
  383. formData.data = { ...row };
  384. formData.data.leaderId = formData.data.leaderId == '-1' ? '' : formData.data.leaderId;
  385. formData.data.directorId = formData.data.directorId == '-1' ? '' : formData.data.directorId;
  386. sourceList.value.pagination.tenantId = row.tenantId;
  387. getUserList()
  388. modalType.value = "edit";
  389. dialogVisible.value = true;
  390. };
  391. const getUserList = () => {
  392. proxy
  393. .get("/tenantUser/list", {
  394. pageNum: 1,
  395. pageSize: 10000,
  396. tenantId: sourceList.value.pagination.tenantId,
  397. })
  398. .then((message) => {
  399. message.rows.map((item) => {
  400. item.label = item.nickName;
  401. item.id = item.userId;
  402. });
  403. formConfig.value[3].data = message.rows;
  404. formConfig.value[4].data = message.rows;
  405. });
  406. };
  407. getUserList();
  408. getTreeList();
  409. getList();
  410. </script>
  411. <style lang="scss" scoped>
  412. .dept {
  413. padding: 20px;
  414. display: flex;
  415. justify-content: space-between;
  416. .tree {
  417. width: 300px;
  418. }
  419. .content {
  420. width: calc(100% - 320px);
  421. }
  422. }
  423. </style>