using VberAdmin.Web.Models.Input; namespace VberAdmin.Web.Models.Search; public class VmSearchItem : VmInput { public VmSearchItem(string name, string displayName) : base(name, displayName) { FieldType = FType.S; ExpType = EType.Contains; InputType = VmInputType.Default; SetOther(); } public VmSearchItem(string name, string displayName, bool isOnlyView) : this(name, displayName) { IsOnlyView = isOnlyView; } public VmSearchItem(string name, string displayName, string options, bool isAddBlank = false, bool isTree = false) : this(name, displayName) { WithSelect(options, isAddBlank, isTree); } public VmSearchItem(string name, string displayName, FType fieldType, EType expType = EType.Contains) : this(name, displayName) { _hasSetFiled = true; FieldType = fieldType; if (FieldType != FType.S) { ExpType = ExpType == EType.Contains ? EType.Equal : expType; } SetOther(); } #region 字段属性 public VmSearch Search { get; set; } public string SearchId => Search?.Id ?? ""; /// /// 不参与参与后台查询,只前台显示 /// public bool IsOnlyView { get; set; } /// /// Date /// public VmInput InputItem { get; set; } /// /// Date /// public VmInputDate DateItem { get; set; } public VmInputDateRange DateRangeItem { get; set; } /// /// Select /// public VmInputSelect SelectItem { get; set; } public VmInputRadio RadioItem { get; set; } public VmInputSwitch SwitchItem { get; set; } public VmInputCheckBox CheckBoxItem { get; set; } /// /// 字段类型 /// public FType FieldType { get; set; } /// /// 表达式类型 /// public EType ExpType { get; set; } #endregion 字段属性 public VmSearchItem WithOnlyView() { IsOnlyView = true; return this; } public VmSearchItem WithFieldType(FType fieldType, EType expType = EType.Contains) { FieldType = fieldType; if (FieldType != FType.S) { ExpType = ExpType == EType.Contains ? EType.Equal : expType; } _hasSetFiled = true; SetOther(); return this; } public VmSearchItem WithExpType(EType expType) { ExpType = expType; if (FieldType != FType.S) { ExpType = ExpType == EType.Contains ? EType.Equal : expType; } _hasSetFiled = true; SetOther(); return this; } private bool _hasSetFiled; private void SetOther() { if (!_hasSetFiled) { Other += SearchDataOption; } } private string SearchDataOption => $" data-search-keyWord=\"advance\" data-search-filed=\"{Name}\" data-search-exp-type=\"{(int)ExpType}\" data-search-filed-type=\"{(int)FieldType}\""; #region Select /// /// Select /// /// /// /// /// /// /// public VmSearchItem WithSelect(string options, bool addBlank = false, bool isTree = false, bool isMultiple = false, string other = "") { InputType = VmInputType.Select; ExpType = EType.Equal; SelectItem = new VmInputSelect(Name, DisplayName, options, addBlank, isTree, isMultiple) { Other = other + SearchDataOption }; return this; } public VmSearchItem WithSelect(VmInputSelect select) { InputType = VmInputType.Select; ExpType = EType.Equal; SelectItem = select; SelectItem.Other += SearchDataOption; return this; } ///// ///// AjaxSelect ///// ///// ///// ///// ///// ///// //public VmInputSelectAjax WithAjaxSelect(string codeKey, string modalId, string clear = "", int takeCount = 10) //{ // return new VmInputSelectAjax(Name, DisplayName, codeKey, modalId, clear, takeCount); //} #endregion Select #region Date public new VmSearchItem WithDate() { InputType = VmInputType.Date; DateItem = new VmInputDate(Name, DisplayName) { Other = SearchDataOption }; return this; } public new VmSearchItem WithDateTime() { InputType = VmInputType.Date; DateItem = new VmInputDateTime(Name, DisplayName) { IsOnlyTime = true, Other = SearchDataOption }; return this; } public VmSearchItem WithDate(VmInputDate date) { InputType = VmInputType.Date; date.Other = SearchDataOption; DateItem = date; return this; } public VmSearchItem WithDateTime(VmInputDateTime date) { InputType = VmInputType.Date; date.Other = SearchDataOption; DateItem = date; return this; } public new VmSearchItem WithDateRange() { InputType = VmInputType.Date; DateItem = new VmInputDateRange(Name, DisplayName) { Other = SearchDataOption }; return this; } public new VmSearchItem WithDateTimeRange() { InputType = VmInputType.DateTime; DateItem = new VmInputDateTimeRange(Name, DisplayName) { IsOnlyTime = true, Other = SearchDataOption }; return this; } public VmSearchItem WithDateRange(VmInputDateRange date) { InputType = VmInputType.Date; date.Other = SearchDataOption; DateItem = date; return this; } public VmSearchItem WithDateTime(VmInputDateTimeRange date) { InputType = VmInputType.Date; date.Other = SearchDataOption; DateItem = date; return this; } #endregion Date #region CheckBox & Radio & Switch /// /// CheckBox (name,value , name,value 成对设置) /// /// name,value , name,value 成对设置 /// public new VmSearchItem WithCheckBox(params string[] items) { InputType = VmInputType.CheckBox; CheckBoxItem = new VmInputCheckBox(Name, DisplayName) { Other = SearchDataOption }.WithItems(items); return this; } /// /// Radio (name,value , name,value 成对设置) /// /// /// public new VmSearchItem WithRadio(params string[] items) { InputType = VmInputType.RadioBox; RadioItem = new VmInputRadio(Name, DisplayName).WithItems(items); RadioItem.Items.ForEach(item => { item.Other = SearchDataOption; }); return this; } /// /// Radio (name,value , name,value 成对设置) /// /// /// public new VmSearchItem WithSwitch(params string[] items) { InputType = VmInputType.Switch; SwitchItem = new VmInputSwitch(Name, DisplayName) { Other = SearchDataOption }.WithItems(items); return this; } #endregion CheckBox & Radio & Switch #region 配合查询模态框使用 /// /// 需展示的字段ID /// 如 名称 等(隐藏编号),名称不参与查询,编号参与查询 /// public string ShowId { get; set; } //private string _targetFormId; //public string TargetFormId => _targetFormId.NotEmpty() ? _targetFormId : SearchId.Empty() ? "vber_search" : SearchId; public VmSearchItem WithQueryIcon(string modalId, string target = null, string clear = null, string showId = null) { base.WithQueryIcon(modalId, target, clear); ShowId = showId; if (showId != null) { IsHidden = true; } return this; } #endregion 配合查询模态框使用 }