| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296 |
- 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 ?? "";
- /// <summary>
- /// 不参与参与后台查询,只前台显示
- /// </summary>
- public bool IsOnlyView { get; set; }
- /// <summary>
- /// Date
- /// </summary>
- public VmInput InputItem { get; set; }
- /// <summary>
- /// Date
- /// </summary>
- public VmInputDate DateItem { get; set; }
- public VmInputDateRange DateRangeItem { get; set; }
- /// <summary>
- /// Select
- /// </summary>
- public VmInputSelect SelectItem { get; set; }
- public VmInputRadio RadioItem { get; set; }
- public VmInputSwitch SwitchItem { get; set; }
- public VmInputCheckBox CheckBoxItem { get; set; }
- /// <summary>
- /// 字段类型
- /// </summary>
- public FType FieldType { get; set; }
- /// <summary>
- /// 表达式类型
- /// </summary>
- 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
- /// <summary>
- /// Select
- /// </summary>
- /// <param name="options"></param>
- /// <param name="addBlank"></param>
- /// <param name="isTree"></param>
- /// <param name="isMultiple"></param>
- /// <param name="other"></param>
- /// <returns></returns>
- 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;
- }
- ///// <summary>
- ///// AjaxSelect
- ///// </summary>
- ///// <param name="codeKey"></param>
- ///// <param name="modalId"></param>
- ///// <param name="clear"></param>
- ///// <param name="takeCount"></param>
- ///// <returns></returns>
- //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
- /// <summary>
- /// CheckBox (name,value , name,value 成对设置)
- /// </summary>
- /// <param name="items">name,value , name,value 成对设置</param>
- /// <returns></returns>
- public new VmSearchItem WithCheckBox(params string[] items)
- {
- InputType = VmInputType.CheckBox;
- CheckBoxItem = new VmInputCheckBox(Name, DisplayName) { Other = SearchDataOption }.WithItems(items);
- return this;
- }
- /// <summary>
- /// Radio (name,value , name,value 成对设置)
- /// </summary>
- /// <param name="items"></param>
- /// <returns></returns>
- 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;
- }
- /// <summary>
- /// Radio (name,value , name,value 成对设置)
- /// </summary>
- /// <param name="items"></param>
- /// <returns></returns>
- 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 配合查询模态框使用
- /// <summary>
- /// 需展示的字段ID
- /// 如 名称 等(隐藏编号),名称不参与查询,编号参与查询
- /// </summary>
- 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 配合查询模态框使用
- }
|