using System.Collections.Generic; using System.Web.Mvc; namespace ContractService.Views.Shared.Query { public class QuerySearchModel { public readonly string _targetField; public QuerySearchModel() { ModalWidth = 900; IsMultiple = false; } public QuerySearchModel(string modalId) : this() { ModalId = modalId; } public QuerySearchModel(string modalId, string targetField) : this(modalId) { _targetField = targetField; } public string ModalId { get; set; } public string ModalName { get; set; } public int ModalWidth { get; set; } public string TargetField { get { if (TargetFields != null && TargetFields.Length > 0) { return string.Join(",", TargetFields); } return _targetField; } } /// /// 目标字段 /// public string[] TargetFields { get; set; } /// /// 有此值会覆盖模板的默认值。正常为空! /// public string OriginField { get; set; } /// /// 配合Ajax-Select 的赋值使用, /// public string AjaxSelectNameField { get; set; } public string SearchBindFun { get; set; } /// /// filed & selectOption /// public Dictionary[] SelectStrDic { get; set; } public QueryTreeSearch QueryTreeSearch { get; set; } /// /// filed & selectOption /// public Dictionary>[] SelectListDic { get; set; } public string SubmitEventName { get; set; } public string ItemClickEventName { get; set; } public string ItemDbClickEventName { get; set; } public bool IsMultiple { get; set; } public QuerySearchModel SetModal(string modalId, string modalName = "", int width = 900) { if (!string.IsNullOrEmpty(modalId)) { ModalId = modalId; } ModalName = modalName; ModalWidth = width; return this; } public QuerySearchModel SetMultiple() { IsMultiple = false; return this; } public QuerySearchModel SetTargetFields(params string[] targets) { TargetFields = targets; return this; } public QuerySearchModel SetAjaxSelectWithTarget(string selectName, params string[] targets) { AjaxSelectNameField = selectName; TargetFields = targets; return this; } public QuerySearchModel SetOriginField(params string[] originFields) { OriginField = string.Join(",", originFields); return this; } public QuerySearchModel SetAjaxSelectName(string name) { AjaxSelectNameField = name; return this; } public QuerySearchModel SetSearchFun(string funName) { SearchBindFun = funName; return this; } public QuerySearchModel SetSelectStrDic(params Dictionary[] dic) { SelectStrDic = dic; return this; } public QuerySearchModel SetSelectListDic(params Dictionary>[] dic) { SelectListDic = dic; return this; } /// /// 0:SubmitEventName(默认),1:ItemClickEventName,2:ItemDbClickEventName /// /// /// /// public QuerySearchModel SetEventName(string name, int type = 0) { switch (type) { case 0: SubmitEventName = name; break; case 1: ItemClickEventName = name; break; case 2: ItemDbClickEventName = name; break; } return this; } } }