@page "/Workflow/Manage"
@using wispro.sp.entity

<PageContainer>
    <Breadcrumb>
        <Breadcrumb>
            <BreadcrumbItem>
                <a href="/Home"><Icon Type="home"></Icon></a>
            </BreadcrumbItem>
            <BreadcrumbItem>
                <Icon Type="apartment" Theme="outline" /><span>流程管理</span>
            </BreadcrumbItem>
        </Breadcrumb>
    </Breadcrumb>
    <Content>
        <Button Type="primary" Icon="plus" OnClick="AddNew" Style="float:right">添加新流程</Button>
    </Content>
    <ChildContent>
        @if (workflows == null)
        {
            <Spin />
        }
        else
        {
            <AntDesign.Table @ref="table" @bind-PageIndex="_pageIndex" @bind-PageSize="_pageSize"
                             TItem="wispro.sp.entity.workflowDefine.Workflow"
                             Loading="_loading"
                             DataSource="@workflows"
                             Total="_total"
                             Bordered=@true
                             Size=@TableSize.Middle
                             HidePagination>
                <ChildContent>
                    <Selection Key="@(context.Id.ToString())" />
                    <AntDesign.Column Title="序号" TData="int">
                        @serialNumber(_pageIndex, _pageSize, context.Id)
                    </AntDesign.Column>
                    <AntDesign.Column Title="流程名称" @bind-Field="@context.Name" Sortable Filterable />
                    <AntDesign.Column Title="创建日期" @bind-Field="@context.CreateTime" Format="yyyy-MM-dd" Sortable Filterable />
                    <AntDesign.Column Title="生效日期" @bind-Field="@context.EffectivrDate" Format="yyyy-MM-dd" Sortable Filterable />
                    <AntDesign.Column Title="失效日期" @bind-Field="@context.ExpirationDate" Format="yyyy-MM-dd" Sortable Filterable />
                    <AntDesign.Column Title="绑定对象" TData="string">
                        @workflowService.GetBindObjectName(context.ContentObjectType)
                    </AntDesign.Column>
                    <AntDesign.Column Title="说明" @bind-Field="@context.Memo" Filterable />
                    <AntDesign.Column Title="创建人" TData="string">

                        @if (context.CreateUser != null)
                        {
                            <span>@context.CreateUser.Name</span>
                        }

                    </AntDesign.Column>
                    <ActionColumn>
                        <Space>
                            <SpaceItem><Button OnClick="()=>Detail(context.Id)">详情</Button></SpaceItem>
                        </Space>
                        <Space>
                            <SpaceItem><Button Danger OnClick="()=>Delete(context)">删除</Button></SpaceItem>
                        </Space>
                    </ActionColumn>
                </ChildContent>
                <PaginationTemplate>
                    <div style="display: flex; align-items: center">
                        <Pagination Class="my-custom-pagination"
                                    Total="@_total"
                                    PageSize="@_pageSize"
                                    Current="@_pageIndex"
                                    ShowSizeChanger="@true" />
                    </div>
                </PaginationTemplate>
            </AntDesign.Table>
        }
        
</ChildContent>
</PageContainer>

<style>
    .my-custom-pagination {
        margin: 15px 0;
    }

        .my-custom-pagination .ant-pagination-item,
        .my-custom-pagination .ant-pagination-item-link {
            border-radius: 100%;
        }
</style>
    
    <Modal Title="修改"
           Visible="@_visible"
           OnOk="@HandleOk"
           OnCancel="@HandleCancel"
           OkText="@("保存")"
           CancelText="@("取消")"
           Width="1000" MaskClosable="false">

        <Form Model="EditingObj" LabelColSpan="6"
              WrapperColSpan="16">
            <FormItem Label="流程名称">
                <Input @bind-Value="@context.Name" />
            </FormItem>
            <FormItem Label="生效日期">
                <DatePicker TValue="DateTime" Picker="@DatePickerType.Date" @bind-Value="@context.EffectivrDate" />
            </FormItem>

            <FormItem Label="失效日期">
                <DatePicker TValue="DateTime?" Picker="@DatePickerType.Date" @bind-Value="@context.ExpirationDate" />
            </FormItem>

            <FormItem Label="启动时绑定对象">
                <Select DataSource="@workflowService.GetBindObjects()"
                        @bind-Value="@context.ContentObjectType"
                        LabelName="@nameof(wispro.sp.entity.workflowDefine.BindObjectType.Name)"
                        ValueName="@nameof(wispro.sp.entity.workflowDefine.BindObjectType.ObjectTypeFullName)"
                        Placeholder="请选项一项"
                        DefaultActiveFirstItem="false"
                        EnableSearch="true"
                        AllowClear="true"
                        Style="width:220px;">
                </Select>
            </FormItem>

            <FormItem Label="说明">
                <TextArea @bind-Value="@context.Memo" MinRows="4" />
            </FormItem>

            <Divider />
            <FormItem Label="初始化操作名称">
                <Input @bind-Value="@InitAction.Action.Name" />
            </FormItem>
            <FormItem Label="初始化界面">
                <Input @bind-Value="@InitAction.Action.InputForm" />
            </FormItem>
            <wispro.sp.web.Components.InputValueSetting EditAction="InitAction" />
        </Form>

    </Modal>
