index.vue 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392
  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 id="kakaka">
  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. {{ node.label }}
  22. <span>
  23. <el-button v-if="node.level > 1" size="mini" type="text" @click="addbumen(data)">
  24. <i class="el-icon-plus"></i>
  25. </el-button>
  26. <el-button v-if="node.level > 2" size="mini" type="text" @click="eidbumen(data)">
  27. <i class="el-icon-edit"></i>
  28. </el-button>
  29. <el-button v-if="node.level > 2" 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 v-if="form2.id" style="width: 100%" v-model="form2.websitId" filterable placeholder="请选择">
  70. <el-option
  71. v-for="(item, index) in keyixuan"
  72. :key="index"
  73. :label="`(${item.websitId})${item.websitName}`"
  74. :value="item.websitId"
  75. >
  76. </el-option>
  77. </el-select>
  78. <el-select v-else style="width: 100%" multiple v-model="form2.websitIds" filterable placeholder="请选择">
  79. <el-option
  80. v-for="(item, index) in keyixuan"
  81. :key="index"
  82. :label="`(${item.websitId})${item.websitName}`"
  83. :value="item.websitId"
  84. >
  85. </el-option>
  86. </el-select>
  87. </el-form-item>
  88. <el-form-item>
  89. <el-button type="primary" @click="queding2">确定</el-button>
  90. <el-button @click="handleClose2">取消</el-button>
  91. </el-form-item>
  92. </el-form>
  93. </el-dialog>
  94. </template-page>
  95. </zj-page-container>
  96. </template>
  97. <script>
  98. import TemplatePage from '@/components/template/template-page-1.vue'
  99. import {
  100. adminDeptList,
  101. adminDeptListExport,
  102. adminDeptTree,
  103. adminDeptAdd,
  104. adminDeptUpdate,
  105. adminDeptDel,
  106. adminDeptAddWebsit,
  107. adminDeptUpdateWebsit,
  108. adminDeptDelWebsit,
  109. adminDeptImport
  110. } from '@/api/departmentManagement.js'
  111. import operation_mixin from '@/components/template/operation_mixin.js'
  112. import { commonTemplateDownload } from '@/api/common.js'
  113. import import_mixin from '@/components/template/import_mixin.js'
  114. export default {
  115. components: {
  116. TemplatePage
  117. },
  118. mixins: [operation_mixin, import_mixin],
  119. data() {
  120. return {
  121. // 表格属性
  122. tableAttributes: {},
  123. // 表格事件
  124. tableEvents: {},
  125. visible: false,
  126. item: null,
  127. treeList: [],
  128. defaultProps: {
  129. children: 'children',
  130. label: 'deptName'
  131. },
  132. filterText: '',
  133. dialogVisible: false,
  134. form: {
  135. pid: '',
  136. pname: '',
  137. deptName: ''
  138. },
  139. dialogVisible2: false,
  140. form2: {
  141. adminDeptId: '',
  142. deptName: '',
  143. adminDeptWebsitId: '',
  144. websitId: '',
  145. websitName: '',
  146. websitIds: []
  147. },
  148. adminDept: null,
  149. keyixuan: []
  150. }
  151. },
  152. mounted() {
  153. this.getTreeListData()
  154. },
  155. computed: {
  156. // 事件组合
  157. optionsEvensGroup() {
  158. return [
  159. [
  160. [
  161. this.optionsEvensAuth('import', ({ moduleName }) => {
  162. return {
  163. name: moduleName,
  164. render: () => {
  165. return this.importButton(adminDeptImport, moduleName)
  166. }
  167. }
  168. })
  169. ],
  170. [
  171. this.optionsEvensAuth('download', {
  172. click: () => {
  173. commonTemplateDownload({ name: '部门网点导入.xlsx' }, `${this.$route.meta.title}`)
  174. .then(res => {
  175. this.$message({
  176. message: '下载成功',
  177. type: 'success'
  178. })
  179. })
  180. .catch(err => {
  181. this.$message.error('下载失败')
  182. })
  183. }
  184. })
  185. ],
  186. this?.keyixuan?.length
  187. ? [
  188. this.optionsEvensAuth('add', {
  189. click: () => {
  190. if (this.adminDept) {
  191. this.form2 = {
  192. deptName: this.adminDept.deptName,
  193. adminDeptId: this.adminDept.adminDeptId,
  194. adminDeptWebsitId: '',
  195. websitId: '',
  196. websitName: '',
  197. websitIds: []
  198. }
  199. this.dialogVisible2 = true
  200. } else {
  201. this.$message.warning('请先选择部门')
  202. }
  203. }
  204. })
  205. ]
  206. : []
  207. ]
  208. ]
  209. }
  210. },
  211. watch: {
  212. filterText(val) {
  213. this?.$refs?.listTree?.filter?.(val)
  214. }
  215. },
  216. methods: {
  217. filterNode(value, data) {
  218. if (!value) return true
  219. return data.deptName.indexOf(value) !== -1
  220. },
  221. // 请求属性数据
  222. getTreeListData() {
  223. adminDeptTree().then(res => {
  224. this.treeList = res.data
  225. this.$refs.pageRef.refreshList()
  226. this.$nextTick(() => {
  227. const tree = document.getElementById('kakaka').getElementsByClassName('el-tree')
  228. const elTreeNodeContent = document.getElementById('kakaka').getElementsByClassName('el-tree-node__content')
  229. if (elTreeNodeContent.length) {
  230. var maxwidth = 0
  231. for (var item of elTreeNodeContent) {
  232. if (maxwidth < item.scrollWidth) {
  233. maxwidth = item.scrollWidth
  234. }
  235. }
  236. }
  237. if (tree.length) {
  238. for (var item of tree) {
  239. item.style.width = `${maxwidth}px`
  240. }
  241. }
  242. })
  243. })
  244. },
  245. // 树形选中
  246. handleNodeClick(e) {
  247. this.adminDept = { ...e }
  248. adminDeptList({
  249. pageNum: 1,
  250. pageSize: -1,
  251. params: [{ param: 'admin_dept_id', compare: '=', value: this?.adminDept?.pid }]
  252. }).then(res => {
  253. this.keyixuan = res.data.records
  254. })
  255. this.$refs.pageRef.refreshList()
  256. },
  257. // gengxin(val) {
  258. // this.form2.websitName = this.keyixuan?.find(item => item.websitId == val)?.websitName
  259. // },
  260. // 列表请求函数
  261. getList(pam, cb) {
  262. try {
  263. if (this?.adminDept?.adminDeptId) {
  264. pam.params.push({ param: 'admin_dept_id', compare: '=', value: this?.adminDept?.adminDeptId })
  265. }
  266. cb && cb(pam)
  267. return adminDeptList(pam)
  268. } catch (err) {
  269. } finally {
  270. }
  271. },
  272. // 列表导出函数
  273. exportList: adminDeptListExport,
  274. // 表格列解析渲染数据更改
  275. columnParsing(item, defaultData) {
  276. return defaultData
  277. },
  278. operation() {
  279. return this.operationBtn({
  280. del: {
  281. click: ({ row, index, column }) => {
  282. adminDeptDelWebsit({
  283. adminDeptWebsitId: row.adminDeptWebsitId
  284. }).then(res => {
  285. this.$refs.pageRef.refreshList()
  286. this.$message({
  287. type: 'success',
  288. message: '删除成功'
  289. })
  290. })
  291. }
  292. }
  293. })
  294. },
  295. addbumen(data) {
  296. this.form.pid = data.adminDeptId
  297. this.form.pname = data.deptName
  298. this.dialogVisible = true
  299. },
  300. eidbumen(data) {
  301. this.form = { ...data }
  302. this.dialogVisible = true
  303. },
  304. delbumen(data) {
  305. adminDeptDel({ adminDeptId: data.adminDeptId }).then(res => {
  306. this.getTreeListData()
  307. this.$message({
  308. type: 'success',
  309. message: '删除成功'
  310. })
  311. })
  312. },
  313. queding() {
  314. if (!this.form.deptName) {
  315. this.$message.warning('名字不能为空')
  316. }
  317. ;(this.form.adminDeptId ? adminDeptUpdate : adminDeptAdd)(this.form).then(res => {
  318. this.getTreeListData()
  319. this.handleClose()
  320. this.$message({
  321. type: 'success',
  322. message: '设置成功'
  323. })
  324. })
  325. },
  326. handleClose() {
  327. this.dialogVisible = false
  328. this.form = {
  329. pid: '',
  330. pname: '',
  331. deptName: ''
  332. }
  333. },
  334. queding2() {
  335. if (!this?.form2?.websitIds?.length && !this?.form2?.websitId) {
  336. this.$message.warning('请选择网点')
  337. }
  338. ;(this.form2.id ? adminDeptUpdateWebsit : adminDeptAddWebsit)({
  339. ...this.form2,
  340. id: this?.form2?.id,
  341. adminDeptId: this?.adminDept?.adminDeptId,
  342. websitIds: this?.form2?.websitIds?.join(','),
  343. adminDeptWebsitId: this?.form2?.adminDeptWebsitId
  344. }).then(res => {
  345. this.$refs.pageRef.refreshList()
  346. this.handleClose2()
  347. this.$message({
  348. type: 'success',
  349. message: '设置成功'
  350. })
  351. })
  352. },
  353. handleClose2() {
  354. this.dialogVisible2 = false
  355. this.form2 = {
  356. deptName: '',
  357. adminDeptId: '',
  358. adminDeptWebsitId: '',
  359. websitId: '',
  360. websitName: '',
  361. websitIds: []
  362. }
  363. }
  364. }
  365. }
  366. </script>
  367. <style lang="scss" scoped>
  368. ::v-deep .zj-page-fill-scroll {
  369. overflow-x: auto;
  370. }
  371. .title {
  372. width: 100%;
  373. padding: 20px 0 10px 20px;
  374. display: flex;
  375. justify-content: space-between;
  376. margin-bottom: 10px;
  377. border-bottom: 1px solid #cccccc;
  378. font-weight: bold;
  379. }
  380. ::v-deep .el-tree-node__content {
  381. display: inline-block; /* 根据内容宽度调整 */
  382. white-space: nowrap; /* 防止换行 */
  383. }
  384. .custom-tree-node {
  385. display: inline-block; /* 根据内容宽度调整 */
  386. white-space: nowrap; /* 防止换行 */
  387. box-sizing: border-box;
  388. }
  389. </style>