@page "/Project/AssignPoint"

<PageContainer>
    <Breadcrumb>
        <Breadcrumb>
            <BreadcrumbItem>
                <a href="/Home"><Icon Type="home"></Icon></a>
            </BreadcrumbItem>
            <BreadcrumbItem>
                <span>分配项目点数</span>
            </BreadcrumbItem>
        </Breadcrumb>
    </Breadcrumb>
    <Content></Content>
    <ChildContent>
        <Card>
            <Card>
                <Form Model="task">
                    <FormItem Label="我方文号">
                        <Input @bind-Value="@context.CaseNo" />
                        <Button Icon="refresh" @onclick="()=>GetProjectInfo()" Loading="@loading">获取专案信息</Button>
                    </FormItem>
                    <FormItem Label="案件名称">
                        <Input @bind-Value="@context.CaseName" />
                    </FormItem>
                    <FormItem Label="分配说明">
                        <TextArea @bind-Value="@context.Reason" Rows="4" />
                    </FormItem>
                    @if (Item != null)
                    {
                        <Collapse DefaultActiveKey="@(new[]{"1"})">
                            <Panel Header="项目详情" Key="1">
                                <FormItem Label="客户">
                                    <span>@Item.Customer.Name</span>
                                </FormItem>
                                <FormItem Label="案件状态">
                                    <span>@Item.CaseState</span>
                                </FormItem>
                                <FormItem Label="案件备注">
                                    <span>@Item.CaseMemo</span>
                                </FormItem>
                            </Panel>
                        </Collapse>
                    }
                </Form>
            </Card>
            <Card>
                <Button OnClick="AddNew">添加人员绩效</Button>
                @if (task.ProjectDoItemPoints != null)
                {
                <AntDesign.Table TItem="wispro.sp.share.ProjectDoItemPoint"
                                 DataSource="task.ProjectDoItemPoints"
                                 Bordered=@true
                                 Size=@TableSize.Small>
                    <RowTemplate Context="pp">
                        <AntDesign.Column Title="处理事项"  @bind-Field="@pp.DoItem" />
                        <AntDesign.Column Title="难度系数"  @bind-Field="@pp.DoItemCoefficient"/>
                        <ActionColumn>
                            <Space>
                                <SpaceItem><Button  OnClick="() => EditDoItem(pp.DoItem)" Type="@ButtonType.Text">修改</Button></SpaceItem>
                                <SpaceItem><Button Danger OnClick="() => DeleteDoItem(pp.DoItem)" Type="@ButtonType.Text">删除</Button></SpaceItem>
                            </Space>
                        </ActionColumn>
                    </RowTemplate>
                    <ExpandTemplate Context="rowData">
                        <Table DataSource="rowData.Data.PersonPoints">
                            <AntDesign.Column Title="处理人" @bind-Field="@context.Person" Sortable Filterable />
                            <AntDesign.Column Title="分配点数" @bind-Field="@context.Point" TData="double">
                                @if (editId == context.Id && _visible== false)
                                {
                                    <AntDesign.InputNumber Type="text" @bind-Value="context.Point" OnBlur="stopEdit" AutoFocus />
                                }
                                else
                                {
                                    <div class="editable-cell-value-wrap" style="padding-right:10px" @onclick="() => startEdit(context.Id)">
                                        @context.Point
                                    </div>
                                }
                            </AntDesign.Column>
                            <ActionColumn>
                                <Space>
                                    <SpaceItem><Button Danger OnClick="() => Delete(rowData.Data.DoItem, context.Id)" Type="@ButtonType.Text">删除</Button></SpaceItem>
                                </Space>
                            </ActionColumn>
                        </Table>
                    </ExpandTemplate>
                    

            </AntDesign.Table>
                }
            </Card>
            
            <Card>
                <Space Style="float:right">
                    <SpaceItem><Button Type="primary" Icon="save" OnClick="OnSave" Style="float:right">保存</Button></SpaceItem>
                    <SpaceItem><Button Icon="cancel" OnClick="OnCancel" Style="float:right">取消</Button></SpaceItem>
                </Space>
            </Card>
        </Card>
        
    </ChildContent>
</PageContainer>


<Modal  Title="分配点数"
       Visible="@_visible"
       OnOk="@HandleOk"
       OnCancel="@HandleCancel" 
       MaskClosable="false"
       DestroyOnClose="true"
       @ref="model">
    <Form Model="addDoItem" LabelColSpan="6"
          WrapperColSpan="16">
        <FormItem Label="处理事项">
            <Input @bind-Value="@context.DoItem" />
        </FormItem>
        <FormItem Label="难度系数">
            <Input @bind-Value="@context.DoItemCoefficient" />
        </FormItem>
        <Button OnClick="addRow" Type="primary" Style="margin-bottom:16px">添加</Button>
        <AntDesign.Table TItem="wispro.sp.share.PersonPoint"
                         DataSource="addDoItem.PersonPoints"
                         Bordered=@true
                         Size=@TableSize.Small>
            <ChildContent Context="pp">
                <AntDesign.Column Title="处理人" TData="string" Sortable Filterable>
                    @if (editId == pp.Id)
                    {
                        
                        <Input Type="text" @bind-Value="pp.Person" />
                    }
                    else
                    {
                        <div class="editable-cell-value-wrap" style="padding-right:10px">
                            @pp.Person
                        </div>
                    }
                </AntDesign.Column>
                <AntDesign.Column Width="30%" Title="分配点数" TData="double">
                    @if (editId == pp.Id)
                    {
                        <AntDesign.InputNumber Type="text" @bind-Value="pp.Point" />
                    }
                    else
                    {
                        <div class="editable-cell-value-wrap" style="padding-right:10px">
                            @pp.Point
                        </div>
                    }
                </AntDesign.Column>
                <ActionColumn Title="Action">
                    @if (editId != pp.Id)
                    {
                        <a @onclick="() => startEdit(pp.Id)">修改</a>
                        <a @onclick="() => deletePersonPoint(pp.Id)">删除</a>
                    }
                    else
                    {
                        <a @onclick="() => stopEdit()" class="save">保存</a>
                    }
                </ActionColumn>
            </ChildContent>

        </AntDesign.Table>
    </Form>
</Modal>

