index.vue 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423
  1. <template>
  2. <div class="app-container" v-loading="loading">
  3. <el-form :model="queryParams" ref="queryForm" :inline="true" v-show="showSearch" >
  4. <el-form-item label="部门名称" prop="name">
  5. <el-input
  6. v-model.trim="queryParams.name"
  7. placeholder="请输入部门名称"
  8. clearable
  9. size="small"
  10. style="width: 140px"
  11. @keyup.enter.native="handleQuery"
  12. />
  13. </el-form-item>
  14. <el-form-item>
  15. <el-button type="primary" size="mini" @click="handleQuery">搜索</el-button>
  16. <el-button plain size="mini" @click="resetQuery">重置</el-button>
  17. </el-form-item>
  18. <br>
  19. <el-form-item>
  20. <el-button plain size="mini" @click="synchrodeptJob">部门信息同步</el-button>
  21. <el-button plain size="mini" @click="batchChange(1)">部门充值比例绑定</el-button>
  22. <el-button plain size="mini" @click="batchChange(0)">部门充值比例解除</el-button>
  23. </el-form-item>
  24. </el-form>
  25. <el-table :data="adminList" ref="tableRef" :header-cell-class-name="cellClass"
  26. @select="handletableSelect"
  27. @selection-change="handletableSelectionChange" height="calc(100vh - 12vh - 120px)" row-key="id"
  28. :tree-props="{children: 'children', hasChildren: 'hasChildren'}">
  29. <el-table-column type="selection" width="50" align="center" />
  30. <el-table-column label="id" align="center" prop="id" show-overflow-tooltip />
  31. <el-table-column label="部门名称" align="center" prop="name" show-overflow-tooltip />
  32. <el-table-column label="创建人" align="center" prop="createBy" show-overflow-tooltip />
  33. <el-table-column label="创建时间" align="center" prop="createTime" show-overflow-tooltip >
  34. <template slot-scope="scope">
  35. <span>{{ parseTime(scope.row.createTime) }}</span>
  36. </template>
  37. </el-table-column>
  38. </el-table>
  39. <!-- 添加或修改参数配置对话框 -->
  40. <el-dialog :title="title" :visible.sync="open" width="600px" append-to-body :before-close="cancel" :close-on-click-modal="false" >
  41. <el-form ref="queryParams" :model="queryParams" :rules="rules" label-width="120px" >
  42. <el-form-item label="到账比例:" prop="id">
  43. <el-select v-model="queryParams.id" style="width: 240px" placeholder="请选择到账比例" clearable size="small" >
  44. <el-option :label="`${item.identity}:${item.proportion}`" :value="item.id" v-for="(item, index) in radioList" :key="index" />
  45. </el-select>
  46. </el-form-item>
  47. </el-form>
  48. <div slot="footer" class="dialog-footer">
  49. <el-button type="primary" @click="submitForm" v-if="!loading">确 定</el-button>
  50. <el-button :loading="loading" type="primary" @click="submitForm" v-else>提交中...</el-button>
  51. <el-button @click="cancel">取 消</el-button>
  52. </div>
  53. </el-dialog>
  54. <pagination
  55. v-show="total>0"
  56. :total="total"
  57. :page.sync="queryParams.current"
  58. :limit.sync="queryParams.size"
  59. @pagination="getList"
  60. />
  61. </div>
  62. </template>
  63. <script>
  64. import { listChannel, deptJob, updataByDept, deptList } from "@/api/recharge/department";
  65. import { listDept, getDept, delDept, addDept, updateDept, listDeptExcludeChild } from "@/api/system/dept";
  66. import { allRadio } from "@/api/recharge/radio";
  67. import Treeselect from "@riophae/vue-treeselect";
  68. import "@riophae/vue-treeselect/dist/vue-treeselect.css";
  69. import qs from 'qs'
  70. export default {
  71. name: "admin",
  72. components: { Treeselect },
  73. data() {
  74. return {
  75. // 遮罩层
  76. loading: true,
  77. // 导出遮罩层
  78. exportLoading: false,
  79. dialogFormVisible:false,
  80. // 选中数组
  81. ids: [],
  82. // 非单个禁用
  83. single: true,
  84. // 非多个禁用
  85. multiple: true,
  86. // 显示搜索条件
  87. showSearch: true,
  88. // 总条数
  89. total: 0,
  90. // 参数表格数据
  91. adminList: [],
  92. // 弹出层标题
  93. title: "",
  94. // 是否显示弹出层
  95. open: false,
  96. // 类型数据字典
  97. typeOptions: [],
  98. // 日期范围
  99. dateRange: [],
  100. // 查询参数
  101. queryParams: {
  102. current: 1,
  103. size: 10,
  104. name: undefined,
  105. id: undefined,
  106. },
  107. //批量到账比例处理
  108. staffList:{},
  109. // 到账比例
  110. radioList:[],
  111. // 表单参数
  112. form: {
  113. name:'',
  114. },
  115. // 表单校验
  116. rules: {
  117. id:[
  118. { required: true, message: "充值比例不能为空", trigger: "change"},
  119. ],
  120. },
  121. tableRadio: {},
  122. deptIds:[],//部门绑定集合,
  123. deptIdsb:[],//部门绑定集合,
  124. tableSelect:[],
  125. };
  126. },
  127. created() {
  128. this.getList();
  129. },
  130. methods: {
  131. //去除全选
  132. cellClass(row) {
  133. if (row.columnIndex === 0) {
  134. return 'disabledCheck';
  135. }
  136. },
  137. // 当用户手动勾选数据行的 Checkbox 时触发的事件
  138. handletableSelect(selection, row) {
  139. if (row.children) { //只对有子节点的行响应
  140. // if (row.isChecked === undefined) row.isChecked = true
  141. if (!row.isChecked) { //由行数据中的元素isChecked判断当前是否被选中
  142. this.traverseChildNodes(row.children, this.$refs.tableRef, true)
  143. row.isChecked = true; //当前行isChecked标志元素切换为false
  144. } else {
  145. this.traverseChildNodes(row.children, this.$refs.tableRef, false)
  146. row.isChecked = false;
  147. }
  148. }
  149. // 处理父级选择逻辑
  150. // tableSelect 字段是 handletableSelectionChange 回调回来的
  151. // 如果不用 this.$nextTick 无法获取到正确数据
  152. this.$nextTick(() => {
  153. // 递归寻找当前子节点的父级节点
  154. let getParentNode = function (data, id) {
  155. for (let i in data) {
  156. if (data.hasOwnProperty(i)) {
  157. if (data[i].id === id) {
  158. return [data[i]]
  159. }
  160. if (data[i].children) {
  161. let node = getParentNode(data[i].children, id);
  162. if (node !== undefined) {
  163. return node.concat(data[i])
  164. }
  165. }
  166. }
  167. }
  168. }
  169. // 设置checkbox半选择状态
  170. // 此处的传入的id就是匹配表格id字段的
  171. let updateCheckboxIndeterminate = function (id, isIndeterminate) {
  172. setTimeout(() => {
  173. // el-table不支持checkbox半选 目前方案是遍历dom获取行节点设置样式
  174. let elementsRow = document.getElementsByClassName("el-table__row");
  175. for (let i = 0; i < elementsRow.length; i++) {
  176. let element = elementsRow.item(i);
  177. // tips: 通过其他手段设置行内row-id的 以下代码需要修改
  178. let childNode = element.childNodes.item(1); // row-key 字段在dom中的索引 第二列=1
  179. if (childNode.innerText === `${id}`) {
  180. let td = element.childNodes.item(0) // 获取要设置半选中状态的checkbox
  181. let div = td.firstChild; // <div class="cell">
  182. let label = div.firstChild; // <label class="el-checkbox">
  183. let span = label.firstChild; // <span class="el-checkbox__input">
  184. if (isIndeterminate)
  185. span.classList.add("is-indeterminate") // 设置半选中状态
  186. else
  187. span.classList.remove("is-indeterminate") // 取消半选中状态
  188. }
  189. }
  190. }, 1)
  191. }
  192. let parentNode = getParentNode(this.$refs.tableRef.data, row.id)
  193. // > 1 说明节点有子节点
  194. if (parentNode.length > 1) {
  195. // 提取兄弟节点ids
  196. let siblingNodeIds = parentNode[1].children.map(item => item.id)
  197. // 提取全选所选择项的ids
  198. let checkedIds = this.tableSelect.map(item => item.id)
  199. // 获取兄弟行选择数
  200. let siblingNodeCheckedIds = siblingNodeIds.filter(id => checkedIds.indexOf(id) !== -1)
  201. if (siblingNodeCheckedIds.length === siblingNodeIds.length) {
  202. // 兄弟节点选择数===兄弟节点数 全选
  203. updateCheckboxIndeterminate(parentNode[1].id, false)
  204. parentNode[1].isChecked = true
  205. this.$refs.tableRef.toggleRowSelection(parentNode[1], true)
  206. } else if (siblingNodeCheckedIds.length === 0) {
  207. // 兄弟节点选择数===0 全不选
  208. parentNode[1].isChecked = false
  209. this.$refs.tableRef.toggleRowSelection(parentNode[1], false)
  210. updateCheckboxIndeterminate(parentNode[1].id, false)
  211. } else if (siblingNodeCheckedIds.length < siblingNodeIds.length) {
  212. parentNode[1].isChecked = true
  213. this.$refs.tableRef.toggleRowSelection(parentNode[1], true)
  214. for (let i = 0; i < parentNode.length; i++) {
  215. if (i > 0) updateCheckboxIndeterminate(parentNode[i].id, true)
  216. }
  217. }
  218. }
  219. })
  220. },
  221. // 当用户手动勾选全选 Checkbox 时触发的事件
  222. handletableSelectAll(selection) {
  223. this.$refs.tableRef.data.map(items => {
  224. if (items.children && items.children.length > 0) {
  225. if (!items.isChecked) {
  226. this.$refs.tableRef.toggleRowSelection(items, true);
  227. items.isChecked = true
  228. this.traverseChildNodes(items.children, this.$refs.tableRef, true)
  229. this.deptIds.push(items.did)
  230. } else {
  231. this.$refs.tableRef.toggleRowSelection(items, false);
  232. items.isChecked = false;
  233. this.traverseChildNodes(items.children, this.$refs.tableRef, false)
  234. this.deptIds=[]
  235. }
  236. } else {
  237. }
  238. })
  239. console.log(this.deptIds)
  240. },
  241. // 当选择项发生变化时会触发该事件
  242. handletableSelectionChange(selection) {
  243. // let that = this
  244. // selection.forEach(item => {
  245. // that.deptIdsb.push(item.did);
  246. // });
  247. // setTimeout(()=>{
  248. // var newArr = that.deptIdsb.filter(function(item,index){
  249. // return that.deptIdsb.indexOf(item) === index; // 因为indexOf 只能查找到第一个
  250. // });
  251. // console.log(newArr)
  252. // },1)
  253. // let arr = []
  254. // for(let i =0;i<selection.length;i++){
  255. // arr.push(selection[i].did)
  256. // }
  257. // console.log(arr)
  258. // if(this.deptIds.length>0){
  259. // }else{
  260. // this.deptIds.push(selection[0].did)
  261. // }
  262. // console.log(selection)
  263. // console.log(this.deptIds)
  264. // let that = this
  265. // setTimeout(()=>{
  266. // that.tableSelect = selection
  267. // console.log(that.tableSelect,Date.parse(new Date()))
  268. // })
  269. // this.deptIds = []
  270. // this.deptIds.push(selection)
  271. // setTimeout(()=>{
  272. // console.log(this.deptIds)
  273. // },1)
  274. // this.tableSelect = selection
  275. },
  276. // 递归设置子节点
  277. traverseChildNodes(children, ref, selected) {
  278. children.map(item => {
  279. ref.toggleRowSelection(item, selected);
  280. item.isChecked = selected;
  281. if (item.children) {
  282. this.traverseChildNodes(item.children, ref, selected)
  283. }
  284. })
  285. },
  286. /** 查询参数列表 */
  287. getList() {
  288. this.loading = true;
  289. deptList(this.addDateRange(this.queryParams)).then(response => {
  290. this.adminList = this.handleTree2(response.data, "id");
  291. this.loading = false;
  292. }
  293. );
  294. },
  295. // 同步部门信息
  296. synchrodeptJob(){
  297. if(this.queryParams.name){
  298. deptJob({"name":this.queryParams.name}).then(response =>{
  299. this.getList();
  300. })
  301. localStorage.setItem("timeout","大于10s")
  302. this.msgSuccess('请在定时任务中部门信息中,选择点击更多--调度日志查询同步进度 ', 5000)
  303. this.$router.push({path:'/system/job/jobTaskIndex'})
  304. localStorage.setItem('department', 1)
  305. }else{
  306. this.$message.error('同步部门信息不能为空')
  307. }
  308. },
  309. /** 搜索按钮操作 */
  310. handleQuery() {
  311. this.queryParams.current = 1;
  312. this.getList();
  313. },
  314. /** 重置按钮操作 */
  315. resetQuery() {
  316. this.dateRange = [];
  317. this.resetForm("queryForm");
  318. this.handleQuery();
  319. },
  320. // 取消按钮
  321. cancel() {
  322. this.open = false;
  323. this.reset();
  324. },
  325. // 单选框选中数据
  326. selectBrand(row) {
  327. this.tableRadio = row
  328. },
  329. /** 获取充值管理的数据用于修改赋值 */
  330. getListczgl() {
  331. allRadio().then(response => {
  332. this.radioList = response.data.map(item=>{
  333. return {
  334. identity:item.identity,
  335. proportion:item.proportion,
  336. id:item.id
  337. }
  338. })
  339. });
  340. },
  341. //批量处理
  342. batchChange(change){
  343. this.staffList.deptIds = []
  344. if(this.$refs.tableRef.selection.length>0){
  345. }else{
  346. this.msgError("请选择部门")
  347. }
  348. if(this.tableRadio){
  349. if(change == "1"){
  350. this.getListczgl()
  351. this.open = true;
  352. this.title = "修改参数";
  353. }else{
  354. this.loading = true;
  355. let formData = new FormData();
  356. let arr = []
  357. for(let i = 0;i<this.$refs.tableRef.selection.length;i++){
  358. arr.push(this.$refs.tableRef.selection[i].did)
  359. }
  360. formData.append('deptIds[]',arr);
  361. formData.append('radioId',1);
  362. formData.append('isBinding',0);
  363. updataByDept(formData).then(response =>{
  364. this.loading = false;
  365. this.msgSuccess(`解绑完成`)
  366. this.getList();
  367. }).catch(err=>{
  368. this.loading = false;
  369. })
  370. }
  371. }else{
  372. this.$message.error('请勾选需要处理充值到账比例部门信息')
  373. }
  374. },
  375. /** 提交按钮 */
  376. submitForm() {
  377. let formData = new FormData();
  378. let arr = []
  379. for(let i = 0;i<this.$refs.tableRef.selection.length;i++){
  380. arr.push(this.$refs.tableRef.selection[i].did)
  381. }
  382. formData.append('deptIds[]',arr);
  383. this.$refs["queryParams"].validate(valid => {
  384. if (valid) {
  385. if(this.queryParams.id){
  386. this.loading = true;
  387. formData.append('radioId',this.queryParams.id);
  388. formData.append('isBinding',1);
  389. updataByDept(formData).then(response =>{
  390. this.loading = false;
  391. this.open = false;
  392. this.msgSuccess(`绑定完成`)
  393. this.getList();
  394. this.reset()
  395. }).catch(err=>{
  396. this.loading = false;
  397. })
  398. }
  399. }
  400. })
  401. },
  402. }
  403. };
  404. </script>
  405. <style lang="scss" scoped>
  406. // 深度选择器 去掉全选按钮
  407. ::v-deep .el-table .disabledCheck .cell .el-checkbox__inner {
  408. display: none;
  409. }
  410. </style>