AssignPoint.razor.cs 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185
  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. //Console.WriteLine(e);
  65. _visible = false;
  66. model.Dispose();
  67. }
  68. string editId = null;
  69. void startEdit(string id)
  70. {
  71. editId = id;
  72. MsgSvr.Info($"开始编辑{editId}");
  73. }
  74. void deletePersonPoint(string id)
  75. {
  76. var delObj = addDoItem.PersonPoints.FirstOrDefault<PersonPoint>(f => f.Id == id);
  77. addDoItem.PersonPoints.Remove(delObj);
  78. }
  79. void stopEdit()
  80. {
  81. //var editedData = addDoItem.AddprojectPoints.FirstOrDefault(x => x.person == editId);
  82. //Console.WriteLine(JsonSerializer.Serialize(editedData));
  83. editId = null;
  84. }
  85. void Delete(string doItem, string person)
  86. {
  87. Console.WriteLine(JsonSerializer.Serialize(task));
  88. if (_visible)
  89. {
  90. var editedData = addDoItem.PersonPoints.FirstOrDefault(x => x.Person == person);
  91. addDoItem.PersonPoints.Remove(editedData);
  92. }
  93. else
  94. {
  95. var editedData = task.ProjectDoItemPoints .FirstOrDefault(x => x.DoItem == doItem);
  96. Console.WriteLine(JsonSerializer.Serialize(editedData));
  97. var personPoint = editedData.PersonPoints.FirstOrDefault(x => x.Id == person);
  98. Console.WriteLine(JsonSerializer.Serialize(personPoint));
  99. editedData.PersonPoints.Remove(personPoint);
  100. }
  101. Console.WriteLine(JsonSerializer.Serialize(task));
  102. StateHasChanged();
  103. }
  104. void DeleteDoItem(string doItem)
  105. {
  106. var delData = task.ProjectDoItemPoints.FirstOrDefault(x => x.DoItem == doItem);
  107. task.ProjectDoItemPoints.Remove(delData);
  108. }
  109. void EditDoItem(string doItem)
  110. {
  111. isAdd = false;
  112. addDoItem = task.ProjectDoItemPoints.FirstOrDefault(x => x.DoItem == doItem);
  113. _visible = true;
  114. }
  115. private string GetId(List<PersonPoint> personPoints)
  116. {
  117. int i = personPoints.Count;
  118. begin:
  119. foreach(var pp in personPoints)
  120. {
  121. if(pp.Id == i.ToString())
  122. {
  123. i++;
  124. goto begin;
  125. }
  126. }
  127. return i.ToString();
  128. }
  129. void addRow()
  130. {
  131. if(addDoItem.PersonPoints == null)
  132. {
  133. addDoItem.PersonPoints = new List<PersonPoint>();
  134. }
  135. string strId = GetId(addDoItem.PersonPoints);
  136. addDoItem.PersonPoints.Add(
  137. new PersonPoint() { Id = strId, Person ="修改处理人姓名", Point = 0}
  138. ) ;
  139. editId = strId;
  140. StateHasChanged();
  141. }
  142. async Task OnSave()
  143. {
  144. //添加保存代码
  145. await _itemService.AddProjectPerformanctItem(task);
  146. await MsgSvr.Info("项目绩效保存成功!");
  147. _NavigationManager.NavigateTo("/MyCaseList");
  148. }
  149. void OnCancel()
  150. {
  151. _NavigationManager.NavigateTo("/MyCaseList");
  152. }
  153. }
  154. }