Skip to content

List列表

本节介绍如何给微信表单添加一个列表组件

表单元数据设计


业务插件过滤列表数据及设置控件样式

CSharp
using Kejie.BOS.Core.ControlModel;
using Kejie.BOS.Core.DynamicForm.Plugin.Args;
using Kejie.BOS.Core.Filter;
using Kejie.BOS.Core.SqlBuilder;
using Kejie.BOS.Core.WxDynamicForm;
using Kejie.BOS.Core.WxDynamicForm.Plugin;
using Kejie.BOS.Core.WxDynamicForm.Plugin.Args;
using System.Data;

namespace Kejie.Template.MultiDev.Plugin
{
    public class WxCustomerOrders : WxDynamicFormPlugin
    {
        public WxCustomerOrders(IWxDynamicFormView view) : base(view)
        {
        }

        public override async Task BeforeInvokeEvent(BeforeInvokeEventArgs e)
        {
            if (e.Key == "FTabs" && e.EventName == "change")
            {
                if (e.EventArgs!.GetValue<string>() == "All")
                {
                    View.GetControlModel<MpInfiniteLoadingList>("FList")!.SetFilterRows().Reload();
                    return;
                }

                //依据前端Tabs所选选项值来过滤列表显示数据
                var filterRow = new FilterRow("FStatus", "Equal", e.EventArgs!.GetValue<string>());
                View.GetControlModel<MpInfiniteLoadingList>("FList")!.SetFilterRows(filterRow).Reload();
                return;
            }

            if (e.Key == "FList" && e.EventName == "itemClick")
            {
                View.NavigateTo("Mt_WxCustomerOrderDetail", false, e.EventArgs!["item"]!["Id"]!.GetValue<string>());
                return;
            }

            await base.BeforeInvokeEvent(e);
        }

        public override void BeforeLoadListData(BeforeLoadListDataEventArgs e)
        {
            //过滤要加载的数据
            var customer = View.SessionManager.GetCustomerContext()!;
            e.Filter = FilterExpression.Create("$FCustomer$=@FCustomer", "FCustomer")
                .AddParameter("@FCustomer", DbType.String, customer.Id)
                .Merge(e.Filter, "AND");
        }

        public override async Task LoadListData(LoadListDataEventArgs e)
        {
            //设置每行的状态字段的字体颜色
            var list = View.GetControlModel<MpInfiniteLoadingList>(e.Key)!;
            for (int index = e.StartIndex; index < e.Rows.Count; index++)
            {
                switch (e.Rows[index]["FStatus"]!.ToString())
                {
                    case "A":
                        list.SetChildrenProps(index, "FStatus", Common.WarningColorProps());
                        break;
                    case "B":
                        list.SetChildrenProps(index, "FStatus", Common.WarningColorProps());
                        break;
                    case "C":
                        list.SetChildrenProps(index, "FStatus", Common.SuccessColorProps());
                        break;
                    case "D":
                        list.SetChildrenProps(index, "FStatus", Common.DisabledColorProps());
                        break;
                }

            }

            await base.LoadListData(e);
        }
    }
}

效果图