CreateAppealModel.cs 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  1. using AntDesign;
  2. using Microsoft.AspNetCore.Components;
  3. using System;
  4. using System.Collections;
  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.web.Services;
  11. namespace wispro.sp.web.Models
  12. {
  13. public class CreateAppealModel
  14. {
  15. public PerformanceItem Item { get; set; }
  16. public AppealType AppealType { get; set; }
  17. public List<InputField> inputFields { get; set; }
  18. public List<InputFieldValue> inputFieldValues { get; set; }
  19. public AppealRecord AppealRecord { get; set; }
  20. public List<UploadFileItem> FileList { get; set; }
  21. //public System.Collections.Hashtable _GroupInputValues { get; set; }
  22. //public List<InputFieldValue> noMultiValues { get; set; }
  23. public CreateAppealModel() { }
  24. public async Task Init(AppealTypeService _atService,PerformanceItem item,AppealType appealType)
  25. {
  26. FileList = new List<UploadFileItem>();
  27. AppealType = appealType;
  28. AppealRecord = new AppealRecord();
  29. AppealRecord.TypeId = appealType.Id;
  30. if (item == null)
  31. {
  32. Item = new PerformanceItem();
  33. }
  34. else
  35. {
  36. Item = item;
  37. }
  38. AppealRecord.ItemId = Item.Id;
  39. AppealRecord.State = 0;
  40. if (AppealType != null)
  41. {
  42. inputFieldValues = new List<InputFieldValue>();
  43. inputFields =await _atService.GetInputFields(AppealType.Id, 0);
  44. foreach (var field in inputFields)
  45. {
  46. if (!string.IsNullOrEmpty(field.MapObjectField) && !string.IsNullOrEmpty(field.MapObjectFieldLabel))
  47. {
  48. List<InputFieldValue> temValues = new List<InputFieldValue>();
  49. string[] pList = field.MapObjectField.Split(new char[] { '.'});
  50. string[] plList = field.MapObjectFieldLabel.Split(new char[] { '.' });
  51. var pInfo = Item.GetType().GetProperty(pList[0]);
  52. var o = pInfo.GetValue(item);
  53. if (Array.IndexOf(o.GetType().GetInterfaces(), typeof(IEnumerable)) > -1)
  54. {
  55. List<string> Values = new List<string>();
  56. List<string> Labels = new List<string>();
  57. var objList = o as IEnumerable;
  58. foreach (var obj in objList)
  59. {
  60. var objValue = obj;
  61. var objLabel = obj;
  62. for (int i = 1; i < pList.Length; i++)
  63. {
  64. objValue = objValue.GetType().GetProperty(pList[i]).GetValue(objValue);
  65. }
  66. for (int i = 1; i < plList.Length; i++)
  67. {
  68. objLabel = objLabel.GetType().GetProperty(plList[i]).GetValue(objLabel);
  69. }
  70. var fValue = new InputFieldValue();
  71. fValue.InputField = field;
  72. fValue.InputFieldId = field.Id;
  73. fValue.Label = objLabel.ToString();
  74. if (objValue != null)
  75. {
  76. fValue.Value = objValue.ToString();
  77. }
  78. inputFieldValues.Add(fValue);
  79. temValues.Add(fValue);
  80. }
  81. }
  82. else
  83. {
  84. var fValue = new InputFieldValue();
  85. fValue.InputField = field;
  86. fValue.InputFieldId = field.Id;
  87. inputFieldValues.Add(fValue);
  88. }
  89. }
  90. else
  91. {
  92. var fValue = new InputFieldValue();
  93. fValue.InputField = field;
  94. fValue.InputFieldId = field.Id;
  95. inputFieldValues.Add(fValue);
  96. }
  97. }
  98. }
  99. }
  100. }
  101. }