index.vue 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491
  1. <template>
  2. <div class="organize pagePadding">
  3. <div
  4. v-loading="loading"
  5. v-if="powers && powers.length > 0 && powers.some((item) => item == '001')"
  6. >
  7. <el-row>
  8. <el-col :span="24">
  9. <el-col :span="24" style="padding: 12px 0 15px 0">
  10. <div class="my-breadcrumb clear">
  11. <div
  12. class="my-breadcrumb-item"
  13. v-for="(item, index) in titleList"
  14. :key="item + index"
  15. :class="{ chover: true }"
  16. @click="changeBreadcrumb(index)"
  17. >
  18. <span class="label">{{ item.titleName }}</span
  19. ><span class="separator" v-if="index + 1 !== titleList.length"
  20. >/</span
  21. >
  22. </div>
  23. </div>
  24. </el-col>
  25. <el-col :span="24">
  26. <el-row style="padding: 0 0 3px 0">
  27. <el-col :span="8" style="width: 200px">
  28. <el-input
  29. placeholder="部门名称"
  30. :size="searchSize"
  31. v-model="parmValue.name"
  32. >
  33. </el-input>
  34. </el-col>
  35. <el-col :span="8" style="width: 250px; padding: 0 0 0 10px">
  36. <el-input
  37. placeholder="员工姓名"
  38. :size="searchSize"
  39. v-model="parmValue.nickname"
  40. >
  41. <el-button
  42. slot="append"
  43. icon="el-icon-search"
  44. @click="searchList"
  45. ></el-button>
  46. </el-input>
  47. </el-col>
  48. <el-col :span="3" style="width: 195px; float: right">
  49. <el-button
  50. type="primary"
  51. :size="searchSize"
  52. style="float: right; margin-left: 5px"
  53. @click="searchList"
  54. >
  55. 刷新
  56. </el-button>
  57. <el-button
  58. v-if="powers.some((item) => item == '003')"
  59. type="success"
  60. :size="searchSize"
  61. style="float: right"
  62. @click="
  63. addEditFn(
  64. 0,
  65. parmValue && parmValue.pid !== '' ? parmValue.pid : '0',
  66. 1,
  67. false,
  68. true,
  69. {}
  70. )
  71. "
  72. >
  73. 添加
  74. </el-button>
  75. </el-col>
  76. </el-row>
  77. </el-col>
  78. </el-col>
  79. </el-row>
  80. <el-row :gutter="10">
  81. <el-col
  82. :span="24"
  83. v-if="
  84. powers && powers.length > 0 && powers.some((item) => item == '001')
  85. "
  86. >
  87. <organize-tree
  88. style="margin-left: -5px"
  89. :list="depart"
  90. :level="1"
  91. :pid="0"
  92. @addEdit="addEditFn"
  93. @openChildren="openChildren"
  94. @status="setstatus"
  95. @del="del"
  96. />
  97. <staff-tree
  98. style="margin-left: -5px"
  99. :list="item"
  100. :level="1"
  101. :pid="0"
  102. @setUpEdit="setUpEdit"
  103. />
  104. </el-col>
  105. <div
  106. class="no-data"
  107. v-if="item && item.length === 0 && depart && depart.length === 0"
  108. >
  109. 暂无数据
  110. </div>
  111. </el-row>
  112. <add-edit
  113. :id="modelId"
  114. :show-model="showModel"
  115. :level="level"
  116. :pid="parentIds"
  117. :is-add="isAdd"
  118. :form-data="formData"
  119. :type="parmValue.type"
  120. :is-detail="isDetail"
  121. @refresh="searchList"
  122. @cancel="showModel = false"
  123. />
  124. </div>
  125. <div v-else>
  126. <no-auth></no-auth>
  127. </div>
  128. </div>
  129. </template>
  130. <script>
  131. import mixinPage from "@/mixins/elPaginationHandle";
  132. import asyncRequest from "@/apis/service/interest/organize";
  133. import addEdit from "./addEdit";
  134. import statusList from "@/assets/js/statusList";
  135. import { mapGetters } from "vuex";
  136. import resToken from "@/mixins/resToken";
  137. export default {
  138. name: "organize",
  139. components: {
  140. addEdit,
  141. },
  142. mixins: [mixinPage, resToken],
  143. computed: {
  144. ...mapGetters(["tablebtnSize", "searchSize", "size"]),
  145. powers() {
  146. let tran =
  147. this.$store.getters.btnList.find(
  148. (item) => item.menu_route == "organize"
  149. ) || {};
  150. if (tran && tran.action && tran.action.length > 0) {
  151. return tran.action;
  152. } else {
  153. return [];
  154. }
  155. },
  156. },
  157. data() {
  158. return {
  159. titleList: [],
  160. sitem: null,
  161. statusList: statusList,
  162. loading: true,
  163. showModel: false,
  164. showInterface: false,
  165. isDetail: false,
  166. isAdd: true,
  167. level: 1,
  168. modelId: 0,
  169. formData: {},
  170. parentIds: "",
  171. parmValue: {
  172. pid: "", //父级部门ID
  173. name: "", // 部门/公司名称
  174. nickname: "", // 员工名称
  175. },
  176. depart: [],
  177. item: [],
  178. passwordModel: false,
  179. passwordModelId: 0,
  180. // 表格 - 数据
  181. // depart: [],
  182. };
  183. },
  184. mounted() {
  185. this.searchList();
  186. },
  187. methods: {
  188. restSearch() {
  189. this.parmValue = {
  190. pid: "", //父级部门ID
  191. name: "", // 部门/公司名称
  192. nickname: "", // 员工名称
  193. };
  194. this.searchList();
  195. },
  196. // 原来
  197. // async changeBreadcrumb(index) {
  198. // if (index + 1 !== this.titleList.length) {
  199. // this.parmValue.pid = this.titleList[index].id;
  200. // this.titleList = this.titleList.slice(0, index + 1);
  201. // } else {
  202. // this.parmValue.pid = 0;
  203. // this.titleList = [];
  204. // }
  205. // await this.searchList();
  206. // },
  207. // 修改后
  208. async changeBreadcrumb(index) {
  209. if (index + 1 === this.titleList.length) {
  210. return;
  211. } else {
  212. this.parmValue.pid = this.titleList[index].id;
  213. this.titleList = this.titleList.slice(0, index + 1);
  214. }
  215. if (this.titleList.length === 1) {
  216. this.titleList = [];
  217. }
  218. await this.searchList();
  219. },
  220. // 原来
  221. // async openChildren(item) {
  222. // this.parmValue.pid = item.id;
  223. // let model = {
  224. // id: item.id,
  225. // titleName: item.name,
  226. // };
  227. // this.titleList.push(model);
  228. // await this.searchList();
  229. // },
  230. // 修改后
  231. async openChildren(item) {
  232. this.parmValue.pid = item.id;
  233. let model = {
  234. id: item.id,
  235. titleName: item.name,
  236. };
  237. if (this.titleList.length === 0) {
  238. this.titleList.push({ id: "", titleName: "全部分类" });
  239. }
  240. this.titleList.push(model);
  241. await this.searchList();
  242. },
  243. openModal(id, isDetail, sitem) {
  244. this.showModel = true;
  245. this.modelId = id;
  246. this.isDetail = isDetail;
  247. this.sitem = sitem;
  248. },
  249. openPasswordModal(id, isDetail) {
  250. this.passwordModel = true;
  251. this.passwordModelId = id;
  252. this.isPasswordDetail = isDetail;
  253. },
  254. async setUpEdit(id, position) {
  255. if (position === "1") {
  256. const model = {
  257. id: id,
  258. position: "2",
  259. };
  260. let res = await asyncRequest.userp(model);
  261. if (res && res.code === 0) {
  262. this.$notify.success({
  263. title: "设置成功!",
  264. message: "",
  265. });
  266. await this.searchList();
  267. } else if (res && res.code >= 100 && res.code <= 104) {
  268. await this.logout();
  269. } else {
  270. this.$message.warning(res.message);
  271. }
  272. } else {
  273. this.$message.warning("该账户已是部门负责人!");
  274. }
  275. },
  276. addEditFn(id, pid, level, isDetail, isAdd, formData) {
  277. this.showModel = true;
  278. this.modelId = id;
  279. this.level = level;
  280. this.parentIds = pid;
  281. this.isDetail = isDetail;
  282. this.isAdd = isAdd;
  283. this.formData = formData;
  284. },
  285. async setstatus(id, parentIds, level, status) {
  286. console.log(
  287. `openChildren-id, parentIds, level:${id}-${parentIds}-${level}-${status}`
  288. );
  289. await this.$confirm(`确定要${status === "0" ? "启用" : "禁用"}?`, {
  290. confirmButtonText: "确定",
  291. cancelButtonText: "取消",
  292. type: "warning",
  293. })
  294. .then(async () => {
  295. const model = {
  296. id: id,
  297. status: status === "1" ? "0" : "1",
  298. };
  299. let res = await asyncRequest.status(model);
  300. if (res && res.code === 0) {
  301. this.$notify.success({
  302. title: "修改成功!",
  303. message: "",
  304. });
  305. await this.searchList();
  306. } else if (res && res.code >= 100 && res.code <= 104) {
  307. await this.logout();
  308. } else {
  309. this.$message.warning(res.message);
  310. }
  311. })
  312. .catch(() => {
  313. console.log("取消");
  314. });
  315. },
  316. async del(id, parentIds, level, status) {
  317. console.log(
  318. `openChildren-id, parentIds, level:${id}-${parentIds}-${level}-${status}`
  319. );
  320. await this.$confirm(`确定要删除?`, {
  321. confirmButtonText: "确定",
  322. cancelButtonText: "取消",
  323. type: "warning",
  324. })
  325. .then(async () => {
  326. const model = {
  327. id: id,
  328. };
  329. let res = await asyncRequest.delete(model);
  330. if (res && res.code === 0) {
  331. this.$notify.success({
  332. title: "删除成功!",
  333. message: "",
  334. });
  335. await this.searchList();
  336. } else if (res && res.code >= 100 && res.code <= 104) {
  337. await this.logout();
  338. }
  339. })
  340. .catch(() => {
  341. console.log("取消");
  342. });
  343. },
  344. async concatData(id, parentIds, level) {
  345. this.loading = true;
  346. const res = await asyncRequest.list({});
  347. let depart = [];
  348. if (res && res.code === 0 && res.data) {
  349. depart = res.data;
  350. } else if (res && res.code >= 100 && res.code <= 104) {
  351. await this.logout();
  352. } else {
  353. this.$message.warning(res.message);
  354. }
  355. let arr = JSON.parse(JSON.stringify(this.depart));
  356. // if (level === 1) {
  357. arr = arr.map((val, index) => {
  358. if (level === 1 ? id : parentIds === val.id) {
  359. val.child = depart[index].child;
  360. }
  361. return val;
  362. });
  363. this.depart = arr;
  364. this.loading = false;
  365. },
  366. async deleteById(id, status) {
  367. await this.$confirm("确定要删除?", {
  368. confirmButtonText: "确定",
  369. cancelButtonText: "取消",
  370. type: "warning",
  371. })
  372. .then(async () => {
  373. const model = {
  374. id: id,
  375. status: status === "1" ? "0" : "1",
  376. };
  377. const res = await asyncRequest.status(model);
  378. if (res && res.code === 0) {
  379. this.$notify.success({
  380. title: "删除成功",
  381. message: "",
  382. });
  383. this.searchList();
  384. } else if (res && res.code >= 100 && res.code <= 104) {
  385. await this.logout();
  386. } else {
  387. this.$message.warning(res.message);
  388. }
  389. })
  390. .catch(() => {
  391. console.log("取消");
  392. });
  393. },
  394. async searchList() {
  395. this.loading = true;
  396. const res = await asyncRequest.list(this.parmValue);
  397. if (res && res.code === 0 && res.data) {
  398. const { depart, item } = res.data;
  399. this.depart = depart;
  400. this.item = item;
  401. } else if (res && res.code >= 100 && res.code <= 104) {
  402. await this.logout();
  403. } else {
  404. this.depart = [];
  405. this.item = [];
  406. }
  407. this.loading = false;
  408. },
  409. async statusConfirm(id, status) {
  410. await this.$confirm(`确定要改为${status === "1" ? "禁用" : "启用"}?`, {
  411. confirmButtonText: "确定",
  412. cancelButtonText: "取消",
  413. type: "warning",
  414. })
  415. .then(async () => {
  416. this.loading = true;
  417. const model = {
  418. id: id,
  419. status: status === "1" ? "0" : "1",
  420. };
  421. const res = await asyncRequest.status(model);
  422. if (res && res.code === 0) {
  423. this.loading = false;
  424. this.$notify.success({
  425. title: "状态修改成功!",
  426. message: "",
  427. });
  428. await this.searchList();
  429. } else if (res && res.code >= 100 && res.code <= 104) {
  430. await this.logout();
  431. } else {
  432. this.$message.warning(res.message);
  433. }
  434. })
  435. .catch(() => {
  436. console.log("取消");
  437. });
  438. },
  439. },
  440. };
  441. </script>
  442. <style lang="scss" scoped>
  443. .organize {
  444. .no-data {
  445. padding: 25px 0;
  446. text-align: center;
  447. color: #909399;
  448. margin: 30px 10px 0 10px;
  449. border-radius: 8px;
  450. border: 1px solid #dfe6ec;
  451. // border-right: 1px solid #dfe6ec;
  452. // border-bottom: 1px solid #dfe6ec;
  453. }
  454. .my-breadcrumb {
  455. .my-breadcrumb-item {
  456. float: left;
  457. span {
  458. height: 21px;
  459. line-height: 21px;
  460. }
  461. .label {
  462. padding: 0 5px 0 0;
  463. color: 010101;
  464. }
  465. .separator {
  466. color: #787878;
  467. font-size: 13px;
  468. padding: 0 5px 0 0;
  469. }
  470. &:last-child {
  471. .label {
  472. color: #787878;
  473. }
  474. }
  475. &.chover {
  476. cursor: pointer;
  477. }
  478. }
  479. }
  480. }
  481. </style>