staffSelection.vue 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406
  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. factoryId:String,
  193. },
  194. created() {},
  195. methods: {
  196. open(selectedList) {
  197. this.dialogVisible = true;
  198. this.selectStafflist = selectedList;
  199. this.getInfo();
  200. },
  201. //初始数据
  202. async getInfo() {
  203. let list = await listOrganizations();
  204. this.treeList = this.$util.toTreeData({
  205. data: list,
  206. idField: 'id',
  207. parentIdField: 'parentId'
  208. });
  209. this.$nextTick(()=>{
  210. this.handleNodeClick(this.treeList[0])
  211. this.$refs.tree.setCurrentKey(this.treeList[0].id)
  212. })
  213. //this.treeList = res.data;
  214. },
  215. //选择分类
  216. handleNodeClick(data) {
  217. this.currentData = data
  218. this.staffList = [];
  219. this.form.groupId = data.id;
  220. let params = {
  221. pageNum: 1,
  222. size: this.size,
  223. groupId: this.form.groupId,
  224. // hasAccount:this.hasAccount
  225. };
  226. this.getStaffList(params);
  227. },
  228. changeUserName() {
  229. this.staffList = [];
  230. this.form.groupId = this.currentData.id;
  231. let params = {
  232. pageNum: 1,
  233. size: this.size,
  234. groupId: this.form.groupId,
  235. name: this.userName
  236. };
  237. this.getStaffList(params);
  238. },
  239. //获取员工列表
  240. async getStaffList(params) {
  241. console.log(this.factoryId,'factoryId')
  242. if(this.factoryId){
  243. params['factoryId']=this.factoryId
  244. }
  245. let res = await getUserPage(params);
  246. let list = res.list;
  247. if (list.length < res.count) {
  248. this.isMore = true;
  249. } else {
  250. this.isMore = false;
  251. }
  252. list.forEach((el) => {
  253. let _index = this.selectStafflist.findIndex((n) => n.id == el.id);
  254. if (_index !== -1) {
  255. el.disabled = true;
  256. } else {
  257. el.disabled = false;
  258. }
  259. });
  260. this.staffList = [...this.staffList, ...list];
  261. // this.pageNum = res.pageNum;
  262. },
  263. //查询更多员工
  264. async getMore() {
  265. this.pageNum = this.pageNum + 1;
  266. let params = {
  267. pageNum:this.pageNum,
  268. size: this.size,
  269. groupId: this.form.groupId
  270. };
  271. this.getStaffList(params);
  272. },
  273. //选择员工
  274. choiceAsset(info) {
  275. let data = JSON.parse(JSON.stringify(info));
  276. if (info.teamId &&this.type!='bpm') {
  277. this.$confirm('当前员工已有所属班组, 是否继续?', '提示', {
  278. confirmButtonText: '确定',
  279. cancelButtonText: '取消',
  280. type: 'warning'
  281. })
  282. .then(() => {
  283. this.selectStafflist.push(data);
  284. info.disabled = true;
  285. })
  286. .catch(() => {});
  287. } else {
  288. this.selectStafflist.push(data);
  289. info.disabled = true;
  290. }
  291. },
  292. //删除已选员工
  293. deleteSelectStaff(info, index) {
  294. this.staffList.forEach((el) => {
  295. if (el.id == info.id) {
  296. el.disabled = false;
  297. }
  298. });
  299. this.selectStafflist.splice(index, 1);
  300. },
  301. //保存
  302. sumbit() {
  303. if (this.selectStafflist.length === 0) {
  304. this.$message.warning('请选择员工');
  305. } else {
  306. this.$emit('confirm', JSON.parse(JSON.stringify(this.selectStafflist)));
  307. this.handleClose();
  308. }
  309. },
  310. handleClose() {
  311. this.staffList = [];
  312. this.selectStafflist = [];
  313. this.dialogVisible = false;
  314. }
  315. }
  316. };
  317. </script>
  318. <style lang="scss" scoped>
  319. .container {
  320. padding: 10px 0;
  321. }
  322. .zw-container {
  323. height: 500px;
  324. overflow-y: auto;
  325. }
  326. .zw-header-title {
  327. display: inline-block;
  328. margin-right: 10px;
  329. font-weight: 600;
  330. }
  331. .details-title {
  332. line-height: 32px;
  333. height: 32px;
  334. }
  335. .zw-page-list-p {
  336. font-size: 14px;
  337. margin-bottom: 18px;
  338. display: flex;
  339. justify-content: space-between;
  340. // align-items: center;
  341. .zw-page-list-right {
  342. display: flex;
  343. }
  344. }
  345. .zw-page {
  346. background: #fff;
  347. //padding: 20px 0;
  348. height: 600px;
  349. .zw-page-left {
  350. padding: 0 10px;
  351. }
  352. .zw-page-main {
  353. padding: 0 10px;
  354. .zw-page-main-list {
  355. span {
  356. margin-right: 10px;
  357. }
  358. .zw-page-span-num {
  359. font-size: 12px;
  360. color: #157a2c;
  361. }
  362. .zw-page-p-operation {
  363. text-align: right;
  364. // width: 200px;
  365. }
  366. .zw-page-operation-num {
  367. width: 100px;
  368. margin: 0 10px;
  369. }
  370. }
  371. .zw-page-list-more {
  372. text-align: center;
  373. }
  374. }
  375. .zw-page-right {
  376. .zw-card-header {
  377. display: flex;
  378. justify-content: space-between;
  379. align-items: center;
  380. height: 32px;
  381. }
  382. span {
  383. margin-right: 10px;
  384. }
  385. .zw-page-span-num {
  386. font-size: 12px;
  387. color: #157a2c;
  388. }
  389. }
  390. }
  391. .notes {
  392. font-size: 12px;
  393. color: #909090;
  394. }
  395. </style>