index.vue 9.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320
  1. <template>
  2. <zj-page-container direction="row">
  3. <div style="min-width: 220px; height: 100%">
  4. <zj-page-container>
  5. <div class="title">
  6. <el-button style="margin-right: 5px" size="mini" icon="el-icon-search" @click="getTreeListData"></el-button>
  7. <el-input size="mini" v-model="filterText" placeholder="请输入内容"></el-input>
  8. </div>
  9. <zj-page-fill>
  10. <el-tree
  11. :data="treeList"
  12. :props="defaultProps"
  13. default-expand-all
  14. :highlight-current="true"
  15. :expand-on-click-node="false"
  16. @node-click="handleNodeClick"
  17. :filter-node-method="filterNode"
  18. ref="listTree"
  19. >
  20. <span class="custom-tree-node" slot-scope="{ node, data }">
  21. <span>{{ node.label }}</span>
  22. <span>
  23. <el-button size="mini" type="text" @click="addbumen(data)">
  24. <i class="el-icon-plus"></i>
  25. </el-button>
  26. <el-button size="mini" type="text" @click="eidbumen(data)">
  27. <i class="el-icon-edit"></i>
  28. </el-button>
  29. <el-button size="mini" type="text" @click="delbumen(data)">
  30. <i class="el-icon-delete"></i>
  31. </el-button>
  32. </span>
  33. </span>
  34. </el-tree>
  35. </zj-page-fill>
  36. </zj-page-container>
  37. </div>
  38. <template-page
  39. ref="pageRef"
  40. :getList="getList"
  41. :columnParsing="columnParsing"
  42. :optionsEvensGroup="optionsEvensGroup"
  43. :tableAttributes="tableAttributes"
  44. :tableEvents="tableEvents"
  45. :operationColumnWidth="160"
  46. :operation="operation()"
  47. :exportList="exportList"
  48. >
  49. <el-dialog title="设置部门" :visible.sync="dialogVisible" width="500px" :before-close="handleClose">
  50. <el-form ref="form" :model="form" label-width="100px" size="mini">
  51. <el-form-item label="上级部门名称">
  52. <el-input disabled v-model="form.pname"></el-input>
  53. </el-form-item>
  54. <el-form-item label="部门名称">
  55. <el-input v-model="form.deptName"></el-input>
  56. </el-form-item>
  57. <el-form-item>
  58. <el-button type="primary" @click="queding">确定</el-button>
  59. <el-button @click="handleClose">取消</el-button>
  60. </el-form-item>
  61. </el-form>
  62. </el-dialog>
  63. <el-dialog title="添加网点" :visible.sync="dialogVisible2" width="500px" :before-close="handleClose2">
  64. <el-form ref="form" :model="form2" label-width="120px" size="mini">
  65. <el-form-item label="部门名称">
  66. <el-input disabled v-model="form2.deptName"></el-input>
  67. </el-form-item>
  68. <el-form-item label="管理网点名称">
  69. <el-select style="width: 100%" v-model="form2.websitId" placeholder="请选择" @change="gengxin">
  70. <el-option v-for="(item, index) in keyixuan" :key="index" :label="item.websitName" :value="item.websitId">
  71. </el-option>
  72. </el-select>
  73. </el-form-item>
  74. <el-form-item>
  75. <el-button type="primary" @click="queding2">确定</el-button>
  76. <el-button @click="handleClose2">取消</el-button>
  77. </el-form-item>
  78. </el-form>
  79. </el-dialog>
  80. </template-page>
  81. </zj-page-container>
  82. </template>
  83. <script>
  84. import TemplatePage from '@/components/template/template-page-1.vue'
  85. import {
  86. adminDeptList,
  87. adminDeptListExport,
  88. adminDeptTree,
  89. adminDeptAdd,
  90. adminDeptUpdate,
  91. adminDeptDel,
  92. adminDeptAddWebsit,
  93. adminDeptUpdateWebsit,
  94. adminDeptDelWebsit
  95. } from '@/api/departmentManagement.js'
  96. import operation_mixin from '@/components/template/operation_mixin.js'
  97. export default {
  98. components: {
  99. TemplatePage
  100. },
  101. mixins: [operation_mixin],
  102. data() {
  103. return {
  104. // 表格属性
  105. tableAttributes: {},
  106. // 表格事件
  107. tableEvents: {},
  108. visible: false,
  109. item: null,
  110. treeList: [],
  111. defaultProps: {
  112. children: 'children',
  113. label: 'deptName'
  114. },
  115. filterText: '',
  116. dialogVisible: false,
  117. form: {
  118. pid: '',
  119. pname: '',
  120. deptName: ''
  121. },
  122. dialogVisible2: false,
  123. form2: {
  124. adminDeptId: '',
  125. deptName: '',
  126. adminDeptWebsitId: '',
  127. websitId: '',
  128. websitName: ''
  129. },
  130. adminDept: null,
  131. keyixuan: []
  132. }
  133. },
  134. mounted() {
  135. this.getTreeListData()
  136. },
  137. computed: {
  138. // 事件组合
  139. optionsEvensGroup() {
  140. return [
  141. [
  142. this?.keyixuan?.length
  143. ? [
  144. this.optionsEvensAuth('add', {
  145. click: () => {
  146. if (this.adminDept) {
  147. this.form2 = {
  148. deptName: this.adminDept.deptName,
  149. adminDeptId: this.adminDept.adminDeptId,
  150. adminDeptWebsitId: '',
  151. websitId: '',
  152. websitName: ''
  153. }
  154. this.dialogVisible2 = true
  155. } else {
  156. this.$message.warning('请先选择部门')
  157. }
  158. }
  159. })
  160. ]
  161. : []
  162. ]
  163. ]
  164. }
  165. },
  166. watch: {
  167. filterText(val) {
  168. this?.$refs?.listTree?.filter?.(val)
  169. }
  170. },
  171. methods: {
  172. filterNode(value, data) {
  173. if (!value) return true
  174. return data.deptName.indexOf(value) !== -1
  175. },
  176. // 请求属性数据
  177. getTreeListData() {
  178. adminDeptTree().then(res => {
  179. this.treeList = res.data
  180. this.$refs.pageRef.refreshList()
  181. })
  182. },
  183. // 树形选中
  184. handleNodeClick(e) {
  185. this.adminDept = { ...e }
  186. adminDeptList({
  187. pageNum: 1,
  188. pageSize: -1,
  189. params: [{ param: 'admin_dept_id', compare: '=', value: this?.adminDept?.pid }]
  190. }).then(res => {
  191. this.keyixuan = res.data.records
  192. })
  193. this.$refs.pageRef.refreshList()
  194. },
  195. gengxin(val) {
  196. this.form2.websitName = this.keyixuan?.find(item => item.websitId == val)?.websitName
  197. },
  198. // 列表请求函数
  199. getList(pam, cb) {
  200. try {
  201. if (this?.adminDept?.adminDeptId) {
  202. pam.params.push({ param: 'admin_dept_id', compare: '=', value: this?.adminDept?.adminDeptId })
  203. }
  204. cb && cb(pam)
  205. return adminDeptList(pam)
  206. } catch (err) {
  207. } finally {
  208. }
  209. },
  210. // 列表导出函数
  211. exportList: adminDeptListExport,
  212. // 表格列解析渲染数据更改
  213. columnParsing(item, defaultData) {
  214. return defaultData
  215. },
  216. operation() {
  217. return this.operationBtn({
  218. del: {
  219. click: ({ row, index, column }) => {
  220. adminDeptDelWebsit({
  221. adminDeptWebsitId: row.adminDeptWebsitId
  222. }).then(res => {
  223. this.$refs.pageRef.refreshList()
  224. this.$message({
  225. type: 'success',
  226. message: '删除成功'
  227. })
  228. })
  229. }
  230. }
  231. })
  232. },
  233. addbumen(data) {
  234. this.form.pid = data.adminDeptId
  235. this.form.pname = data.deptName
  236. this.dialogVisible = true
  237. },
  238. eidbumen(data) {
  239. this.form = { ...data }
  240. this.dialogVisible = true
  241. },
  242. delbumen(data) {
  243. adminDeptDel({ adminDeptId: data.adminDeptId }).then(res => {
  244. this.getTreeListData()
  245. this.$message({
  246. type: 'success',
  247. message: '删除成功'
  248. })
  249. })
  250. },
  251. queding() {
  252. if (!this.form.deptName) {
  253. this.$message.warning('名字不能为空')
  254. }
  255. ;(this.form.adminDeptId ? adminDeptUpdate : adminDeptAdd)(this.form).then(res => {
  256. this.getTreeListData()
  257. this.handleClose()
  258. this.$message({
  259. type: 'success',
  260. message: '设置成功'
  261. })
  262. })
  263. },
  264. handleClose() {
  265. this.dialogVisible = false
  266. this.form = {
  267. pid: '',
  268. pname: '',
  269. deptName: ''
  270. }
  271. },
  272. queding2() {
  273. if (!this.form2.websitId) {
  274. this.$message.warning('请选择网点')
  275. }
  276. ;(this.form2.id ? adminDeptUpdateWebsit : adminDeptAddWebsit)({
  277. ...this.form2,
  278. adminDeptId: this.adminDept.adminDeptId,
  279. adminDeptWebsitId: this?.form2?.adminDeptWebsitId
  280. }).then(res => {
  281. this.$refs.pageRef.refreshList()
  282. this.handleClose2()
  283. this.$message({
  284. type: 'success',
  285. message: '设置成功'
  286. })
  287. })
  288. },
  289. handleClose2() {
  290. this.dialogVisible2 = false
  291. this.form2 = {
  292. deptName: '',
  293. adminDeptId: '',
  294. adminDeptWebsitId: '',
  295. websitId: '',
  296. websitName: ''
  297. }
  298. }
  299. }
  300. }
  301. </script>
  302. <style lang="scss" scoped>
  303. .title {
  304. width: 100%;
  305. padding: 20px 0 10px 20px;
  306. display: flex;
  307. justify-content: space-between;
  308. margin-bottom: 10px;
  309. border-bottom: 1px solid #cccccc;
  310. font-weight: bold;
  311. }
  312. .custom-tree-node {
  313. flex: 1;
  314. display: flex;
  315. justify-content: space-between;
  316. align-items: center;
  317. }
  318. </style>