OrganizationEditPanel.vue 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517
  1. <template>
  2. <header>
  3. <h3 style="margin: 0px; padding: 5px 0px 9px 0px">
  4. {{ $t("lang.OrganizationEditPanel.departmentManagement") }}
  5. </h3>
  6. <a-divider style="margin: 0px" />
  7. </header>
  8. <div style="margin-top: 8px">
  9. <a-button type="primary" @click="editOrganization(true)">
  10. {{ $t("lang.OrganizationEditPanel.newDepartment") }}
  11. </a-button>
  12. <a-button type="dashed" style="margin-left: 8px" @click="getOrganization">
  13. {{ $t("lang.OrganizationEditPanel.refresh") }}
  14. </a-button>
  15. <a-select
  16. v-model:value="clientIdStr"
  17. show-search
  18. option-filter-prop="label"
  19. style="width: 50%; margin-left: 16px"
  20. placeholder="请选择公司"
  21. :options="companies.map((item) => ({ value: item.id, label: item.name }))"
  22. @change="getClientId"
  23. />
  24. </div>
  25. <a-table
  26. style="margin-top: 6px"
  27. :columns="columns"
  28. :data-source="dataSource"
  29. :pagination="false"
  30. :scroll="{ y: 440 }"
  31. filter-search
  32. >
  33. <template #bodyCell="{ column, record }">
  34. <template v-if="column.dataIndex === 'operation'">
  35. <div class="editable-row-operations">
  36. <span>
  37. <a @click="editOrganization(false, record.key)">{{
  38. $t("lang.OrganizationEditPanel.edit")
  39. }}</a>
  40. </span>
  41. <span>
  42. <a-popconfirm
  43. title="确定删除吗!"
  44. ok-text="确定"
  45. cancel-text="取消"
  46. @confirm="deleteOrganization(record.key)"
  47. >
  48. <a style="color: red">删除</a>
  49. </a-popconfirm>
  50. </span>
  51. </div>
  52. </template>
  53. </template>
  54. </a-table>
  55. <a-drawer
  56. v-model:visible="editVisible"
  57. :title="drawerTitle"
  58. :width="500"
  59. placement="right"
  60. >
  61. <div class="form-group">
  62. <label>{{ $t("lang.OrganizationEditPanel.corporateName") }}</label>
  63. <!-- v-if="organization.id" -->
  64. <a-input v-model:value="organization.clientName" disabled />
  65. <!-- <SearchWidget
  66. v-else
  67. info-window-no="286633"
  68. :field-value="clientFieldValue"
  69. :title-name="$t('lang.OrganizationEditPanel.departmentInquiry')"
  70. display-name="ct.name"
  71. :where-clause-source="clientAdditionHql"
  72. @value-changed="clientValueChanged"
  73. /> -->
  74. </div>
  75. <div class="form-group">
  76. <label>{{ $t("lang.OrganizationEditPanel.departmentNumber") }}</label>
  77. <a-input v-model:value="organization.no" />
  78. </div>
  79. <div class="form-group">
  80. <label>{{ $t("lang.OrganizationEditPanel.departmentName") }}</label>
  81. <a-input v-model:value="organization.name" />
  82. </div>
  83. <div class="form-group">
  84. <label>{{ $t("lang.OrganizationEditPanel.superiorDepartment") }}</label>
  85. <SearchWidget
  86. info-window-no="20220420_233656"
  87. :field-value="parentOrganizationFieldValue"
  88. :title-name="$t('lang.OrganizationEditPanel.departmentInquiry')"
  89. display-name="name"
  90. :where-clause-source="parentOrganizationAdditionHql"
  91. @value-changed="parentOrganizationValueChanged"
  92. />
  93. </div>
  94. <div class="form-group">
  95. <label>{{ $t("lang.OrganizationEditPanel.departmentProfile") }}</label>
  96. <textarea
  97. v-model="organization.description"
  98. class="form-control"
  99. rows="3"
  100. />
  101. </div>
  102. <div class="form-group">
  103. <label>{{ $t("lang.OrganizationEditPanel.departmentManager") }}</label>
  104. <div>
  105. <v-select
  106. id="departmentManagerSelect"
  107. v-model="organization.managerUsers"
  108. multiple
  109. label="name"
  110. :options="userList"
  111. @search="fetchUserList"
  112. />
  113. </div>
  114. </div>
  115. <template #footer>
  116. <a-button v-if="isCreate" type="primary" @click="createNew(organization)">
  117. 创建
  118. </a-button>
  119. <a-button
  120. v-else
  121. type="primary"
  122. @click="updateOrganization(organization.id)"
  123. >
  124. {{ $t("lang.OrganizationEditPanel.save") }}
  125. </a-button>
  126. </template>
  127. </a-drawer>
  128. </template>
  129. <script setup>
  130. import vSelect from 'vue-select';
  131. import 'vue-select/dist/vue-select.css';
  132. import Common from '../common/Common.js';
  133. import { Notify } from 'pc-component-v3';
  134. import { ref, onMounted, getCurrentInstance } from 'vue';
  135. import {
  136. columns,
  137. create,
  138. update,
  139. getCompony,
  140. getUsersByName,
  141. loadOrganization,
  142. deleteDepartment,
  143. getAllOrganization,
  144. } from '../api/department/index';
  145. import { message } from 'ant-design-vue';
  146. const clientId = ref(''); //公司id
  147. const id = ref(''); //公司id
  148. const companies = ref([]); //所有公司
  149. const clientIdStr = ref(undefined);
  150. const userList = ref([]); // 用户清单
  151. const isCreate = ref(false); // 是否新建
  152. const dataSource = ref([]); // 表格部门
  153. const drawerTitle = ref(''); //抽屉标题
  154. const organization = ref({}); // 部门详情
  155. const editVisible = ref(false); // 抽屉开关
  156. const organizationId = ref(''); // 所选部门ID
  157. // const clientAdditionHql = ref({});
  158. const clientNameStr = ref('');
  159. const { proxy } = getCurrentInstance(); //访问this
  160. const parentOrganizationAdditionHql = ref('');
  161. const parentOrganizationFieldValue = ref({
  162. displayValue: [],
  163. fieldType: 'Key',
  164. id: null,
  165. });
  166. const clientFieldValue = ref({
  167. displayValue: [],
  168. fieldType: 'Key',
  169. id: null,
  170. });
  171. onMounted(() => {
  172. getCompony().then(
  173. success => {
  174. if (success.errorCode == 0) {
  175. companies.value = success.datas;
  176. } else {
  177. message.error(success.errorMessage);
  178. }
  179. },
  180. err => {
  181. Common.processException(err);
  182. },
  183. );
  184. });
  185. // 获取所选公司id 名字
  186. const getClientId = (value, client) => {
  187. id.value = value;
  188. clientId.value = value;
  189. clientNameStr.value = client.label;
  190. getOrganization();
  191. };
  192. // 新建部门
  193. const createOrganization = () => {
  194. organization.value = {};
  195. organization.value.clientName = clientNameStr.value;
  196. organization.value.clientName = clientNameStr.value;
  197. (clientFieldValue.value = {
  198. displayValue: [],
  199. fieldType: 'Key',
  200. id: null,
  201. }),
  202. (parentOrganizationFieldValue.value = {
  203. displayValue: [],
  204. fieldType: 'Key',
  205. id: null,
  206. });
  207. parentOrganizationAdditionHql.value = '';
  208. };
  209. // 创建按钮
  210. const createNew = organization => {
  211. organization.parentName = parentOrganizationFieldValue.value.displayValue[0];
  212. organization.clientId = id.value;
  213. create(organization).then(
  214. success => {
  215. if (success.errorCode == 0) {
  216. message.success('新建部门成功');
  217. getOrganization();
  218. editVisible.value = false;
  219. } else {
  220. message.error(success.errorMessage);
  221. }
  222. },
  223. err => {
  224. Common.processException(err);
  225. },
  226. );
  227. };
  228. // 获取所有部门
  229. const getOrganization = () => {
  230. dataSource.value = [];
  231. const datas = [];
  232. const id = clientId.value;
  233. getAllOrganization(id).then(
  234. success => {
  235. if (success.errorCode == 0) {
  236. success.datas.forEach(item => {
  237. datas.push(item.childrenOrganizations);
  238. });
  239. traversalTree(datas.flat(1), dataSource.value);
  240. }
  241. // loadAllSubClients();
  242. },
  243. err => {
  244. Common.processException(err);
  245. },
  246. );
  247. };
  248. // 编辑部门
  249. const editOrganization = (flag, id) => {
  250. organizationId.value = id;
  251. if (flag) {
  252. if (clientNameStr.value !== '') {
  253. editVisible.value = true;
  254. drawerTitle.value = '新建部门';
  255. createOrganization();
  256. fetchUserList();
  257. isCreate.value = true;
  258. } else {
  259. message.warning('请选择公司');
  260. }
  261. } else {
  262. editVisible.value = true;
  263. drawerTitle.value = '编辑部门';
  264. loadOrganization(id).then(
  265. success => {
  266. if (success.errorCode == 0) {
  267. organization.value = success.data;
  268. parentOrganizationFieldValue.value = {
  269. displayValue: [success.data.parentName],
  270. fieldType: 'Key',
  271. id: success.data.parentId,
  272. };
  273. clientFieldValue.value = {
  274. displayValue: [success.data.clientName],
  275. fieldType: 'Key',
  276. id: success.data.clientId,
  277. };
  278. fetchUserList();
  279. } else {
  280. message.error(success.errorMessage);
  281. }
  282. },
  283. err => {
  284. Common.processException(err);
  285. },
  286. (isCreate.value = false),
  287. );
  288. }
  289. };
  290. //保存事件
  291. const updateOrganization = () => {
  292. const organizationValue = JSON.parse(JSON.stringify(organization.value));
  293. const { clientId, name, no } = organizationValue;
  294. if (
  295. clientId == undefined ||
  296. clientId == '' ||
  297. name == undefined ||
  298. name == '' ||
  299. no == undefined ||
  300. no == ''
  301. ) {
  302. Notify.error(
  303. proxy.$t('lang.Notify.error'),
  304. proxy.$t('lang.OrganizationEditPanel.describe5'),
  305. true,
  306. );
  307. return;
  308. }
  309. update(organizationValue).then(
  310. success => {
  311. if (success.errorCode == 0) {
  312. if (success.data) {
  313. Notify.success(
  314. proxy.$t('lang.Notify.success'),
  315. proxy.$t('lang.OrganizationEditPanel.describe6'),
  316. true,
  317. );
  318. organization.value = {};
  319. organization.value.clientId = clientFieldValue.value.id;
  320. parentOrganizationFieldValue.value = {
  321. displayValue: [],
  322. fieldType: 'Key',
  323. id: null,
  324. };
  325. getOrganization();
  326. }
  327. } else {
  328. message.error(success.errorMessage);
  329. }
  330. editVisible.value = false;
  331. },
  332. err => {
  333. Common.processException(err);
  334. },
  335. );
  336. };
  337. // 删除部门
  338. const deleteOrganization = id => {
  339. loadOrganization(id).then(
  340. success => {
  341. const organization = success.data;
  342. if (organization == undefined) {
  343. Notify.error(
  344. proxy.$t('lang.Notify.error'),
  345. proxy.$t('lang.OrganizationEditPanel.describe4'),
  346. true,
  347. );
  348. return;
  349. }
  350. const params = {
  351. id: organization.id,
  352. no: organization.no,
  353. name: organization.name,
  354. };
  355. deleteDepartment(params).then(
  356. success => {
  357. if (success.errorCode == 0) {
  358. Notify.success(
  359. proxy.$t('lang.Notify.success'),
  360. proxy.$t('lang.OrganizationEditPanel.describe3'),
  361. true,
  362. );
  363. organization.value = undefined;
  364. getOrganization();
  365. } else {
  366. message.error(success.errorMessage);
  367. }
  368. },
  369. err => {
  370. Common.processException(err);
  371. },
  372. );
  373. },
  374. err => {
  375. Common.processException(err);
  376. },
  377. );
  378. };
  379. // 部门管理员输入的过滤条件发生改变
  380. const fetchUserList = (search, loading) => {
  381. if (loading != null) {
  382. loading(true);
  383. }
  384. let searchQueryParam = {
  385. conditional: search,
  386. range: {
  387. start: 0,
  388. length: 100,
  389. },
  390. };
  391. getUsersByName(searchQueryParam).then(
  392. successData => {
  393. if (loading != null) {
  394. loading(false);
  395. }
  396. userList.value = successData.resultList;
  397. },
  398. errorData => {
  399. if (loading != null) {
  400. loading(false);
  401. }
  402. Common.processException(errorData);
  403. },
  404. );
  405. };
  406. // 公司change事件
  407. const clientValueChanged = newFieldValue => {
  408. clientFieldValue.value = newFieldValue;
  409. organization.value.clientId = newFieldValue.id;
  410. parentOrganizationAdditionHql.value = ' client.id = ' + newFieldValue.id; // 添加部门约束
  411. };
  412. // 上级部门change事件
  413. const parentOrganizationValueChanged = newFieldValue => {
  414. if (organizationId.value == newFieldValue.id) {
  415. message.warning('不能将自己作为上级部门!');
  416. parentOrganizationFieldValue.value = {
  417. displayValue: [],
  418. fieldType: 'Key',
  419. id: null,
  420. };
  421. } else {
  422. parentOrganizationFieldValue.value = newFieldValue;
  423. organization.value.parentId = newFieldValue.id;
  424. organization.value.parentName = newFieldValue.displayValue[0];
  425. }
  426. };
  427. // 递归将childrenOrganizations赋值给children
  428. const traversalTree = (array, target) => {
  429. array.map((item, index) => {
  430. target.push({
  431. id: item.id,
  432. no: item.no,
  433. key: item.id,
  434. children: [],
  435. type: item.type,
  436. name: item.name,
  437. description: item.description,
  438. });
  439. if (
  440. item.childrenOrganizations !== null &&
  441. item.childrenOrganizations.length !== 0
  442. ) {
  443. traversalTree(item.childrenOrganizations, target[index].children);
  444. } else {
  445. delete target[index].children;
  446. }
  447. });
  448. };
  449. // 获取所有子部门
  450. /**
  451. const loadAllSubClients = () => {
  452. var rootClientId = null;
  453. for (let i = 0; i < dataSource.value.length; i++) {
  454. var clientOrganization = dataSource.value[i];
  455. if (clientOrganization.children == null) {
  456. rootClientId = clientOrganization.key;
  457. }
  458. }
  459. loadSubClients(rootClientId).then(
  460. success => {
  461. if (success.errorCode == 0) {
  462. if (success.datas) {
  463. clientAdditionHql.value = ' ct.id in (' + success.join(',') + ')';
  464. } else {
  465. clientAdditionHql.value = {
  466. customerDataDimensions: [
  467. {
  468. fieldName: 'ct.id',
  469. dataDimensionTypeNo: '202201191757',
  470. defaultDataDimensionTypeValueNo: '1',
  471. },
  472. ],
  473. };
  474. parentOrganizationAdditionHql.value = {
  475. customerDataDimensions: [
  476. {
  477. fieldName: 'organization.id',
  478. dataDimensionTypeNo: '202201191700',
  479. defaultDataDimensionTypeValueNo: '1',
  480. },
  481. ],
  482. };
  483. }
  484. } else {
  485. message.error(success.errorMessage);
  486. }
  487. },
  488. err => {
  489. Common.processException(err);
  490. },
  491. );
  492. };*/
  493. </script>
  494. <style scoped>
  495. .editable-row-operations a {
  496. margin-right: 8px;
  497. }
  498. </style>