CreateAppealModel.cs 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  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. Item = item;
  28. AppealType = appealType;
  29. AppealRecord = new AppealRecord();
  30. AppealRecord.TypeId = appealType.Id;
  31. AppealRecord.ItemId = item.Id;
  32. AppealRecord.State = 0;
  33. if (AppealType != null)
  34. {
  35. inputFieldValues = new List<InputFieldValue>();
  36. inputFields =await _atService.GetInputFields(AppealType.Id, 0);
  37. foreach (var field in inputFields)
  38. {
  39. if (!string.IsNullOrEmpty(field.MapObjectField) && !string.IsNullOrEmpty(field.MapObjectFieldLabel))
  40. {
  41. List<InputFieldValue> temValues = new List<InputFieldValue>();
  42. string[] pList = field.MapObjectField.Split(new char[] { '.'});
  43. string[] plList = field.MapObjectFieldLabel.Split(new char[] { '.' });
  44. var pInfo = Item.GetType().GetProperty(pList[0]);
  45. var o = pInfo.GetValue(item);
  46. if (Array.IndexOf(o.GetType().GetInterfaces(), typeof(IEnumerable)) > -1)
  47. {
  48. List<string> Values = new List<string>();
  49. List<string> Labels = new List<string>();
  50. var objList = o as IEnumerable;
  51. foreach (var obj in objList)
  52. {
  53. var objValue = obj;
  54. var objLabel = obj;
  55. for (int i = 1; i < pList.Length; i++)
  56. {
  57. objValue = objValue.GetType().GetProperty(pList[i]).GetValue(objValue);
  58. }
  59. for (int i = 1; i < plList.Length; i++)
  60. {
  61. objLabel = objLabel.GetType().GetProperty(plList[i]).GetValue(objLabel);
  62. }
  63. var fValue = new InputFieldValue();
  64. fValue.InputField = field;
  65. fValue.InputFieldId = field.Id;
  66. fValue.Label = objLabel.ToString();
  67. if (objValue != null)
  68. {
  69. fValue.Value = objValue.ToString();
  70. }
  71. inputFieldValues.Add(fValue);
  72. temValues.Add(fValue);
  73. }
  74. }
  75. else
  76. {
  77. var fValue = new InputFieldValue();
  78. fValue.InputField = field;
  79. fValue.InputFieldId = field.Id;
  80. inputFieldValues.Add(fValue);
  81. }
  82. }
  83. else
  84. {
  85. var fValue = new InputFieldValue();
  86. fValue.InputField = field;
  87. fValue.InputFieldId = field.Id;
  88. inputFieldValues.Add(fValue);
  89. }
  90. }
  91. }
  92. }
  93. }
  94. }