EmployeeSelector.vue 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567
  1. <template>
  2. <div style=" background-color: #fff;">
  3. <el-row :gutter="15" style="border:1px solid #eee;">
  4. <el-col :span="24" style="margin-bottom:0; border-bottom:1px solid #eee;">
  5. <div style="margin-bottom:0; padding:15px;" class="inline-block-btn-list">
  6. <div class="gap-right-8" style="display:inline-block; width:100%; margin-bottom:0;">
  7. <el-input
  8. placeholder="输入关键词查找"
  9. ref="search-bar"
  10. v-model="filter.keywords"
  11. class="input-with-select"
  12. @keyup.enter.native="onFilterChanged"
  13. >
  14. <el-button slot="append" icon="el-icon-search" @click="onFilterChanged"></el-button>
  15. </el-input>
  16. </div>
  17. </div>
  18. </el-col>
  19. <el-col :span="6" style="margin-bottom:0;">
  20. <div style="padding:15px; padding-left:0; padding-right:0;">
  21. <el-scrollbar
  22. wrap-class="column-wrapper scrollable-items-container check-item-box dept_tree"
  23. :native="false"
  24. style="height: 350px;"
  25. >
  26. <a
  27. @click="handleNodeClick({value:0})"
  28. v-show="profile.manager_type > 2"
  29. :class="{on:filter.dept_id.length == 0}"
  30. style="display: block; padding:7px;"
  31. >
  32. <img src="static/images/two.png" style="width: 16px;height: 16px;vertical-align: text-bottom;margin-right: 8px;" />
  33. 所有部门
  34. </a>
  35. <!-- <el-tree
  36. ref="dept_tree_com"
  37. highlight-current
  38. :default-expand-all="true"
  39. :expand-on-click-node="false"
  40. :data="deptTree"
  41. img="static/images/one.jpg"
  42. @node-click="handleNodeClick"
  43. ></el-tree> -->
  44. <el-tree :data="deptTree" highlight-current :expand-on-click-node="false" node-key="id" default-expand-all @node-click="handleNodeClick">
  45. <span class="custom-tree-node" slot-scope="{ node, data }">
  46. <span >
  47. <img v-if="data.children.length!=0" src="static/images/one.png" style="width: 16px;height: 216x;vertical-align: text-bottom;margin-right: 8px;" />
  48. {{data.label}}
  49. </span>
  50. </span>
  51. </el-tree>
  52. </el-scrollbar>
  53. </div>
  54. </el-col>
  55. <el-col :span="9" style="border-left:1px solid #eee; margin-bottom:0; padding-right:0;">
  56. <div style="padding:15px; padding-right:0;">
  57. <el-scrollbar
  58. wrap-class="column-wrapper scrollable-items-container dept_tree"
  59. :native="false"
  60. style="height: 350px;"
  61. >
  62. <div style="padding-right:15px;">
  63. <el-table
  64. v-loading="loading"
  65. ref="multipleTable"
  66. :data="tableData"
  67. :border="false"
  68. tooltip-effect="dark"
  69. @row-click="rowClick"
  70. @selection-change="handleSelectionChange"
  71. @select-all="select_all"
  72. style="width: 100%"
  73. >
  74. <el-table-column type="selection" width="42" :selectable="isSelectable"></el-table-column>
  75. <el-table-column prop="name" label="选择人员">
  76. <template slot-scope="scope">
  77. <div class="rank_head" style="cursor: pointer;">
  78. <img
  79. v-if="scope.row.img_url != null"
  80. v-bind:src="scope.row.img_url"
  81. width="42px"ss
  82. height="42px"
  83. >
  84. <img
  85. v-if="scope.row.img_url == null"
  86. src="static/images/head_default.png"
  87. width="42px"
  88. height="42px"
  89. >
  90. <span>
  91. {{scope.row.name}}
  92. </span>
  93. </div>
  94. </template>
  95. </el-table-column>
  96. </el-table>
  97. </div>
  98. </el-scrollbar>
  99. </div>
  100. </el-col>
  101. <el-col :span="9" style="border-left:1px solid #eee; margin-bottom:0; padding-right:0;">
  102. <div style="padding:15px; padding-right:0;">
  103. <el-scrollbar
  104. wrap-class="column-wrapper scrollable-items-container check-item-box dept_tree"
  105. :native="false"
  106. style="height: 350px;"
  107. >
  108. <div style="padding-right:15px;">
  109. <el-table
  110. @header-click="clearEmployee"
  111. :data="multipleSelection"
  112. :border="false"
  113. tooltip-effect="dark"
  114. style="width: 100%"
  115. >
  116. <el-table-column prop="name" :label="'已选择人员('+(multipleSelection.length)+'人)'">
  117. <template slot-scope="scope">
  118. <div class="rank_head" style="cursor: pointer;">
  119. <img
  120. v-if="scope.row.img_url != null"
  121. v-bind:src="scope.row.img_url"
  122. width="42px"
  123. height="42px"
  124. >
  125. <img
  126. v-if="scope.row.img_url == null"
  127. src="static/images/head_default.png"
  128. width="42px"
  129. height="42px"
  130. >
  131. {{scope.row.name}}
  132. </div>
  133. </template>
  134. </el-table-column>
  135. <el-table-column
  136. label="清空"
  137. width="50"
  138. column-key="clear"
  139. label-class-name="clearEmployeeBtn"
  140. >
  141. <template slot-scope="scope">
  142. <div class="rank_head" style="cursor: pointer; text-align: center;">
  143. <a
  144. @click="removeEmployee(scope.row.id)"
  145. class="el-icon-circle-close"
  146. style="color:#ff7d79;"
  147. ></a>
  148. </div>
  149. </template>
  150. </el-table-column>
  151. </el-table>
  152. </div>
  153. </el-scrollbar>
  154. </div>
  155. </el-col>
  156. <el-col :span="24" style="border-top:1px solid #eee; margin-bottom:0;">
  157. <el-pagination
  158. background
  159. style="margin-top:0;"
  160. :page-sizes="[10, 20, 50, 100]"
  161. layout="sizes, prev, pager, next"
  162. @size-change="handleSizeChange"
  163. :page-size="pageLimit"
  164. :total="totalCount"
  165. :current-page.sync="currentPage"
  166. @current-change="changePage"
  167. ></el-pagination>
  168. </el-col>
  169. </el-row>
  170. </div>
  171. </template>
  172. <script>
  173. export default {
  174. // multipleSelectionId
  175. props: {
  176. employeeSelectorIds: {
  177. type: Array,
  178. default: () => {return []}
  179. },
  180. include_admin: {
  181. type: Boolean,
  182. default: false
  183. },
  184. },
  185. watch: {
  186. tableData(val) {
  187. this.$nextTick(() => {
  188. this.pageSelectedId = []
  189. val.forEach(item => {
  190. if (this.employeeSelectorIds.indexOf(item.id) >= 0) {
  191. this.$refs['multipleTable'].toggleRowSelection(item, true)
  192. this.pageSelectedId.push(item.id)
  193. }
  194. })
  195. })
  196. },
  197. employeeSelectorIds(val) {
  198. this.$nextTick(() => {
  199. if (!this.tableData) { return }
  200. this.pageSelectedId = []
  201. this.tableData.forEach(item => {
  202. this.$refs['multipleTable'].toggleRowSelection(item, false)
  203. if (val.indexOf(item.id) >= 0) {
  204. this.$refs['multipleTable'].toggleRowSelection(item, true)
  205. this.pageSelectedId.push(item.id)
  206. }
  207. })
  208. })
  209. }
  210. },
  211. data() {
  212. return {
  213. loading: false,
  214. profile: this.$store.getters.user_info,
  215. accessEnabled: false,
  216. dialogTableVisible: false,
  217. filter: {
  218. dept_id: [],
  219. status: 1,
  220. keywords: ''
  221. },
  222. totalCount: 0,
  223. pageLimit: 6,
  224. currentPage: 1,
  225. tableData: null,
  226. multipleSelection: [],
  227. multipleSelectionId: [],
  228. multipleSelectionJson: {},
  229. pageSelectedId: [],
  230. dialogExcelVisible: false,
  231. deptTree: [],
  232. creatorId: '',
  233. department_list: []
  234. }
  235. },
  236. methods: {
  237. clearChild(column, event) {
  238. const self = this
  239. if (column == 'clear') {
  240. console.log("jinlail")
  241. for (const i in this.tableData) {
  242. self.$refs['multipleTable'].toggleRowSelection(
  243. self.tableData[i],
  244. false
  245. )
  246. }
  247. this.multipleSelectionId = []
  248. this.multipleSelectionJson = {}
  249. this.multipleSelection = []
  250. this.pageSelectedId = []
  251. }
  252. },
  253. clearEmployee(column, event) {
  254. const self = this
  255. if (column.columnKey == 'clear') {
  256. console.log("jinlail")
  257. for (const i in this.tableData) {
  258. self.$refs['multipleTable'].toggleRowSelection(
  259. self.tableData[i],
  260. false
  261. )
  262. }
  263. this.multipleSelectionId = []
  264. this.multipleSelectionJson = {}
  265. this.multipleSelection = []
  266. this.pageSelectedId = []
  267. }
  268. },
  269. removeEmployee(id) {
  270. console.log("kkkkkkkkkkkkkkkkkkkkkkk")
  271. let self = this
  272. const multipleSelectionId = []
  273. const multipleSelectionJson = {}
  274. const multipleSelection = []
  275. const pageSelectedId = []
  276. for (const i in this.tableData) {
  277. if (this.tableData[i].id == id) {
  278. this.$refs['multipleTable'].toggleRowSelection(
  279. this.tableData[i],
  280. false
  281. )
  282. }
  283. }
  284. for (const i in this.multipleSelection) {
  285. if (this.multipleSelection[i].id != id) {
  286. multipleSelection.push(this.multipleSelection[i])
  287. multipleSelectionJson[
  288. this.multipleSelection[i].id
  289. ] = this.multipleSelection[i]
  290. multipleSelectionId.push(this.multipleSelection[i].id)
  291. }
  292. }
  293. this.multipleSelectionId = multipleSelectionId
  294. this.multipleSelectionJson = multipleSelectionJson
  295. this.multipleSelection = multipleSelection
  296. self.$nextTick(() => {
  297. self.$emit('check', self.multipleSelection)
  298. // self.$parent.$parent.$parent.$parent.set_target_ids(self.multipleSelection)
  299. })
  300. },
  301. handleNodeClick(data) {
  302. if (data.value == 0) {
  303. this.loadBaseData()
  304. this.filter.dept_id = []
  305. } else {
  306. this.filter.dept_id = [data.value]
  307. }
  308. this.onFilterChanged()
  309. },
  310. handleSizeChange(val) {
  311. this.pageLimit = val
  312. this.onFilterChanged()
  313. },
  314. onFilterChanged: function() {
  315. this.currentPage = 1
  316. this.loadEmployeeList()
  317. },
  318. toggleSelection: function(rows) {
  319. if (rows) {
  320. rows.forEach(row => {
  321. this.$refs.multipleTable.toggleRowSelection(row)
  322. })
  323. } else {
  324. this.$refs.multipleTable.clearSelection()
  325. }
  326. },
  327. select_all(all) {
  328. const ids = []
  329. for (const i in all) {
  330. ids.push(all[i].id)
  331. }
  332. },
  333. handleSelectionChange: function(val) {
  334. // console.log(this.multipleSelectionId)
  335. const ids = []
  336. for (const i in val) {
  337. ids.push(val[i].id)
  338. }
  339. for (const i in val) {
  340. if (this.multipleSelectionId.indexOf(val[i].id) < 0) {
  341. this.multipleSelectionId.push(val[i].id)
  342. this.multipleSelectionJson[val[i].id] = val[i]
  343. this.multipleSelection.push(val[i])
  344. }
  345. if (this.pageSelectedId.indexOf(val[i].id) < 0) {
  346. this.pageSelectedId.push(val[i].id)
  347. }
  348. }
  349. const ids_cancel = []
  350. if (this.pageSelectedId.length > ids.length) {
  351. // 之前被选择的数量比现在的数量多,说明有一些被取消了选择
  352. // 求出这些被取消的选择id
  353. for (const i in this.pageSelectedId) {
  354. if (ids.indexOf(this.pageSelectedId[i]) < 0) {
  355. ids_cancel.push(this.pageSelectedId[i])
  356. }
  357. }
  358. this.pageSelectedId = ids
  359. }
  360. if (ids_cancel.length > 0) {
  361. const multipleSelectionId = []
  362. const multipleSelection = []
  363. const multipleSelectionJson = {}
  364. for (const i in this.multipleSelectionId) {
  365. if (ids_cancel.indexOf(this.multipleSelectionId[i]) < 0) {
  366. multipleSelectionId.push(this.multipleSelectionId[i])
  367. }
  368. }
  369. this.multipleSelectionId = multipleSelectionId
  370. for (const i in this.multipleSelection) {
  371. if (ids_cancel.indexOf(this.multipleSelection[i].id) < 0) {
  372. multipleSelection.push(this.multipleSelection[i])
  373. }
  374. }
  375. this.multipleSelection = multipleSelection
  376. for (const i in this.multipleSelection) {
  377. multipleSelectionJson[i] = this.multipleSelection[i]
  378. }
  379. this.multipleSelectionJson = multipleSelectionJson
  380. }
  381. const self = this
  382. self.$nextTick(() => {
  383. self.$emit('check', self.multipleSelection)
  384. // self.$parent.$parent.$parent.$parent.set_target_ids(self.multipleSelection)
  385. })
  386. },
  387. rowClick(row, event, column) {
  388. this.$refs['multipleTable'].toggleRowSelection(row)
  389. },
  390. isSelectable: function(row, index) {
  391. return true
  392. },
  393. toSexName: function(row, column, cellValue) {
  394. return cellValue == '1' ? '女' : '男'
  395. },
  396. dateFormatter: function(row, column, cellValue) {
  397. return this.$moment(cellValue * 1000).format('YYYY年MM月DD日')
  398. },
  399. // 获取基本数据
  400. loadBaseData: function() {
  401. var self = this
  402. this.$http('get','/integral.php/ajax_request_common/prepare_integral_options', {
  403. id: this.profile.id,
  404. category_tree: 1,
  405. dept_tree: 1})
  406. .then(function(response) {
  407. if (response.status == 200) {
  408. var jsonData = response.data
  409. try {
  410. self.deptTree = jsonData.dept_tree
  411. self.creatorId = jsonData.creator_id
  412. if (self.profile.manager_type < 2) {
  413. self.filter.dept_id = [self.deptTree[0].value]
  414. self.loadEmployeeList()
  415. }
  416. } catch (err) {
  417. console.log(err)
  418. }
  419. }
  420. })
  421. .catch(function(error) {
  422. console.log(error)
  423. })
  424. },
  425. // 获取员工列表
  426. loadEmployeeList: function() {
  427. var self = this
  428. self.loading = true
  429. const params = {
  430. site_id: this.$store.getters.site_id,
  431. page: this.currentPage,
  432. interval: this.pageLimit
  433. }
  434. for (const item in this.filter) {
  435. const value = this.filter[item]
  436. if (item == 'dept_id') {
  437. if (!value || value.length == 0) {
  438. continue
  439. }
  440. params[item] = value[value.length - 1]
  441. } else {
  442. const valueStr = value.toString()
  443. if (valueStr && valueStr.length > 0) {
  444. params[item] = valueStr
  445. }
  446. }
  447. }
  448. if(self.include_admin){
  449. params['include_admin'] = 1
  450. }
  451. this.$http('get','/integral.php/ajax_request_common/get_employee_list',params)
  452. .then(function(response) {
  453. if (response.status == 200) {
  454. self.loading = false
  455. var jsonData = response.data
  456. try {
  457. self.department_list = jsonData.filter_list.department
  458. self.totalCount = jsonData.total_count
  459. self.tableData = jsonData.list_data
  460. self.pageSelectedId = []
  461. const pageSelectedId = []
  462. self.$nextTick(() => {
  463. // console.log(self.multipleSelectionId)
  464. for (const i in jsonData.list_data) {
  465. // console.log(self.multipleSelectionId.indexOf(jsonData.list_data[i].id),jsonData.list_data[i].id,self.multipleSelectionJson[jsonData.list_data[i].id])
  466. if (
  467. self.multipleSelectionId.indexOf(
  468. jsonData.list_data[i].id
  469. ) >= 0
  470. ) {
  471. self.$refs['multipleTable'].toggleRowSelection(
  472. self.tableData[i],
  473. true
  474. )
  475. pageSelectedId.push(self.tableData[i].id)
  476. }
  477. }
  478. self.pageSelectedId = pageSelectedId
  479. })
  480. } catch (err) {
  481. console.log(err)
  482. }
  483. }
  484. })
  485. .catch(function(error) {
  486. console.log(error)
  487. })
  488. },
  489. changePage: function(current) {
  490. if (isNaN(current) || current < 1) {
  491. return false
  492. }
  493. this.loadEmployeeList()
  494. }
  495. },
  496. created() {
  497. console.log(this.profile)
  498. this.loadBaseData()
  499. if (this.profile.manager_type > 1) {
  500. this.loadEmployeeList()
  501. }
  502. }
  503. }
  504. </script>
  505. <style scoped>
  506. .el-pagination {
  507. text-align: center;
  508. margin-top: 15px;
  509. }
  510. .dept_tree a.on {
  511. background-color: #f0f7ff;
  512. }
  513. .clearEmployeeBtn {
  514. cursor: pointer;
  515. color: #409eff;
  516. font-weight: normal;
  517. }
  518. .clearEmployeeBtn:hover {
  519. color: #66b1ff;
  520. }
  521. .rank_head img {
  522. width: 30px;
  523. height: 30px;
  524. -webkit-border-radius: 20px;
  525. -moz-border-radius: 20px;
  526. border-radius: 20px;
  527. margin-right: 5px;
  528. }
  529. .rank_head * {
  530. vertical-align: middle;
  531. }
  532. </style>