活动基础单位查询为空,活动单位没有同步sys_unit

This commit is contained in:
2026-09-24 14:51:05 +08:00
parent 0204dc8c92
commit 811e35750e
8 changed files with 267 additions and 113 deletions
@@ -1,25 +1,14 @@
package com.budwk.app.zhgh.activity.basic.controller; package com.budwk.app.zhgh.activity.basic.controller;
import cn.dev33.satoken.annotation.SaCheckPermission; import cn.dev33.satoken.annotation.SaCheckPermission;
import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.lang.tree.Tree;
import cn.hutool.core.lang.tree.TreeNode;
import cn.hutool.core.lang.tree.TreeUtil;
import cn.hutool.core.util.StrUtil;
import com.budwk.app.base.page.Pagination;
import com.budwk.app.base.param.PageForm; import com.budwk.app.base.param.PageForm;
import com.budwk.app.base.result.Result; import com.budwk.app.base.result.Result;
import com.budwk.app.base.service.BaseService;
import com.budwk.app.sys.models.Sys_unit;
import com.budwk.app.sys.services.SysUnitService;
import com.budwk.app.zhgh.activity.basic.models.ActivityBasicUnion;
import com.budwk.app.zhgh.activity.basic.models.ActivityBasicUnit; import com.budwk.app.zhgh.activity.basic.models.ActivityBasicUnit;
import com.budwk.app.zhgh.activity.basic.service.ActivityBasicUnitService;
import org.nutz.aop.interceptor.ioc.TransAop; import org.nutz.aop.interceptor.ioc.TransAop;
import org.nutz.dao.Chain; import org.nutz.dao.Chain;
import org.nutz.dao.Cnd; import org.nutz.dao.Cnd;
import org.nutz.dao.Dao; import org.nutz.dao.Dao;
import org.nutz.dao.Sqls;
import org.nutz.dao.sql.Sql;
import org.nutz.ioc.aop.Aop; import org.nutz.ioc.aop.Aop;
import org.nutz.ioc.loader.annotation.Inject; import org.nutz.ioc.loader.annotation.Inject;
import org.nutz.ioc.loader.annotation.IocBean; import org.nutz.ioc.loader.annotation.IocBean;
@@ -27,9 +16,7 @@ import org.nutz.mvc.annotation.At;
import org.nutz.mvc.annotation.Ok; import org.nutz.mvc.annotation.Ok;
import org.nutz.mvc.annotation.Param; import org.nutz.mvc.annotation.Param;
import java.util.ArrayList;
import java.util.List; import java.util.List;
import java.util.Map;
/** /**
* @ClassName ActivityBasicUnitController * @ClassName ActivityBasicUnitController
@@ -43,7 +30,7 @@ import java.util.Map;
public class ActivityBasicUnitController { public class ActivityBasicUnitController {
@Inject @Inject
private BaseService baseService; private ActivityBasicUnitService activityBasicUnitService;
@Inject @Inject
private Dao dao; private Dao dao;
@@ -54,45 +41,25 @@ public class ActivityBasicUnitController {
public void index() { public void index() {
} }
/**
* 查询选中单位的直属下级;parentId 为空时查询学校 0000 下的单位。
* pageForm 传入页码、页大小及单位名称或代码关键词,返回 Result,data 为包含 list、totalCount 的分页对象。
*/
@At @At
@SaCheckPermission("activity.basic.unit") @SaCheckPermission("activity.basic.unit")
public Result pageData(@Param(value = "parentId") String parentId, PageForm pageForm) { public Result pageData(@Param(value = "parentId") String parentId, PageForm pageForm) {
Cnd cnd = Cnd.NEW(); return Result.success(activityBasicUnitService.listUnitPage(parentId, pageForm));
if (StrUtil.isBlank(parentId)) {
cnd.and("parentId", "=", "1");
} else {
cnd.and("parentId", "=", parentId);
}
if (StrUtil.isNotBlank(pageForm.getSearchName()) && StrUtil.isNotBlank(pageForm.getSearchKeyword())) {
cnd.and(Cnd.likeEX(pageForm.getSearchName(), pageForm.getSearchKeyword()));
}
Sql sql = Sqls.create("select id,parentId,name,unitcode,unitLevel,unionId from activity_basic_unit $condition");
cnd.asc("unitcode");
sql.setCondition(cnd);
Pagination pagination = baseService.listPageMap(pageForm.getPageNumber(), pageForm.getPageSize(), sql);
return Result.success(pagination);
} }
/**
* pid 为空时返回整棵活动单位树,传入单位 ID 时返回其下级子树。
* 返回 Result,data 为节点列表,节点包含 id、parentId、name、unitTypeCode,子节点字段为 children。
*/
@At @At
@SaCheckPermission("activity.basic.unit") @SaCheckPermission("activity.basic.unit")
public Result tree(@Param("pid") String pid) { public Result tree(@Param("pid") String pid) {
try { try {
Cnd cnd = Cnd.NEW(); return Result.success(activityBasicUnitService.getUnitTree(pid));
cnd.andEX("id", "=", pid);
cnd.asc("unitcode");
List<ActivityBasicUnit> list = baseService.dao().query(ActivityBasicUnit.class, cnd);
List<TreeNode<String>> nodeList = CollUtil.newArrayList();
for (int i = 0; i < list.size(); i++) {
nodeList.add(new TreeNode<>(list.get(i).getId(), list.get(i).getParentId(), list.get(i).getName(), i)
.setExtra(
Map.of(
"unitTypeCode", list.get(i).getUnitTypeCode()
)
));
}
List<Tree<String>> treeList = TreeUtil.build(nodeList, StrUtil.blankToDefault(pid, "J"));
return Result.success(treeList);
} catch (Exception e) { } catch (Exception e) {
return Result.error(); return Result.error();
} }
@@ -0,0 +1,27 @@
package com.budwk.app.zhgh.activity.basic.service;
import cn.hutool.core.lang.tree.Tree;
import com.budwk.app.base.page.Pagination;
import com.budwk.app.base.param.PageForm;
import com.budwk.app.base.service.BaseService;
import com.budwk.app.zhgh.activity.basic.models.ActivityBasicUnit;
import java.util.List;
/**
* 活动单位查询,使用活动单位表中的层级及活动工会归属。
*/
public interface ActivityBasicUnitService extends BaseService<ActivityBasicUnit> {
/**
* @param parentId 直属上级单位 ID,空值默认使用学校节点 0000
* @param pageForm 页码、页大小及 name/unitcode 对应的搜索关键词
* @return 包含 list 和 totalCount 的分页结果,list 中为单位字段映射
*/
Pagination listUnitPage(String parentId, PageForm pageForm);
/**
* @param pid 构树父节点 ID,空值使用与系统单位一致的虚拟根 0
* @return 按单位代码排序的子树,节点的 children 字段包含下级单位
*/
List<Tree<String>> getUnitTree(String pid);
}
@@ -0,0 +1,63 @@
package com.budwk.app.zhgh.activity.basic.service.impl;
import cn.hutool.core.lang.tree.Tree;
import cn.hutool.core.lang.tree.TreeNode;
import cn.hutool.core.lang.tree.TreeUtil;
import cn.hutool.core.util.StrUtil;
import com.budwk.app.base.page.Pagination;
import com.budwk.app.base.param.PageForm;
import com.budwk.app.base.service.impl.BaseServiceImpl;
import com.budwk.app.zhgh.activity.basic.models.ActivityBasicUnit;
import com.budwk.app.zhgh.activity.basic.service.ActivityBasicUnitService;
import org.nutz.dao.Cnd;
import org.nutz.dao.Dao;
import org.nutz.dao.Sqls;
import org.nutz.dao.sql.Sql;
import org.nutz.ioc.loader.annotation.IocBean;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
/**
* 根据从 sys_unit 同步的完整单位层级提供活动单位树和直属下级列表。
*/
@IocBean(args = {"refer:dao"})
public class ActivityBasicUnitServiceImpl extends BaseServiceImpl<ActivityBasicUnit> implements ActivityBasicUnitService {
public ActivityBasicUnitServiceImpl(Dao dao) {
super(dao);
}
/** {@inheritDoc} */
@Override
public Pagination listUnitPage(String parentId, PageForm pageForm) {
// 0 是构树用的虚拟根,0000 才是学校实体;默认列表展示学校的直属单位。
Cnd cnd = Cnd.where("parentId", "=", StrUtil.blankToDefault(parentId, "0000"));
String searchName = pageForm.getSearchName();
if (("name".equals(searchName) || "unitcode".equals(searchName))
&& StrUtil.isNotBlank(pageForm.getSearchKeyword())) {
cnd.and(Cnd.likeEX(searchName, pageForm.getSearchKeyword()));
}
cnd.asc("unitcode");
Sql sql = Sqls.create("select id,parentId,name,unitcode,unitLevel,unionId from activity_basic_unit $condition");
sql.setCondition(cnd);
return listPageMap(pageForm.getPageNumber(), pageForm.getPageSize(), sql);
}
/** {@inheritDoc} */
@Override
public List<Tree<String>> getUnitTree(String pid) {
// 必须保留完整父子关系;按 id = pid 过滤会丢失全部下级,无法构建子树。
List<ActivityBasicUnit> units = query(Cnd.NEW().asc("unitcode"));
List<TreeNode<String>> nodes = new ArrayList<>();
for (int i = 0; i < units.size(); i++) {
ActivityBasicUnit unit = units.get(i);
// 机构类别可为空,使用可容纳 null 的映射避免整棵树返回失败。
Map<String, Object> extra = new HashMap<>();
extra.put("unitTypeCode", unit.getUnitTypeCode());
nodes.add(new TreeNode<>(unit.getId(), unit.getParentId(), unit.getName(), i).setExtra(extra));
}
return TreeUtil.build(nodes, StrUtil.blankToDefault(pid, "0"));
}
}
@@ -50,6 +50,16 @@ public class ActivitySportsApplyUserController {
public void index() { public void index() {
} }
/**
* 无请求参数;返回 Result,data.options 为活动工会 id/name 列表,
* data.defaultUnionId 为当前单位关联的活动工会 ID,未设置时为空字符串。
*/
@At
@SaCheckPermission("activity.apply")
public Result unionOptions() {
return Result.success(activitySportsApplyUserService.getApplyUnionOptions());
}
@@ -118,9 +128,7 @@ public class ActivitySportsApplyUserController {
@At @At
@SaCheckPermission("activity.apply") @SaCheckPermission("activity.apply")
public Result getUniteApplyInfo(@Param("data") ActivitySportsApplyUserPageParam applyUserPageParam, Integer isMenWomenTwo) { public Result getUniteApplyInfo(@Param("data") ActivitySportsApplyUserPageParam applyUserPageParam, Integer isMenWomenTwo) {
if (StrUtil.isBlank(activitySportsApplyUserService.getUnionId())) { // 由 service 校验所选活动工会;超管已选择工会时无需绑定本人单位的活动工会。
return Result.error("您暂未设置活动工会");
}
return Result.success(activitySportsApplyUserService.getUniteApplyInfo(applyUserPageParam, isMenWomenTwo)); return Result.success(activitySportsApplyUserService.getUniteApplyInfo(applyUserPageParam, isMenWomenTwo));
} }
@@ -128,6 +136,7 @@ public class ActivitySportsApplyUserController {
@At @At
@SLog(tag = "体育活动", msg = "提交运动员") @SLog(tag = "体育活动", msg = "提交运动员")
@SaCheckPermission("activity.apply") @SaCheckPermission("activity.apply")
@Aop(TransAop.READ_COMMITTED)
public Result doApplyUser(@Param(value = "data") ActivitySchoolApply[] userList, public Result doApplyUser(@Param(value = "data") ActivitySchoolApply[] userList,
String eventId, String eventId,
String activityId, String activityId,
@@ -11,8 +11,12 @@ import java.util.List;
public interface ActivitySportsApplyUserService extends BaseService<ActivitySchoolApply> { public interface ActivitySportsApplyUserService extends BaseService<ActivitySchoolApply> {
/** 返回当前单位关联的有效活动工会 ID;未配置或关联失效时返回空字符串。 */
String getUnionId(); String getUnionId();
/** 返回报名工会配置:options 为活动工会 id/name 列表,defaultUnionId 为当前单位的活动工会 ID。 */
NutMap getApplyUnionOptions();
Pagination pageData(ActivitySportsApplyUserPageParam pageParam); Pagination pageData(ActivitySportsApplyUserPageParam pageParam);
Pagination activityData(Integer year, Integer isActivity,Integer applyStatus); Pagination activityData(Integer year, Integer isActivity,Integer applyStatus);
@@ -3,6 +3,7 @@ package com.budwk.app.zhgh.activity.sports.service.impl;
import cn.hutool.core.date.DateUtil; import cn.hutool.core.date.DateUtil;
import cn.hutool.core.util.StrUtil; import cn.hutool.core.util.StrUtil;
import com.budwk.app.base.constant.RoleConstant; import com.budwk.app.base.constant.RoleConstant;
import com.budwk.app.base.exception.BaseException;
import com.budwk.app.base.page.Pagination; import com.budwk.app.base.page.Pagination;
import com.budwk.app.base.param.PageForm; import com.budwk.app.base.param.PageForm;
import com.budwk.app.base.service.impl.BaseServiceImpl; import com.budwk.app.base.service.impl.BaseServiceImpl;
@@ -49,20 +50,51 @@ public class ActivitySportsApplyUserServiceImpl extends BaseServiceImpl<Activity
} }
/** 当前单位可能未配置活动工会,浏览活动列表时允许返回空值。 */
@Override @Override
public String getUnionId() { public String getUnionId() {
ActivityBasicUnit basicUnit = dao().fetch(ActivityBasicUnit.class, Cnd.where("id", "=", SecurityUtil.getUnitId())); String unitId = SecurityUtil.getUnitId();
if (StrUtil.isBlank(unitId)) {
return "";
}
ActivityBasicUnit basicUnit = dao().fetch(ActivityBasicUnit.class, unitId);
if (basicUnit == null || StrUtil.isBlank(basicUnit.getUnionId())) {
return "";
}
ActivityBasicUnion basicUnion = dao().fetch(ActivityBasicUnion.class, Cnd.where("id", "=", basicUnit.getUnionId())); ActivityBasicUnion basicUnion = dao().fetch(ActivityBasicUnion.class, Cnd.where("id", "=", basicUnit.getUnionId()));
return basicUnion == null ? "" : basicUnion.getId();
}
return StrUtil.isBlank(SecurityUtil.getUnitId()) ? "" : basicUnion.getId(); /** {@inheritDoc} */
@Override
public NutMap getApplyUnionOptions() {
// 活动工会可能与系统工会同名但 ID 不同,选项与默认值必须来自活动体系。
Sql sql = Sqls.create("select id,name from activity_basic_union order by unionCode,id");
return NutMap.NEW().setv("options", listMap(sql)).setv("defaultUnionId", getUnionId());
}
/**
* unionId 为活动工会 ID,空值回退当前单位配置;required 表示业务是否必须指定工会。
* 返回经过存在性校验的活动工会 ID;仅浏览且未配置时返回空字符串,失效 ID 明确报错。
*/
private String resolveApplyUnionId(String unionId, boolean required) {
String resolved = StrUtil.isBlank(unionId) ? getUnionId() : unionId;
if (StrUtil.isBlank(resolved)) {
if (required) {
throw new BaseException("请选择活动工会,或先为当前单位设置活动工会");
}
return "";
}
if (dao().fetch(ActivityBasicUnion.class, resolved) == null) {
throw new BaseException("所选活动工会不存在,请刷新页面后重新选择");
}
return resolved;
} }
@Override @Override
public Pagination pageData(ActivitySportsApplyUserPageParam pageParam) { public Pagination pageData(ActivitySportsApplyUserPageParam pageParam) {
Cnd cnd = Cnd.NEW(); Cnd cnd = Cnd.NEW();
if (StrUtil.isBlank(pageParam.getUnionId())) { pageParam.setUnionId(resolveApplyUnionId(pageParam.getUnionId(), false));
pageParam.setUnionId(getUnionId());
}
Sql sql = Sqls.create(""" Sql sql = Sqls.create("""
SELECT SELECT
ase.*, ase.*,
@@ -217,9 +249,7 @@ public class ActivitySportsApplyUserServiceImpl extends BaseServiceImpl<Activity
@Override @Override
public Object getUnionCoachLeaderHead(String activityId, String unionId) { public Object getUnionCoachLeaderHead(String activityId, String unionId) {
if (StrUtil.isBlank(unionId)) { unionId = resolveApplyUnionId(unionId, false);
unionId = getUnionId();
}
Map result = new HashMap(); Map result = new HashMap();
Sql sql = Sqls.create(""" Sql sql = Sqls.create("""
SELECT apply.*,us.unitname FROM activity_school_apply apply LEFT JOIN `vw_user` us ON us.id=apply.userId WHERE apply.activityId=@activityId and apply.activityUnionId=@activityUnionId SELECT apply.*,us.unitname FROM activity_school_apply apply LEFT JOIN `vw_user` us ON us.id=apply.userId WHERE apply.activityId=@activityId and apply.activityUnionId=@activityUnionId
@@ -270,6 +300,8 @@ public class ActivitySportsApplyUserServiceImpl extends BaseServiceImpl<Activity
@Override @Override
public Object getUniteApplyInfo(ActivitySportsApplyUserPageParam applyUserPageParam, Integer isMenWomen) { public Object getUniteApplyInfo(ActivitySportsApplyUserPageParam applyUserPageParam, Integer isMenWomen) {
// 可报人员与已报名记录共用同一活动工会,避免一边回退默认值、另一边仍使用空值。
applyUserPageParam.setUnionId(resolveApplyUnionId(applyUserPageParam.getUnionId(), true));
Map result = new HashMap(); Map result = new HashMap();
ActivitySchool activity = dao().fetch(ActivitySchool.class, applyUserPageParam.getActivityId()); ActivitySchool activity = dao().fetch(ActivitySchool.class, applyUserPageParam.getActivityId());
@@ -296,7 +328,7 @@ public class ActivitySportsApplyUserServiceImpl extends BaseServiceImpl<Activity
cnd.and(new Static("u.id not in (SELECT IFNULL(app.userId,'') from activity_school_apply app WHERE app.activityId = '" + applyUserPageParam.getActivityId() + "' AND app.eventId='" + applyUserPageParam.getEventId() + "')")); cnd.and(new Static("u.id not in (SELECT IFNULL(app.userId,'') from activity_school_apply app WHERE app.activityId = '" + applyUserPageParam.getActivityId() + "' AND app.eventId='" + applyUserPageParam.getEventId() + "')"));
cnd.and(new Static("u.id IN (SELECT userId FROM activity_user_scope aus WHERE aus.groupId='" + activity.getActivityGroupId() + "')")); cnd.and(new Static("u.id IN (SELECT userId FROM activity_user_scope aus WHERE aus.groupId='" + activity.getActivityGroupId() + "')"));
cnd.and("un.unionid", "=", StrUtil.isNotBlank(applyUserPageParam.getUnionId()) ? applyUserPageParam.getUnionId() : getUnionId()); cnd.and("un.unionid", "=", applyUserPageParam.getUnionId());
if (isMenWomen != null && isMenWomen == 1) if (isMenWomen != null && isMenWomen == 1)
cnd.and("u.sex", "=", "男性"); cnd.and("u.sex", "=", "男性");
if (isMenWomen != null && isMenWomen == 2) if (isMenWomen != null && isMenWomen == 2)
@@ -367,9 +399,8 @@ public class ActivitySportsApplyUserServiceImpl extends BaseServiceImpl<Activity
@Override @Override
@Aop(TransAop.READ_COMMITTED) @Aop(TransAop.READ_COMMITTED)
public void doApplyUser(ActivitySchoolApply[] userList, String eventId, String activityId, Boolean pass, String unionId) { public void doApplyUser(ActivitySchoolApply[] userList, String eventId, String activityId, Boolean pass, String unionId) {
// 写入或清除报名记录前确认活动工会有效,禁止把系统工会 ID 写入活动归属字段。
ActivityBasicUnit basicUnit = dao().fetch(ActivityBasicUnit.class, Cnd.where("id", "=", SecurityUtil.getUnitId())); ActivityBasicUnion basicUnion = dao().fetch(ActivityBasicUnion.class, resolveApplyUnionId(unionId, true));
ActivityBasicUnion basicUnion = dao().fetch(ActivityBasicUnion.class, Cnd.where("id", "=", StrUtil.isNotBlank(unionId) ? unionId : basicUnit.getUnionId()));
for (ActivitySchoolApply apply : userList) { for (ActivitySchoolApply apply : userList) {
@@ -401,9 +432,7 @@ public class ActivitySportsApplyUserServiceImpl extends BaseServiceImpl<Activity
@Override @Override
public Pagination applyPageData(PageForm page, String activityId, String eventId, String unionId) { public Pagination applyPageData(PageForm page, String activityId, String eventId, String unionId) {
Cnd cnd = Cnd.NEW(); Cnd cnd = Cnd.NEW();
if (StrUtil.isBlank(unionId)) { unionId = resolveApplyUnionId(unionId, true);
unionId = getUnionId();
}
Sql sql = Sqls.create(""" Sql sql = Sqls.create("""
SELECT SELECT
apply.*,team.`name`,acts.name actsname,ev.allName apply.*,team.`name`,acts.name actsname,ev.allName
@@ -6,13 +6,13 @@ layout("/layouts/platform.html"){
<el-row :gutter="10" type="flex" style="height: calc(100vh - 126px)"> <el-row :gutter="10" type="flex" style="height: calc(100vh - 126px)">
<el-col :span="5"> <el-col :span="5">
<el-card shadow="never" style="height: 100%" body-style="{ height: '100%' }"> <el-card shadow="never" style="height: 100%" body-style="{ height: '100%' }">
<div style="max-height: calc(100vh - 160px); overflow-y: auto"> <div v-loading="treeLoading" style="max-height: calc(100vh - 160px); overflow-y: auto">
<el-tree <el-tree
:data="treeData" :data="treeData"
:default-expanded-keys="['1']" :default-expanded-keys="['0000']"
:expand-on-click-node="false" :expand-on-click-node="false"
:props="{ :props="{
children: 'child', children: 'children',
label: 'name' label: 'name'
}" }"
@node-click="treeNodeClick" @node-click="treeNodeClick"
@@ -57,7 +57,7 @@ layout("/layouts/platform.html"){
</el-card> </el-card>
<el-card shadow="never" style="border: 1px solid var(--border-color-lighter)"> <el-card shadow="never" style="border: 1px solid var(--border-color-lighter)">
<table-tool></table-tool> <table-tool></table-tool>
<el-table :data="tableData" height="calc(100vh - 380px)" border size="small"> <el-table :data="tableData" v-loading="tableLoading" height="calc(100vh - 380px)" border size="small">
<el-table-column label="序号" type="index"> <el-table-column label="序号" type="index">
<template scope="scope"> <template scope="scope">
<span>{{scope.$index+(pageForm.pageNumber - 1) * pageForm.pageSize + 1}}</span> <span>{{scope.$index+(pageForm.pageNumber - 1) * pageForm.pageSize + 1}}</span>
@@ -95,50 +95,75 @@ layout("/layouts/platform.html"){
data() { data() {
return { return {
pageForm: { pageForm: {
searchName: "name" searchName: "name",
parentId: "0000"
}, },
treeData: [], treeData: [],
treeLoading: false,
currentTreeNode: null, currentTreeNode: null,
currentTreeData: null currentTreeData: null
} }
}, },
components: {}, components: {},
methods: { methods: {
async doDelete(id) { doDelete(id) {
const confirm = await this.$confirm("确定要删除该单位吗?", "提示", { this.$confirm("确定要删除该单位吗?", "提示", {
confirmButtonText: "确定", confirmButtonText: "确定",
cancelButtonText: "取消", cancelButtonText: "取消",
type: "warning" type: "warning"
}).then(() => {
return this.$axios.post(loc() + "/doDelete", { id }).then((resp) => {
if (resp.code === 0) {
// 树刷新后统一恢复选中节点并查询列表,避免旧节点条件与新树不一致。
this.getTreeData()
this.$message.success(resp.msg)
} else {
this.notifyWarning(resp.msg)
}
})
}, () => {
// 取消确认时保留当前单位树及列表。
}) })
if (confirm === "confirm") {
const resp = await this.$axios.post(loc() + "/doDelete", { id })
if (resp.code === 0) {
this.getTreeData()
this.doSearch()
this.$message.success(resp.msg)
} else {
this.notifyWarning(resp.msg)
}
}
}, },
treeNodeClick(data, node) { treeNodeClick(data, node) {
this.currentTreeData = data this.currentTreeData = data
this.currentTreeNode = node this.currentTreeNode = node
this.pageForm.parentId = data.id // 直属下级查询复用 mixin 的搜索及分页重置逻辑。
this.$set(this.pageForm, "parentId", data.id)
this.doSearch() this.doSearch()
}, },
getTreeData() { getTreeData() {
this.$axios.post(loc() + "/tree").then((res) => { this.treeLoading = true
this.treeData = res.data return this.$axios.post(loc() + "/tree").then((res) => {
if (this.treeData) { if (res.code !== 0) {
this.currentTreeData = this.treeData[0] this.notifyWarning(res.msg)
return
} }
this.treeData = res.data || []
return this.$nextTick(() => {
// 首次选择学校节点;刷新时保留当前选择,节点不存在时回退到首个根节点。
const selectedNode = this.currentTreeData
? this.$refs.treeRef.getNode(this.currentTreeData.id) : null
const selectedData = selectedNode ? selectedNode.data : this.treeData[0]
if (selectedData) {
this.$refs.treeRef.setCurrentKey(selectedData.id)
this.treeNodeClick(selectedData, this.$refs.treeRef.getNode(selectedData.id))
} else {
// 空树时清除旧列表,避免继续显示已经删除或失效的单位。
this.currentTreeData = null
this.currentTreeNode = null
this.tableData = []
this.$set(this.pageForm, "parentId", "")
this.$set(this.pageForm, "totalCount", 0)
}
})
}).finally(() => {
this.treeLoading = false
}) })
}, },
openUnit() {} openUnit() {}
}, },
created() { created() {
this.pageData()
this.getTreeData() this.getTreeData()
} }
}) })
@@ -362,6 +362,7 @@ layout("/layouts/platform.html"){
activityList: [], activityList: [],
pageForm: { pageForm: {
isMenWomen: [], isMenWomen: [],
unionId: "",
isActivity: "2", isActivity: "2",
year: new Date().getFullYear() + "" year: new Date().getFullYear() + ""
}, },
@@ -379,6 +380,7 @@ layout("/layouts/platform.html"){
{prop: "apply_num_bc", label: "暂保存人数"} {prop: "apply_num_bc", label: "暂保存人数"}
], ],
unionOptions: [], unionOptions: [],
defaultUnionId: "",
dialogLeaderCoach: false, dialogLeaderCoach: false,
userOptions: [], userOptions: [],
@@ -392,6 +394,27 @@ layout("/layouts/platform.html"){
"activity-sports-delete-user": ACTIVITY_SPORTS_DELETE_USER "activity-sports-delete-user": ACTIVITY_SPORTS_DELETE_USER
}, },
methods: { methods: {
getApplyUnionOptions() {
// 报名只使用活动工会,默认值取当前单位的活动工会关联。
return this.$axios.post(loc() + "/unionOptions").then((res) => {
if (res.code !== 0) {
this.notifyWarning(res.msg)
return
}
this.unionOptions = res.data.options || []
this.defaultUnionId = res.data.defaultUnionId || ""
this.$set(this.pageForm, "unionId", this.defaultUnionId)
})
},
getSelectedApplyUnionId() {
// 清空选项时回退活动工会默认值,不能使用登录信息中的系统工会 ID。
const unionId = this.pageForm.unionId || this.defaultUnionId
if (!unionId || !this.unionOptions.some((item) => item.id === unionId)) {
this.notifyWarning("请选择有效的活动工会")
return ""
}
return unionId
},
changeLeader(id) { changeLeader(id) {
if (id) { if (id) {
const userList = this.$refs.userData.options const userList = this.$refs.userData.options
@@ -501,27 +524,27 @@ layout("/layouts/platform.html"){
this.activityNoticeDialog = true this.activityNoticeDialog = true
}, },
async getUnionCoachLeaderHead() { getUnionCoachLeaderHead() {
this.leaderData = {} this.leaderData = {}
this.coachData = {} this.coachData = {}
this.headData = {} this.headData = {}
this.staffData = {} this.staffData = {}
const resp = await this.$axios.post(loc() + "/getUnionCoachLeaderHead", {activityId: this.pageForm.activityId}) // 领队教练回显跟随报名选择的活动工会。
const {unionCoach, unionLeader, unionHead, unionStaff, userOptions} = resp.data return this.$axios.post(loc() + "/getUnionCoachLeaderHead", {
if (unionCoach) { activityId: this.pageForm.activityId,
this.coachData = unionCoach unionId: this.pageForm.unionId || this.defaultUnionId
} }).then((resp) => {
if (unionLeader) { if (resp.code !== 0) {
this.leaderData = unionLeader this.notifyWarning(resp.msg)
} return
if (unionHead) { }
this.headData = unionHead const {unionCoach, unionLeader, unionHead, unionStaff, userOptions} = resp.data
} this.coachData = unionCoach || {}
if (unionStaff) { this.leaderData = unionLeader || {}
this.staffData = unionStaff this.headData = unionHead || {}
} this.staffData = unionStaff || {}
this.userOptions = userOptions
this.userOptions = userOptions })
}, },
async changeActivity() { async changeActivity() {
const resp = await this.$axios.post("/platform/activity/apply/getEvents", {activityId: this.pageForm.activityId}) const resp = await this.$axios.post("/platform/activity/apply/getEvents", {activityId: this.pageForm.activityId})
@@ -539,14 +562,15 @@ layout("/layouts/platform.html"){
}) })
}, },
async openUniteApply(data) { openUniteApply(data) {
const now = moment().valueOf() const now = moment().valueOf()
if (now < moment(data.applyStartTime).valueOf() || now > moment(data.applyEndTime).valueOf()) { if (now < moment(data.applyStartTime).valueOf() || now > moment(data.applyEndTime).valueOf()) {
this.notifyWarning("此活动不在报名时间内") this.notifyWarning("此活动不在报名时间内")
return return
} }
const union = this.$store.state.user.union const unionId = this.getSelectedApplyUnionId()
data.unionId = this.pageForm.unionId ? this.pageForm.unionId : union.id if (!unionId) return
this.$set(data, "unionId", unionId)
this.$refs.guava.edit(() => { this.$refs.guava.edit(() => {
this.$refs.activityApplyUser.openUniteApply(data) this.$refs.activityApplyUser.openUniteApply(data)
}) })
@@ -555,8 +579,9 @@ layout("/layouts/platform.html"){
this.$refs.activityApplyUser.doApplyUser(flag) this.$refs.activityApplyUser.doApplyUser(flag)
}, },
doDelete(data) { doDelete(data) {
const union = this.$store.state.user.union const unionId = this.getSelectedApplyUnionId()
data.unionId = this.pageForm.unionId ? this.pageForm.unionId : union.id if (!unionId) return
this.$set(data, "unionId", unionId)
this.$refs.guava.public(() => { this.$refs.guava.public(() => {
this.$refs.activityDeleteUser.openDelete(data) this.$refs.activityDeleteUser.openDelete(data)
}) })
@@ -566,11 +591,16 @@ layout("/layouts/platform.html"){
this.$refs.guava.index() this.$refs.guava.index()
} }
}, },
async created() { created() {
await this.activityInfoData() // 工会选项就绪后加载活动,防止报名入口使用尚未初始化的默认工会。
this.unitOptions = await this.$businessTool.listUnit() this.getApplyUnionOptions().then(() => {
this.unionOptions = await this.$businessTool.listUnion() return this.activityInfoData()
await this.focusGroup() }).then(() => {
return this.$businessTool.listUnit()
}).then((units) => {
this.unitOptions = units
return this.focusGroup()
})
} }
}) })
</script> </script>