ModalBodyViewModel.cs 7.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267
  1. using System.Collections.Generic;
  2. using System.Linq;
  3. using System.Web.Mvc;
  4. using Abp.Extensions;
  5. using Abp.Localization;
  6. namespace ShwasherSys.Models.Modal
  7. {
  8. public class ModalBodyViewModel
  9. {
  10. public ModalBodyViewModel(List<InputViewModel> inputs, string formId = "form", List<SpecialInputModel> specials = null)
  11. {
  12. FormId = formId;
  13. Inputs = inputs;
  14. Specials = specials;
  15. }
  16. public string FormId { get; set; }
  17. public string ModalId { get; set; }
  18. public List<InputViewModel> Inputs { get; set; }
  19. public List<SpecialInputModel> Specials { get; set; }
  20. }
  21. public class InputViewModel
  22. {
  23. public InputViewModel(string id, InputTypes types = InputTypes.Text, string displayName = "", string value = "", string @class = "", string dataOptions = "", string events = "", string styles = "", string other = "", bool hide = false, string label = "", string searchModalId = "",string name="")
  24. {
  25. Id = id;
  26. DisplayName = displayName.IsNullOrEmpty() ? L(id) : displayName;
  27. Types = types;
  28. Value = value;
  29. _class = @class;
  30. DataOptions = dataOptions;
  31. Events = events;
  32. Styles = styles;
  33. Other = other;
  34. SearchModalId = searchModalId;
  35. IsHidden = hide;
  36. IsRequired = !hide;
  37. IsDisabled = false;
  38. IsReadOnly = false;
  39. _lable = label;
  40. Name = string.IsNullOrEmpty(name) ? id : name;
  41. }
  42. #region 方法
  43. public InputViewModel SetDataOptions(string dataOptions)
  44. {
  45. DataOptions = dataOptions;
  46. return this;
  47. }
  48. public InputViewModel SetEvents(string events)
  49. {
  50. Events = events;
  51. return this;
  52. }
  53. public InputViewModel SetHidden()
  54. {
  55. IsHidden = true;
  56. return this;
  57. }
  58. public InputViewModel SetNotRequired()
  59. {
  60. IsRequired = false;
  61. return this;
  62. }
  63. public InputViewModel SetDisabled()
  64. {
  65. IsDisabled = true;
  66. return this;
  67. }
  68. public InputViewModel SetReadOnly()
  69. {
  70. IsReadOnly = true;
  71. return this;
  72. }
  73. public InputViewModel SetSelectOptions(List<SelectListItem> poSelectOptions)
  74. {
  75. string lcRetval = "";
  76. if (poSelectOptions != null && poSelectOptions.Any())
  77. {
  78. foreach (var s in poSelectOptions)
  79. {
  80. lcRetval += "<option value=\"" + s.Value + "\">" + s.Text + "</option>\r\n";
  81. }
  82. }
  83. SelectOptions = lcRetval;
  84. return this;
  85. }
  86. public InputViewModel SetSelectOptions(string options)
  87. {
  88. SelectOptions = options;
  89. return this;
  90. }
  91. public InputViewModel SetOuterDiv(string classStr, string other = "")
  92. {
  93. DivClass = classStr;
  94. DivOther = other;
  95. return this;
  96. }
  97. /// <summary>
  98. /// 外层上面其他标签
  99. /// </summary>
  100. /// <param name="beforeStr"></param>
  101. /// <returns></returns>
  102. public InputViewModel SetOuterBefore(string beforeStr)
  103. {
  104. DivOutBefore = beforeStr;
  105. return this;
  106. }
  107. /// <summary>
  108. /// 外层下面其他标签
  109. /// </summary>
  110. /// <param name="afterStr"></param>
  111. /// <returns></returns>
  112. public InputViewModel SetOuterAfter(string afterStr)
  113. {
  114. DivOutAfter = afterStr;
  115. return this;
  116. }
  117. /// <summary>
  118. /// 内层上面其他标签
  119. /// </summary>
  120. /// <param name="beforeStr"></param>
  121. /// <returns></returns>
  122. public InputViewModel SetInterBefore(string beforeStr)
  123. {
  124. DivInterBefore = beforeStr;
  125. return this;
  126. }
  127. /// <summary>
  128. /// 内层下面其他标签
  129. /// </summary>
  130. /// <param name="afterStr"></param>
  131. /// <returns></returns>
  132. public InputViewModel SetInterAfter(string afterStr)
  133. {
  134. DivInterAfter = afterStr;
  135. return this;
  136. }
  137. /// <summary>
  138. /// 内层下面其他标签
  139. /// </summary>
  140. /// <param name="searchModalId"></param>
  141. /// <returns></returns>
  142. public InputViewModel SetSearchIcon(string searchModalId,string targetDom="")
  143. {
  144. SearchModalId = searchModalId;
  145. TargetDom = targetDom;
  146. return this;
  147. }
  148. #endregion
  149. #region 字段属性
  150. public string Id { get; set; }
  151. public string DisplayName { get; set; }
  152. public InputTypes Types { get; set; }
  153. public string Value { get; set; }
  154. public string SelectOptions { get; private set; }
  155. private string _class;
  156. public string Class
  157. {
  158. get => "form-control " + _class;
  159. set => _class = value;
  160. }
  161. public string DataOptions { get; set; }
  162. public string Events { get; set; }
  163. public string Styles { get; set; }
  164. public string Other { get; set; }
  165. public bool IsHidden { get; set; }
  166. public bool IsRequired { get; set; }
  167. public bool IsDisabled { get; set; }
  168. public bool IsReadOnly { get; set; }
  169. public string TypeStr
  170. {
  171. get
  172. {
  173. switch (Types)
  174. {
  175. case InputTypes.Text:
  176. return "text";
  177. case InputTypes.Password:
  178. return "password";
  179. case InputTypes.Checkbox:
  180. return "checkbox";
  181. case InputTypes.Radio:
  182. return "radio";
  183. case InputTypes.File:
  184. return "file";
  185. default:
  186. return "text";
  187. }
  188. }
  189. }
  190. public string Required => IsHidden ? "" : (IsRequired ? " required" : "");
  191. public string DivClass { get; set; }
  192. public string DivOther { get; set; }
  193. public string DivOutBefore { get; set; }
  194. public string DivOutAfter { get; set; }
  195. public string DivInterBefore { get; set; }
  196. public string DivInterAfter { get; set; }
  197. public string SearchModalId { get; set; }
  198. private readonly string _lable;
  199. public string Lable => IsHidden
  200. ? ""
  201. : string.IsNullOrEmpty(_lable)
  202. ? (IsRequired
  203. ? "<label class=\"iwb-label col-md-2 control-label iwb-label-required\" for=\"" + Id + "\">" +
  204. DisplayName + "</label>"
  205. : "<label class=\"iwb-label col-md-2 control-label\" for=\"" + Id + "\">" + DisplayName +
  206. "</label>")
  207. : _lable;
  208. public string Disabled => IsDisabled ? "disabled=\"disabled\"" : "";
  209. public string ReadOnly => IsReadOnly ? "readonly=\"readonly\"" : "";
  210. public string Name { get; set; }
  211. public string TargetDom { get; set; }
  212. #endregion
  213. private static string L(string name)
  214. {
  215. var str = LocalizationHelper.GetSource(ShwasherConsts.LocalizationSourceName).GetString(name);
  216. return str;
  217. }
  218. }
  219. public class SpecialInputModel
  220. {
  221. public string Id { get; set; }
  222. public string InputStr { get; set; }
  223. }
  224. //public class SelectOption
  225. //{
  226. // public SelectOption(string text, string value = "")
  227. // {
  228. // Text = text;
  229. // Value = value;
  230. // }
  231. // public string Value { get; set; }
  232. // public string Text { get; set; }
  233. //}
  234. public enum InputTypes
  235. {
  236. Text, List, Checkbox, Radio, Password, Textarea, File
  237. }
  238. }