staffSelection.vue 11 KB

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