staffSelection.vue 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399
  1. <template>
  2. <div class="container">
  3. <!-- 单据弹窗 -->
  4. <el-dialog
  5. title="员工"
  6. :before-close="handleClose"
  7. :visible.sync="dialogVisible"
  8. :close-on-click-modal="false"
  9. :append-to-body="true"
  10. width="80%"
  11. >
  12. <el-row class="zw-page">
  13. <el-col :span="6" class="zw-page-left">
  14. <el-card>
  15. <div class="zw-card-header" slot="header">
  16. <span class="zw-header-title details-title">部门</span>
  17. </div>
  18. <div class="zw-page-left-tree">
  19. <el-container class="zw-container">
  20. <el-tree
  21. ref="tree"
  22. :data="treeList"
  23. highlight-current
  24. node-key="id"
  25. :props="{ label: 'name' }"
  26. :expand-on-click-node="false"
  27. :default-expand-all="true"
  28. @node-click="handleNodeClick"
  29. >
  30. </el-tree>
  31. </el-container>
  32. </div>
  33. </el-card>
  34. </el-col>
  35. <el-col :span="9" class="zw-page-main">
  36. <el-card>
  37. <div class="zw-card-header" slot="header">
  38. <span class="zw-header-title details-title">员工明细 </span>
  39. </div>
  40. <div class="zw-page-main-list">
  41. <el-container class="zw-container">
  42. <el-table
  43. :data="staffList"
  44. tooltip-effect="dark"
  45. style="width: 100%"
  46. max-height="500"
  47. :header-cell-style="{
  48. background: '#F0F3F3',
  49. border: 'none'
  50. }"
  51. >
  52. <el-table-column prop="code" label="姓名">
  53. <template slot-scope="{ row }">
  54. <div>{{ row.name }}</div>
  55. </template>
  56. </el-table-column>
  57. <el-table-column label="工号">
  58. <template slot-scope="{ row }">
  59. <div>{{ row.jobNumber }}</div>
  60. </template>
  61. </el-table-column>
  62. <el-table-column width="180" label="操作" align="right">
  63. <template slot="header" slot-scope="scope">
  64. <div style="display: flex">
  65. <el-input v-model="userName" placeholder="输入姓名查询" clearable
  66. @change="changeUserName"></el-input>
  67. <div
  68. v-if="staffList.length !== 0 && isMore"
  69. class="zw-page-list-more"
  70. >
  71. <el-button type="text" @click="getMore()">更多<i class="el-icon-caret-bottom"></i></el-button>
  72. </div>
  73. </div>
  74. </template>
  75. <template slot-scope="{ row }">
  76. <el-button
  77. size="mini"
  78. type="primary"
  79. @click="choiceAsset(row)"
  80. :disabled="row.disabled"
  81. icon="el-icon-arrow-right"
  82. circle
  83. >
  84. </el-button>
  85. </template>
  86. </el-table-column>
  87. <el-table-column width="80" label="操作">
  88. <!-- <template slot-scope="{ row }">-->
  89. <!-- <el-button-->
  90. <!-- size="mini"-->
  91. <!-- type="primary"-->
  92. <!-- @click="choiceAsset(row)"-->
  93. <!-- :disabled="row.disabled"-->
  94. <!-- icon="el-icon-arrow-right"-->
  95. <!-- circle-->
  96. <!-- >-->
  97. <!-- </el-button>-->
  98. <!-- </template>-->
  99. </el-table-column>
  100. </el-table>
  101. <!-- <div-->
  102. <!-- v-if="staffList.length !== 0 && isMore"-->
  103. <!-- class="zw-page-list-more"-->
  104. <!-- >-->
  105. <!-- <el-link @click="getMore()" type="primary"-->
  106. <!-- >更多<i class="el-icon-caret-bottom"></i>-->
  107. <!-- </el-link>-->
  108. <!-- </div>-->
  109. </el-container>
  110. </div>
  111. </el-card>
  112. </el-col>
  113. <el-col :span="9" class="zw-page-right">
  114. <el-card>
  115. <div class="zw-card-header" slot="header">
  116. <span class="zw-header-title">已选员工</span>
  117. </div>
  118. <div class="zw-page-right-list">
  119. <el-container class="zw-container">
  120. <el-table
  121. :data="selectStafflist"
  122. tooltip-effect="dark"
  123. style="width: 100%"
  124. max-height="500"
  125. :header-cell-style="{
  126. background: '#F0F3F3',
  127. border: 'none'
  128. }"
  129. >
  130. <el-table-column prop="code" label="姓名">
  131. <template slot-scope="{ row }">
  132. <div>{{ row.name }}</div>
  133. </template>
  134. </el-table-column>
  135. <el-table-column label="工号">
  136. <template slot-scope="{ row }">
  137. <div>{{ row.jobNumber }}</div>
  138. </template>
  139. </el-table-column>
  140. <el-table-column width="80" label="操作">
  141. <template slot-scope="scope">
  142. <el-button
  143. @click="deleteSelectStaff(scope.row, scope.$index)"
  144. size="mini"
  145. type="danger"
  146. >删除
  147. </el-button>
  148. </template>
  149. </el-table-column>
  150. </el-table>
  151. </el-container>
  152. </div>
  153. </el-card>
  154. </el-col>
  155. </el-row>
  156. <div slot="footer" class="dialog-footer">
  157. <el-button size="small" @click="handleClose">关 闭</el-button>
  158. <el-button size="small" @click="sumbit" type="primary">确 认</el-button>
  159. </div>
  160. </el-dialog>
  161. </div>
  162. </template>
  163. <script>
  164. import { listOrganizations, getUserPage } from '@/api/system/organization';
  165. export default {
  166. data() {
  167. return {
  168. form: {
  169. groupId: null
  170. },
  171. treeList: [],
  172. staffList: [],
  173. selectStafflist: [], //已选员工
  174. defaultProps: {
  175. children: 'children',
  176. label: 'name',
  177. value: 'code'
  178. },
  179. userName: '',
  180. currentData: {},
  181. pageNum: 1, //设备当前页数
  182. size: 10,
  183. isMore: false,
  184. dialogVisible: false
  185. };
  186. },
  187. props: {
  188. type: {},
  189. hasAccount:{
  190. default:0
  191. }
  192. },
  193. created() {},
  194. methods: {
  195. open(selectedList) {
  196. this.dialogVisible = true;
  197. this.selectStafflist = selectedList;
  198. this.getInfo();
  199. },
  200. //初始数据
  201. async getInfo() {
  202. let list = await listOrganizations();
  203. this.treeList = this.$util.toTreeData({
  204. data: list,
  205. idField: 'id',
  206. parentIdField: 'parentId'
  207. });
  208. this.$nextTick(()=>{
  209. this.handleNodeClick(this.treeList[0])
  210. this.$refs.tree.setCurrentKey(this.treeList[0].id)
  211. })
  212. //this.treeList = res.data;
  213. },
  214. //选择分类
  215. handleNodeClick(data) {
  216. this.currentData = data
  217. this.staffList = [];
  218. this.form.groupId = data.id;
  219. let params = {
  220. pageNum: 1,
  221. size: this.size,
  222. groupId: this.form.groupId,
  223. hasAccount:this.hasAccount
  224. };
  225. this.getStaffList(params);
  226. },
  227. changeUserName() {
  228. this.staffList = [];
  229. this.form.groupId = this.currentData.id;
  230. let params = {
  231. pageNum: 1,
  232. size: this.size,
  233. groupId: this.form.groupId,
  234. name: this.userName
  235. };
  236. this.getStaffList(params);
  237. },
  238. //获取员工列表
  239. async getStaffList(params) {
  240. let res = await getUserPage(params);
  241. let list = res.list;
  242. if (list.length < res.count) {
  243. this.isMore = true;
  244. } else {
  245. this.isMore = false;
  246. }
  247. list.forEach((el) => {
  248. let _index = this.selectStafflist.findIndex((n) => n.id == el.id);
  249. if (_index !== -1) {
  250. el.disabled = true;
  251. } else {
  252. el.disabled = false;
  253. }
  254. });
  255. this.staffList = [...this.staffList, ...list];
  256. // this.pageNum = res.pageNum;
  257. },
  258. //查询更多员工
  259. async getMore() {
  260. this.pageNum = this.pageNum + 1;
  261. let params = {
  262. pageNum:this.pageNum,
  263. size: this.size,
  264. groupId: this.form.groupId
  265. };
  266. this.getStaffList(params);
  267. },
  268. //选择员工
  269. choiceAsset(info) {
  270. let data = JSON.parse(JSON.stringify(info));
  271. if (info.teamId &&this.type!='bpm') {
  272. this.$confirm('当前员工已有所属班组, 是否继续?', '提示', {
  273. confirmButtonText: '确定',
  274. cancelButtonText: '取消',
  275. type: 'warning'
  276. })
  277. .then(() => {
  278. this.selectStafflist.push(data);
  279. info.disabled = true;
  280. })
  281. .catch(() => {});
  282. } else {
  283. this.selectStafflist.push(data);
  284. info.disabled = true;
  285. }
  286. },
  287. //删除已选员工
  288. deleteSelectStaff(info, index) {
  289. this.staffList.forEach((el) => {
  290. if (el.id == info.id) {
  291. el.disabled = false;
  292. }
  293. });
  294. this.selectStafflist.splice(index, 1);
  295. },
  296. //保存
  297. sumbit() {
  298. if (this.selectStafflist.length === 0) {
  299. this.$message.warning('请选择员工');
  300. } else {
  301. this.$emit('confirm', JSON.parse(JSON.stringify(this.selectStafflist)));
  302. this.handleClose();
  303. }
  304. },
  305. handleClose() {
  306. this.staffList = [];
  307. this.selectStafflist = [];
  308. this.dialogVisible = false;
  309. }
  310. }
  311. };
  312. </script>
  313. <style lang="scss" scoped>
  314. .container {
  315. padding: 10px 0;
  316. }
  317. .zw-container {
  318. height: 500px;
  319. overflow-y: auto;
  320. }
  321. .zw-header-title {
  322. display: inline-block;
  323. margin-right: 10px;
  324. font-weight: 600;
  325. }
  326. .details-title {
  327. line-height: 32px;
  328. height: 32px;
  329. }
  330. .zw-page-list-p {
  331. font-size: 14px;
  332. margin-bottom: 18px;
  333. display: flex;
  334. justify-content: space-between;
  335. // align-items: center;
  336. .zw-page-list-right {
  337. display: flex;
  338. }
  339. }
  340. .zw-page {
  341. background: #fff;
  342. //padding: 20px 0;
  343. height: 600px;
  344. .zw-page-left {
  345. padding: 0 10px;
  346. }
  347. .zw-page-main {
  348. padding: 0 10px;
  349. .zw-page-main-list {
  350. span {
  351. margin-right: 10px;
  352. }
  353. .zw-page-span-num {
  354. font-size: 12px;
  355. color: #157a2c;
  356. }
  357. .zw-page-p-operation {
  358. text-align: right;
  359. // width: 200px;
  360. }
  361. .zw-page-operation-num {
  362. width: 100px;
  363. margin: 0 10px;
  364. }
  365. }
  366. .zw-page-list-more {
  367. text-align: center;
  368. }
  369. }
  370. .zw-page-right {
  371. .zw-card-header {
  372. display: flex;
  373. justify-content: space-between;
  374. align-items: center;
  375. height: 32px;
  376. }
  377. span {
  378. margin-right: 10px;
  379. }
  380. .zw-page-span-num {
  381. font-size: 12px;
  382. color: #157a2c;
  383. }
  384. }
  385. }
  386. .notes {
  387. font-size: 12px;
  388. color: #909090;
  389. }
  390. </style>