index.vue 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465
  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. ],
  161. sitem: null,
  162. statusList: statusList,
  163. loading: true,
  164. showModel: false,
  165. showInterface: false,
  166. isDetail: false,
  167. isAdd: true,
  168. level: 1,
  169. modelId: 0,
  170. formData: {},
  171. parentIds: "",
  172. parmValue: {
  173. pid: "", //父级部门ID
  174. name: "", // 部门/公司名称
  175. nickname: "", // 员工名称
  176. },
  177. depart: [],
  178. item: [],
  179. passwordModel: false,
  180. passwordModelId: 0,
  181. // 表格 - 数据
  182. // depart: [],
  183. };
  184. },
  185. mounted() {
  186. this.searchList();
  187. },
  188. methods: {
  189. restSearch() {
  190. this.parmValue = {
  191. pid: "", //父级部门ID
  192. name: "", // 部门/公司名称
  193. nickname: "", // 员工名称
  194. };
  195. this.searchList();
  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. async openChildren(item) {
  208. this.parmValue.pid = item.id;
  209. let model = {
  210. id: item.id,
  211. titleName: item.name,
  212. };
  213. this.titleList.push(model);
  214. await this.searchList();
  215. },
  216. openModal(id, isDetail, sitem) {
  217. this.showModel = true;
  218. this.modelId = id;
  219. this.isDetail = isDetail;
  220. this.sitem = sitem;
  221. },
  222. openPasswordModal(id, isDetail) {
  223. this.passwordModel = true;
  224. this.passwordModelId = id;
  225. this.isPasswordDetail = isDetail;
  226. },
  227. async setUpEdit(id, position) {
  228. if (position === "1") {
  229. const model = {
  230. id: id,
  231. position: "2",
  232. };
  233. let res = await asyncRequest.userp(model);
  234. if (res && res.code === 0) {
  235. this.$notify.success({
  236. title: "设置成功!",
  237. message: "",
  238. });
  239. await this.searchList();
  240. } else if (res && res.code >= 100 && res.code <= 104) {
  241. await this.logout();
  242. } else {
  243. this.$message.warning(res.message);
  244. }
  245. } else {
  246. this.$message.warning("该账户已是部门负责人!");
  247. }
  248. },
  249. addEditFn(id, pid, level, isDetail, isAdd, formData) {
  250. this.showModel = true;
  251. this.modelId = id;
  252. this.level = level;
  253. this.parentIds = pid;
  254. this.isDetail = isDetail;
  255. this.isAdd = isAdd;
  256. this.formData = formData;
  257. },
  258. async setstatus(id, parentIds, level, status) {
  259. console.log(
  260. `openChildren-id, parentIds, level:${id}-${parentIds}-${level}-${status}`
  261. );
  262. await this.$confirm(`确定要${status === "0" ? "启用" : "禁用"}?`, {
  263. confirmButtonText: "确定",
  264. cancelButtonText: "取消",
  265. type: "warning",
  266. })
  267. .then(async () => {
  268. const model = {
  269. id: id,
  270. status: status === "1" ? "0" : "1",
  271. };
  272. let res = await asyncRequest.status(model);
  273. if (res && res.code === 0) {
  274. this.$notify.success({
  275. title: "修改成功!",
  276. message: "",
  277. });
  278. await this.searchList();
  279. } else if (res && res.code >= 100 && res.code <= 104) {
  280. await this.logout();
  281. } else {
  282. this.$message.warning(res.message);
  283. }
  284. })
  285. .catch(() => {
  286. console.log("取消");
  287. });
  288. },
  289. async del(id, parentIds, level, status) {
  290. console.log(
  291. `openChildren-id, parentIds, level:${id}-${parentIds}-${level}-${status}`
  292. );
  293. await this.$confirm(`确定要删除?`, {
  294. confirmButtonText: "确定",
  295. cancelButtonText: "取消",
  296. type: "warning",
  297. })
  298. .then(async () => {
  299. const model = {
  300. id: id,
  301. };
  302. let res = await asyncRequest.delete(model);
  303. if (res && res.code === 0) {
  304. this.$notify.success({
  305. title: "删除成功!",
  306. message: "",
  307. });
  308. await this.searchList();
  309. } else if (res && res.code >= 100 && res.code <= 104) {
  310. await this.logout();
  311. }
  312. })
  313. .catch(() => {
  314. console.log("取消");
  315. });
  316. },
  317. async concatData(id, parentIds, level) {
  318. console.log(id, parentIds, level);
  319. this.loading = true;
  320. const res = await asyncRequest.list({});
  321. let depart = [];
  322. if (res && res.code === 0 && res.data) {
  323. depart = res.data;
  324. } else if (res && res.code >= 100 && res.code <= 104) {
  325. await this.logout();
  326. } else {
  327. this.$message.warning(res.message);
  328. }
  329. let arr = JSON.parse(JSON.stringify(this.depart));
  330. // if (level === 1) {
  331. arr = arr.map((val, index) => {
  332. if (level === 1 ? id : parentIds === val.id) {
  333. val.child = depart[index].child;
  334. }
  335. return val;
  336. });
  337. this.depart = arr;
  338. this.loading = false;
  339. },
  340. async deleteById(id, status) {
  341. await this.$confirm("确定要删除?", {
  342. confirmButtonText: "确定",
  343. cancelButtonText: "取消",
  344. type: "warning",
  345. })
  346. .then(async () => {
  347. const model = {
  348. id: id,
  349. status: status === "1" ? "0" : "1",
  350. };
  351. const res = await asyncRequest.status(model);
  352. if (res && res.code === 0) {
  353. this.$notify.success({
  354. title: "删除成功",
  355. message: "",
  356. });
  357. this.searchList();
  358. } else if (res && res.code >= 100 && res.code <= 104) {
  359. await this.logout();
  360. } else {
  361. this.$message.warning(res.message);
  362. }
  363. })
  364. .catch(() => {
  365. console.log("取消");
  366. });
  367. },
  368. async searchList() {
  369. this.loading = true;
  370. const res = await asyncRequest.list(this.parmValue);
  371. if (res && res.code === 0 && res.data) {
  372. const { depart, item } = res.data;
  373. this.depart = depart;
  374. this.item = item;
  375. } else if (res && res.code >= 100 && res.code <= 104) {
  376. await this.logout();
  377. } else {
  378. this.depart = [];
  379. this.item = [];
  380. }
  381. this.loading = false;
  382. },
  383. async statusConfirm(id, status) {
  384. await this.$confirm(`确定要改为${status === "1" ? "禁用" : "启用"}?`, {
  385. confirmButtonText: "确定",
  386. cancelButtonText: "取消",
  387. type: "warning",
  388. })
  389. .then(async () => {
  390. this.loading = true;
  391. const model = {
  392. id: id,
  393. status: status === "1" ? "0" : "1",
  394. };
  395. const res = await asyncRequest.status(model);
  396. if (res && res.code === 0) {
  397. this.loading = false;
  398. this.$notify.success({
  399. title: "状态修改成功!",
  400. message: "",
  401. });
  402. await this.searchList();
  403. } else if (res && res.code >= 100 && res.code <= 104) {
  404. await this.logout();
  405. } else {
  406. this.$message.warning(res.message);
  407. }
  408. })
  409. .catch(() => {
  410. console.log("取消");
  411. });
  412. },
  413. },
  414. };
  415. </script>
  416. <style lang="scss" scoped>
  417. .organize {
  418. .no-data {
  419. padding: 25px 0;
  420. text-align: center;
  421. color: #909399;
  422. margin: 30px 10px 0 10px;
  423. border-radius: 8px;
  424. border: 1px solid #dfe6ec;
  425. // border-right: 1px solid #dfe6ec;
  426. // border-bottom: 1px solid #dfe6ec;
  427. }
  428. .my-breadcrumb {
  429. .my-breadcrumb-item {
  430. float: left;
  431. span {
  432. height: 21px;
  433. line-height: 21px;
  434. }
  435. .label {
  436. padding: 0 5px 0 0;
  437. color: 010101;
  438. }
  439. .separator {
  440. color: #787878;
  441. font-size: 13px;
  442. padding: 0 5px 0 0;
  443. }
  444. &:last-child {
  445. .label {
  446. color: #787878;
  447. }
  448. }
  449. &.chover {
  450. cursor: pointer;
  451. }
  452. }
  453. }
  454. }
  455. </style>