department.vue 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542
  1. <template>
  2. <div>
  3. <el-row class="handle-box" style="margin-bottom: 10px">
  4. <el-col :span="24">
  5. <el-radio-group v-model="deptGroup" size="small" @change="initData">
  6. <el-radio-button v-for="item in GroupDataAll" :key="item.value" :label="item.value" size="small">{{ item.label }}</el-radio-button>
  7. </el-radio-group> &nbsp;&nbsp;
  8. <el-select v-model="deptAttr" clearable filterable placeholder="组织架构类型" size="small" @change="initData">
  9. <el-option v-for="item in DeptAttrDataAll" :key="item.value" :label="item.label" :value="item.value" />
  10. </el-select> &nbsp;&nbsp;
  11. <el-input v-model="deptName" class="ch-input ch-input-size" placeholder="部门名称" size="small" @keyup.enter.native="handleSearch()" /> &nbsp;&nbsp;
  12. <el-button class="ch-button" size="small" style="float: right; margin-top: 4px;margin-left: 10px;" @click="handleAdd()"><i class="el-icon-menu" />&nbsp;新增</el-button>
  13. <el-button class="ch-button-export" size="small" style="float: right; margin-top: 4px;margin-right: 10px;" @click="confirmOutput()"><i class="el-icon-download" />&nbsp;导出</el-button>
  14. <el-button class="ch-button" size="small" style="float: right; margin-top: 4px;margin-right: 10px;" @click="handleSearch()"><i class="el-icon-search" />&nbsp;搜索</el-button>
  15. <el-button class="ch-button-warning" size="small" style="float: right; margin-top: 4px;margin-right: 10px;" @click="handleReset()"><i class="el-icon-refresh" />&nbsp;重置</el-button>
  16. </el-col>
  17. </el-row>
  18. <div class="custom-tree-container">
  19. <div class="block-l">
  20. <el-card shadow="hover">
  21. <el-tag class="full space-vertical">当前所选:{{ selectDeptNode.name || '暂无' }}</el-tag>
  22. <el-tree
  23. ref="selectTree"
  24. :data="DeptTree"
  25. :default-expanded-keys="expandedDeptKey"
  26. :expand-on-click-node="expandDeptClick"
  27. :indent="deptTreeIndent"
  28. accordion
  29. node-key="id"
  30. @node-click="handleDeptNodeClick"
  31. >
  32. <span slot-scope="{ node, data }" class="custom-tree-node">
  33. <span>
  34. <i v-if="data.level == 0" class="el-icon-s-home" />
  35. <i v-else-if="data.level == 1" class="el-icon-menu" />
  36. <i v-else class="el-icon-link" />
  37. {{ node.label }}
  38. </span>
  39. <span v-if="data.level == 0">
  40. <el-link class="space" type="primary" @click="() => unFoldAll()">展开</el-link>
  41. <el-link class="space" type="primary" @click="() => collapseAll()">折叠</el-link>
  42. </span>
  43. </span>
  44. </el-tree>
  45. </el-card>
  46. </div>
  47. <div class="block-r">
  48. <el-row class="handle-box">
  49. <el-col :span="24">
  50. <el-table v-loading="loading" :data="AllData" :max-height="tableMax" row-class-name="g_table_row" stripe>
  51. <el-table-column type="index" width="60" />
  52. <el-table-column label="部门名称" prop="deptName" />
  53. <el-table-column v-if="!currGroup" align="center" header-align="center" label="所属组织" prop="groupStr" />
  54. <el-table-column align="center" header-align="center" label="组织架构类型" prop="deptAttrStr" />
  55. <el-table-column align="center" header-align="center" label="顺序号" prop="deptOrder" />
  56. <el-table-column align="center" header-align="center" label="操作" width="160">
  57. <template scope="scope">
  58. <el-link v-if="scope.row.deptLevel!==0" :underline="false" type="primary" @click="handleEdit(scope.row)">编辑&nbsp;</el-link>
  59. <el-link v-if="scope.row.deptLevel!==0" :underline="false" type="danger" @click="handleDelete(scope.row)">删除&nbsp;</el-link>
  60. </template>
  61. </el-table-column>
  62. </el-table>
  63. <div class="table-page">
  64. <el-pagination
  65. :current-page.sync="currentPage"
  66. :page-size="pageSize"
  67. :total="allpage"
  68. background
  69. layout="total, prev, pager, next"
  70. @current-change="handleCurrentChange"
  71. />
  72. </div>
  73. </el-col>
  74. </el-row>
  75. </div>
  76. </div>
  77. <el-dialog v-dialogDrag :title="dialogTitle" :visible.sync="dialogVisible" append-to-body top="50px" width="75%" @open="dlgOpen">
  78. <el-form ref="form" :model="form" :rules="rules" style="width: 100%;padding: 5px">
  79. <el-row>
  80. <el-col style="padding-bottom: 10px">
  81. <el-card shadow="always" style="padding: 15px 5px 5px 15px">
  82. <el-row>
  83. <el-col :span="4" class="col-txt"><span>上级部门</span></el-col>
  84. <el-col :span="20" class="col-input">
  85. <el-form-item>
  86. <el-cascader
  87. v-model="form.parentId"
  88. :options="DeptTree"
  89. :props="{ checkStrictly: true }"
  90. class="full"
  91. />
  92. </el-form-item>
  93. </el-col>
  94. </el-row>
  95. <el-row>
  96. <el-col :span="4" class="col-txt"><span>顺序号</span></el-col>
  97. <el-col :span="20" class="col-input">
  98. <el-form-item>
  99. <el-input v-model="form.deptOrder" />
  100. </el-form-item>
  101. </el-col>
  102. </el-row>
  103. <el-row>
  104. <el-col :span="4" class="col-txt"><span>部门名称</span></el-col>
  105. <el-col :span="20" class="col-input">
  106. <el-form-item>
  107. <el-input v-model="form.deptName" />
  108. </el-form-item>
  109. </el-col>
  110. </el-row>
  111. <el-row>
  112. <el-col :span="4" class="col-txt"><span>部门编码</span></el-col>
  113. <el-col :span="20" class="col-input">
  114. <el-form-item>
  115. <el-input v-model="form.deptCode" :disabled="form.deptCode==='TOP'" />
  116. </el-form-item>
  117. </el-col>
  118. </el-row>
  119. <el-row v-if="!currGroup">
  120. <el-col :span="4" class="col-txt"><span>所属组织</span></el-col>
  121. <el-col :span="20" class="col-input">
  122. <el-form-item>
  123. <el-select v-model="form.groupId" clearable filterable placeholder="所属组织">
  124. <el-option
  125. v-for="item in GroupData"
  126. :key="item.value"
  127. :label="item.label"
  128. :value="item.value"
  129. />
  130. </el-select>
  131. </el-form-item>
  132. </el-col>
  133. </el-row>
  134. <el-row>
  135. <el-col :span="4" class="col-txt"><span>部门负责人</span></el-col>
  136. <el-col :span="20" class="col-input">
  137. <el-form-item>
  138. <el-select v-model="form.chargedBy" clearable filterable multiple placeholder="部门负责人">
  139. <el-option
  140. v-for="item in StaffData"
  141. :key="item.value"
  142. :label="item.label"
  143. :value="item.value"
  144. />
  145. </el-select>
  146. </el-form-item>
  147. </el-col>
  148. </el-row>
  149. <el-row v-if="!isAdd || (isAdd && !selectDeptNode.id)">
  150. <el-col :span="4" class="col-txt"><span>组织架构类型</span></el-col>
  151. <el-col :span="20" class="col-input">
  152. <el-form-item>
  153. <el-select v-model="form.deptAttr" clearable filterable placeholder="组织架构类型">
  154. <el-option
  155. v-for="item in DeptAttrData"
  156. :key="item.value"
  157. :label="item.label"
  158. :value="item.value"
  159. />
  160. </el-select>
  161. </el-form-item>
  162. </el-col>
  163. </el-row>
  164. </el-card>
  165. </el-col>
  166. </el-row>
  167. </el-form>
  168. <div slot="footer">
  169. <el-button @click="dialogVisible = false">取 消</el-button>
  170. <el-button type="primary" @click="confirmSubmit()">确 定</el-button>
  171. </div>
  172. </el-dialog>
  173. </div>
  174. </template>
  175. <script>
  176. import Base from '../base/base'
  177. import BaseData from '../base/baseData'
  178. import BaseDept from '../base/baseDept'
  179. import '../../assets/drag'
  180. export default {
  181. name: 'Department',
  182. mixins: [Base, BaseData, BaseDept],
  183. data() {
  184. return {
  185. // 列表相关
  186. deptGroup: '',
  187. deptAttr: '',
  188. deptName: '',
  189. AllData: [],
  190. loading: false,
  191. topId: '0',
  192. // 弹框相关
  193. dialogVisible: false,
  194. dialogTitle: '新增',
  195. isAdd: true,
  196. // selectParent: [],
  197. form: this.initForm(),
  198. rules: {},
  199. // 判定组织
  200. currGroup: ''
  201. }
  202. },
  203. mounted() {
  204. this.initDeptAttr({}, true)
  205. this.currGroup = this.$common.currUser().groupId
  206. this.initStaff()
  207. this.initGroup({}, !this.currGroup).then(() => {
  208. this.deptGroup = this.GroupDataAll.length > 0 ? this.GroupDataAll[0].value : ''
  209. this.selectDeptNode = {}
  210. this.initData()
  211. })
  212. },
  213. methods: {
  214. initData: function() {
  215. this.initDepartment({
  216. groupId: this.deptGroup,
  217. deptName: this.deptName,
  218. deptAttr: this.deptAttr
  219. }).then(() => {
  220. if (this.selectDeptNode.id) {
  221. this.expandedDeptKey = []
  222. this.expandedDeptKey.push(this.selectDeptNode.id)
  223. }
  224. //console.log('初始化', this.selectDeptNode)
  225. this.getData()
  226. })
  227. },
  228. handleDelete: function(row){
  229. // //console.log("row_:", row);
  230. this.pubRequest("getSubset", {id: row.id}).then((res) => {
  231. if(res.data.data > 0){
  232. this.$message({
  233. message: '已绑定下级,无法删除!',
  234. type: 'warning'
  235. });
  236. }else{
  237. this.handleDel(row)
  238. }
  239. }).catch(() => {
  240. })
  241. },
  242. getData: function() {
  243. const _this = this
  244. _this.loading = true
  245. _this.AllData = []
  246. const postData = this.getPostData()
  247. this.baseRequest('list', postData).then((res) => {
  248. if (res.data.rows) {
  249. res.data.rows.forEach(function(item) {
  250. const json = _this.getItemJson(item)
  251. _this.AllData.push(json)
  252. })
  253. _this.allpage = res.data.total
  254. }
  255. _this.loading = false
  256. }).catch(() => {
  257. })
  258. this.initOutData()
  259. },
  260. handleSearch: function() {
  261. this.initData()
  262. },
  263. handleReset: function() {
  264. this.deptName = ''
  265. this.deptAttr = ''
  266. // this.initDeptTopNodeSelect(this.topId)
  267. this.selectDeptNode = {}
  268. this.handleSearch()
  269. },
  270. initOutData: function() {
  271. const _this = this
  272. this.OutData = []
  273. const title = []
  274. title.push('部门名称')
  275. title.push('所属组织')
  276. title.push('部门编码')
  277. title.push('顺序号')
  278. title.push('架构类型')
  279. this.OutData.push(title)
  280. const postData = this.getPostData()
  281. this.baseRequest('listAll', postData).then((res) => {
  282. if (res.data) {
  283. res.data.forEach(function(item) {
  284. const jsonMap = _this.getItemJson(item)
  285. const jsonArray = []
  286. jsonArray.push(jsonMap.deptName)
  287. jsonArray.push(jsonMap.groupStr)
  288. jsonArray.push(jsonMap.deptCode)
  289. jsonArray.push(jsonMap.deptOrder)
  290. jsonArray.push(jsonMap.deptAttrStr)
  291. _this.OutData.push(jsonArray)
  292. })
  293. }
  294. }).catch(() => {
  295. })
  296. },
  297. getPostData: function() {
  298. return {
  299. parentId: this.selectDeptNode.id === '0' ? '' : this.selectDeptNode.id,
  300. groupId: this.deptGroup,
  301. deptName: this.deptName,
  302. deptAttr: this.deptAttr,
  303. pageNum: this.currentPage,
  304. pageSize: this.pageSize
  305. }
  306. },
  307. getItemJson: function(item) {
  308. const attrs = item.deptAttr ? item.deptAttr.split(',') : []
  309. if (attrs.length > 0) {
  310. const attrStr = []
  311. attrs.forEach(attr => {
  312. attrStr.push(this.DeptAttrMap[attr])
  313. })
  314. item.deptAttrStr = attrStr.join(',')
  315. }
  316. const groupIds = item.groupId ? item.groupId.split(',') : []
  317. if (groupIds.length > 0) {
  318. const groupStr = []
  319. groupIds.forEach(groupId => {
  320. groupStr.push(this.GroupMap[groupId])
  321. })
  322. item.groupStr = groupStr.join(',')
  323. }
  324. return item
  325. },
  326. initForm: function(_selectNode) {
  327. // this.selectParent = _selectNode ? [_selectNode.id] : []
  328. //console.log('_selectNode', _selectNode)
  329. return {
  330. id: '',
  331. deptName: '',
  332. deptCode: '',
  333. deptOrder: 0,
  334. parentId: _selectNode ? (_selectNode.id ? _selectNode.id : '0') : '0',
  335. parentName: _selectNode ? _selectNode.name : '',
  336. deptLevel: _selectNode ? (_selectNode.level ? _selectNode.level + 1 : 1) : 1,
  337. deptAttr: _selectNode ? _selectNode.deptAttr : '',
  338. groupId: _selectNode ? (_selectNode.groupId ? _selectNode.groupId : this.currGroup) : this.currGroup,
  339. chargedBy: []
  340. }
  341. },
  342. // initDeptTopNodeSelect: function(_deptId) {
  343. // return this.getDeptTopNode(_deptId).then(topNode => {
  344. // if (topNode) {
  345. // this.selectDeptNode = topNode
  346. // } else {
  347. // this.selectDeptNode = this.getDeptDefaultTopNode()
  348. // }
  349. // })
  350. // },
  351. confirmOutput: function() {
  352. const OutSize = [{ wch: 30 }, { wch: 15 }, { wch: 15 }, { wch: 15 }, { wch: 15 }]
  353. const fileName = 'department导出' + new Date().Format('yyyyMMddhhmm')
  354. this.$outputXlsxFile(this.OutData, OutSize, fileName)
  355. },
  356. dlgOpen: function() {
  357. const _this = this
  358. if (_this.form.id) {
  359. const postData = {
  360. id: _this.form.id
  361. }
  362. this.baseRequest('getById', postData).then((res) => {
  363. if (res.data) {
  364. _this.form.deptName = res.data.deptName
  365. _this.form.deptCode = res.data.deptCode
  366. _this.form.deptOrder = res.data.deptOrder
  367. _this.form.deptLevel = res.data.deptLevel
  368. // _this.form.deptAttr = res.data.deptAttr ? res.data.deptAttr.split(',') : []
  369. _this.form.deptAttr = res.data.deptAttr
  370. // _this.form.groupIds = res.data.groupId ? res.data.groupId.split(',') : []
  371. _this.form.groupId = res.data.groupId
  372. _this.form.parentId = res.data.parentId
  373. _this.form.parentName = _this.DeptTreeMap[res.data.parentId].label
  374. _this.form.chargedBy = res.data.chargedBy ? res.data.chargedBy.split(',') : []
  375. _this.form.id = res.data.id
  376. // _this.selectParent = []
  377. // if (res.data.parentId) {
  378. // _this.selectParent.push(res.data.parentId)
  379. // }
  380. }
  381. }).catch(() => {
  382. })
  383. }
  384. },
  385. /* 编辑*/
  386. handleEdit: function(val) {
  387. this.isAdd = false
  388. this.form.id = val.id
  389. this.dialogVisible = true
  390. this.dialogTitle = '编辑'
  391. },
  392. /* 新增*/
  393. handleAdd: function() {
  394. this.form = this.initForm(this.selectDeptNode)
  395. this.isAdd = true
  396. this.dialogVisible = true
  397. this.dialogTitle = '新增'
  398. },
  399. confirmSubmit: function() {
  400. const _this = this
  401. this.$refs.form.validate(valid => {
  402. if (valid) {
  403. let soaUrl = 'edit'
  404. const postData = {
  405. deptName: _this.form.deptName,
  406. deptAttr: _this.form.deptAttr,
  407. // deptLevel: _this.form.deptLevel,
  408. groupId: _this.form.groupId,
  409. chargedBy: _this.form.chargedBy.join(','),
  410. id: _this.form.id
  411. }
  412. if (postData.deptCode !== 'TOP') {
  413. // postData.groupId = _this.form.groupIds.join(',')
  414. postData.deptOrder = _this.form.deptOrder ? _this.form.deptOrder : 0
  415. postData.deptCode = _this.form.deptCode
  416. const parents = this.form.parentId
  417. if (parents) {
  418. if (this.$common.isArrayFn(parents)) {
  419. if (parents.length > 0) {
  420. postData.parentId = parents[parents.length - 1]
  421. }
  422. } else {
  423. postData.parentId = parents
  424. }
  425. }
  426. }
  427. if (this.isAdd) {
  428. soaUrl = 'add'
  429. }
  430. this.opRecord(postData, soaUrl)
  431. } else {
  432. //console.log('error submit!!')
  433. return false
  434. }
  435. })
  436. },
  437. opRefresh: function() {
  438. this.initData()
  439. this.dialogVisible = false
  440. // this.$notify({
  441. // title: '处理成功',
  442. // type: 'info'
  443. // })
  444. },
  445. // // 全部展开
  446. // unFoldAll: function() {
  447. // const _this = this
  448. // // 将没有转换成树的原数据
  449. // const keyList = this.DeptTreeMap
  450. // for (const _id in keyList) {
  451. // // 将没有转换成树的原数据设置key为... 的展开
  452. // _this.$refs.selectTree.store.nodesMap[_id].expanded = true
  453. // }
  454. // },
  455. // // 全部折叠
  456. // collapseAll: function() {
  457. // const _this = this
  458. // const keyList = this.DeptTreeMap
  459. // for (const _id in keyList) {
  460. // // 将没有转换成树的原数据设置key为... 的展开
  461. // _this.$refs.selectTree.store.nodesMap[_id].expanded = false
  462. // }
  463. // },
  464. // 字典项
  465. baseRequest: function(opUrl, postData) {
  466. return this.$channel.globeRequest('SysDeptController', opUrl, postData, 'project')
  467. },
  468. pubRequest: function(opUrl, postData) {
  469. return this.$channel.globeRequest('pub', opUrl, postData, 'project')
  470. }
  471. }
  472. }
  473. </script>
  474. <style scoped>
  475. .custom-tree-node {
  476. flex: 1;
  477. display: flex;
  478. align-items: center;
  479. justify-content: space-between;
  480. font-size: 16px;
  481. padding-right: 8px;
  482. }
  483. .custom-tree-container .block-l {
  484. /*flex-grow: 2 ;*/
  485. float: left;
  486. width: 20%;
  487. padding: 0 8px 0 0;
  488. }
  489. .custom-tree-container .block-r {
  490. /*flex-grow: 10;*/
  491. float: left;
  492. width: 80%;
  493. /*padding: 0 0 0 8px;*/
  494. }
  495. </style>
  496. <style scoped>
  497. .ch-input .el-input__inner {
  498. border-radius: 0px;
  499. border-color: #32323A;
  500. }
  501. .ch-input-size {
  502. width: 150px;
  503. }
  504. .ch-button {
  505. border-radius: 0px;
  506. border-color: #32323A;
  507. background-color: #32323A;
  508. color: #fff;
  509. }
  510. .ch-button-warning {
  511. margin-left: 10px;
  512. border-radius: 0px;
  513. border-color: #E6A23C;
  514. background-color: #E6A23C;
  515. color: #fff;
  516. }
  517. .ch-button-export {
  518. margin-left: 10px;
  519. border-radius: 0px;
  520. border-color: #98CC1F;
  521. background-color: #98CC1F;
  522. color: #fff;
  523. }
  524. </style>