1
0

index.vue 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191
  1. <template>
  2. <div class="page_content">
  3. <div class="page_title">
  4. <div class="title">
  5. <svg-icon className="documentation" iconClass="documentation" />
  6. <span>公司部门</span>
  7. </div>
  8. </div>
  9. <div class="page_main">
  10. <div class="organi">
  11. <div class="outer">
  12. <DeptItem v-for="item in dataList" :data="item" :key="item.id" />
  13. </div>
  14. </div>
  15. </div>
  16. <!-- 添加或修改部门对话框 -->
  17. <el-dialog :title="title" :visible.sync="show" width="600px" append-to-body @close="cancel">
  18. <el-form ref="deptForm" :model="deptForm" :rules="deptFormRules" label-width="100px">
  19. <el-row>
  20. <el-col :span="24">
  21. <el-form-item label="上级部门">
  22. <el-input v-model="deptForm.parentName" disabled />
  23. </el-form-item>
  24. </el-col>
  25. <el-col :span="24">
  26. <el-form-item label="部门名称" prop="deptName">
  27. <el-input v-model.trim="deptForm.deptName" placeholder="请输入部门名称" maxlength="20" show-word-limit @input="setShortList" />
  28. </el-form-item>
  29. </el-col>
  30. <el-col :span="24">
  31. <el-form-item label="公司简称">
  32. <ul class="short">
  33. <li v-for="item in shortList" :key="item.title">
  34. <span>{{ item.title }}</span>
  35. <input type="checkbox" v-model="item.checked" />
  36. </li>
  37. </ul>
  38. </el-form-item>
  39. </el-col>
  40. </el-row>
  41. </el-form>
  42. <div slot="footer" class="dialog-footer">
  43. <el-button size="small" @click="cancel">取 消</el-button>
  44. <el-button size="small" type="primary" @click="sub">保 存</el-button>
  45. </div>
  46. </el-dialog>
  47. </div>
  48. </template>
  49. <script>
  50. import { treeselect, addDept } from '@/api/system/dept.js'
  51. import DeptItem from './components/deptItem.vue'
  52. export default {
  53. components: { DeptItem },
  54. data() {
  55. return {
  56. checked: true,
  57. //组织架构数据
  58. dataList: [],
  59. //弹窗显示
  60. show: false,
  61. //弹窗标题
  62. title: '',
  63. //弹窗表单
  64. deptForm: {
  65. //上级部门id
  66. parentId: 0,
  67. //上级部门名称
  68. parentName: '',
  69. //部门名称
  70. deptName: '',
  71. //部门简称
  72. shortName: '',
  73. //简称索引
  74. shortNameIndex: ''
  75. },
  76. //表单验证
  77. deptFormRules: {
  78. deptName: [{ required: true, message: '部门名称不能为空', trigger: 'submit' }]
  79. },
  80. //简写数据
  81. shortList: []
  82. }
  83. },
  84. created() {
  85. treeselect().then(res => {
  86. if (res.code === 200) {
  87. this.dataList = res.data.map(item => {
  88. return {
  89. ...item,
  90. root: true
  91. }
  92. })
  93. }
  94. })
  95. },
  96. provide() {
  97. return {
  98. updData: this.updData,
  99. delData: this.delData,
  100. resetDel: this.resetDel
  101. }
  102. },
  103. methods: {
  104. //弹窗关闭
  105. cancel() {
  106. this.show = false
  107. this.resetForm()
  108. },
  109. //表单重置
  110. resetForm() {
  111. this.deptForm = {
  112. parentId: 0,
  113. parentName: '',
  114. deptName: '',
  115. shortName: '',
  116. shortNameIndex: ''
  117. }
  118. },
  119. //弹窗提交
  120. sub() {
  121. this.$refs['deptForm'].validate(valid => {
  122. if (valid) {
  123. if (this.deptForm.deptId != undefined) {
  124. } else {
  125. addDept(this.deptForm).then(res => {
  126. if (res.code === 200) {
  127. this.$msg({ message: '添加成功' })
  128. this.cancel()
  129. }
  130. })
  131. }
  132. }
  133. })
  134. },
  135. //编辑部门
  136. updData(type, data) {
  137. this.show = true
  138. //添加
  139. if (type == 0) {
  140. this.title = '部门添加'
  141. this.deptForm.parentId = data.id
  142. this.deptForm.parentName = data.label
  143. } else {
  144. this.title = '部门修改'
  145. }
  146. },
  147. //设置简写
  148. setShortList() {
  149. this.shortList = this.deptForm.deptName.split('').map((title, index) => {
  150. return {
  151. index,
  152. title,
  153. checked: true
  154. }
  155. })
  156. },
  157. delData() {},
  158. resetDel() {}
  159. }
  160. }
  161. </script>
  162. <style scoped lang="scss">
  163. ::v-deep .org-chart-node-label {
  164. background-color: #199ed8;
  165. color: #fff;
  166. border-radius: 5px;
  167. }
  168. .organi {
  169. width: 100%;
  170. height: 100%;
  171. background-color: #fff;
  172. overflow: auto;
  173. padding: 30px;
  174. }
  175. .outer {
  176. width: auto;
  177. display: inline-block;
  178. }
  179. .short {
  180. display: flex;
  181. flex-wrap: wrap;
  182. li {
  183. height: 36px;
  184. line-height: 36px;
  185. margin-right: 10px;
  186. }
  187. }
  188. </style>