@page "/Project/WorkContent/{Id:int?}"
@attribute [Authorize]
<PageContainer>
    <Breadcrumb>
        <Breadcrumb>
            <BreadcrumbItem>
                <a href="/Home"><Icon Type="home"></Icon></a>
            </BreadcrumbItem>
            <BreadcrumbItem>
                <span>专案工作内容提报</span>
            </BreadcrumbItem>
        </Breadcrumb>
    </Breadcrumb>
    <Content></Content>
    <ChildContent>
        <Card>
            @if (isLoading)
            {
                <Spin></Spin>
            }
            else
            {
                //Console.WriteLine(System.Text.Json.JsonSerializer.Serialize(task));
                //Console.WriteLine(System.Text.Json.JsonSerializer.Serialize(ProjectInfos));
                <Card>
                    <Form Model="task">
                        @if (!Id.HasValue)
                        {
                            
                            <FormItem Label="我方文号">
                                <Select DataSource="@ProjectInfos"
                                        @bind-Value="@task.ProjectContentRecord.ProjectNo"
                                        LabelName="@nameof(wispro.sp.entity.ProjectInfo.CaseNo)"
                                        ValueName="@nameof(wispro.sp.entity.ProjectInfo.CaseNo)"
                                        Style="width: 200px"
                                        Placeholder="请选择"
                                        OnSelectedItemChanged="OnSelectedItemChangedHandler"
                                        IgnoreItemChanges="false"
                                        EnableSearch="true"
                                        AllowClear
                                        OnSearch="OnSearch"
                                        >
                                </Select>
                            </FormItem>
                        }
                        else
                        {
                            Console.WriteLine(System.Text.Json.JsonSerializer.Serialize(task));
                            <FormItem Label="我方文号">
                                <span>@task.ProjectContentRecord.ProjectNo</span>
                            </FormItem>
                        }

                        @if (task.ProjectContentRecord.Project != null)
                        {
                            <FormItem Label="案件名称">
                                <span>@task.ProjectContentRecord.Project.CaseName</span>
                            </FormItem>
                            <Collapse DefaultActiveKey="@(new[] { "1" })">
                                <Panel Header="项目详情" Key="1">
                                    <FormItem Label="业务类型">
                                        <span>@task.ProjectContentRecord.Project.BusinessType</span>
                                    </FormItem>
                                    <FormItem Label="客户">
                                        <span>@task.ProjectContentRecord.Project.Customer?.Name</span>
                                    </FormItem>
                                </Panel>
                            </Collapse>
                        }
                    </Form>
                </Card>
                <Card Title="工作内容清单">
                    <Extra>
                        <Button OnClick="AddNew" Type="@ButtonType.Primary">添加</Button>
                    </Extra>
                    <Body>
                        @if (task.ProjectWorkContents != null)
                        {
                            <AntDesign.Table TItem="share.ViewProjectWorkContent"
                                             DataSource="_ShowWorkContent"
                                             Bordered=@true
                                             Size=@TableSize.Small
                                             HidePagination="@true">
                                <RowTemplate Context="pp">
                                    <AntDesign.Column Title="工作内容" TData="string">
                                        @if (addDoItem == pp)
                                        {
                                            <TextArea Rows="2" @bind-Value="@pp.Content" />
                                        }
                                        else
                                        {
                                            <span>@pp.Content</span>
                                        }
                                    </AntDesign.Column>
                                    <AntDesign.Column Title="工作日期" TData="string">
                                        @if (addDoItem == pp)
                                        {
                                            <DatePicker TValue="DateTime" Picker="@DatePickerType.Date" @bind-Value="pp.WorkDate" />

                                        }
                                        else
                                        {
                                            <span>@pp.WorkDate.ToString("yyyy-MM-dd")</span>
                                        }
                                    </AntDesign.Column>
                                    <AntDesign.Column Title="时间跨度" TData="string">
                                        @if (addDoItem == pp)
                                        {
                                            <AntDesign.InputNumber @bind-Value="pp.TimeSpan" Min="1" Max="60" DefaultValue="1"></AntDesign.InputNumber>
                                            <span>天</span>

                                        }
                                        else
                                        {
                                            <span>@(pp.TimeSpan)天</span>
                                        }
                                    </AntDesign.Column>
                                    <AntDesign.Column Title="耗时" TData="string">
                                        @if (addDoItem == pp)
                                        {
                                            <AntDesign.InputNumber Step="0.1" Min="-1" Max="160" @bind-Value="pp.TakeTime" /><span>小时</span>
                                        }
                                        else
                                        {
                                            <span>@(pp.TakeTime)小时</span>
                                        }
                                    </AntDesign.Column>
                                    <ActionColumn>
                                        @if (addDoItem == pp)
                                        {
                                            <Space>
                                                <SpaceItem><Button OnClick="() => stopEdit()" Type="@ButtonType.Text">保存</Button></SpaceItem>
                                                <SpaceItem><Button Danger OnClick="() => DeleteDoItem(pp)" Type="@ButtonType.Text">取消</Button></SpaceItem>
                                            </Space>
                                        }
                                        else
                                        {
                                            <Space>
                                                <SpaceItem><Button OnClick="() => EditDoItem(pp)" Type="@ButtonType.Text">修改</Button></SpaceItem>
                                                <SpaceItem><Button Danger OnClick="() => DeleteDoItem(pp)" Type="@ButtonType.Text">删除</Button></SpaceItem>
                                            </Space>
                                        }

                                    </ActionColumn>
                                </RowTemplate>

                            </AntDesign.Table>
                        }
                    </Body>
                </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>


