index.vue 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439
  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" @click="submitForm('byform')" 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: 0,
  209. },
  210. {
  211. label: proxy.t('dept.businessCenter'),
  212. value: 1,
  213. },
  214. {
  215. label: proxy.t('dept.department'),
  216. value: 2,
  217. },
  218. {
  219. label: proxy.t('dept.group'),
  220. value: 3,
  221. },
  222. ],
  223. },
  224. {
  225. type: "select",
  226. label: proxy.t('dept.deptManager'),
  227. prop: "leaderId",
  228. itemWidth: 50,
  229. data: [],
  230. },
  231. {
  232. type: "select",
  233. label: proxy.t('dept.deptDirector'),
  234. prop: "directorId",
  235. itemWidth: 50,
  236. data: [],
  237. },
  238. {
  239. type: "input",
  240. prop: "orderNum",
  241. label: proxy.t('common.serialNumber'),
  242. required: true,
  243. itemWidth: 50,
  244. //disabled:true,
  245. itemType: "number",
  246. },
  247. ];
  248. });
  249. const newPassword = () => {
  250. formData.data.password = generatePassword();
  251. };
  252. const generatePassword = () => {
  253. var length = 12,
  254. charset = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789",
  255. password = "";
  256. for (var i = 0, n = charset.length; i < length; ++i) {
  257. password += charset.charAt(Math.floor(Math.random() * n));
  258. }
  259. return password;
  260. };
  261. const getTreeList = () => {
  262. proxy.post("/tenantInfo/list").then((message) => {
  263. message.map((item) => {
  264. item.label = item.enterpriseName;
  265. item.id = item.tenantId;
  266. item.children = [];
  267. });
  268. treeListData.value = message;
  269. console.log(treeListData.value);
  270. });
  271. };
  272. const getList = async (req) => {
  273. if (req) {
  274. req.deptName = req.keyword;
  275. }
  276. sourceList.value.pagination = { ...sourceList.value.pagination, ...req };
  277. loading.value = true;
  278. proxy.get("/tenantDept/list", sourceList.value.pagination).then((message) => {
  279. recursive(message.data);
  280. sourceList.value.data = proxy.handleTree(message.data, "deptId");
  281. console.log(sourceList.value);
  282. formConfig.value[0].data = proxy.handleTree(message.data, "deptId");
  283. console.log(formConfig.value[0].data);
  284. setTimeout(() => {
  285. loading.value = false;
  286. }, 200);
  287. });
  288. };
  289. const treeChange = (e) => {
  290. sourceList.value.pagination.tenantId = e.id;
  291. getList({ tenantId: e.id });
  292. };
  293. const handleAdd = (row) => {
  294. dialogVisible.value = true;
  295. modalType.value = "add";
  296. console.log(row);
  297. formData.data = {
  298. parentId: row.deptId,
  299. tenantId: row.tenantId,
  300. };
  301. };
  302. const openModal = () => {
  303. dialogVisible.value = true;
  304. modalType.value = "add";
  305. formData.data = {
  306. orderNum: 1,
  307. };
  308. getUserList();
  309. };
  310. const TreetenantId = ref("");
  311. const selection = ref({
  312. data: [],
  313. });
  314. const select = (_selection, row) => {
  315. selection.value.data = _selection;
  316. console.log(_selection.length);
  317. };
  318. const tree = ref(null);
  319. const submitForm = () => {
  320. byform.value.handleSubmit((valid) => {
  321. const method = modalType.value == "add" ? "POST" : "PUT";
  322. console.log(method);
  323. if (!formData.data.parentId) formData.data.parentId = 0;
  324. proxy
  325. .post(
  326. "/tenantDept",
  327. {
  328. ...formData.data,
  329. tenantId: formData.data.tenantId ? formData.data.tenantId : sourceList.value.pagination.tenantId,
  330. },
  331. method
  332. )
  333. .then((res) => {
  334. ElMessage({
  335. message: modalType.value == "add" ? proxy.t('common.addSuccess') : proxy.t('common.editSuccess'),
  336. type: "success",
  337. });
  338. dialogVisible.value = false;
  339. getList();
  340. });
  341. });
  342. };
  343. const recursive = (data) => {
  344. data.map((item) => {
  345. item.label = item.deptName;
  346. item.id = item.deptId;
  347. if (item.children) {
  348. recursive(item.children);
  349. } else {
  350. item.children = [];
  351. }
  352. });
  353. };
  354. const listDelete = (row) => {
  355. // 弹窗提示是否删除
  356. ElMessageBox.confirm(proxy.t('common.thisOperationWillPermanentlyDeleteTheData'),proxy.t('common.prompt'), {
  357. confirmButtonText: proxy.t('common.confirm'),
  358. cancelButtonText: proxy.t('common.cancel'),
  359. type: "warning",
  360. }).then(() => {
  361. // 删除
  362. proxy.post("/tenantDept/" + row.deptId, {}, "delete").then((res) => {
  363. ElMessage({
  364. message: proxy.t('common.deleteSuccess'),
  365. type: "success",
  366. });
  367. getList();
  368. });
  369. });
  370. };
  371. const showType = (type) => {
  372. return type == 0 ?
  373. proxy.t('dept.company') : type == 1 ?
  374. proxy.t('dept.businessCenter') : type == 2 ?
  375. proxy.t('dept.department') :
  376. proxy.t('dept.group');
  377. };
  378. const getDtl = (row) => {
  379. formData.data = { ...row };
  380. sourceList.value.pagination.tenantId = row.tenantId;
  381. getUserList()
  382. modalType.value = "edit";
  383. dialogVisible.value = true;
  384. };
  385. const getUserList = () => {
  386. proxy
  387. .get("/tenantUser/list", {
  388. pageNum: 1,
  389. pageSize: 10000,
  390. tenantId: sourceList.value.pagination.tenantId,
  391. })
  392. .then((message) => {
  393. message.rows.map((item) => {
  394. item.label = item.nickName;
  395. item.id = item.userId;
  396. });
  397. message.rows.unshift({
  398. label:'无',
  399. id:'',
  400. })
  401. formConfig.value[3].data = message.rows;
  402. formConfig.value[4].data = message.rows;
  403. });
  404. };
  405. getUserList();
  406. getTreeList();
  407. getList();
  408. </script>
  409. <style lang="scss" scoped>
  410. .dept {
  411. padding: 20px;
  412. display: flex;
  413. justify-content: space-between;
  414. .tree {
  415. width: 300px;
  416. }
  417. .content {
  418. width: calc(100% - 320px);
  419. }
  420. }
  421. </style>