personnel.vue 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705
  1. <template>
  2. <div>
  3. <el-container>
  4. <div class="block-l">
  5. <el-card shadow="hover">
  6. <div class="left_list">
  7. <el-row>
  8. <span style="padding-left: 25px;" v-if="dialogfrom=='message'">应急通讯录</span>
  9. <span style="padding-left: 25px;" v-else>联动通讯录</span>
  10. <el-link v-if="dialogfrom!='index'&&dialogfrom!='message'" :underline="false" style="margin:0 20px;" type="primary" @click="addOrg()">添加组织</el-link>
  11. <el-link :underline="false" type="primary" @click="confirmOutput()" v-if="dialogfrom!='message'">导出</el-link>
  12. </el-row>
  13. <div>
  14. <el-tree
  15. ref="selectTree"
  16. :data="orgData"
  17. accordion
  18. node-key="id"
  19. @node-click="setOrgId"
  20. >
  21. <span slot-scope="{ node, data }" class="custom-tree-node">
  22. <span>
  23. <i v-if="data.level == 0" class="el-icon-s-home" />
  24. <i v-else-if="data.level == 1" class="el-icon-menu" />
  25. <i v-else class="el-icon-link" />
  26. {{ node.label }}
  27. </span>
  28. &nbsp; &nbsp;
  29. <div v-if="data.show == true&&dialogfrom!='index'&&dialogfrom!='message'" style="display: inline-block;float: right;position: absolute;right: 2%;" width="100" >
  30. <el-link :underline="false" size="mini" style="float: right" type="danger" @click="removeOrg(data)">&nbsp;删除&nbsp;</el-link>
  31. &nbsp; &nbsp;
  32. <el-link :underline="false" size="mini" style="float: right" type="primary" @click="editOrg(data)">&nbsp;修改&nbsp;</el-link>
  33. </div>
  34. <span v-if="data.level == 0">
  35. <el-link class="space" type="primary" @click="() => unFoldAll()">展开</el-link>
  36. <el-link class="space" type="primary" @click="() => collapseAll()">折叠</el-link>
  37. </span>
  38. </span>
  39. </el-tree>
  40. </div>
  41. </div>
  42. </el-card>
  43. </div>
  44. <el-container>
  45. <el-header style="height: 85px">
  46. <div style="width: 100%;text-align: center;margin-top: 20px">
  47. <span style="font-size: 25px;">
  48. &nbsp;{{ orgName }}
  49. </span>
  50. </div>
  51. <el-button v-if="dialogfrom!='index'&&dialogfrom!='message'" class="ch-button" size="small" style="float: right; margin-top: 4px" @click="handleAdd()">
  52. <i class="el-icon-menu" />&nbsp;新增
  53. </el-button>
  54. </el-header>
  55. <el-main>
  56. <el-row class="handle-box">
  57. <el-col :span="24" style="position: relative;">
  58. <el-checkbox ref="checkAll" v-model="pageChecked" @change="checkedChange" :indeterminate="isIndeterminate" class="selectAll" v-if="AllData.length>0&&dialogfrom=='message'"></el-checkbox>
  59. <el-table
  60. v-loading="loading"
  61. :data="AllData" :max-height="tableMax"
  62. row-class-name="g_table_row"
  63. stripe class="schemeIn"
  64. ref="mListTable"
  65. @select="handleSelectionChange" @select-all="selectAll"
  66. >
  67. <el-table-column label="序号" type="index" width="60" />
  68. <el-table-column v-if="false" prop="id" />
  69. <el-table-column v-if="false" prop="orgId" />
  70. <el-table-column label="姓名" prop="name" />
  71. <el-table-column label="部门" prop="department" />
  72. <el-table-column label="岗位" prop="post" />
  73. <el-table-column label="联系方式" prop="phone" />
  74. <el-table-column fixed="left" type="selection" width="55" v-if="dialogfrom=='message'"/>
  75. <el-table-column v-if="dialogfrom!='index'&&dialogfrom!='message'" align="center" header-align="center" label="操作" width="150">
  76. <template scope="scope">
  77. <el-link :underline="false" size="mini" type="primary" @click="handleEdit(scope.row)"> 修改&nbsp; </el-link>
  78. <el-link :underline="false" size="mini" type="primary" @click="handleDel(scope.row)"> 删除&nbsp; </el-link>
  79. </template>
  80. </el-table-column>
  81. </el-table>
  82. <div class="table-page">
  83. <el-pagination
  84. :current-page.sync="currentPage"
  85. :page-size="pageSize"
  86. :total="allpage"
  87. background
  88. layout="total, prev, pager, next"
  89. @current-change="handleCurrentChange"
  90. />
  91. </div>
  92. </el-col>
  93. </el-row>
  94. </el-main>
  95. <el-footer />
  96. </el-container>
  97. </el-container>
  98. <!--组织-->
  99. <el-dialog v-dialogDrag
  100. :append-to-body="true"
  101. :modal-append-to-body="true"
  102. :title="dialogTitleOrg"
  103. :visible.sync="dialogVisibleOrg"
  104. style="text-align: left"
  105. top="50px" class="statistic_base"
  106. width="50%"
  107. >
  108. <el-form ref="formOrg" :model="formOrg" :rules="rulesOrg" style="width: 100%; padding: 5px">
  109. <el-row>
  110. <el-col style="padding-bottom: 10px">
  111. <!-- <span class="card_title">基本信息</span> -->
  112. <el-card shadow="always" style="padding: 15px 5px 5px 15px">
  113. <el-row>
  114. <el-col :span="3" class="col-txt">
  115. <span class="span_red">*</span>
  116. <span>组织名称</span>
  117. </el-col>
  118. <el-col :span="20" class="col-input">
  119. <el-form-item prop="name">
  120. <el-input v-model="formOrg.name" />
  121. </el-form-item>
  122. </el-col>
  123. </el-row>
  124. </el-card>
  125. </el-col>
  126. </el-row>
  127. </el-form>
  128. <div slot="footer">
  129. <el-button @click="dialogVisibleOrg = false">取 消</el-button>
  130. <el-button type="primary" @click="confirmSubmitOrg()">确 定</el-button>
  131. </div>
  132. </el-dialog>
  133. <!--人员-->
  134. <el-dialog v-dialogDrag
  135. :append-to-body="true"
  136. :modal-append-to-body="true"
  137. :title="dialogTitle"
  138. :visible.sync="dialogVisible"
  139. style="text-align: left"
  140. top="50px" class="statistic_base"
  141. width="75%"
  142. @open="dlgOpen"
  143. >
  144. <el-form ref="form" :model="form" :rules="rules" style="width: 100%; padding: 5px">
  145. <el-row>
  146. <el-col style="padding-bottom: 10px">
  147. <!-- <span class="card_title">基本信息</span> -->
  148. <el-card shadow="always" style="padding: 15px 5px 5px 15px">
  149. <el-row>
  150. <el-col :span="3" class="col-txt">
  151. <span>组织名称</span>
  152. </el-col>
  153. <el-col :span="10" class="col-input">
  154. {{ form.orgName }}
  155. </el-col>
  156. </el-row>
  157. <el-row>
  158. <el-col :span="3" class="col-txt">
  159. <span class="span_red">*</span>
  160. <span>姓名</span>
  161. </el-col>
  162. <el-col :span="20" class="col-input">
  163. <el-form-item prop="name">
  164. <el-input v-model="form.name" />
  165. </el-form-item>
  166. </el-col>
  167. </el-row>
  168. <el-row>
  169. <el-col :span="3" class="col-txt">
  170. <span>部门</span>
  171. </el-col>
  172. <el-col :span="20" class="col-input">
  173. <el-form-item prop="department">
  174. <el-input v-model="form.department" />
  175. </el-form-item>
  176. </el-col>
  177. </el-row>
  178. <el-row>
  179. <el-col :span="3" class="col-txt">
  180. <span>岗位</span>
  181. </el-col>
  182. <el-col :span="20" class="col-input">
  183. <el-form-item prop="post">
  184. <el-input v-model="form.post" />
  185. </el-form-item>
  186. </el-col>
  187. </el-row>
  188. <el-row>
  189. <el-col :span="3" class="col-txt">
  190. <span class="span_red">*</span>
  191. <span>联系方式</span>
  192. </el-col>
  193. <el-col :span="20" class="col-input">
  194. <el-form-item prop="phone">
  195. <el-input v-model="form.phone" />
  196. </el-form-item>
  197. </el-col>
  198. </el-row>
  199. </el-card>
  200. </el-col>
  201. </el-row>
  202. </el-form>
  203. <div slot="footer">
  204. <el-button @click="dialogVisible = false">取 消</el-button>
  205. <el-button type="primary" @click="confirmSubmit()">确 定</el-button>
  206. </div>
  207. </el-dialog>
  208. </div>
  209. </template>
  210. <script>
  211. import Base from '@/views/base/base'
  212. import BaseData from '@/views/base/baseData'
  213. import '../../assets/drag'
  214. export default {
  215. name: 'Personnel',
  216. components: {},
  217. mixins: [Base, BaseData],
  218. props: ['dialogfrom'],
  219. data() {
  220. return {
  221. // 列表相关
  222. search: {},
  223. AllData: [],
  224. orgData: [],
  225. loading: false,
  226. loadingOrg: false,
  227. // 弹框相关
  228. dialogVisible: false,
  229. dialogTitle: '',
  230. dialogVisibleOrg: false,
  231. dialogTitleOrg: '',
  232. isAdd: true,
  233. isAddOrg: true,
  234. form: this.initForm(),
  235. formOrg: this.initFormOrg(),
  236. rules: {
  237. name: [{ required: true, message: '请填写姓名', trigger: 'blur' }],
  238. phone: [{ required: true, message: '请填写联系方式', trigger: 'blur' },
  239. {
  240. validator: function(rule, value, callback) {
  241. if (/^(13[0-9]|14[0-9]|15[0-9]|16[6]|18[0-9]|19[6,9]|17[0-9])\d{8}$/i.test(value) === false) {
  242. callback(new Error('请输入正确的手机号'))
  243. } else {
  244. // 校验通过
  245. callback()
  246. }
  247. },
  248. trigger: 'blur'
  249. }]
  250. },
  251. rulesOrg: {
  252. name: [{ required: true, message: '请填写组织名称', trigger: 'blur' }]
  253. },
  254. orgId: '',
  255. orgName: '',
  256. defaultProps: {
  257. children: 'children',
  258. label: 'label'
  259. },
  260. saveCheckList: [],
  261. pageChecked:false,
  262. isIndeterminate:false,
  263. }
  264. },
  265. watch:{
  266. saveCheckList(val){
  267. this.$emit('getUser',val)
  268. }
  269. },
  270. mounted() {
  271. console.log(this.dialogfrom)
  272. this.getOrgDate()
  273. },
  274. methods: {
  275. handleSelectionChange(selection,row){
  276. console.log("selection", selection);
  277. // 从保存项saveCheckList里面寻找,如果找到了row则删除,如果没找到则添加
  278. let fitemIndex = this.saveCheckList.findIndex((item) => {
  279. return item.id == row.id;
  280. });
  281. if (fitemIndex < 0) {
  282. this.saveCheckList.push(row);
  283. } else {
  284. this.saveCheckList.splice(fitemIndex, 1);
  285. }
  286. console.log("this.saveCheckList", this.saveCheckList);
  287. },
  288. selectAll(val){
  289. console.log("selectAll", val);
  290. // 如果为空,则为清除选项状态,此时将table中的所有内容都从saveCheckList移除
  291. if (val && val.length == 0) {
  292. this.AllData.forEach((row) => {
  293. // 从保存项saveCheckList里面寻找,如果找到了row则删除,如果没找到则添加
  294. let fitemIndex = this.saveCheckList.findIndex((item) => {
  295. return item.id == row.id;
  296. });
  297. // 找到了就删除掉
  298. if (fitemIndex >= 0) {
  299. this.saveCheckList.splice(fitemIndex, 1);
  300. }
  301. });
  302. } else if (val && val.length != 0 && this.saveCheckList.length != 0) {
  303. // 如果不为空,且this.saveCheckList也不为空则从val里面找
  304. val.forEach((row) => {
  305. // 从保存项saveCheckList里面寻找,如果找到了row则删除,如果没找到则添加
  306. let fitemIndex = this.saveCheckList.findIndex((item) => {
  307. return item.id == row.id;
  308. });
  309. // 没找到就push进去
  310. if (fitemIndex < 0) {
  311. this.saveCheckList.push(row);
  312. }
  313. });
  314. } else if (val && val.length != 0 && this.saveCheckList.length == 0) {
  315. val.forEach((row) => {
  316. this.saveCheckList.push(row);
  317. });
  318. }
  319. },
  320. checkedChange(val){
  321. // 全选操作
  322. if (this.pageChecked) {
  323. // 调用接口查询所有的列表数据并且保存起来
  324. this.baseRequest('listAll', this.search).then(res=>{
  325. // console.log(res)
  326. this.saveCheckList=res.data
  327. this.$nextTick(() => {
  328. this.$refs["mListTable"].clearSelection();
  329. this.$refs["mListTable"].toggleAllSelection();
  330. });
  331. console.log("this.saveCheckList", this.saveCheckList);
  332. })
  333. } else {
  334. // 取消全选,当前所有选择项清空
  335. this.saveCheckList = [];
  336. // 将当前的页的所有内容取消勾选状态
  337. this.$nextTick(() => {
  338. this.$refs["mListTable"].clearSelection();
  339. });
  340. console.log("this.saveCheckList", this.saveCheckList);
  341. }
  342. },
  343. checkPageStatus(tableList) {
  344. tableList.forEach((row) => {
  345. let findex = this.saveCheckList.findIndex((item) => {
  346. return item.id == row.id;
  347. });
  348. // console.log("checkPageStatus", findex);
  349. if (findex >= 0) {
  350. this.$nextTick(() => {
  351. this.$refs["mListTable"].toggleRowSelection(row);
  352. });
  353. }
  354. });
  355. },
  356. getData: function() {
  357. const _this = this
  358. _this.loading = true
  359. _this.AllData = []
  360. this.search.pageNum = this.currentPage
  361. this.search.pageSize = this.pageSize
  362. this.baseRequest('list', this.search)
  363. .then((res) => {
  364. if (res.data.rows) {
  365. res.data.rows.forEach(function(item) {
  366. const json = _this.getItemJson(item)
  367. _this.AllData.push(json)
  368. })
  369. _this.allpage = res.data.total
  370. this.checkPageStatus(this.AllData);
  371. }
  372. _this.loading = false
  373. })
  374. .catch(() => {
  375. })
  376. },
  377. getOrgDate: function() {
  378. const _this = this
  379. _this.loadingOrg = true
  380. _this.orgData = []
  381. this.baseRequest('listAllOrg', this.search)
  382. .then((res) => {
  383. if (res.data) {
  384. res.data.forEach(function(item) {
  385. _this.orgData.push(
  386. {
  387. orgId: item.id,
  388. name: item.name,
  389. label: item.name,
  390. show: false
  391. }
  392. )
  393. })
  394. }
  395. _this.loadingOrg = false
  396. })
  397. .catch(() => {
  398. })
  399. },
  400. handleSearch: function() {
  401. this.getData()
  402. },
  403. handleReset: function() {
  404. for (const i in this.search) {
  405. if (i !== 'pageNum' && i !== 'pageSize') {
  406. this.search[i] = ''
  407. }
  408. }
  409. this.handleSearch()
  410. },
  411. initOutData: function() {
  412. const _this = this
  413. this.OutData = []
  414. const title = [
  415. ' 序号', ' 组织名称', ' 姓名', ' 部门', ' 岗位', ' 联系方式'
  416. ]
  417. this.OutData.push(title)
  418. return this.baseRequest('getAllPersonnel', {})
  419. .then((res) => {
  420. if (res.data) {
  421. res.data.forEach(function(item, index) {
  422. const jsonArray = []
  423. jsonArray.push(index + 1)
  424. jsonArray.push(item.orgname)
  425. jsonArray.push(item.name)
  426. jsonArray.push(item.department)
  427. jsonArray.push(item.post)
  428. jsonArray.push(item.phone)
  429. _this.OutData.push(jsonArray)
  430. })
  431. }
  432. })
  433. .catch(() => {
  434. })
  435. },
  436. getItemJson: function(item) {
  437. return item
  438. },
  439. initForm: function() {
  440. return {
  441. id: '',
  442. orgId: '',
  443. orgName: '',
  444. name: '',
  445. department: '',
  446. post: '',
  447. phone: ''
  448. }
  449. },
  450. initFormOrg: function() {
  451. return {
  452. name: ''
  453. }
  454. },
  455. confirmOutput() {
  456. this.initOutData().then(() => {
  457. const OutSize = [
  458. { wch: 15 },
  459. { wch: 15 },
  460. { wch: 15 },
  461. { wch: 15 },
  462. { wch: 15 },
  463. { wch: 15 },
  464. { wch: 15 }
  465. ]
  466. const fileName = '联动通讯录' + new Date().Format('yyyyMMddhhmm')
  467. this.$outputXlsxFile(this.OutData, OutSize, fileName)
  468. })
  469. },
  470. dlgOpen: function() {
  471. const _this = this
  472. if (_this.form.id !== '') {
  473. const postData = {
  474. id: _this.form.id
  475. }
  476. this.baseRequest('getById', postData)
  477. .then((res) => {
  478. if (res.data) {
  479. _this.form = Object.assign({}, _this.form, res.data)
  480. }
  481. })
  482. .catch(() => {
  483. })
  484. }
  485. },
  486. /* 编辑*/
  487. handleEdit: function(val) {
  488. this.isAdd = false
  489. this.form.id = val.id
  490. this.dialogVisible = true
  491. this.dialogTitle = '修改人员'
  492. },
  493. /* 新增*/
  494. handleAdd: function() {
  495. if (this.orgName === undefined || this.orgName === null || this.orgName === '') {
  496. this.$message.error('请选择组织')
  497. return false
  498. }
  499. this.form = this.initForm()
  500. this.form.orgId = this.orgId
  501. this.form.orgName = this.orgName
  502. this.isAdd = true
  503. this.content = ''
  504. this.dialogVisible = true
  505. this.dialogTitle = '新增人员'
  506. },
  507. confirmSubmit: function() {
  508. const _this = this
  509. this.$refs.form.validate((valid) => {
  510. if (valid) {
  511. let soaUrl = 'edit'
  512. const extraData = {}
  513. const postData = Object.assign({}, _this.form, extraData)
  514. if (this.isAdd) {
  515. soaUrl = 'add'
  516. }
  517. this.opRecord(postData, soaUrl)
  518. } else {
  519. // //console.log('error submit!!')
  520. return false
  521. }
  522. })
  523. },
  524. baseRequest(opUrl, postData) {
  525. // return this.$channel.globeRequest(
  526. // 'ArchivesPersonnelController',
  527. // opUrl,
  528. // postData,
  529. // 'project'
  530. // )
  531. return this.$channel.baseRequest('ArchivesPersonnelController', opUrl, postData, 'User')
  532. },
  533. // 删除
  534. handleDel(val) {
  535. const message = '确认要删除该人员?'
  536. this.confirm(message, '提示', {
  537. confirmButtonText: '确定',
  538. cancelButtonText: '取消',
  539. type: 'warning'
  540. }).then(() => {
  541. this.baseRequest('remove/' + val.id, '')
  542. .then((res) => {
  543. this.getData()
  544. })
  545. .catch(() => {
  546. })
  547. })
  548. },
  549. addOrg() {
  550. this.formOrg = this.initForm()
  551. this.dialogTitleOrg = '新增组织'
  552. this.isAddOrg = true
  553. this.dialogVisibleOrg = true
  554. },
  555. editOrg(data) {
  556. this.formOrg.id = data.orgId
  557. this.formOrg.name = data.name
  558. this.dialogTitleOrg = '修改组织'
  559. this.isAddOrg = false
  560. this.dialogVisibleOrg = true
  561. },
  562. removeOrg(data) {
  563. const message = '确认要删除该组织?'
  564. this.confirm(message, '提示', {
  565. confirmButtonText: '确定',
  566. cancelButtonText: '取消',
  567. type: 'warning'
  568. }).then(() => {
  569. this.baseRequest('removeOrg/' + data.orgId, '')
  570. .then((res) => {
  571. this.getOrgDate()
  572. if (data.orgId === this.orgId) {
  573. this.OrgName = ''
  574. this.AllData = []
  575. }
  576. })
  577. .catch(() => {
  578. })
  579. })
  580. },
  581. setOrgId(node) {
  582. this.search = {
  583. orgId: node.orgId
  584. }
  585. this.orgName = node.name
  586. this.orgId = node.orgId
  587. node.show = true
  588. this.orgData.forEach((data) => {
  589. if (data.orgId !== node.orgId) {
  590. data.show = false
  591. }
  592. })
  593. this.getData()
  594. },
  595. confirmSubmitOrg() {
  596. const _this = this
  597. this.$refs.formOrg.validate((valid) => {
  598. if (valid) {
  599. let soaUrl = 'editOrg'
  600. const postData = Object.assign({}, _this.formOrg)
  601. if (this.isAddOrg) {
  602. soaUrl = 'addOrg'
  603. }
  604. this.opRecord(postData, soaUrl, false).then(() => {
  605. this.getOrgDate()
  606. this.dialogVisibleOrg = false
  607. })
  608. } else {
  609. // //console.log('error submit!!')
  610. return false
  611. }
  612. })
  613. }
  614. }
  615. }
  616. </script>
  617. <style lang="scss" scoped>
  618. .selectAll{
  619. position: absolute;
  620. z-index: 99;
  621. top: 17px;
  622. left: 14px;
  623. }
  624. </style>
  625. <style scoped>
  626. .block-l{
  627. width: 400px;
  628. }
  629. span.span_red {
  630. color: red;
  631. }
  632. .left_list {
  633. height: calc(100vh - 225px);
  634. width: 100%;
  635. background: white;
  636. overflow: auto;
  637. }
  638. .ch-input .el-input__inner {
  639. border-color: #32323a;
  640. }
  641. .ch-input-size {
  642. width: 150px;
  643. }
  644. .ch-button {
  645. border-color: #32323a;
  646. background-color: #32323a;
  647. color: #fff;
  648. }
  649. .ch-button-warning {
  650. margin-left: 10px;
  651. border-color: #e6a23c;
  652. background-color: #e6a23c;
  653. color: #fff;
  654. }
  655. .ch-button-export {
  656. margin-left: 10px;
  657. border-color: #98cc1f;
  658. background-color: #98cc1f;
  659. color: #fff;
  660. }
  661. /deep/ .el-tree{
  662. padding-top: 20px;
  663. }
  664. /deep/ .el-tree-node{
  665. height: 30px;
  666. }
  667. /deep/ .el-dialog__header {
  668. padding: 20px 30px 0px 30px;
  669. /* text-align: left; */
  670. }
  671. /deep/ .el-dialog__body {
  672. padding: 10px 20px;
  673. }
  674. </style>