using System.Collections.Generic; using System.Linq; using System.Web.Mvc; using Abp.Localization; using IwbZero; namespace ContractService.Views.Shared.Modals { public class ModalInputViewModel { public ModalInputViewModel(List inputs, List specials) { Specials = specials; Inputs = inputs; } public List Specials { get; set; } public List Inputs { get; set; } } public class ModalTabInputViewModel { public ModalTabInputViewModel(List tabs, List specials) { Tabs = tabs; Specials = specials; } public List Tabs { get; set; } public List Specials { get; set; } } #region ModalBody public class Input { public Input() { InputType = InputTypes.Text; LayoutClassDefault = true; DivClassDefault = true; } public Input(string id, string displayName = "", InputTypes inputType = InputTypes.Text, string placeholder = "", string name = null, string value = "", string @class = "", string dataOptions = "", string events = "", string styles = "", string other = "", bool hide = false, string label = "", string help = "") : this() { Id = id; Name = string.IsNullOrEmpty(name) ? id : name; DisplayName = string.IsNullOrEmpty(displayName) ? L(id) : displayName; InputType = inputType; _placeholder = placeholder; Value = value; _class = @class; DataOptions = dataOptions; Events = events; Styles = styles; Other = other; IsHidden = hide; IsRequired = !hide; IsDisabled = false; IsReadOnly = false; _label = label; Help = help; IsSm = true; } #region 方法 public Input SetType(InputTypes inputType = InputTypes.Text) { InputType = inputType; return this; } public Input SetList() { InputType = InputTypes.List; return this; } public Input SetList(List selectOptions, bool isMultiple = false, bool isAddBlank = false) { return SetSelectOptions(selectOptions, isMultiple, isAddBlank); } public Input SetList(string selectOptions, bool isMultiple = false, bool isAddBlank = false) { return SetSelectOptions(selectOptions, isMultiple, isAddBlank); } public Input SetSelectOptions(List selectOptions, bool isMultiple = false, bool isAddBlank = false) { string str = isAddBlank ? "" : ""; IsMultiple = isMultiple; if (selectOptions != null && selectOptions.Any()) { foreach (var s in selectOptions) { str += "\r\n"; } } SelectOptions = str; InputType = InputTypes.List; return this; } public Input SetSelectOptions(string selectOptions, bool isMultiple = false, bool isAddBlank = false) { string str = isAddBlank ? "" : ""; IsMultiple = isMultiple; if (!string.IsNullOrEmpty(selectOptions)) { str += selectOptions; } SelectOptions = str; InputType = InputTypes.List; return this; } public Input SetDataOptions(string dataOptions) { DataOptions = dataOptions; return this; } public Input SetOthers(string other) { Other = other; return this; } public Input SetStyles(string styles) { Styles = styles; return this; } public Input SetEvents(string events) { Events = events; return this; } public Input SetName(string name) { Name = name; return this; } public Input SetHelp(string help) { Help = help; return this; } public Input SetMaxLength(int maxLength) { MaxLength = maxLength; return this; } public Input SetMinLength(int minLength) { MinLength = minLength; return this; } public Input SetHidden() { IsHidden = true; return this; } public Input SetLabel(string label) { _label = label; return this; } public Input SetLabelName(string label) { _label = ""; return this; } public Input SetLabelNameRequired(string label) { _label = ""; return this; } public Input SetSpecial(string special) { Special = special; return this; } public Input SetNotRequired() { IsRequired = false; return this; } public Input SetDisabled() { IsDisabled = true; return this; } public Input SetReadonly() { IsReadOnly = true; return this; } public Input SetLayout(string labelLayout, string inputLayout) { LabelLayoutClass = labelLayout; InputLayoutClass = inputLayout; LayoutClassDefault = false; return this; } //public Input SetLayout(int labelLayout, int? inputLayout = null, string layoutPrefix = "col-md-") //{ // inputLayout = inputLayout ?? 12 - labelLayout; // LabelLayout = $"{layoutPrefix}{labelLayout}"; // InputLayout = $"{layoutPrefix}{inputLayout}"; // return this; //} public Input SetDivId(string id) { DivId = id; return this; } public Input SetDivClass(string classStr, string other = "") { DivClass = classStr; DivOther = other; DivClassDefault = false; return this; } /// /// 外层上面其他标签 /// /// /// public Input SetOuterBefore(string beforeStr) { DivOutBefore = beforeStr; return this; } /// /// 外层下面其他标签 /// /// /// public Input SetOuterAfter(string afterStr) { DivOutAfter = afterStr; return this; } /// /// 内层上面其他标签 /// /// /// public Input SetInterBefore(string beforeStr) { DivInterBefore = beforeStr; return this; } /// /// 内层下面其他标签 /// /// /// public Input SetInterAfter(string afterStr) { DivInterAfter = afterStr; return this; } /// /// 添加搜索按钮 /// /// /// /// /// public Input SetSearchIcon(string searchModalId) { SearchModalId = searchModalId; return this; } /// /// 添加搜索按钮 /// /// /// /// /// public Input SetSearchIcon(string searchModalId, string target, string clear = "") { SearchModalId = searchModalId; _target = target; if (!string.IsNullOrEmpty(clear)) { SetSearchClear(clear, true); } return this; } /// /// 添加搜索范围Class /// /// /// public Input SetSearchClass(string @class) { DivSearchClass = @class; return this; } /// /// 添加搜索按钮 /// /// /// /// /// public Input SetSearchIconWithClass(string searchModalId, string @class, string clear = "") { SearchModalId = searchModalId; _target = "." + @class; DivSearchClass = @class; if (!string.IsNullOrEmpty(clear)) { SetSearchClear(clear, true); } return this; } /// /// 配置需要清空的INPUT Id /// /// /// /// public Input SetSearchClear(string clear, bool isDefault = false) { Clear = isDefault ? $"{clear}No,{clear}Name" : clear; return this; } /// /// 输入提示 /// /// /// public Input SetPlaceholder(string placeholder) { _placeholder = placeholder; return this; } public Input SetNotSmall() { IsSm = false; return this; } #endregion #region 字段属性 public string Id { get; set; } public string Name { get; set; } public string DisplayName { get; set; } public string Help { get; set; } private string PlaceholderPrefix => InputType == InputTypes.List ? L("PlaceholderSelectHeader") : L("PlaceholderHeader"); private string _placeholder; public string Placeholder => string.IsNullOrEmpty(_placeholder) ? $"{PlaceholderPrefix}{DisplayName}..." : _placeholder; public InputTypes InputType { get; set; } public string TypeStr { get { switch (InputType) { case InputTypes.Text: return "text"; case InputTypes.Password: return "password"; case InputTypes.Checkbox: return "checkbox"; case InputTypes.Radio: return "radio"; case InputTypes.File: return "file"; case InputTypes.Number: return "number"; default: return "text"; } } } public DateTypes DateType { get; set; } public bool IsSm { get; set; } public string Number { get; set; } public int? MinLength { get; set; } public int? MaxLength { get; set; } public int? Min { get; set; } public int? Max { get; set; } public string Value { get; set; } public string SelectOptions { get; private set; } private string _class; public string Class { get { var classStr = $"form-control {_class}"; if (IsDisabled) { classStr += " disabled "; } if (IsReadOnly) { classStr += " readonly "; } if (InputType == InputTypes.Number) { classStr += $" {Number} "; } if (InputType == InputTypes.Date) { classStr += DateType == DateTypes.DateTime ? " iwb-date-time " : " iwb-date "; } return classStr; } set => _class = value; } public string DataOptions { get; set; } public string Events { get; set; } public string Styles { get; set; } private string _other; public string Other { get { if (MinLength != null) { _other += $" minlength={MinLength}"; } if (MaxLength != null) { _other += $" maxlength={MaxLength}"; } if (Min != null) { _other += $" min={Min}"; } if (Max != null) { _other += $" max={Max}"; } return _other; } set => _other = value; } public bool IsHidden { get; set; } public bool IsRequired { get; set; } public bool IsDisabled { get; set; } public bool IsReadOnly { get; set; } public bool IsMultiple { get; private set; } public string Required => IsHidden ? "" : (IsRequired ? " required" : ""); public string DivId { get; set; } public string DivClass { get; set; } public string DivSearchClass { get; set; } public bool DivClassDefault { get; set; } public string DivOther { get; set; } public string DivOutBefore { get; set; } public string DivOutAfter { get; set; } public string DivInterBefore { get; set; } public string DivInterAfter { get; set; } public string SearchModalId { get; set; } public string LabelLayoutClass { get; set; } public string InputLayoutClass { get; set; } public bool LayoutClassDefault { get; set; } private string _label; public string Label => IsHidden ? "" : string.IsNullOrEmpty(_label) ? (IsRequired ? $"" : $"") : _label; public string Disabled => IsDisabled ? "disabled=\"disabled\"" : ""; public string ReadOnly => IsReadOnly ? "readonly=\"readonly\"" : ""; public FileInputOption FileOption { get; set; } private string _target; public string Target => string.IsNullOrEmpty(_target) ? DefaultTarget ?? "" : _target.StartsWith(".") ? _target : _target.StartsWith("#") ? _target : $"#{_target}"; public string DefaultTarget { get; set; } public string Clear { get; set; } public string Special { get; set; } public bool IsAjaxSelect { get; protected set; } public string TableKey { get; protected set; } public string ColumnKey { get; protected set; } public int TakeCount { get; protected set; } /// /// 展示模板函数 /// public string FunResultTemplateName { get; protected set; } #endregion private static string L(string name) { var str = LocalizationHelper.GetSource(IwbZeroConsts.LocalizationSourceName).GetString(name); return str; } } public class InputHide : Input { public InputHide(string id, string displayName = "", string placeholder = "", string name = "", string value = "", string @class = "", string dataOptions = "", string events = "", string styles = "", string other = "", string label = "") : base(id, displayName, InputTypes.Textarea, placeholder, name, value, @class, dataOptions, events, styles, other, true, label) { } } public class InputTextarea : Input { public InputTextarea(string id, string displayName = "", string placeholder = "", string name = "", string value = "", string @class = "", string dataOptions = "", string events = "", string styles = "", string other = "", bool hide = false, string label = "") : base(id, displayName, InputTypes.Textarea, placeholder, name, value, @class, dataOptions, events, styles, other, hide, label) { } } public class InputKindeditor : InputTextarea { public InputKindeditor(string id, string displayName = "", string placeholder = "", string name = "", string value = "", string dataOptions = "", string events = "", string styles = "", string other = "", bool hide = false, string label = "") : base(id, displayName, placeholder, name, value, "kindeditor", dataOptions, events, styles, other, hide, label) { } } public class InputWangEditor : Input { public InputWangEditor(string id, string displayName = "", string placeholder = "", string name = "", string value = "", string @class = "", string dataOptions = "head,bold,fontSize,fontName,italic,underline,strikeThrough,indent,lineHeight,foreColor,backColor,justify,image", string events = "", string styles = "", string other = "", bool hide = false, string label = "") : base(id, displayName, InputTypes.WangEditor, placeholder, name, value, @class, dataOptions, events, styles, dataOptions, hide, label) { IsRequired = false; } public InputWangEditor SetMenus(string menu) { Other = menu; return this; } public InputWangEditor SetOptions(string opts) { DataOptions = opts; return this; } } public class InputDate : Input { public InputDate(string id, string displayName = "", DateTypes date = DateTypes.Date, string placeholder = "", string name = "", string value = "", string @class = "", string dataOptions = "", string events = "", string styles = "", string other = "", bool hide = false, string label = "") : base(id, displayName, InputTypes.Date, placeholder, name, value, @class, dataOptions, events, styles, other, hide, label) { DateType = date; } public InputDate SetDateType(DateTypes date) { DateType = date; return this; } public InputDate SetDateTime() { DateType = DateTypes.DateTime; return this; } } public class InputDateTime : Input { public InputDateTime(string id, string displayName = "", DateTypes date = DateTypes.DateTime, string placeholder = "", string name = "", string value = "", string @class = "", string dataOptions = "", string events = "", string styles = "", string other = "", bool hide = false, string label = "") : base(id, displayName, InputTypes.Date, placeholder, name, value, @class, dataOptions, events, styles, other, hide, label) { DateType = date; } public InputDateTime SetDateType(DateTypes date) { DateType = date; return this; } public InputDateTime SetDate() { DateType = DateTypes.Date; return this; } } public class InputNumber : Input { /// /// /// /// /// /// 0是整数,其他是小数 /// /// /// /// /// /// /// /// /// /// /// /// public InputNumber(string id, string displayName = "", int numberType = 0, int? min = null, int? max = null, string placeholder = "", string name = "", string value = "", string @class = "", string dataOptions = "", string events = "", string styles = "", string other = "", bool hide = false, string label = "") : base(id, displayName, InputTypes.Number, placeholder, name, value, @class, dataOptions, events, styles, other, hide, label) { Number = numberType == 0 ? "number" : "digits"; Min = min; Max = max; } public InputNumber SetRange(int? min = null, int? max = null, int numberType = 1) { Min = min; Max = max; Number = numberType == 0 ? "number" : "digits"; return this; } public InputNumber SetNumberType(int numberType = 1, int? min = null, int? max = null) { Number = numberType == 0 ? "number" : "digits"; Min = min; Max = max; return this; } public InputNumber SetMin(int min) { Min = min; return this; } public InputNumber SetMax(int max) { Max = max; return this; } } public class AjaxSelect : Input { public AjaxSelect(string id, string displayName, string tableKey, string columnKey, string searchModalId, string clear = "", int takeCount = 10, string placeholder = "", string name = "", string value = "", string @class = "", string dataOptions = "", string events = "", string styles = "", string other = "", bool hide = false, string label = "") : base(id, displayName, InputTypes.List, placeholder, name, value, @class, dataOptions, events, styles, other, hide, label) { IsAjaxSelect = true; TableKey = tableKey; ColumnKey = columnKey; TakeCount = takeCount; SearchModalId = searchModalId; if (string.IsNullOrEmpty(clear)) { SetSearchClear(id); } else { SetSearchClear(clear, true); } } public AjaxSelect SetResultTemplateName(string resultTemplateName) { FunResultTemplateName = resultTemplateName; return this; } } public class InputFile : Input { public InputFile(string id, string displayName = "", string placeholder = "", string name = "", string value = "", string @class = "", string dataOptions = "", string events = "", string styles = "", string other = "", bool hide = false, string label = "") : base(id, displayName, InputTypes.File, placeholder, name, value, @class, dataOptions, events, styles, other, hide, label) { FileOption = new FileInputOption(id); } /// /// 文件选择框设置信息 /// /// /// public InputFile SetFileOption(FileInputOption opt) { opt.FileInfoField = string.IsNullOrEmpty(opt.FileInfoField) ? Id : opt.FileInfoField; FileOption = opt; InputType = InputTypes.File; return this; } /// /// 文件选择框设置信息 /// /// public InputFile SetFileOption(string fileInfoField = "", string fileNameField = "", string fileExtField = "", int maxSize = 5) { fileInfoField = string.IsNullOrEmpty(fileInfoField) ? Id : fileInfoField; FileOption = new FileInputOption(fileInfoField, fileNameField, fileExtField, false, maxSize); return this; } /// /// 图片选择框设置信息 /// /// public InputFile SetImageOption(string fileInfoField = "", string fileNameField = "", string fileExtField = "", int maxSize = 5) { fileInfoField = string.IsNullOrEmpty(fileInfoField) ? Id : fileInfoField; FileOption = new FileInputOption(fileInfoField, fileNameField, fileExtField, true, maxSize); return this; } } public class SpecialInputModel { public string Id { get; set; } public string InputStr { get; set; } } public class FileInputOption { public FileInputOption(string fileInfoField, string fileNameField = "", string fileExtField = "", bool isImage = true, int maxSize = 5, string fileIdField = null) { FileInfoField = fileInfoField; FileNameField = fileNameField; FileExtField = fileExtField; IsImage = isImage; MaxSize = maxSize; FileIdField = fileIdField; } public string FileIdField { get; set; } public string FileInfoField { get; set; } public string FileNameField { get; set; } public string FileExtField { get; set; } public bool IsImage { get; set; } /// /// 文件最大M(默认5M) /// public int MaxSize { get; set; } } public enum InputTypes { Text, List, Checkbox, Radio, Password, Textarea, File, Number, Date, WangEditor } public enum DateTypes { Date, DateTime } #endregion }