AssignPoint.razor.cs 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202
  1. using AntDesign;
  2. using Microsoft.AspNetCore.Components;
  3. using Microsoft.AspNetCore.Components.Web;
  4. using System;
  5. using System.Collections.Generic;
  6. using System.Linq;
  7. using System.Text.Json;
  8. using System.Threading.Tasks;
  9. using wispro.sp.entity;
  10. using wispro.sp.share;
  11. using wispro.sp.web.Models;
  12. using wispro.sp.web.Services;
  13. namespace wispro.sp.web.Pages.Project
  14. {
  15. public partial class AssignPoint
  16. {
  17. [Inject] public MessageService MsgSvr { get; set; }
  18. [Inject] protected PerformanceItemServices _itemService { get; set; }
  19. [Inject] NavigationManager _NavigationManager { get; set; }
  20. private AntDesign.Modal model;
  21. ProjectPointRecord task = new()
  22. {
  23. //CaseNo = "S2112394",
  24. //CaseName = "美的-洗碗机专利调查",
  25. // ProjectDoItemPoints = new List<ProjectDoItemPoint>()
  26. // {
  27. // new ProjectDoItemPoint(){ DoItem="检索策略评估", DoItemCoefficient="B",
  28. // PersonPoints=new List<PersonPoint>{
  29. // new PersonPoint(){Id="1", Person ="李申", Point=1.0 },
  30. // new PersonPoint(){Id="2", Person ="张三", Point=1.0 },
  31. // new PersonPoint(){Id="3", Person ="李四", Point=1.0 },
  32. // }},
  33. // new ProjectDoItemPoint(){ DoItem="专利分类", DoItemCoefficient="A",
  34. // PersonPoints=new List<PersonPoint>{
  35. // new PersonPoint(){Id="1", Person ="李申", Point=2.0 },
  36. // new PersonPoint(){Id="2", Person ="张三", Point=1.50 },
  37. // new PersonPoint(){Id="3", Person ="李四", Point=2.5 },
  38. // }},
  39. // }
  40. };
  41. ProjectDoItemPoint addDoItem;
  42. bool isAdd = false;
  43. private bool _visible = false;
  44. private void AddNew()
  45. {
  46. addDoItem = new ProjectDoItemPoint();
  47. isAdd = true;
  48. _visible = true;
  49. }
  50. private void HandleOk(MouseEventArgs e)
  51. {
  52. if (isAdd)
  53. {
  54. if (!string.IsNullOrEmpty(addDoItem.DoItem))
  55. {
  56. task.ProjectDoItemPoints.Add(addDoItem);
  57. }
  58. }
  59. _visible = false;
  60. model.Dispose();
  61. }
  62. private void HandleCancel(MouseEventArgs e)
  63. {
  64. _visible = false;
  65. model.Dispose();
  66. }
  67. string editId = null;
  68. void startEdit(string id)
  69. {
  70. editId = id;
  71. MsgSvr.Info($"开始编辑{editId}");
  72. }
  73. void deletePersonPoint(string id)
  74. {
  75. var delObj = addDoItem.PersonPoints.FirstOrDefault<PersonPoint>(f => f.Id == id);
  76. addDoItem.PersonPoints.Remove(delObj);
  77. }
  78. void stopEdit()
  79. {
  80. //var editedData = addDoItem.AddprojectPoints.FirstOrDefault(x => x.person == editId);
  81. editId = null;
  82. }
  83. void Delete(string doItem, string person)
  84. {
  85. if (_visible)
  86. {
  87. var editedData = addDoItem.PersonPoints.FirstOrDefault(x => x.Person == person);
  88. addDoItem.PersonPoints.Remove(editedData);
  89. }
  90. else
  91. {
  92. var editedData = task.ProjectDoItemPoints .FirstOrDefault(x => x.DoItem == doItem);
  93. var personPoint = editedData.PersonPoints.FirstOrDefault(x => x.Id == person);
  94. editedData.PersonPoints.Remove(personPoint);
  95. }
  96. StateHasChanged();
  97. }
  98. void DeleteDoItem(string doItem)
  99. {
  100. var delData = task.ProjectDoItemPoints.FirstOrDefault(x => x.DoItem == doItem);
  101. task.ProjectDoItemPoints.Remove(delData);
  102. }
  103. void EditDoItem(string doItem)
  104. {
  105. isAdd = false;
  106. addDoItem = task.ProjectDoItemPoints.FirstOrDefault(x => x.DoItem == doItem);
  107. _visible = true;
  108. }
  109. private string GetId(List<PersonPoint> personPoints)
  110. {
  111. int i = personPoints.Count;
  112. begin:
  113. foreach(var pp in personPoints)
  114. {
  115. if(pp.Id == i.ToString())
  116. {
  117. i++;
  118. goto begin;
  119. }
  120. }
  121. return i.ToString();
  122. }
  123. void addRow()
  124. {
  125. if(addDoItem.PersonPoints == null)
  126. {
  127. addDoItem.PersonPoints = new List<PersonPoint>();
  128. }
  129. string strId = GetId(addDoItem.PersonPoints);
  130. addDoItem.PersonPoints.Add(
  131. new PersonPoint() { Id = strId, Person ="修改处理人姓名", Point = 0}
  132. ) ;
  133. editId = strId;
  134. StateHasChanged();
  135. }
  136. async Task OnSave()
  137. {
  138. //添加保存代码
  139. var response = await _itemService.AddProjectPerformanctItem(task);
  140. if (response.Success)
  141. {
  142. await MsgSvr.Info("项目绩效保存成功!");
  143. _NavigationManager.NavigateTo("/MyCaseList");
  144. }
  145. else
  146. {
  147. await MsgSvr.Error(response.ErrorMessage);
  148. }
  149. }
  150. void OnCancel()
  151. {
  152. _NavigationManager.NavigateTo("/MyCaseList");
  153. }
  154. private PerformanceItem Item;
  155. private bool loading = false;
  156. async Task GetProjectInfo()
  157. {
  158. loading = true;
  159. Item = await _itemService.GetProjectInfo(task.CaseNo);
  160. if(Item != null)
  161. {
  162. task.CaseName = Item.CaseName;
  163. task.CaseNo = Item.CaseNo;
  164. }
  165. loading = false;
  166. }
  167. }
  168. }