service.ts 9.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302
  1. /*
  2. * @Author: code4eat awesomedema@gmail.com
  3. * @Date: 2025-09-30 00:00:00
  4. * @LastEditors: code4eat awesomedema@gmail.com
  5. * @LastEditTime: 2025-09-30 00:00:00
  6. * @FilePath: /KC-MiddlePlatform/src/pages/platform/setting/serviceEvaluate/service.ts
  7. * @Description: 服务评价管理 - 服务层封装(默认使用 mock 接口)
  8. */
  9. // 本地模拟返回:使用前端内存数据替代实际请求,方便在后端未就绪时开发、联调
  10. import { request } from 'umi';
  11. // 分类树节点
  12. export type CategoryNode = {
  13. id: string;
  14. name: string;
  15. children?: CategoryNode[];
  16. };
  17. // 评价项目
  18. export type ProjectItem = {
  19. projectId: string;
  20. projectCode: string;
  21. projectName: string;
  22. weight: number; // 0-100
  23. };
  24. // 选项
  25. export type OptionItem = {
  26. optionId: string;
  27. optionCode: string;
  28. optionName: string;
  29. score: number;
  30. };
  31. // 分页响应(为兼容 KCTable 的 request,保持 list 字段)
  32. export type ListResp<T> = {
  33. list: T[];
  34. };
  35. // ------------------ 真实接口:系统树获取 ------------------
  36. // 注意:页面内仍使用本地 mock 的分类树/项目/选项。
  37. // 本方法用于“添加系统”弹窗的数据源,请求服务端返回的 systemList 结构。
  38. export type SystemTreeNode = {
  39. code: string;
  40. name: string;
  41. sort?: number;
  42. type?: number;
  43. children?: SystemTreeNode[];
  44. };
  45. export type GetSystemListResp = { systemList: SystemTreeNode[]; selectSystemList: (string | number)[] };
  46. export const getSystemListForModal = async (): Promise<GetSystemListResp> => {
  47. const resp = await request<any>(
  48. '/centerSys/evaluation/getSystemList',
  49. { method: 'GET' },
  50. );
  51. // 后端返回形如 { status, msg, data: { systemList, selectSystemList } }
  52. const data = resp?.data || resp || {};
  53. const selectedRaw = data.selectSystemList || [];
  54. const normalizeKey = (x: any) => String((x && (x.systemId || x.code)) || x);
  55. const selected = Array.isArray(selectedRaw) ? selectedRaw.map((x: any) => normalizeKey(x)) : [];
  56. return {
  57. systemList: data.systemList || [],
  58. selectSystemList: selected,
  59. };
  60. };
  61. // 保存所选系统
  62. export const addSystems = async (
  63. data: { systemId: string | number; systemName: string }[],
  64. ) => {
  65. return request('/centerSys/evaluation/addSystem', {
  66. method: 'POST',
  67. data,
  68. });
  69. };
  70. // 获取左侧“已选系统”列表
  71. export type SelectedSystemItem = { id: string | number; hospId: string | number; systemId: string | number; systemName: string };
  72. export const getSelectedSystemList = async (): Promise<SelectedSystemItem[]> => {
  73. const resp = await request<any>('/centerSys/evaluation/getSelectSystemList', { method: 'GET' });
  74. // 兼容后端返回 { data: [...] }
  75. return resp?.data || resp || [];
  76. };
  77. // 在系统下添加服务类型
  78. export const addServiceTypes = async (systemId: string | number, serviceTypes: (string | number)[]) => {
  79. return request('/centerSys/evaluation/addService', {
  80. method: 'POST',
  81. data: { systemId, serviceTypes },
  82. });
  83. };
  84. // 根据服务类型获取评价项列表
  85. export const getServiceEvaluationItem = async (serviceType: string) => {
  86. return request<any>('/centerSys/evaluation/getServiceEvaluationItem', {
  87. method: 'GET',
  88. params: { serviceType },
  89. });
  90. };
  91. // 获取右侧表格:评价项目列表(按 ItemCode)
  92. export const getEvaluationSelect = async (ItemCode: string) => {
  93. return request<any>('/centerSys/evaluation/getEvaluationSelect', {
  94. method: 'GET',
  95. params: { ItemCode },
  96. });
  97. };
  98. // 保存评价项目
  99. export const addEvaluationItem = async (
  100. serviceType: string,
  101. itemCodes: { itemCode: string; itemName: string; itemValue: number; sort: number }[],
  102. ) => {
  103. return request('/centerSys/evaluation/addEvaluationItem', {
  104. method: 'POST',
  105. data: { serviceType, itemCodes },
  106. });
  107. };
  108. // 保存评价项的"选项"
  109. export const addEvaluationSelect = async (
  110. itemCode: string,
  111. selectCodes: { itemCode: string; itemName: string; itemValue: number; sort: number }[],
  112. ) => {
  113. return request('/centerSys/evaluation/addEvaluationSelect', {
  114. method: 'POST',
  115. data: { itemCode, selectCodes },
  116. });
  117. };
  118. // 编辑选项得分
  119. export const editEvaluationSelect = async (id: number | string, value: number) => {
  120. return request('/centerSys/evaluation/editEvaluationSelect', {
  121. method: 'POST',
  122. data: { id, value },
  123. });
  124. };
  125. // 删除评价项目
  126. export const deleteEvaluationItem = async (id: number | string) => {
  127. return request(`/centerSys/evaluation/deleteEvaluationItem?id=${id}`, {
  128. method: 'POST',
  129. });
  130. };
  131. // 删除选项
  132. export const deleteEvaluationSelect = async (id: number | string) => {
  133. return request(`/centerSys/evaluation/deleteEvaluationSelect?id=${id}`, {
  134. method: 'POST',
  135. });
  136. };
  137. // 获取分类树
  138. // 内存数据:分类树
  139. const __categoryTree__: CategoryNode[] = [
  140. {
  141. id: 'park-app',
  142. name: '停车服务APP',
  143. children: [
  144. { id: 'park-service', name: '停车服务', children: [] },
  145. { id: 'guard-service', name: '护工服务', children: [] },
  146. { id: 'food-app', name: '食堂点餐APP', children: [] },
  147. ],
  148. },
  149. ];
  150. // 内存数据:项目、选项
  151. const __projects__: Record<string, ProjectItem[]> = {
  152. 'park-service': [
  153. { projectId: 'p1', projectCode: 'P0001', projectName: '专业能力', weight: 25 },
  154. { projectId: 'p2', projectCode: 'P0002', projectName: '服务态度', weight: 20 },
  155. ],
  156. };
  157. const __options__: Record<string, OptionItem[]> = {
  158. p1: [
  159. { optionId: 'o11', optionCode: 'X0006', optionName: '1星', score: 100 },
  160. { optionId: 'o12', optionCode: 'X0007', optionName: '2星', score: 2 },
  161. { optionId: 'o13', optionCode: 'X0008', optionName: '3星', score: 3 },
  162. { optionId: 'o14', optionCode: 'X0009', optionName: '4星', score: 4 },
  163. { optionId: 'o15', optionCode: 'X0010', optionName: '5星', score: 5 },
  164. ],
  165. p2: [],
  166. };
  167. // 工具:模拟异步
  168. const delay = (ms = 200) => new Promise((r) => setTimeout(r, ms));
  169. export const getCategoryTree = async () => {
  170. await delay();
  171. return __categoryTree__;
  172. };
  173. // 新增分类节点(默认添加到指定父节点 children 下;未传 parentId 则添加到根)
  174. export const addCategory = async (parentId: string | undefined, name: string) => {
  175. await delay();
  176. const newNode: CategoryNode = { id: `cat_${Date.now()}`, name, children: [] };
  177. if (!parentId) {
  178. __categoryTree__.push(newNode);
  179. return newNode;
  180. }
  181. // 递归查找父节点
  182. const dfs = (list: CategoryNode[]): boolean => {
  183. for (const node of list) {
  184. if (node.id === parentId) {
  185. node.children = node.children || [];
  186. node.children.push(newNode);
  187. return true;
  188. }
  189. if (node.children && node.children.length > 0) {
  190. if (dfs(node.children)) return true;
  191. }
  192. }
  193. return false;
  194. };
  195. dfs(__categoryTree__);
  196. return newNode;
  197. };
  198. // 获取项目列表
  199. export const getProjectList = async (params: { categoryId: string; current?: number; pageSize?: number }) => {
  200. await delay();
  201. const list = __projects__[params.categoryId] || [];
  202. return { list };
  203. };
  204. // 新增项目
  205. export const addProject = async (data: { categoryId: string; projectCode: string; projectName: string; weight: number }) => {
  206. await delay();
  207. const newItem: ProjectItem = {
  208. projectId: `p_${Date.now()}`,
  209. projectCode: data.projectCode,
  210. projectName: data.projectName,
  211. weight: Number(data.weight) || 0,
  212. };
  213. __projects__[data.categoryId] = __projects__[data.categoryId] || [];
  214. __projects__[data.categoryId].push(newItem);
  215. return true as unknown as any;
  216. };
  217. // 删除项目
  218. export const delProject = async (projectId: string) => {
  219. await delay();
  220. Object.keys(__projects__).forEach((k) => {
  221. __projects__[k] = (__projects__[k] || []).filter((p) => p.projectId !== projectId);
  222. });
  223. delete __options__[projectId];
  224. return true as unknown as any;
  225. };
  226. // 更新项目权重
  227. export const updateProjectWeight = async (projectId: string, weight: number) => {
  228. await delay();
  229. Object.keys(__projects__).forEach((k) => {
  230. (__projects__[k] || []).forEach((p) => {
  231. if (p.projectId === projectId) p.weight = Number(weight) || 0;
  232. });
  233. });
  234. return true as unknown as any;
  235. };
  236. // 获取选项列表
  237. export const getOptionList = async (params: { projectId: string }) => {
  238. await delay();
  239. return __options__[params.projectId] || [];
  240. };
  241. // 新增选项
  242. export const addOption = async (data: { projectId: string; optionCode: string; optionName: string; score: number }) => {
  243. await delay();
  244. __options__[data.projectId] = __options__[data.projectId] || [];
  245. __options__[data.projectId].push({ optionId: `o_${Date.now()}`, optionCode: data.optionCode, optionName: data.optionName, score: Number(data.score) || 0 });
  246. return true as unknown as any;
  247. };
  248. // 删除选项
  249. export const delOption = async (optionId: string) => {
  250. await delay();
  251. Object.keys(__options__).forEach((k) => {
  252. __options__[k] = (__options__[k] || []).filter((o) => o.optionId !== optionId);
  253. });
  254. return true as unknown as any;
  255. };
  256. // 更新选项分数
  257. export const updateOptionScore = async (optionId: string, score: number) => {
  258. await delay();
  259. Object.keys(__options__).forEach((k) => {
  260. (__options__[k] || []).forEach((o) => {
  261. if (o.optionId === optionId) o.score = Number(score) || 0;
  262. });
  263. });
  264. return true as unknown as any;
  265. };