staffManager.vue 35 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181
  1. <template>
  2. <div class="m-container">
  3. <h2>
  4. <div class="squrt"></div>
  5. 员工管理
  6. </h2>
  7. <div class="m-core">
  8. <save-form
  9. :inline="true"
  10. class="searchForm"
  11. ref="searchForm"
  12. @submit="search"
  13. @reset="reset"
  14. :model="searchForm"
  15. >
  16. <el-form-item prop="search">
  17. <el-input
  18. type="text"
  19. clearable
  20. v-model.trim="searchForm.search"
  21. @keyup.enter.native="search"
  22. placeholder="姓名、编号、手机号"
  23. ></el-input>
  24. </el-form-item>
  25. <el-form-item prop="jobNature">
  26. <el-select
  27. v-model.trim="searchForm.jobNature"
  28. clearable
  29. filterable
  30. placeholder="请选择工作类型"
  31. >
  32. <el-option label="全职" value="FULL_TIME"></el-option>
  33. <el-option label="兼职" value="PART_TIME"></el-option>
  34. <!-- <el-option label="临时"
  35. value="TEMPORARY"></el-option> -->
  36. </el-select>
  37. </el-form-item>
  38. <el-form-item prop="organId">
  39. <el-select
  40. v-model.trim="searchForm.organId"
  41. clearable
  42. filterable
  43. placeholder="请选择分部"
  44. >
  45. <el-option
  46. v-for="item in selects.branchs"
  47. :key="item.id"
  48. :label="item.name"
  49. :value="item.id"
  50. ></el-option>
  51. </el-select>
  52. </el-form-item>
  53. <el-form-item prop="roleId">
  54. <!-- multiple -->
  55. <el-select
  56. v-model.trim="searchForm.roleId"
  57. clearable
  58. filterable
  59. placeholder="请选择角色"
  60. >
  61. <el-option
  62. v-for="item in roleList"
  63. :key="item.value"
  64. :label="item.label"
  65. :value="item.value"
  66. ></el-option>
  67. </el-select>
  68. </el-form-item>
  69. <el-form-item>
  70. <el-button native-type="submit" type="danger">搜索</el-button>
  71. <el-button native-type="reset" type="primary">重置</el-button>
  72. </el-form-item>
  73. </save-form>
  74. <el-button
  75. type="primary"
  76. style="margin-bottom: 20px"
  77. @click="roleOperation('create')"
  78. v-permission="'employee/add'"
  79. >添加</el-button
  80. >
  81. <!-- 列表 -->
  82. <div class="tableWrap">
  83. <el-table
  84. :data="tableList"
  85. :header-cell-style="{ background: '#EDEEF0', color: '#444' }"
  86. >
  87. <el-table-column align="center" prop="id" label="员工编号">
  88. <template slot-scope="scope">
  89. <copy-text>{{ scope.row.id }}</copy-text>
  90. </template>
  91. </el-table-column>
  92. <el-table-column align="center" prop="realName" label="姓名">
  93. <template slot-scope="scope">
  94. <copy-text>{{ scope.row.realName }}</copy-text>
  95. </template>
  96. </el-table-column>
  97. <el-table-column align="center" prop="phone" label="手机号">
  98. <template slot-scope="scope">
  99. <copy-text>{{ scope.row.phone }}</copy-text>
  100. </template>
  101. </el-table-column>
  102. <el-table-column align="center" label="角色分类">
  103. <template slot-scope="scope">
  104. <tooltip
  105. :content="scope.row.roleNames | joinArray(',')"
  106. ></tooltip>
  107. </template>
  108. </el-table-column>
  109. <el-table-column align="center" label="职位">
  110. <template slot-scope="scope">
  111. <tooltip :content="scope.row.positionNames"></tooltip>
  112. </template>
  113. </el-table-column>
  114. <el-table-column align="center" prop="jobNature" label="工作类型">
  115. <template slot-scope="scope">
  116. {{ scope.row.jobNature | jobNature }}
  117. </template>
  118. </el-table-column>
  119. <el-table-column align="center" label="所属分部">
  120. <template slot-scope="scope">
  121. <tooltip
  122. :content="scope.row.organNameList | joinArray(',')"
  123. ></tooltip>
  124. </template>
  125. </el-table-column>
  126. <el-table-column
  127. align="center"
  128. label="状态"
  129. :formatter="formatLockFlag"
  130. >
  131. </el-table-column>
  132. <el-table-column align="center" label="入职时间">
  133. <template slot-scope="scope">
  134. {{ scope.row.entryDate | formatTimer }}
  135. </template>
  136. </el-table-column>
  137. <el-table-column align="center" label="离职时间">
  138. <template slot-scope="scope">
  139. {{ scope.row.demissionDate | formatTimer }}
  140. </template>
  141. </el-table-column>
  142. <el-table-column
  143. align="center"
  144. width="250px"
  145. fixed="right"
  146. label="操作"
  147. >
  148. <template slot-scope="scope">
  149. <el-button
  150. @click="roleOperation('update', scope.row)"
  151. v-if="permission('employee/update')"
  152. type="text"
  153. >修改</el-button
  154. >
  155. <el-button
  156. @click="onStaffOperation('RESET_PASSWORD', scope.row)"
  157. v-if="permission('employee/employeeOperate/RESET_PASSWORD')"
  158. type="text"
  159. >重置密码</el-button
  160. >
  161. <el-button
  162. @click="onStaffOperation('LOCK_UNLOCK', scope.row)"
  163. v-if="
  164. permission(
  165. scope.row.lockFlag == 1
  166. ? 'employee/employeeOperate/unlock'
  167. : 'employee/employeeOperate/lock'
  168. )
  169. "
  170. type="text"
  171. >{{ scope.row.lockFlag == 1 ? "解冻" : "冻结" }}</el-button
  172. >
  173. <el-button
  174. @click="onStaffOperation('REINSTATE', scope.row)"
  175. v-if="
  176. scope.row.demissionDate &&
  177. permission('employee/employeeOperate/REINSTATE')
  178. "
  179. type="text"
  180. >复职</el-button
  181. >
  182. <el-button
  183. @click="handover(scope.row)"
  184. v-if="
  185. !scope.row.demissionDate &&
  186. permission('employee/level') &&
  187. permission('employee/levelDetail')
  188. "
  189. type="text"
  190. >离职</el-button
  191. >
  192. </template>
  193. </el-table-column>
  194. </el-table>
  195. <pagination
  196. sync
  197. :total.sync="pageInfo.total"
  198. :page.sync="pageInfo.page"
  199. :limit.sync="pageInfo.limit"
  200. :page-sizes="pageInfo.page_size"
  201. @pagination="getList"
  202. />
  203. </div>
  204. </div>
  205. <el-dialog
  206. :title="formTitle[formActionTitle]"
  207. :visible.sync="roleStatus"
  208. @close="onFormClose('ruleForm')"
  209. width="650px"
  210. >
  211. <el-form :model="form" :rules="rules" ref="ruleForm">
  212. <el-alert
  213. style="margin: 10px 0"
  214. title="基础信息"
  215. :closable="false"
  216. type="info"
  217. >
  218. </el-alert>
  219. <el-row>
  220. <el-col :span="12">
  221. <el-form-item
  222. label="姓名"
  223. prop="realName"
  224. :label-width="formLabelWidth"
  225. >
  226. <el-input
  227. v-model.trim="form.realName"
  228. placeholder="请输入姓名"
  229. autocomplete="off"
  230. ></el-input>
  231. </el-form-item>
  232. </el-col>
  233. <el-col :span="12">
  234. <el-form-item
  235. label="性别"
  236. prop="gender"
  237. :label-width="formLabelWidth"
  238. >
  239. <el-select
  240. v-model.trim="form.gender"
  241. placeholder="请选择性别"
  242. clearable
  243. filterable
  244. >
  245. <el-option label="男" :value="1"></el-option>
  246. <el-option label="女" :value="0"></el-option>
  247. </el-select>
  248. </el-form-item>
  249. </el-col>
  250. </el-row>
  251. <el-row>
  252. <el-col :span="12">
  253. <el-form-item
  254. label="手机号"
  255. prop="phone"
  256. :label-width="formLabelWidth"
  257. >
  258. <el-input
  259. v-model.trim.number="form.phone"
  260. placeholder="请输入手机号"
  261. autocomplete="off"
  262. ></el-input>
  263. </el-form-item>
  264. </el-col>
  265. <el-col :span="12">
  266. <el-form-item
  267. label="工作类型"
  268. prop="jobNature"
  269. :label-width="formLabelWidth"
  270. >
  271. <el-select
  272. v-model.trim="form.jobNature"
  273. clearable
  274. placeholder="请选择工作类型"
  275. filterable
  276. >
  277. <el-option label="全职" value="FULL_TIME"></el-option>
  278. <el-option label="兼职" value="PART_TIME"></el-option>
  279. <!-- <el-option label="临时"
  280. value="TEMPORARY"></el-option> -->
  281. </el-select>
  282. </el-form-item>
  283. </el-col>
  284. </el-row>
  285. <el-row>
  286. <el-col :span="12">
  287. <el-form-item
  288. label="入职时间"
  289. prop="entryDate"
  290. :label-width="formLabelWidth"
  291. >
  292. <el-date-picker
  293. v-model.trim="form.entryDate"
  294. type="date"
  295. :picker-options="{
  296. firstDayOfWeek: 1,
  297. }"
  298. value-format="yyyy-MM-dd HH:mm:ss"
  299. placeholder="选择入职日期"
  300. >
  301. </el-date-picker>
  302. </el-form-item>
  303. </el-col>
  304. <el-col :span="12">
  305. <el-form-item
  306. label="邮政编码"
  307. prop="postalCode"
  308. :label-width="formLabelWidth"
  309. >
  310. <el-input
  311. v-model.trim="form.postalCode"
  312. placeholder="请输入邮政编码"
  313. autocomplete="off"
  314. ></el-input>
  315. </el-form-item>
  316. </el-col>
  317. </el-row>
  318. <el-row>
  319. <el-form-item
  320. label="通讯地址"
  321. prop="contactAddress"
  322. :label-width="formLabelWidth"
  323. >
  324. <el-input
  325. v-model.trim="form.contactAddress"
  326. placeholder="请输入通讯地址"
  327. autocomplete="off"
  328. ></el-input>
  329. </el-form-item>
  330. </el-row>
  331. <el-alert
  332. style="margin: 10px 0"
  333. title="角色权限"
  334. :closable="false"
  335. type="info"
  336. >
  337. </el-alert>
  338. <el-row>
  339. <el-col :span="24">
  340. <el-form-item
  341. label="所属分部"
  342. prop="organIdLists"
  343. :label-width="formLabelWidth"
  344. >
  345. <select-all
  346. filterable
  347. clearable
  348. placeholder="请选择所属分部"
  349. collapse-tags
  350. v-model.trim="form.organIdLists"
  351. multiple
  352. >
  353. <el-option
  354. v-for="item in organList"
  355. :key="item.id"
  356. :label="item.name"
  357. :value="item.id"
  358. ></el-option>
  359. </select-all>
  360. </el-form-item>
  361. </el-col>
  362. </el-row>
  363. <el-row>
  364. <el-col :span="24">
  365. <el-form-item
  366. label="员工角色"
  367. prop="roleIds"
  368. :label-width="formLabelWidth"
  369. >
  370. <select-all
  371. v-model.trim="form.roleIds"
  372. placeholder="请选择员工角色"
  373. clearable
  374. filterable
  375. collapse-tags
  376. multiple
  377. >
  378. <el-option
  379. v-for="item in roleList"
  380. :key="item.value"
  381. :label="item.label"
  382. :value="item.value"
  383. ></el-option>
  384. </select-all>
  385. </el-form-item>
  386. </el-col>
  387. </el-row>
  388. <el-row>
  389. <el-col :span="24">
  390. <el-form-item
  391. label="员工职位"
  392. prop="positionIds"
  393. :label-width="formLabelWidth"
  394. >
  395. <select-all
  396. v-model.trim="form.positionIds"
  397. placeholder="请选择员工职位"
  398. clearable
  399. filterable
  400. collapse-tags
  401. multiple
  402. >
  403. <el-option
  404. v-for="item in positionList"
  405. :key="item.id"
  406. :label="item.roleName"
  407. :value="item.id"
  408. ></el-option>
  409. </select-all>
  410. </el-form-item>
  411. </el-col>
  412. </el-row>
  413. <!-- <el-alert
  414. style="margin: 10px 0"
  415. title="OA信息"
  416. :closable="false"
  417. type="info"
  418. >
  419. </el-alert> -->
  420. <!-- <el-row>
  421. <el-col :span="12">
  422. <el-form-item
  423. label="所属部门"
  424. prop="deptIds"
  425. :label-width="formLabelWidth"
  426. >
  427. <el-cascader
  428. v-model="form.deptIds"
  429. placeholder="请选择所属部门"
  430. clearable
  431. style="width: 100%"
  432. :options="deptList"
  433. :show-all-levels="false"
  434. :collapse-tags="true"
  435. @change="onDeptChange"
  436. :props="{ multiple: true, checkStrictly: false }"
  437. ></el-cascader>
  438. </el-form-item>
  439. </el-col>
  440. <el-col :span="12">
  441. <el-form-item
  442. label="社保分部"
  443. prop="deptId"
  444. :label-width="formLabelWidth"
  445. >
  446. <el-cascader
  447. v-model="form.deptId"
  448. placeholder="请选择社保分部"
  449. clearable
  450. style="width: 100%"
  451. :options="deptSmallList"
  452. :show-all-levels="false"
  453. :collapse-tags="true"
  454. :props="{ checkStrictly: false }"
  455. ></el-cascader>
  456. </el-form-item>
  457. </el-col>
  458. </el-row> -->
  459. <!-- <div v-for="(postDeptIds, index) in form.postDeptIds" :key="index">
  460. <el-form-item
  461. :label="'岗位管理' + (index + 1)"
  462. :label-width="formLabelWidth"
  463. class="setWidth"
  464. :prop="'postDeptIds.' + index + '.postId'"
  465. >
  466. <el-select
  467. filterable
  468. clearable
  469. placeholder="所属岗位"
  470. style="width: 180px !important"
  471. v-model.trim="postDeptIds.postId"
  472. >
  473. <el-option
  474. v-for="item in postList"
  475. :key="item.value"
  476. :label="item.label"
  477. :value="item.value"
  478. ></el-option>
  479. </el-select>
  480. </el-form-item>
  481. <el-form-item
  482. class="setWidth"
  483. style="margin: 0 10px; width: 190px !important"
  484. :prop="'postDeptIds.' + index + '.deptIds'"
  485. >
  486. <el-cascader
  487. v-model="postDeptIds.deptIds"
  488. placeholder="管理部门"
  489. clearable
  490. :options="deptList"
  491. :show-all-levels="false"
  492. :collapse-tags="true"
  493. :props="{ multiple: true, checkStrictly: false }"
  494. ></el-cascader>
  495. </el-form-item>
  496. <el-button
  497. icon="el-icon-minus"
  498. circle
  499. v-if="form.postDeptIds.length > 1"
  500. @click.prevent="removePostDept(postDeptIds)"
  501. ></el-button>
  502. <el-button
  503. icon="el-icon-plus"
  504. @click.prevent="addPostDept"
  505. circle
  506. style="margin-left: 5px"
  507. ></el-button>
  508. </div> -->
  509. </el-form>
  510. <span slot="footer" class="dialog-footer">
  511. <el-button @click="roleStatus = false">取 消</el-button>
  512. <el-button @click="onRoleSubmit('ruleForm')" type="primary"
  513. >确 定</el-button
  514. >
  515. </span>
  516. </el-dialog>
  517. <el-dialog title="工作交接" :visible.sync="handoverVisible" width="500px">
  518. <handover
  519. v-if="handoverVisible"
  520. :detail="detail"
  521. @close="handoverVisible = false"
  522. @submited="getList"
  523. />
  524. </el-dialog>
  525. <el-dialog
  526. title="教务交接"
  527. width="400px"
  528. destroy-on-close
  529. close-on-click-modal
  530. :visible.sync="educationViseble"
  531. >
  532. <el-form :model="educationForm" :inline="true" ref="educationForm">
  533. <el-form-item
  534. label="乐团主管"
  535. :rules="[
  536. {
  537. required: true,
  538. message: '请选择乐团主管',
  539. trigger: 'blur',
  540. },
  541. ]"
  542. >
  543. <el-select
  544. v-model.trim="educationForm.targetUserId"
  545. clearable
  546. filterable
  547. >
  548. <el-option
  549. v-for="item in selects.roles.EDUCATION"
  550. :key="item.userId"
  551. :label="item.userName"
  552. :value="item.userId"
  553. ></el-option>
  554. </el-select>
  555. </el-form-item>
  556. </el-form>
  557. <span slot="footer" class="dialog-footer">
  558. <el-button @click="educationViseble = false">取 消</el-button>
  559. <el-button @click="submitEducation" type="primary">确 定</el-button>
  560. </span>
  561. </el-dialog>
  562. </div>
  563. </template>
  564. <script>
  565. import pagination from "@/components/Pagination/index";
  566. import { permission } from "@/utils/directivePage";
  567. import {
  568. queryEmployByOrganId,
  569. employeeOperate,
  570. getUserRole,
  571. employeeAdd,
  572. employeeUpdate,
  573. hasCourseGroupRelation,
  574. updateEducationTeacherId,
  575. queryEmployeeOrganByUser,
  576. getPosition,
  577. getDepts,
  578. getPosts,
  579. } from "@/api/systemManage";
  580. import { userRole } from "./api";
  581. import deepClone from "@/helpers/deep-clone";
  582. // import Treeselect from '@riophae/vue-treeselect'
  583. // import '@riophae/vue-treeselect/dist/vue-treeselect.css'
  584. import Tooltip from "@/components/Tooltip/index";
  585. import { isvalidPhone } from "@/utils/validate";
  586. import handover from "./modals/handover";
  587. let validPhone = (rule, value, callback) => {
  588. if (!value) {
  589. callback(new Error("请输入电话号码"));
  590. } else if (!isvalidPhone(value)) {
  591. callback(new Error("请输入正确的11位手机号码"));
  592. } else {
  593. callback();
  594. }
  595. };
  596. export default {
  597. name: "staffManager",
  598. components: { pagination, Tooltip, handover },
  599. data() {
  600. return {
  601. roleResetList: [],
  602. organList: [],
  603. tableList: [],
  604. deptList: [],
  605. deptSmallList: [],
  606. postList: [],
  607. educationForm: {
  608. targetUserId: "",
  609. },
  610. educationViseble: false,
  611. activeRow: null,
  612. pageInfo: {
  613. // 分页规则
  614. limit: 10, // 限制显示条数
  615. page: 1, // 当前页
  616. total: 0, // 总条数
  617. page_size: [10, 20, 40, 50], // 选择限制显示条数
  618. },
  619. detail: null,
  620. handoverVisible: false,
  621. roleStatus: false,
  622. formActionTitle: "create",
  623. roleList: [], // 角色列表,
  624. roleBaseList: [], // 登陆人角色
  625. formTitle: {
  626. create: "添加员工",
  627. update: "修改员工",
  628. },
  629. formLabelWidth: "100px",
  630. form: {
  631. realName: null,
  632. gender: null,
  633. phone: null,
  634. roleIds: [],
  635. deptId: null, // 社保分部
  636. organIdLists: [],
  637. postDeptIds: [
  638. {
  639. postId: null,
  640. deptIds: [],
  641. },
  642. ],
  643. deptIds: [],
  644. // postIds: [],
  645. jobNature: null,
  646. entryDate: null,
  647. contactAddress: null,
  648. postalCode: null,
  649. },
  650. rules: {
  651. realName: [{ required: true, message: "请输入姓名", trigger: "blur" }],
  652. gender: [{ required: true, message: "请选择性别", trigger: "change" }],
  653. phone: [
  654. {
  655. type: "number",
  656. required: true,
  657. validator: validPhone,
  658. trigger: "blur",
  659. },
  660. {
  661. pattern: /^1[3456789]\d{9}$/,
  662. message: "请输入正确的手机号",
  663. trigger: "blur",
  664. },
  665. ],
  666. roleIds: [
  667. {
  668. type: "array",
  669. required: true,
  670. message: "请选择分类",
  671. trigger: "change",
  672. },
  673. ],
  674. // deptId: [{ required: true, message: '请选择社保分部', trigger: 'change' }],
  675. organIdLists: [
  676. {
  677. type: "array",
  678. required: true,
  679. message: "请选择所属分部",
  680. trigger: "change",
  681. },
  682. ],
  683. positionIds: [
  684. {
  685. type: "array",
  686. required: true,
  687. message: "请选择员工职位",
  688. trigger: "change",
  689. },
  690. ],
  691. // deptIds: [{ type: 'array', required: true, message: '请选择所属部门', trigger: 'change' }],
  692. // postIds: [{ type: 'array', required: true, message: '请选择所属岗位', trigger: 'change' }],
  693. jobNature: [
  694. { required: true, message: "请选择工作类型", trigger: "change" },
  695. ],
  696. entryDate: [
  697. { required: true, message: "请选择入职时间", trigger: "blur" },
  698. ],
  699. },
  700. searchForm: {
  701. search: null,
  702. jobNature: null,
  703. organId: null,
  704. roleId: null,
  705. },
  706. positionList:[]
  707. };
  708. },
  709. mounted() {
  710. this.getList();
  711. this.getRoleList();
  712. },
  713. methods: {
  714. permission,
  715. handover(row) {
  716. this.detail = row;
  717. this.handoverVisible = true;
  718. },
  719. onBranchCheckAll() {
  720. this.form.organIdLists = [];
  721. this.organList.forEach((item) => {
  722. this.form.organIdLists.push(item.id);
  723. });
  724. },
  725. onRoleSubmit(formName) {
  726. this.$refs[formName].validate((valid) => {
  727. if (valid) {
  728. const { organIdLists, postDeptIds, deptIds, deptId, ...res } =
  729. this.form;
  730. let tempPost = [];
  731. postDeptIds.forEach((post) => {
  732. let tempIds = [];
  733. post.deptIds.forEach((item) => {
  734. tempIds.push(item[item.length - 1]);
  735. });
  736. tempPost.push({
  737. postId: post.postId,
  738. deptIds: tempIds,
  739. });
  740. });
  741. const tempDeptIds = [];
  742. deptIds.forEach((ds) => {
  743. tempDeptIds.push(ds[ds.length - 1]);
  744. });
  745. const tempDeptId = deptId ? deptId[deptId.length - 1] : "";
  746. let tempForm = {
  747. postDeptIds: JSON.stringify(tempPost),
  748. organIdList: organIdLists.join(","),
  749. deptIds: tempDeptIds,
  750. deptId: tempDeptId,
  751. ...res,
  752. };
  753. if (this.formActionTitle == "create") {
  754. if (this.form.id) {
  755. // 判断有没有Id,如果有则删除
  756. delete this.form.id;
  757. }
  758. employeeAdd(tempForm).then((res) => {
  759. this.messageTips("添加", res);
  760. });
  761. } else if (this.formActionTitle == "update") {
  762. employeeUpdate(tempForm).then((res) => {
  763. this.messageTips("修改", res);
  764. });
  765. }
  766. } else {
  767. return;
  768. }
  769. });
  770. },
  771. messageTips(title, res) {
  772. if (res.code == 200) {
  773. this.$message.success(title + "成功");
  774. this.roleStatus = false;
  775. this.getList();
  776. } else {
  777. this.$message.error(res.msg);
  778. }
  779. },
  780. search() {
  781. this.pageInfo.page = 1;
  782. this.getList();
  783. },
  784. reset() {
  785. this.$refs.searchForm.resetFields();
  786. this.search();
  787. },
  788. getList() {
  789. let searchForm = this.searchForm;
  790. let params = {
  791. search: searchForm.search ? searchForm.search : null,
  792. jobNature: searchForm.jobNature ? searchForm.jobNature : null,
  793. organId: searchForm.organId ? searchForm.organId : null,
  794. roleId: searchForm.roleId ? searchForm.roleId : null,
  795. rows: this.pageInfo.limit,
  796. page: this.pageInfo.page,
  797. };
  798. queryEmployByOrganId(params).then((res) => {
  799. if (res.code == 200 && res.data) {
  800. this.tableList = res.data.rows;
  801. this.pageInfo.total = res.data.total;
  802. }
  803. });
  804. },
  805. /** 转换菜单数据结构 */
  806. normalizer(node) {
  807. let temp = [];
  808. if (node.children && node.children.length > 0) {
  809. node.children.forEach((item) => {
  810. let child = this.normalizer(item, status);
  811. let obj = {
  812. value: item.deptId,
  813. label: item.deptName,
  814. };
  815. if (child && child.length > 0) {
  816. obj.children = child;
  817. }
  818. temp.push(obj);
  819. });
  820. }
  821. return temp;
  822. },
  823. async getRoleList() {
  824. // 获取角色
  825. getUserRole({ delFlag: 0, rows: 9999 }).then((res) => {
  826. let result = res.data;
  827. if (res.code == 200 && result && result.rows.length > 0) {
  828. this.roleList = [];
  829. result.rows.forEach((item) => {
  830. this.roleList.push({
  831. label: item.roleName,
  832. value: item.id,
  833. disabled: false,
  834. });
  835. });
  836. }
  837. });
  838. // 获取可编辑角色
  839. // try {
  840. // const res = await userRole();
  841. // this.roleResetList = [];
  842. // res.data.forEach((item) => {
  843. // this.roleResetList.push({
  844. // label: item.roleName,
  845. // value: item.id,
  846. // disabled: false,
  847. // });
  848. // });
  849. // } catch (e) {
  850. // console.log(e);
  851. // }
  852. // getDepts({ rows: 9999 }).then((res) => {
  853. // if (res.code == 200 && res.data && res.data.length > 0) {
  854. // const depts = res.data || [];
  855. // const formatArr = [];
  856. // depts.forEach((dep) => {
  857. // formatArr.push({
  858. // value: dep.deptId,
  859. // label: dep.deptName,
  860. // children: this.normalizer(dep),
  861. // });
  862. // });
  863. // this.deptList = formatArr;
  864. // }
  865. // });
  866. // 岗位
  867. // getPosts({ rows: 9999 }).then((res) => {
  868. // if (res.code == 200 && res.data && res.data.length > 0) {
  869. // this.postList = [];
  870. // res.data.forEach((item) => {
  871. // this.postList.push({
  872. // label: item.postName,
  873. // value: item.postId,
  874. // });
  875. // });
  876. // }
  877. // });
  878. this.$store.dispatch("setBranchs");
  879. },
  880. onDeptChange(value) {
  881. this.form.deptId = null;
  882. this.deptSmallList = [];
  883. let selectList = value.flat(Infinity);
  884. selectList = [...new Set(selectList)];
  885. const depts = deepClone(this.deptList);
  886. const formatArr = [];
  887. depts.forEach((dep) => {
  888. formatArr.push({
  889. value: dep.value,
  890. label: dep.label,
  891. disabled: !selectList.includes(dep.value),
  892. children: this.normalizer2(dep, selectList),
  893. });
  894. });
  895. this.deptSmallList = formatArr;
  896. },
  897. /** 转换菜单数据结构 */
  898. normalizer2(node, selectList) {
  899. let temp = [];
  900. if (node.children && node.children.length > 0) {
  901. node.children.forEach((item) => {
  902. let child = this.normalizer2(item, selectList);
  903. let obj = {
  904. value: item.value,
  905. label: item.label,
  906. disabled: !selectList.includes(item.value),
  907. };
  908. if (child && child.length > 0) {
  909. obj.children = child;
  910. }
  911. temp.push(obj);
  912. });
  913. }
  914. return temp;
  915. },
  916. async roleOperation(type, data) {
  917. // 获取分部
  918. await queryEmployeeOrganByUser().then((res) => {
  919. if (res.code == 200) {
  920. this.organList = res.data;
  921. }
  922. });
  923. // 获取员工职位
  924. try{
  925. const res = await getPosition()
  926. this.positionList = res.data;
  927. }catch(e){
  928. console.log(e)
  929. }
  930. this.formActionTitle = type;
  931. this.roleStatus = true;
  932. // 格式化 可选角色
  933. // 修改的时候
  934. if (type == "update") {
  935. let roleIdList = [...data.roleIds];
  936. // this.roleBaseList.forEach((item) => {
  937. // if (roleIdList.indexOf(item.value) == -1) {
  938. // roleIdList.push(item.value);
  939. // }
  940. // });
  941. // this.roleResetList = [...this.roleList];
  942. // this.roleList.forEach((role) => {
  943. // if (roleIdList.indexOf(role.value) != -1) {
  944. // this.roleResetList.push(role);
  945. // }
  946. // });
  947. // 初始化数据
  948. let postDeptArr = [];
  949. const postDept = data.postDeptIds ? JSON.parse(data.postDeptIds) : [];
  950. if (postDept.length > 0) {
  951. postDept.forEach((dept) => {
  952. let deptIds = dept.deptIds || [];
  953. let deptArr = [];
  954. deptIds.forEach((ds) => {
  955. deptArr.push(this.formatParentId(ds, this.deptList));
  956. });
  957. postDeptArr.push({
  958. postId: dept.postId,
  959. deptIds: deptArr,
  960. });
  961. });
  962. } else {
  963. postDeptArr = [
  964. {
  965. postId: null,
  966. deptIds: [],
  967. },
  968. ];
  969. }
  970. const deptIds = data.deptIds ? eval(data.deptIds) : [];
  971. const tempDeptIds = [];
  972. if (deptIds.length > 0) {
  973. deptIds.forEach((ds) => {
  974. tempDeptIds.push(this.formatParentId(ds, this.deptList));
  975. });
  976. }
  977. this.onDeptChange(tempDeptIds);
  978. this.form = {
  979. id: data.id,
  980. realName: data.realName,
  981. gender: data.gender,
  982. phone: Number(data.phone),
  983. roleIds: data.roleIds,
  984. deptId: data.deptId
  985. ? this.formatParentId(data.deptId, this.deptList)
  986. : null,
  987. organIdLists: data.organIdList ? data.organIdList : [],
  988. jobNature: data.jobNature,
  989. entryDate: data.entryDate,
  990. contactAddress: data.contactAddress,
  991. postalCode: data.postalCode,
  992. postDeptIds: postDeptArr,
  993. deptIds: tempDeptIds,
  994. };
  995. } else {
  996. this.roleResetList = [...this.roleBaseList];
  997. }
  998. },
  999. formatParentId(id, list, ids = []) {
  1000. for (const item of list) {
  1001. if (item.children) {
  1002. const cIds = this.formatParentId(id, item.children, [
  1003. ...ids,
  1004. item.value,
  1005. ]);
  1006. if (cIds.includes(id)) {
  1007. return cIds;
  1008. }
  1009. }
  1010. if (item.value === id) {
  1011. return [...ids, id];
  1012. }
  1013. }
  1014. return ids;
  1015. },
  1016. onFormClose(formName) {
  1017. // 关闭弹窗重置验证
  1018. this.form = {
  1019. realName: null,
  1020. gender: null,
  1021. phone: null,
  1022. roleName: null,
  1023. roleIds: [],
  1024. deptId: null,
  1025. organIdLists: [],
  1026. jobNature: null,
  1027. entryDate: null,
  1028. contactAddress: null,
  1029. postalCode: null,
  1030. deptIds: [],
  1031. postDeptIds: [
  1032. {
  1033. postId: null,
  1034. deptIds: [],
  1035. },
  1036. ],
  1037. };
  1038. this.$refs[formName].resetFields();
  1039. },
  1040. formatLockFlag(row) {
  1041. let reuslt = ["正常", "冻结"];
  1042. if (row.demissionDate) {
  1043. return "离职";
  1044. } else {
  1045. return reuslt[row.lockFlag];
  1046. }
  1047. },
  1048. async checkStatus(data) {
  1049. let status;
  1050. await hasCourseGroupRelation({ employeeId: data.id }).then(
  1051. async (res) => {
  1052. if (res.code === 200) {
  1053. if (res.data.hasCourseSchedule) {
  1054. this.$message.error("请先交接指导老师课程");
  1055. status = false;
  1056. } else {
  1057. if (res.data.hasCourseGroupRelation) {
  1058. let userId = data.id;
  1059. await this.$store.dispatch("setOrganRole");
  1060. this.educationViseble = true;
  1061. status = false;
  1062. } else {
  1063. // 1 要弹出
  1064. status = true;
  1065. }
  1066. }
  1067. }
  1068. }
  1069. );
  1070. return status;
  1071. },
  1072. onStaffOperation(type, data) {
  1073. const tempStatus = type == "RESET_PASSWORD" ? true : false;
  1074. this.$confirm(
  1075. `您确定${tempStatus ? "重置密码" : "修改员工状态"}?`,
  1076. "提示",
  1077. {
  1078. confirmButtonText: "确定",
  1079. cancelButtonText: "取消",
  1080. type: "warning",
  1081. }
  1082. )
  1083. .then(async () => {
  1084. if (type === "DEMISSION" && !data.demissionDate) {
  1085. this.activeRow = data;
  1086. // 1.点击的是离职按钮
  1087. // 2.判断该考级是否存在乐团主管
  1088. const status = await this.checkStatus(data);
  1089. if (!status) {
  1090. return;
  1091. }
  1092. }
  1093. employeeOperate({
  1094. employeeId: data.id,
  1095. operate: type,
  1096. }).then((res) => {
  1097. if (res.code == 200) {
  1098. this.$message.success(tempStatus ? "重置密码成功" : "更改成功");
  1099. this.roleStatus = false;
  1100. this.getList();
  1101. } else {
  1102. this.$message.error(res.msg);
  1103. }
  1104. });
  1105. })
  1106. .catch((err) => {});
  1107. },
  1108. submitEducation() {
  1109. // 发请求 提交信息
  1110. updateEducationTeacherId({
  1111. currentUserId: this.activeRow.id,
  1112. targetUserId: this.educationForm.targetUserId,
  1113. }).then((res) => {
  1114. if (res.code === 200) {
  1115. const type = "DEMISSION";
  1116. const data = this.activeRow;
  1117. employeeOperate({
  1118. employeeId: data.id,
  1119. operate: type,
  1120. }).then((res) => {
  1121. if (res.code == 200) {
  1122. this.$message.success("更改成功");
  1123. this.roleStatus = false;
  1124. this.educationViseble = false;
  1125. this.getList();
  1126. } else {
  1127. this.$message.error(res.msg);
  1128. }
  1129. });
  1130. }
  1131. });
  1132. },
  1133. removePostDept(item) {
  1134. const index = this.form.postDeptIds.indexOf(item);
  1135. if (index !== -1) {
  1136. this.form.postDeptIds.splice(index, 1);
  1137. }
  1138. },
  1139. addPostDept() {
  1140. this.form.postDeptIds.push({
  1141. postId: null,
  1142. deptIds: [],
  1143. });
  1144. },
  1145. },
  1146. watch: {
  1147. educationViseble(val) {
  1148. if (!val) {
  1149. this.educationForm.targetUserId = "";
  1150. this.$refs["educationForm"].resetFields();
  1151. }
  1152. },
  1153. },
  1154. };
  1155. </script>
  1156. <style lang="scss" scoped>
  1157. /deep/.el-dialog__body {
  1158. // padding: 0 20px;
  1159. }
  1160. /deep/.el-select,
  1161. /deep/.el-date-editor.el-input {
  1162. width: 100% !important;
  1163. }
  1164. .setWidth {
  1165. display: inline-block;
  1166. }
  1167. </style>