ModalViewModel.cs 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140
  1. using System.Collections.Generic;
  2. namespace ContractService.Views.Shared.Modals
  3. {
  4. public class ModalViewModel
  5. {
  6. public ModalViewModel()
  7. {
  8. IsCenter = true;
  9. ModalId = "modal";
  10. }
  11. public ModalViewModel(string header, string modalId = "modal", int footer = 0, string sizeClass = "lg", int? width = null) : this()
  12. {
  13. Header = new ModalHeaderViewModel(header);
  14. Footer = footer + "";
  15. ModalId = modalId;
  16. Width = width;
  17. SizeClass = sizeClass;
  18. }
  19. public ModalViewModel(string header1, string header2, string modalId = "modal", int footer = 0, string sizeClass = "lg", int? width = null) : this()
  20. {
  21. Header = new ModalHeaderViewModel(header1, header2);
  22. Footer = footer + "";
  23. ModalId = modalId;
  24. Width = width;
  25. SizeClass = sizeClass;
  26. IsCenter = true;
  27. }
  28. public ModalViewModel(string header, ModalBodyViewModel body, string modalId = "modal", string footer = "0", string sizeClass = "lg", int? width = null) : this()
  29. {
  30. Header = new ModalHeaderViewModel(header);
  31. Body = body;
  32. Body.ModalId = modalId;
  33. Footer = footer;
  34. ModalId = modalId;
  35. Width = width;
  36. SizeClass = sizeClass;
  37. IsCenter = true;
  38. }
  39. public ModalViewModel(string header1, string header2, ModalBodyViewModel body, string modalId = "modal", int footer = 0, string sizeClass = "lg", int? width = null) : this()
  40. {
  41. Header = new ModalHeaderViewModel(header1, header2);
  42. Body = body;
  43. if (body != null)
  44. {
  45. Body.ModalId = modalId;
  46. }
  47. Footer = footer + "";
  48. ModalId = modalId;
  49. Width = width;
  50. SizeClass = sizeClass;
  51. }
  52. public ModalViewModel(ModalHeaderViewModel header, ModalBodyViewModel body, string modalId = "modal", int footer = 0, string sizeClass = "lg", int? width = null) : this()
  53. {
  54. Header = header;
  55. Body = body;
  56. Body.ModalId = modalId;
  57. Footer = footer + "";
  58. ModalId = modalId;
  59. Width = width;
  60. SizeClass = sizeClass;
  61. }
  62. public ModalHeaderViewModel Header { get; set; }
  63. public ModalBodyViewModel Body { get; set; }
  64. public string Footer { get; set; }
  65. public string ModalId { get; set; }
  66. public int? Width { get; set; }
  67. public string SizeClass { get; set; }
  68. public bool IsCenter { get; set; }
  69. public ModalViewModel SetModalId(string id)
  70. {
  71. ModalId = id;
  72. return this;
  73. }
  74. public ModalViewModel SetHeader(string header1, string header2 = null)
  75. {
  76. Header = new ModalHeaderViewModel(header1, header2);
  77. return this;
  78. }
  79. public ModalViewModel SetHeader(ModalHeaderViewModel header)
  80. {
  81. Header = header;
  82. return this;
  83. }
  84. public ModalViewModel SetBody(ModalBodyViewModel body)
  85. {
  86. Body = body;
  87. return this;
  88. }
  89. public ModalViewModel SetInputs(List<Input> inputs, string formId = "form")
  90. {
  91. Body = new ModalBodyViewModel(inputs, formId, ModalId);
  92. return this;
  93. }
  94. public ModalViewModel SetSpecials(List<SpecialInputModel> inputs)
  95. {
  96. if (Body != null)
  97. {
  98. Body.Specials = inputs;
  99. }
  100. return this;
  101. }
  102. public ModalViewModel SetFooter(string footer)
  103. {
  104. Footer = footer;
  105. return this;
  106. }
  107. public ModalViewModel SetFooter(int footer)
  108. {
  109. Footer = footer + "";
  110. return this;
  111. }
  112. public ModalViewModel SetSize(string sizeClass)
  113. {
  114. SizeClass = sizeClass;
  115. return this;
  116. }
  117. public ModalViewModel SetSize(int width)
  118. {
  119. Width = width;
  120. return this;
  121. }
  122. /// <summary>
  123. ///取消垂直居中 (默认垂直居中)
  124. /// </summary>
  125. /// <returns></returns>
  126. public ModalViewModel SetNotCenter()
  127. {
  128. IsCenter = false;
  129. return this;
  130. }
  131. }
  132. }