index.vue 12 KB

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