local _, ZLAUTO = ...
local ZL = ZLAUTO.mainFrame
local pruneCrossRealm = ZL.pruneCrossRealm
local ZLCreateFrame = ZL.ZLCreateFrame
local CreateHeaderButton = ZL.CreateHeaderButton
local CreateButton = ZL.CreateButton
local CreateEditBox = ZL.CreateEditBox
local GameTooltipShow = ZL.GameTooltipShow
local ScrollFrame_OnMouseWheel = ZL.ScrollFrame_OnMouseWheel
local ParseClassColorName = ZL.ParseClassColorName
local GroupMembersActivityMenu = ZL.GroupMembersActivityMenu
local EditOnMouseWheel = ZL.EditOnMouseWheel
local GetAveWages = ZL.GetAveWages
local PlayerIsML = ZL.PlayerIsML
local tdGUI_DropMenuIsShown = ZL.tdGUI_DropMenuIsShown
local cGetItemInfo = C_Item and C_Item.GetItemInfo or GetItemInfo
local cGetItemIcon = C_Item and C_Item.GetItemIconByID or GetItemIcon
local GetItemInfoInstant = C_Item and C_Item.GetItemInfoInstant or GetItemInfoInstant
local MyAddon = ZL.MyAddon
local itemStr = "|c.-|Hitem:.+|h%[.-%]|h|r"

function ZL.CreateBillOverviewFrame()
    ZL.BillOverviewFrame = ZLCreateFrame("ZLBillOverviewFrame", ZL, nil, nil, "DIALOG", false, true, "账单总览")
    local BillOverviewFrame = ZL.BillOverviewFrame
    BillOverviewFrame.Background:SetColorTexture(0, 0, 0, 0.9)
    BillOverviewFrame:SetPoint("CENTER")
    BillOverviewFrame:SetResizable(false)
    local maxlevel = ZL.AuctionFrame2:GetFrameLevel()
    BillOverviewFrame:SetFrameLevel(maxlevel + 10)
    BillOverviewFrame.resizeButton:Hide()
    BillOverviewFrame:SetSize(GetScreenWidth()-65, GetScreenHeight()-50)
    BillOverviewFrame:Hide()
    tinsert(UISpecialFrames, BillOverviewFrame:GetName())
    local UIScale = UIParent:GetScale()
    local height = 20
    local gapwidth = 20/UIScale
    local gapheight = 0
    local itemNamewidth = 160/UIScale
    local playerNamewidth = 100/UIScale
    local amountwidth = 70/UIScale
    local BOSSwidth =(GetScreenWidth()-40-23-2*gapwidth-3*(itemNamewidth+playerNamewidth+amountwidth))/3
    BOSSwidth = BOSSwidth > 160 and 160 or BOSSwidth
    local totalColomnWidth = BOSSwidth+itemNamewidth+playerNamewidth+amountwidth
    local board_r, board_g, board_b, board_a = 0.24, 0.25, 0.3, 1
    local btnTexture = [[Interface\ACHIEVEMENTFRAME\UI-Achievement-Parchment-Horizontal]]
    local function CreateTitleButton(btnName, point, relativeto, relativePoint, offsetX, offsetY, btnwidth)
        local btn = CreateButton(nil, BillOverviewFrame, btnName, point, relativeto, relativePoint, offsetX, offsetY, btnwidth, height)
        btn:GetFontString():SetFont(GameFontNormal:GetFont(), 14, "OUTLINE")
        btn:SetNormalTexture(btnTexture)
        btn:ClearHighlightTexture()
        return btn
    end
    BillOverviewFrame.BOSSHeaderBtn1 = CreateTitleButton("|cff00aaff项目|r", "TOPLEFT", BillOverviewFrame.TitleBottom, "BOTTOMLEFT", 3, -5, BOSSwidth)
    local BOSSHeaderBtn1 = BillOverviewFrame.BOSSHeaderBtn1

    BillOverviewFrame.itemNameHeaderBtn1 = CreateTitleButton("|cffffffff物品名称×数量|r", "LEFT", BOSSHeaderBtn1, "RIGHT", 0, 0, itemNamewidth)
    local itemNameHeaderBtn1 = BillOverviewFrame.itemNameHeaderBtn1

    BillOverviewFrame.playerNameHeaderBtn1 = CreateTitleButton("|cffffffff买家名字|r", "LEFT", itemNameHeaderBtn1, "RIGHT", 0, 0, playerNamewidth)
    local playerNameHeaderBtn1 = BillOverviewFrame.playerNameHeaderBtn1

    BillOverviewFrame.amountHeaderBtn1 = CreateTitleButton("|cffffffff总金额|r", "LEFT", playerNameHeaderBtn1, "RIGHT", 0, 0, amountwidth)
    local amountHeaderBtn1 = BillOverviewFrame.amountHeaderBtn1

    do
        local texture = amountHeaderBtn1:CreateTexture(nil, "BACKGROUND")
        texture:SetColorTexture(1,1,1,0.5)
        texture:SetPoint("TOPLEFT", BOSSHeaderBtn1, "BOTTOMLEFT", 0, 0)
        texture:SetPoint("BOTTOMRIGHT", amountHeaderBtn1, "BOTTOMRIGHT", 0, -1)
    end

    BillOverviewFrame.BOSSHeaderBtn2 = CreateTitleButton("|cff00aaff项目|r", "LEFT", amountHeaderBtn1, "RIGHT", gapwidth, 0, BOSSwidth)
    local BOSSHeaderBtn2 = BillOverviewFrame.BOSSHeaderBtn2

    BillOverviewFrame.itemNameHeaderBtn2 = CreateTitleButton("|cffffffff物品名称×数量|r", "LEFT", BOSSHeaderBtn2, "RIGHT", 0, 0, itemNamewidth)
    local itemNameHeaderBtn2 = BillOverviewFrame.itemNameHeaderBtn2

    BillOverviewFrame.playerNameHeaderBtn2 = CreateTitleButton("|cffffffff买家名字|r", "LEFT", itemNameHeaderBtn2, "RIGHT", 0, 0, playerNamewidth)
    local playerNameHeaderBtn2 = BillOverviewFrame.playerNameHeaderBtn2

    BillOverviewFrame.amountHeaderBtn2 = CreateTitleButton("|cffffffff总金额|r", "LEFT", playerNameHeaderBtn2, "RIGHT", 0, 0, amountwidth)
    local amountHeaderBtn2 = BillOverviewFrame.amountHeaderBtn2

    do
        local texture = amountHeaderBtn2:CreateTexture(nil, "BACKGROUND")
        texture:SetColorTexture(1,1,1,0.5)
        texture:SetPoint("TOPLEFT", BOSSHeaderBtn2, "BOTTOMLEFT", 0, 0)
        texture:SetPoint("BOTTOMRIGHT", amountHeaderBtn2, "BOTTOMRIGHT", 0, -1)
    end

    BillOverviewFrame.BOSSHeaderBtn3 = CreateTitleButton("|cff00aaff项目|r", "LEFT", amountHeaderBtn2, "RIGHT", gapwidth, 0, BOSSwidth)
    local BOSSHeaderBtn3 = BillOverviewFrame.BOSSHeaderBtn3

    BillOverviewFrame.itemNameHeaderBtn3 = CreateTitleButton("|cffffffff物品名称×数量|r", "LEFT", BOSSHeaderBtn3, "RIGHT", 0, 0, itemNamewidth)
    local itemNameHeaderBtn3 = BillOverviewFrame.itemNameHeaderBtn3

    BillOverviewFrame.playerNameHeaderBtn3 = CreateTitleButton("|cffffffff买家名字|r", "LEFT", itemNameHeaderBtn3, "RIGHT", 0, 0, playerNamewidth)
    local playerNameHeaderBtn3 = BillOverviewFrame.playerNameHeaderBtn3

    BillOverviewFrame.amountHeaderBtn3 = CreateTitleButton("|cffffffff总金额|r", "LEFT", playerNameHeaderBtn3, "RIGHT", 0, 0, amountwidth)
    local amountHeaderBtn3 = BillOverviewFrame.amountHeaderBtn3

    do
        local texture = amountHeaderBtn3:CreateTexture(nil, "BACKGROUND")
        texture:SetColorTexture(1,1,1,0.5)
        texture:SetPoint("TOPLEFT", BOSSHeaderBtn3, "BOTTOMLEFT", 0, 0)
        texture:SetPoint("BOTTOMRIGHT", amountHeaderBtn3, "BOTTOMRIGHT", 0, -1)
    end
    --创建滚动条
    BillOverviewFrame.scrollFrame = CreateFrame("ScrollFrame", nil, BillOverviewFrame, "UIPanelScrollFrameTemplate")
    BillOverviewFrame.scrollFrame:SetFrameLevel(BillOverviewFrame:GetFrameLevel() + 1) -- 设置为比父框架高1级
    BillOverviewFrame.scrollFrame:SetPoint("TOPLEFT", BOSSHeaderBtn1, "BOTTOMLEFT", 0, 0)
    BillOverviewFrame.scrollFrame:SetPoint("BOTTOMRIGHT", BillOverviewFrame, "BOTTOMRIGHT", 0, 3)
    BillOverviewFrame.scrollFrame:SetClipsChildren(true) --必须设置为true，scrollFrame所有的子元素才会被剪切
    BillOverviewFrame.scrollFrame:SetScript("OnMouseWheel", ScrollFrame_OnMouseWheel) --重设滑动条鼠标滚轮事件
    --重设ScrollBar位置，放置到scrollFrame内，防止被剪切掉
    BillOverviewFrame.scrollFrame.ScrollBar:ClearAllPoints()
    BillOverviewFrame.scrollFrame.ScrollBar:SetPoint("TOPLEFT", BillOverviewFrame.scrollFrame, "TOPRIGHT", -20, -16)
    BillOverviewFrame.scrollFrame.ScrollBar:SetPoint("BOTTOMRIGHT", BillOverviewFrame.scrollFrame, "BOTTOMRIGHT", 0, 16)
    BillOverviewFrame.scrollFrame.content = CreateFrame("Frame", nil, BillOverviewFrame.scrollFrame)
    local content = BillOverviewFrame.scrollFrame.content
    content:SetPoint("TOPRIGHT", BillOverviewFrame.scrollFrame, "TOPRIGHT", 0, 0)
    content:SetSize(BillOverviewFrame.scrollFrame:GetWidth()-20, 100)
    BillOverviewFrame.scrollFrame:SetScrollChild(content)
    local function OnEnter(f)
        f.zlHighlight:Show()
    end
    local function OnLeave(f)
        if not (f.data.type == "auction" and f.data.playerName == "拍卖中") then
            f.zlHighlight:Hide()
        end
    end
    local function itemNameBoxMenu(self)
        local menuList = {}
        local selectCharKey = ZL.GetClassColorName() .. " - " .. GetRealmName()
        local f = self:GetParent()
        local isML = PlayerIsML()
        if f.data.type == "auction" then
            local _, v = ZL.FetchDataFromItemId(f.data.itemlink, f.data.itemindex)
            local curAuctionList = ZL_CURRENT.auctionlist[v]
            local itemId = curAuctionList.itemId
            local bidderlist = curAuctionList.bidderlist
            local Frame1 = ZL.AuctionFrame2.entries[v]
            local hasSeperator = true
            if curAuctionList.state == "auctioning" then
                if not Frame1.maxAutoBid then
                    tinsert(menuList, {
                        text = "自动出价",
                        func = function()
                            local data = {index=v, f=Frame1}
                            StaticPopup_Show("ZL_AUTOBID", curAuctionList.itemlink, nil, data)
                        end
                    })
                else
                    tinsert(menuList, {
                        text = "停止自动出价",
                        func = function()
                            Frame1.maxAutoBid = nil
                            Frame1.bidFrame.bidEditBox:Enable()
                            Frame1.bidFrame.bidBtn:SetText("出价")
                            Frame1.bidFrame.lgnoreBtn:Enable()
                            if Frame1.autoBid then
                                if (not Frame1.autoBid:IsCancelled()) then
                                    Frame1.autoBid:Cancel()
                                end
                                Frame1.autoBid = nil
                                local isSelf
                                local totalBidCount = 0
                                local msgStr = ""
                                for _, bidData in ipairs(bidderlist) do
                                    if totalBidCount < curAuctionList.itemCount then
                                        local count = bidData["bidCount"] or 1
                                        local newTotalBidCount = totalBidCount + count
                                        if newTotalBidCount > curAuctionList.itemCount then
                                            count = curAuctionList.itemCount - totalBidCount
                                        end
                                        totalBidCount = newTotalBidCount
                                        if ParseClassColorName(bidData.bidder) == ZL.GetFullName() then
                                            isSelf = true
                                            break
                                        end
                                    else
                                        break
                                    end
                                end
                                if isSelf then
                                    msgStr = curAuctionList.itemlink .. "自动出价结束，竞价|cff00ff00成功|r！"
                                else
                                    msgStr = curAuctionList.itemlink .. "自动出价结束，竞价|cffff0000失败|r！"
                                end
                                ZL.ScrollingMessageFrame:AddMessage(msgStr)
                            end
                        end
                    })
                end
                tinsert(menuList, {isSeparator = true})
                hasSeperator = true
            end
            if isML then
                if curAuctionList.state == "waiting" or curAuctionList.state == "failed" then
                    tinsert(menuList, {
                        text = "|T130866:18:18:2:0|t " .. "开始拍卖",
                        func =function ()
                            ZL.startOrCanelAuction(v)
                        end
                    })
                    if curAuctionList.state == "waiting" then
                        tinsert(menuList, {
                            text = "|T576625:18:18:2:0|t " .. "直接流拍",
                            func =function ()
                                ZL.startOrCanelAuction(v, true)
                            end
                        })
                    end
                    tinsert(menuList, {
                        text = "|T384756:18:18:2:0|t " .. "快速拍卖",
                        func =function ()
                            ZL.quickStartAuction(v)
                        end
                    })
                elseif curAuctionList.state == "success" then
                    tinsert(menuList, {
                        text = "|T130866:18:18:2:0|t " .. "重拍",
                        func =function ()
                            ZL.startOrCanelAuction(v)
                        end
                    })
                    tinsert(menuList, {
                        text = "|T576625:18:18:2:0|t " .. "快速流拍",
                        func =function ()
                            ZL.startOrCanelAuction(v, true)
                        end
                    })
                elseif curAuctionList.state == "auctioning" then
                    tinsert(menuList, {
                        text = "|T137048:18:18:2:0|t " .. "取消",
                        func =function ()
                            ZL.startOrCanelAuction(v)
                        end
                    })
                    if curAuctionList["isPaused"] then
                        tinsert(menuList, {
                            text = "|T130866:18:18:2:0|t " .. "继续",
                            func =function ()
                                ZL.pauseOrResumeAuction(v)
                            end
                        })
                    else
                        tinsert(menuList, {
                            text = "|T137047:18:18:2:0|t " .. "暂停",
                            func =function ()
                                ZL.pauseOrResumeAuction(v)
                            end
                        })
                    end
                end
                hasSeperator = nil
                if curAuctionList.state == "auctioning" then
                    tinsert(menuList, {isSeparator = true})
                    tinsert(menuList, {
                        text = "|TInterface\\AddOns\\AutoAuction\\Images\\5countdown_normal.png:14:14:2:2|t " .. "5秒倒数",
                        func = function ()
                            ZL.coundownAuction(v)
                        end
                    })
                    tinsert(menuList, {
                        text = "|TInterface\\AddOns\\AutoAuction\\Images\\reset_time.png:14:14:2:0|t " .. "重置倒计时",
                        func = function ()
                            ZL.resetAuctionTime(v)
                        end
                    })
                    hasSeperator = nil
                end

                if curAuctionList.state == "waiting" or curAuctionList.state == "failed" then
                    tinsert(menuList, {isSeparator = true})
                    if curAuctionList.itemlink ~= "[打包拍卖]" then
                        tinsert(menuList, {
                            text = "|T346111:16:16:2:0|t " .. "打包拍卖",
                            func = function ()
                                ZL.packageAuction(v)
                            end
                        })
                    end
                    tinsert(menuList, {
                        text = "|T136813:16:16:2:0|t " .. "删除拍卖",
                        func = function ()
                            if ZL.syncAll or Frame1.sync then
                                ZL.Print("通信被占用，请稍后重试。")
                                return
                            end
                            local msgStr = "警告！确定删除" .. ZL_CURRENT.auctionlist[v].itemlink .. "的拍卖记录?"
                            StaticPopup_Show("ZL_DELETEAUCTIONWARNING", msgStr, nil, v)
                        end
                    })
                    hasSeperator = nil
                elseif curAuctionList.state == "auctioning" then
                    tinsert(menuList, {isSeparator = true})
                    tinsert(menuList, {
                        text = "|A:chatframe-button-icon-voicechat:16:16:2:0|a 通报竞拍信息",
                        func = function ()
                            ZL.sendAuctionInfo(v)
                        end
                    })
                    if #bidderlist > 0 then
                        tinsert(menuList, {isSeparator = true})
                        tinsert(menuList, {
                            text = "撤销第一名出价",
                            func = function ()
                                ZL.revokeBidAmount(v)
                            end
                        })
                    end
                    hasSeperator = nil
                end
            end
            if not hasSeperator then
                tinsert(menuList, {isSeparator = true})
            end
            if (not ZL.opt.concernList) or (not ZL.opt.concernList[selectCharKey]) or
            (not ZL.opt.concernList[selectCharKey]["itemList"][itemId]) then
                tinsert(menuList, {
                    text = "|A:auctionhouse-icon-favorite:15:15:2:2|a " .. "关注", --VignetteKill
                    func = function ()
                        ZL.addItem(itemId)
                    end
                })
            else
                tinsert(menuList, {
                    text = "|A:auctionhouse-icon-favorite-off:15:15:2:2|a " .. "取消关注",
                    func = function ()
                        ZL.deleteItem(itemId)
                    end
                })
            end
            tinsert(menuList, {
                text = "|T130775:15:15:2:0|t " .. (curAuctionList["lgnore"] and "取消忽略" or "忽略"),
                func = function ()
                    Frame1.bidFrame.lgnoreBtn:Click()
                end
            })
            tinsert(menuList, {isSeparator = true})
            tinsert(menuList, {text = "关闭"})
        elseif f.data.type == "auctionzip" then
            local itemLink = f.data.itemlink
            local itemId = tonumber(itemLink:match("|Hitem:(%d+):"))
            if isML then
                tinsert(menuList, {
                    text = "删除打包",
                    func = function ()
                        local _, _index = ZL.FetchDataFromItemId("[打包拍卖]", 1)
                        local itemindexList = ZL_CURRENT.auctionlist[_index]["itemList"][itemLink]["itemindex"]
                        --先把需要剔除的物品isPackage清除
                        if itemindexList and #itemindexList > 0 then
                            for _, _itemindex in ipairs(itemindexList) do
                                local _, index = ZL.FetchDataFromItemId(itemLink, _itemindex)
                                if index then
                                    ZL_CURRENT.auctionlist[index]["isPackage"] = nil
                                end
                            end
                        end
                        --将需要删除的打包物品发送给其他成员
                        local fdata = {
                            type = "删除打包里面的物品",
                            itemLink = itemLink,
                            globalConfigData = ZL.globalConfigData(),
                        }
                        MyAddon:TransmitAddonInfo("AUTOAUC SYNC15", fdata, "BULK")
                        --ML开始删除自己的打包物品
                        ZL_CURRENT.auctionlist[_index]["itemList"][itemLink] = nil
                        ZL.PackageListFrame:Update(_index)
                        ZL.AuctionFrame2:Update()
                        BillOverviewFrame:Update()
                    end
                })
                tinsert(menuList, {isSeparator = true})
            end
            if (not ZL.opt.concernList) or (not ZL.opt.concernList[selectCharKey]) or
            (not ZL.opt.concernList[selectCharKey]["itemList"][itemId]) then
                tinsert(menuList, {
                    text = "|A:auctionhouse-icon-favorite:15:15:2:2|a " .. "关注", --VignetteKill
                    func = function ()
                        ZL.addItem(itemId)
                    end
                })
            else
                tinsert(menuList, {
                    text = "|A:auctionhouse-icon-favorite-off:15:15:2:2|a " .. "取消关注",
                    func = function ()
                        ZL.deleteItem(itemId)
                    end
                })
            end
            tinsert(menuList, {isSeparator = true})
            tinsert(menuList, {text = "关闭"})
        elseif f.data.type == "butie" then
            if f.data.itemlink == "|cffffde00补贴配置 ▼|r" then
                tinsert(menuList, {
                    text = "配置",
                    notClickable = 1,
                    hasArrow = 1,
                    menuTable = function ()
                        local tempList = {}
                        for index, profileName in ipairs(ZL.opt.subsidyProfileList.profileKeys) do
                            tinsert(tempList, {
                                text = profileName,
                                checkable = 1,
                                checked = ZL.opt.subsidyProfileSelect == index,
                                hasArrow = 1,
                                menuTable = function ()
                                    local _tempList = {}
                                    local subsidyParentData = ZL.opt.subsidyProfileList["profile"][profileName]["parent"]
                                    local subsidyData = ZL.opt.subsidyProfileList["profile"][profileName]["child"]
                                    for _, subsidyParentName in ipairs(ZL.subsidyParentTypeList) do
                                        local childMenuList = {}
                                        for _, subsidyName in ipairs(ZL.subsidyChildrenList[subsidyParentName]) do
                                            local subsidyNameGsub = subsidyName:gsub("%d+", "")
                                            if subsidyName == "主T" or subsidyName == "副T" or subsidyName == "双休T" then
                                                subsidyNameGsub = "T"
                                            end
                                            local icon = ZL.subsidyTypeFunc[subsidyNameGsub].icon or "|T:13|t"
                                            tinsert(childMenuList, {
                                                text = icon .. subsidyName,
                                                checkable = 1,
                                                isNotRadio = 1,
                                                checked = subsidyData[subsidyName],
                                                keepShownOnClick = 1,
                                                func = function ()
                                                    if subsidyData[subsidyName] then
                                                        subsidyData[subsidyName] = nil
                                                        if ZL_CURRENT.subsidy then
                                                            ZL_CURRENT.subsidy[subsidyName] = nil
                                                        end
                                                    else
                                                        subsidyParentData[subsidyParentName] = subsidyParentData[subsidyParentName] or 0
                                                        subsidyData[subsidyName] = 0
                                                        if subsidyName == "鱼" then
                                                            subsidyData["猪"] = nil
                                                            ZL_CURRENT.subsidy["猪"] = nil
                                                        elseif subsidyName == "猪" then
                                                            subsidyData["鱼"] = nil
                                                            ZL_CURRENT.subsidy["鱼"] = nil
                                                        elseif subsidyName == "DPS" then
                                                            for i = 1, 10 do
                                                                subsidyData["DPS" .. i] = nil
                                                                ZL_CURRENT.subsidy["DPS" .. i] = nil
                                                            end
                                                        elseif subsidyName:match("^DPS%d+$") then
                                                            subsidyData["DPS"] = nil
                                                            ZL_CURRENT.subsidy["DPS"] = nil
                                                        elseif subsidyName == "RL" then
                                                            local RL = select(4, ZL.GetWagesGroupMembers())
                                                            if RL then
                                                                ZL_CURRENT.subsidy = ZL_CURRENT.subsidy or {}
                                                                ZL_CURRENT.subsidy["RL"] = {}
                                                                ZL_CURRENT.subsidy["RL"][RL] = true
                                                            end
                                                        end
                                                    end
                                                    ZL.SubsidyFrame:Update()
                                                end
                                            })
                                        end
                                        tinsert(_tempList, {
                                            text = subsidyParentName,
                                            checkable = 1,
                                            isNotRadio = 1,
                                            checked = subsidyParentData[subsidyParentName],
                                            keepShownOnClick = 1,
                                            -- hasArrow = 1,
                                            menuTable = childMenuList,
                                            func = function ()
                                                if subsidyParentData[subsidyParentName] then
                                                    subsidyParentData[subsidyParentName] = nil
                                                    if ZL_CURRENT.subsidyParent then
                                                        ZL_CURRENT.subsidyParent[subsidyParentName] = nil
                                                    end
                                                    for _, subsidyName in ipairs(ZL.subsidyChildrenList[subsidyParentName]) do
                                                        subsidyData[subsidyName] = nil
                                                        if ZL_CURRENT.subsidy then
                                                            ZL_CURRENT.subsidy[subsidyName] = nil
                                                        end
                                                    end
                                                else
                                                    subsidyParentData[subsidyParentName] = 0
                                                    if #ZL.subsidyChildrenList[subsidyParentName] == 1 then
                                                        subsidyData[ZL.subsidyChildrenList[subsidyParentName][1]] = 0
                                                        if subsidyParentName == "RL补贴" then
                                                            local RL = select(4, ZL.GetWagesGroupMembers())
                                                            if RL then
                                                                ZL_CURRENT.subsidy = ZL_CURRENT.subsidy or {}
                                                                ZL_CURRENT.subsidy["RL"] = {}
                                                                ZL_CURRENT.subsidy["RL"][RL] = true
                                                            end
                                                        end
                                                    end
                                                end
                                                ZL.SubsidyFrame:Update()
                                                BillOverviewFrame:Update()
                                            end,
                                        })
                                    end
                                    return _tempList
                                end,
                                func = function ()
                                    ZL.opt.subsidyProfileSelect = index
                                    ZL_CURRENT.subsidy = {}
                                    ZL_CURRENT.subsidyParent = {}
                                    ZL.SubsidyFrame.historyProfileDropdown:SetValue(ZL.opt.subsidyProfileSelect)
                                    ZL.SubsidyFrame:Update()
                                    if ZL_CURRENT.WagesBiLi then
                                        for _, data in pairs(ZL_CURRENT.WagesBiLi) do
                                            data["buTie"] = nil
                                        end
                                        if ZL.AuctionRecordFrame.playerBalanceFrame:IsShown() then
                                            ZL.AuctionRecordFrame.playerBalanceFrame:Update()
                                        end
                                    end
                                    BillOverviewFrame:Update()
                                    ZL.GUI:CloseMenu()
                                end
                            })
                        end
                        return tempList
                    end
                })
                tinsert(menuList, {
                    text = "方案",
                    notClickable = 1,
                    hasArrow = 1,
                    menuTable = function ()
                        local tempList = {}
                        for i, text in ipairs({"无补贴", "|cfff58cba按父补贴金额|r"}) do
                            tinsert(tempList, {
                                text = text,
                                checkable = 1,
                                checked = ZL.opt.wagesSubsidyType == i,
                                func = function ()
                                    ZL.opt.wagesSubsidyType = i
                                    ZL.SubsidyFrame.wagesSubsidyTypeDropdown:SetValue(ZL.opt.wagesSubsidyType)
                                    if ZL_CURRENT.WagesBiLi then
                                        for _, data in pairs(ZL_CURRENT.WagesBiLi) do
                                            data["buTie"] = nil
                                        end
                                        if ZL.AuctionRecordFrame.playerBalanceFrame:IsShown() then
                                            ZL.AuctionRecordFrame.playerBalanceFrame:Update()
                                        end
                                    end
                                    BillOverviewFrame:Update()
                                    ZL.GUI:CloseMenu()
                                end
                            })
                        end
                        return tempList
                    end
                })
                tinsert(menuList, {
                    text = "|cffffde00更多设置|r",
                    func = function ()
                        ZL.SubsidyFrame:Show()
                        ZL.GUI:CloseMenu()
                    end
                })
                tinsert(menuList, {isSeparator=1})
                tinsert(menuList, {text = "关闭"})
            elseif f.data.itemlink == "RL补贴" then
                local profileName = ZL.opt.subsidyProfileList["profileKeys"][ZL.opt.subsidyProfileSelect]
                local subsidyData = ZL.opt.subsidyProfileList["profile"][profileName]["child"]
                local subsidyMoney = subsidyData["RL"]
                local RLSubsidyType = "固定"
                if type(subsidyMoney) == "number" then
                    RLSubsidyType = "固定"
                elseif subsidyMoney == "团双" then
                    RLSubsidyType = "团双"
                elseif type(subsidyMoney) == "string" and subsidyMoney:match("(%d+%%)") then
                    RLSubsidyType = "提成"
                end
                for _, value in ipairs({"固定", "团双", "提成"}) do
                    tinsert(menuList, {
                        text = value,
                        checked = value == RLSubsidyType,
                        func = function ()
                            if value == "团双" then
                                subsidyData["RL"] = value
                            elseif value == "固定" then
                                subsidyData["RL"] = 20000
                            elseif value == "提成" then
                                subsidyData["RL"] = "3%"
                            end
                            if ZL.SubsidyFrame:IsShown() then
                                ZL.SubsidyFrame:Update()
                            end
                            BillOverviewFrame:Update()
                        end,
                        hasArrow = value ~= "团双",
                        menuTable = function ()
                            local _menuList = {}
                            local _tempList
                            if value == "固定" then
                                _tempList = {20000, 30000, 40000, 50000, 60000, 70000, 80000, 90000, 100000}
                            else
                                _tempList = {"1%", "2%", "3%", "4%", "5%"}
                            end
                            for _, _value in ipairs(_tempList) do
                                tinsert(_menuList, {
                                    text = _value,
                                    func = function ()
                                        subsidyData["RL"] = _value
                                        if ZL.SubsidyFrame:IsShown() then
                                            ZL.SubsidyFrame:Update()
                                        end
                                        BillOverviewFrame:Update()
                                        ZL.GUI:CloseMenu()
                                    end
                                })
                            end
                            return _menuList
                        end,
                    })
                end
                tinsert(menuList, {isSeparator=1})
                tinsert(menuList, {text = "关闭"})
            end
        end
        return menuList
    end
    local function playerNameBoxMenu(self)
        local menuTable = {}
        if not PlayerIsML() then return menuTable end
        local currentRoster = ZL.GetCurrentRoster()
        if not currentRoster then return menuTable end
        local f = self:GetParent()
        local _playerName = f.data.playerName
        if f.data.type == "auction" then
            if _playerName ~= "待拍卖" and _playerName ~= "拍卖中" and _playerName ~= "流拍" then
                local itemlink = f.data.itemlink
                local itemindex = f.data.itemindex
                local _, index = ZL.FetchDataFromItemId(itemlink, itemindex)
                local curAuctionList = ZL_CURRENT.auctionlist[index]
                local bidderlist = curAuctionList.bidderlist
                for i = 1, #currentRoster do
                    if #currentRoster[i] > 0 then
                        local group = {
                            text = "|cffffffff小队" .. tostring(i) .. "|r",
                            hasArrow = true,
                            isTitle = true,
                            menuTable = {},
                        }
                        for _, playerName in ipairs(currentRoster[i]) do
                            local isCandidate = ZL.IsCandidate(index, playerName)
                            local nameIsExist
                            for _, data in ipairs(bidderlist) do
                                if data.bidder == playerName then
                                    nameIsExist = true
                                    break
                                end
                            end
                            tinsert(group.menuTable, {
                                text = function ()
                                    if nameIsExist then
                                        return ZL.GetNoRealmName(playerName).."(已存在)"
                                    else
                                        if isCandidate then
                                            return ZL.GetNoRealmName(playerName, true)
                                        else
                                            return ZL.GetNoRealmName(playerName).."(不可交易)"
                                        end
                                    end
                                end,
                                disabled = function ()
                                    if not isCandidate or nameIsExist then return true end
                                end,
                                func = function ()
                                    ZL.GUI:CloseMenu()
                                    local data = {
                                        type = "修改名字",
                                        data2 = {
                                            itemlink = itemlink,
                                            itemindex = itemindex,
                                            oldName = _playerName,
                                            newName = playerName,
                                        },
                                    }
                                    MyAddon:TransmitAddonInfo("AUTOAUC SYNC6", data)
                                end,
                            })
                        end
                        tinsert(menuTable, group)
                        group = nil
                    end
                end
            end
            if #menuTable > 0 then
                tinsert(menuTable, 1, {text="修改名字", isTitle=1})
            end
        elseif f.data.type == "manualIncome" then
            for i = 1, #currentRoster do
                if #currentRoster[i] > 0 then
                    local group = {
                        text = "|cffffffff小队" .. tostring(i) .. "|r",
                        hasArrow = true,
                        isTitle = true,
                        menuTable = {},
                    }
                    for _, playerName in ipairs(currentRoster[i]) do
                        tinsert(group.menuTable, {
                            text = function ()
                                if _playerName ~= playerName then
                                    return ZL.GetNoRealmName(playerName, true)
                                else
                                    return ZL.GetNoRealmName(playerName)
                                end
                            end,
                            disabled = _playerName == playerName,
                            func = function ()
                                self.fontstring:SetText(ZL.GetNoRealmName(playerName, true))
                                f.data.playerName = playerName
                                ZL.GUI:CloseMenu()
                                if f.data.childType ~= "add" then
                                    ZL_CURRENT["IncomeList"][f.data.index].player = playerName
                                    local fdata = {
                                        type = "添加收支",
                                        data = ZL_CURRENT.IncomeList,
                                        globalConfigData = ZL.globalConfigData(),
                                    }
                                    MyAddon:TransmitAddonInfo("AUTOAUC SYNC11", fdata)
                                    if ZL.AuctionRecordFrame.currentIncomeFrame:IsShown() then
                                        ZL.AuctionRecordFrame.currentIncomeFrame:Update()
                                    end
                                    if ZL.AuctionRecordFrame.playerBalanceFrame:IsShown() then
                                        ZL.AuctionRecordFrame.playerBalanceFrame:Update()
                                    end
                                else
                                    f.itemicon:Click()
                                end
                            end,
                        })
                    end
                    tinsert(menuTable, group)
                    group = nil
                end
            end
            if f.data.playerName ~= "" then
                if #menuTable > 0 then
                    tinsert(menuTable, 1, {isSeparator=1})
                end
                tinsert(menuTable, 1, {
                    text = "清空",
                    func = function ()
                        self.fontstring:SetText("")
                        f.data.playerName = ""
                        ZL.GUI:CloseMenu()
                        if f.data.childType ~= "add" then
                            ZL_CURRENT["IncomeList"][f.data.index].player = ""
                            local fdata = {
                                type = "添加收支",
                                data = ZL_CURRENT.IncomeList,
                                globalConfigData = ZL.globalConfigData(),
                            }
                            MyAddon:TransmitAddonInfo("AUTOAUC SYNC11", fdata)
                            if ZL.AuctionRecordFrame.currentIncomeFrame:IsShown() then
                                ZL.AuctionRecordFrame.currentIncomeFrame:Update()
                            end
                            if ZL.AuctionRecordFrame.playerBalanceFrame:IsShown() then
                                ZL.AuctionRecordFrame.playerBalanceFrame:Update()
                            end
                        end
                    end
                })

            end
        end
        return menuTable
    end
    BillOverviewFrame.entries = setmetatable({}, {
        __index = function (t, v)
            local f = CreateFrame("Button", nil, content)
            f:SetSize(totalColomnWidth, height)
            f.Background = f:CreateTexture(nil,"BACKGROUND")
            f.Background:SetPoint("TOPLEFT")
            f.Background:SetPoint("BOTTOMRIGHT")
            f.Background:SetColorTexture(0.15, 0.15, 0.15, 1)
            f:SetScript("OnEnter", function (self)
                OnEnter(f)
            end)
            f:SetScript("OnLeave", function (self)
                OnLeave(f)
            end)

            f.zlHighlight = f:CreateTexture(nil, "BACKGROUND")
            f.zlHighlight:SetColorTexture(1, 0.82, 0, 0.3)
            f.zlHighlight:SetPoint("TOPLEFT", BOSSwidth, 0)
            f.zlHighlight:SetPoint("BOTTOMRIGHT")
            f.zlHighlight:SetBlendMode("ADD")
            f.zlHighlight:Hide()

            f.bossfontstring = f:CreateFontString(nil, "OVERLAY")
            f.bossfontstring:SetPoint("TOPLEFT", 3, 0)
            f.bossfontstring:SetWidth(BOSSwidth-6)
            f.bossfontstring:SetFont(GameFontNormal:GetFont(), 15, "THICKOUTLINE")
            f.bossfontstring:SetWordWrap(true)
            f.bossfontstring:SetJustifyH("CENTER")
            f.bossfontstring:SetJustifyV("MIDDLE")
            -- f.bossfontstring:SetTextColor(0.95, 0.95, 0.95, 1)

            f.itemicon = CreateButton(nil, f, " ", "TOPLEFT", f.bossfontstring, "TOPRIGHT", 3, 0, 20, 20, 12)
            f.itemicon.BorderRight:Hide()
            f.itemicon:SetScript("OnEnter", function(self)
                OnEnter(f)
                if not PlayerIsML() then return end
                if f.data.type == "manualIncome" then
                    GameTooltipShow(self, "TOPLEFT", "BOTTOMRIGHT")
                    if f.data.childType == "add" then
                        GameTooltip:AddLine("新增")
                    else
                        GameTooltip:AddLine("删除")
                        GameTooltip:AddLine("不可恢复", 1, 0 ,0)
                    end
                    GameTooltip:Show()
                elseif f.data.type == "qiankuan" then
                    GameTooltipShow(self, "TOPLEFT", "BOTTOMRIGHT")
                    GameTooltip:AddLine("平账")
                    GameTooltip:AddLine("清除欠款", 1, 1, 1)
                    GameTooltip:Show()
                elseif f.data.type == "butie" then
                    if f.data.itemlink ~= "|cffffde00补贴配置 ▼|r" then
                        GameTooltipShow(self, "TOPLEFT", "BOTTOMRIGHT")
                        GameTooltip:AddLine("删除")
                        GameTooltip:AddLine("删除后可到配\n置里重新勾选", 1, 1, 1)
                        GameTooltip:Show()
                    end
                end
            end)
            f.itemicon:SetScript("OnLeave", function()
                OnLeave(f)
                GameTooltip:Hide()
            end)
            f.itemicon:SetScript("OnClick", function ()
                if not PlayerIsML() then return end
                if f.data.type == "manualIncome" then
                    if f.data.childType == "add" then
                        local itemName = f.data.itemlink
                        local playerName = f.data.playerName or ""
                        local totalAmount = tonumber(f.data.totalAmount) or 0
                        if not itemName or #itemName == 0 or itemName:match("名称和金额为必填") then
                            ZL.Print("名称为必填项。", true)
                            f.itemNamebox:SetFocus()
                            return
                        end
                        if totalAmount == 0 then
                            f.amountbox:SetFocus()
                            ZL.Print("总金额为必填项。", true)
                            return
                        end
                        ZL_CURRENT.IncomeList = ZL_CURRENT.IncomeList or {}
                        tinsert(ZL_CURRENT.IncomeList, {
                            ["notes"] = itemName,
                            ["player"] = playerName,
                            ["itemCount"] = 1,
                            ["amount"] = totalAmount,
                        })
                    else
                        tremove(ZL_CURRENT["IncomeList"], f.data.index)
                    end
                    local fdata = {
                        type = "添加收支",
                        data = ZL_CURRENT.IncomeList,
                        globalConfigData = ZL.globalConfigData(),
                    }
                    MyAddon:TransmitAddonInfo("AUTOAUC SYNC11", fdata)
                    BillOverviewFrame:Update()
                    if ZL.AuctionRecordFrame.currentIncomeFrame:IsShown() then
                        ZL.AuctionRecordFrame.currentIncomeFrame:Update()
                    end
                    if ZL.AuctionRecordFrame.playerBalanceFrame:IsShown() then
                        ZL.AuctionRecordFrame.playerBalanceFrame:Update()
                    end
                elseif f.data.type == "qiankuan" then
                    local qiankuan = f.data.totalAmount
                    if qiankuan < 0 then
                        ZL_CURRENT.playerPayToML = ZL_CURRENT.playerPayToML or {}
                        ZL_CURRENT.playerPayToML[f.data.playerName]= (ZL_CURRENT.playerPayToML[f.data.playerName] or 0 ) - qiankuan
                        if ZL.AuctionRecordFrame.playerBalanceFrame:IsShown() then
                            ZL.AuctionRecordFrame.playerBalanceFrame:Update()
                        end
                        BillOverviewFrame:Update()
                    end
                elseif f.data.type == "butie" then
                    if f.data.itemlink ~= "|cffffde00补贴配置 ▼|r" then
                        local profileName = ZL.opt.subsidyProfileList["profileKeys"][ZL.opt.subsidyProfileSelect]
                        local subsidyParentData = ZL.opt.subsidyProfileList["profile"][profileName]["parent"]
                        local subsidyData = ZL.opt.subsidyProfileList["profile"][profileName]["child"]
                        local subsidyParentName = f.data.itemlink
                        subsidyParentData[subsidyParentName] = nil
                        if ZL_CURRENT.subsidyParent then
                            ZL_CURRENT.subsidyParent[subsidyParentName] = nil
                        end
                        for _, subsidyName in ipairs(ZL.subsidyChildrenList[subsidyParentName]) do
                            subsidyData[subsidyName] = nil
                            if ZL_CURRENT.subsidy then
                                ZL_CURRENT.subsidy[subsidyName] = nil
                            end
                        end
                        BillOverviewFrame:Update()
                        if ZL.SubsidyFrame:IsShown() then
                            ZL.SubsidyFrame:Update()
                        end
                    end
                end
            end)
            f.itemicon:SetScript("OnDoubleClick", function (self, button)
                if f.data.type == "manualIncome" or f.data.type == "qiankuan" or f.data.type == "butie" then return end
                local itemlink = f.data.itemlink
                if (not itemlink) or itemlink == "" then return end
                local itemId = tonumber(itemlink:match("|Hitem:(%d+):"))
                if itemId then
                    local selectCharKey = ZL.GetClassColorName() .. " - " .. GetRealmName()
                    if (not ZL.opt.concernList) or (not ZL.opt.concernList[selectCharKey]) or
                    (not ZL.opt.concernList[selectCharKey]["itemList"][itemId]) then
                        ZL.addItem(itemId)
                    else
                        ZL.deleteItem(itemId)
                    end
                    ZL.AuctionFrame2:Update()
                end
            end)
            
            f.itemicon.itemNumbersIcon = f.itemicon:CreateTexture(nil, "OVERLAY")
            local itemNumbersIcon = f.itemicon.itemNumbersIcon
            itemNumbersIcon:SetPoint("TOP", f.itemicon, "TOP")
            itemNumbersIcon:SetSize(15,15)
            -- itemNumbersIcon:SetAllPoints(f.itemicon)

            f.level = f.itemicon:CreateFontString(nil, "OVERLAY")
            f.level:SetPoint("BOTTOMLEFT", 1, 0)
            -- f.level:SetPoint("BOTTOMRIGHT", -1, 0)
            f.level:SetFont(GameFontNormal:GetFont(), 9, "OUTLINE")
            f.level:SetWordWrap(false)
            f.level:SetJustifyH("LEFT")
            f.level:SetTextColor(0.95, 0.95, 0.95, 1)

            f.itemNamebox = CreateEditBox(f, itemNamewidth-f.itemicon:GetWidth(), 20, 12, "RIGHT", nil, nil, board_r, board_g, board_b, board_a, "BILLOVERVIEW_ITEMNAME"..v)
            f.itemNamebox:SetPoint("LEFT", f.itemicon, "RIGHT", 0, 0)
            f.itemNamebox.Background:SetColorTexture(0,0,0,0)
            f.itemNamebox.BorderRight:Hide()
            f.itemNamebox:SetScript("OnEnter", function (self)
                if not self:HasFocus() then
                    OnEnter(f)
                end
                if f.data.type == "manualIncome" and f.data.childType ~= "add" and PlayerIsML() then
                    GameTooltipShow(self, "TOPLEFT", "BOTTOMRIGHT")
                    GameTooltip:AddLine("按Enter键保存")
                    GameTooltip:AddLine("会占用通信资源\n不要频繁修改", 1, 1, 1)
                    GameTooltip:Show()
                elseif f.data.itemlink and not ZL.tdGUI_DropMenuIsShown() then
                    local itemlink = f.data.itemlink
                    if (not itemlink) or itemlink == "" then return end
                    local itemId = tonumber(itemlink:match("|Hitem:(%d+):"))
                    if itemId then
                        local uiScale, x, y = UIParent:GetEffectiveScale(), GetCursorPosition()
                        x, y = x/uiScale, y/uiScale
                        local screenWidth = GetScreenWidth() / 2
                        if x < screenWidth then
                            GameTooltipShow(self, "TOPLEFT", "TOPRIGHT")
                        else
                            GameTooltipShow(self, "TOPRIGHT", "TOPLEFT")
                        end
                        GameTooltip:ClearLines()
                        GameTooltip:SetHyperlink(itemlink)
                        GameTooltip:Show()
                        if _G["ShoppingTooltip1"] and _G["ShoppingTooltip1"]:IsShown() then
                            _G["ShoppingTooltip1"]:ClearAllPoints()
                            if x < screenWidth then
                                _G["ShoppingTooltip1"]:SetPoint("TOPLEFT", GameTooltip, "TOPRIGHT", 0, 0)
                            else
                                _G["ShoppingTooltip1"]:SetPoint("TOPRIGHT", GameTooltip, "TOPLEFT", 0, 0)
                            end
                        end
                        if _G["ShoppingTooltip2"] and _G["ShoppingTooltip2"]:IsShown() then
                            _G["ShoppingTooltip2"]:ClearAllPoints()
                            if x < screenWidth then
                                _G["ShoppingTooltip2"]:SetPoint("TOPLEFT", _G["ShoppingTooltip1"], "TOPRIGHT", 0, 0)
                            else
                                _G["ShoppingTooltip2"]:SetPoint("TOPRIGHT", _G["ShoppingTooltip1"], "TOPLEFT", 0, 0)
                            end
                        end
                    end
                end
            end)
            f.itemNamebox:SetScript("OnLeave", function (self)
                OnLeave(f)
                GameTooltip:Hide()
            end)
            f.itemNamebox:SetScript("OnEditFocusGained", function (self)
                OnLeave(f)
                f.itemNamebox.fontstring:Hide()
                if f.data.itemlink == "|cff595959名称和金额为必填|r" then
                    self:SetText("")
                else
                    self:SetText(f.data.itemlink)
                end
                self:HighlightText()
            end)
            f.itemNamebox:SetScript("OnEditFocusLost", function (self)
                self:HighlightText(0, 0)
                f.itemNamebox.fontstring:SetText(f.data.itemlink)
                f.itemNamebox.fontstring:Show()
                self:SetText("")
            end)
            f.itemNamebox:SetScript("OnTextChanged", function (self)
                local txt = self:GetText() or ""
                if f.data.type == "manualIncome" and #txt > 0 then
                    if f.data.childType ~= "add" then
                        f.data.newItemlink = txt
                    else
                        f.data.itemlink = txt
                    end
                end
            end)
            f.itemNamebox:SetScript("OnMouseDown", function (self, button)
                if button == "LeftButton" then
                    local menuList = itemNameBoxMenu(self)
                    if #menuList > 0 then
                        ZL.GUI:ToggleMenu(self, menuList, 'cursor')
                        if ZL.tdGUI_DropMenuIsShown() then
                            GameTooltip:Hide()
                        end
                    end
                end
            end)
            f.itemNamebox:HookScript("OnEnterPressed", function ()
                if not PlayerIsML() then return end
                if f.data.type == "manualIncome" then
                    if f.data.childType == "add" then
                        f.itemicon:Click()
                    else
                        local newItemlink = f.data.newItemlink
                        if newItemlink and newItemlink ~= f.data.itemlink then
                            ZL_CURRENT["IncomeList"][f.data.index].notes = newItemlink
                            local fdata = {
                                type = "添加收支",
                                data = ZL_CURRENT.IncomeList,
                                globalConfigData = ZL.globalConfigData(),
                            }
                            MyAddon:TransmitAddonInfo("AUTOAUC SYNC11", fdata)
                            BillOverviewFrame:Update()
                            if ZL.AuctionRecordFrame.currentIncomeFrame:IsShown() then
                                ZL.AuctionRecordFrame.currentIncomeFrame:Update()
                            end
                            if ZL.AuctionRecordFrame.playerBalanceFrame:IsShown() then
                                ZL.AuctionRecordFrame.playerBalanceFrame:Update()
                            end
                        end
                    end
                end
            end)
            f.itemNamebox.fontstring = f.itemNamebox:CreateFontString(nil, "OVERLAY")
            f.itemNamebox.fontstring:SetPoint("TOPLEFT", 3, -1)
            f.itemNamebox.fontstring:SetPoint("BOTTOMRIGHT", -3, 1)
            f.itemNamebox.fontstring:SetFont(GameFontNormal:GetFont(), 13, "OUTLINE")
            f.itemNamebox.fontstring:SetWordWrap(true)
            f.itemNamebox.fontstring:SetJustifyH("LEFT")
            f.itemNamebox.fontstring:SetJustifyV("MIDDLE")
            f.itemNamebox.fontstring:SetTextColor(0.95, 0.95, 0.95, 1)
            
            f.playerNamebox = CreateEditBox(f, playerNamewidth, 20, 12, "LEFT", nil, nil, board_r, board_g, board_b, board_a, "BILLOVERVIEW_PLAYERNAME"..v)
            f.playerNamebox:SetPoint("LEFT", f.itemNamebox, "RIGHT", 0, 0)
            f.playerNamebox.Background:SetColorTexture(0,0,0,0)
            f.playerNamebox.BorderRight:Hide()
            f.playerNamebox:SetScript("OnEnter", function (self)
                if not self:HasFocus() then
                    OnEnter(f)
                end
            end)
            f.playerNamebox:SetScript("OnLeave", function (self)
                OnLeave(f)
            end)
            f.playerNamebox:SetScript("OnEditFocusGained", function (self)
                OnLeave(f)
                f.playerNamebox.fontstring:Hide()
                self:SetText(f.data.playerName or "")
                self:HighlightText()
            end)
            f.playerNamebox:SetScript("OnEditFocusLost", function (self)
                ZL.GUI:CloseMenu()
                self:HighlightText(0, 0)
                f.playerNamebox.fontstring:SetText(f.data.playerName or "")
                f.playerNamebox.fontstring:Show()
                self:SetText("")
            end)
            f.playerNamebox:SetScript("OnMouseDown", function (self, button)
                local menuList = playerNameBoxMenu(self)
                if #menuList > 0 then
                    ZL.GUI:ToggleMenu(self, menuList, "cursor")
                end
            end)
            f.playerNamebox.fontstring = f.playerNamebox:CreateFontString(nil, "OVERLAY")
            f.playerNamebox.fontstring:SetPoint("TOPLEFT", 3, -1)
            f.playerNamebox.fontstring:SetPoint("BOTTOMRIGHT", -3, 1)
            f.playerNamebox.fontstring:SetFont(GameFontNormal:GetFont(), 13, "OUTLINE")
            f.playerNamebox.fontstring:SetWordWrap(true)
            f.playerNamebox.fontstring:SetJustifyH("LEFT")
            f.playerNamebox.fontstring:SetJustifyV("MIDDLE")
            f.playerNamebox.fontstring:SetTextColor(0.95, 0.95, 0.95, 1)

            f.amountbox = CreateEditBox(f, amountwidth, 20, 12, "RIGHT", nil, nil, board_r, board_g, board_b, board_a, "BILLOVERVIEW_AMOUNT"..v)
            f.amountbox:SetPoint("LEFT", f.playerNamebox, "RIGHT", 0, 0)
            f.amountbox.Background:SetColorTexture(0,0,0,0)
            f.amountbox:SetScript("OnEnter", function (self)
                if not self:HasFocus() then
                    OnEnter(f)
                end
                if not PlayerIsML() then return end
                if f.data.type == "butie" then
                    GameTooltipShow(self, "TOP", "BOTTOM")
                    if f.data.itemlink == "RL补贴" then
                        GameTooltip:AddLine("RL补贴方式")
                        local txt = f.itemNamebox.fontstring:GetText()
                        if txt:match("(固定)") then
                            GameTooltip:AddLine("固定：输入|cff4080FF不小于0的数|r")
                            GameTooltip:AddLine("|cff595959团双：点击左侧名称选择团双|r")
                            GameTooltip:AddLine("|cff595959提成：输入0-99的数|r")
                            GameTooltip:AddLine(" ")
                            GameTooltip:AddLine("按Enter键保存")
                        elseif txt:match("(团双)") then
                            GameTooltip:AddLine("|cff595959固定：输入不小于0的数|r")
                            GameTooltip:AddLine("团双：点击左侧名称选择|cff4080FF团双|r")
                            GameTooltip:AddLine("|cff595959提成：输入0-99的数|r")
                        else
                            GameTooltip:AddLine("|cff595959固定：输入不小于0的数|r")
                            GameTooltip:AddLine("|cff595959团双：点击左侧名称选择团双|r")
                            GameTooltip:AddLine("提成：输入|cff4080FF0-99的数|r")
                            GameTooltip:AddLine(" ")
                            GameTooltip:AddLine("按Enter键保存")
                        end
                    else
                        GameTooltip:AddLine("按Enter键保存")
                    end
                    GameTooltip:Show()
                elseif (f.data.type == "auction" or (f.data.type == "manualIncome" and f.data.childType ~= "add")) and self:IsEnabled() then
                    GameTooltipShow(self, "TOPLEFT", "BOTTOMRIGHT")
                    GameTooltip:AddLine("按Enter键保存")
                    GameTooltip:AddLine("会占用通信资源\n不要频繁修改", 1, 1, 1)
                    GameTooltip:Show()
                end
            end)
            f.amountbox:SetScript("OnLeave", function (self)
                OnLeave(f)
                GameTooltip:Hide()
            end)
            f.amountbox:SetScript("OnEditFocusGained", function (self)
                OnLeave(f)
                if f.data.type == "butie" then
                    local ticheng = f.itemNamebox.fontstring:GetText():match("%(([%d.]+)%%%)")
                    if ticheng then
                        self:SetText(ticheng)
                    else
                        self:SetText(f.data.totalAmount and abs(f.data.totalAmount) or "")
                    end
                else
                    self:SetText(f.data.totalAmount and abs(f.data.totalAmount) or "")
                end
                if not (f.data.type == "butie" or f.data.type == "auction" or (f.data.type == "manualIncome" and f.data.childType ~= "add")) then
                    GameTooltip:Hide()
                end
                self:HighlightText()
                f.amountbox.fontstring:Hide()
            end)
            f.amountbox:SetScript("OnEditFocusLost", function (self)
                self:HighlightText(0, 0)
                f.amountbox.fontstring:SetText(f.data.totalAmount or "")
                f.amountbox.fontstring:Show()
                self:SetText("")
            end)
            f.amountbox:SetScript("OnTextChanged", function (self)
                local newAmount = tonumber(self:GetText() or "")
                if newAmount then
                    newAmount = abs(newAmount)
                    if f.data.type == "manualIncome" then
                        if f.data.childType ~= "add" then
                            f.data.newAmount = newAmount
                        else
                            f.data.totalAmount = newAmount
                        end
                    elseif f.data.type == "auction" or f.data.type == "butie" then
                        f.data.newAmount = newAmount
                    end
                end
            end)
            f.amountbox:HookScript("OnEnterPressed", function (self)
                if not PlayerIsML() then return end
                if f.data.type == "auction" then
                    local newAmount = f.data.newAmount
                    if newAmount and newAmount ~= f.data.totalAmount then
                        local data = {
                            type = "修改出价",
                            data2 = {
                                itemlink = f.data.itemlink,
                                itemindex = f.data.itemindex,
                                oldName = f.data.playerName,
                                newBidAmount = newAmount,
                            },
                        }
                        MyAddon:TransmitAddonInfo("AUTOAUC SYNC6", data)
                        f.data.newAmount = nil
                    end
                elseif f.data.type == "manualIncome" then
                    if f.data.childType == "add" then
                        f.itemicon:Click()
                    else
                        local newAmount = f.data.newAmount
                        if newAmount and newAmount ~= f.data.totalAmount then
                            ZL_CURRENT["IncomeList"][f.data.index].amount = newAmount
                            local fdata = {
                                type = "添加收支",
                                data = ZL_CURRENT.IncomeList,
                                globalConfigData = ZL.globalConfigData(),
                            }
                            MyAddon:TransmitAddonInfo("AUTOAUC SYNC11", fdata)
                            BillOverviewFrame:Update()
                            if ZL.AuctionRecordFrame.currentIncomeFrame:IsShown() then
                                ZL.AuctionRecordFrame.currentIncomeFrame:Update()
                            end
                            if ZL.AuctionRecordFrame.playerBalanceFrame:IsShown() then
                                ZL.AuctionRecordFrame.playerBalanceFrame:Update()
                            end
                        end
                    end
                elseif f.data.type == "butie" then
                    local newAmount = f.data.newAmount
                    if newAmount and newAmount ~= f.data.totalAmount then
                        local profileName = ZL.opt.subsidyProfileList["profileKeys"][ZL.opt.subsidyProfileSelect]
                        local subsidyParentData = ZL.opt.subsidyProfileList["profile"][profileName]["parent"]
                        local subsidyData = ZL.opt.subsidyProfileList["profile"][profileName]["child"]
                        local subsidyName = f.data.itemlink
                        if subsidyName == "RL补贴" then
                            local txt = f.itemNamebox.fontstring:GetText()
                            if txt:match("(团双)") then
                                subsidyData["RL"] = "团双"
                            elseif txt:match("(固定)") then
                                subsidyData["RL"] = newAmount
                            else
                                subsidyData["RL"] = newAmount .. "%"
                            end
                        else
                            subsidyParentData[subsidyName] = newAmount
                        end
                        BillOverviewFrame:Update()
                        if ZL.SubsidyFrame:IsShown() then
                            ZL.SubsidyFrame:Update()
                        end
                    end
                end
            end)
            f.amountbox:SetScript("OnMouseDown", function (self, button)
                -- if button == "RightButton" and self:HasFocus() then
                --     C_Timer.After(0.5, function ()
                --         -- amountChange(self)
                --     end)
                -- end
            end)

            f.amountbox.fontstring = f.amountbox:CreateFontString(nil, "OVERLAY")
            f.amountbox.fontstring:SetPoint("TOPLEFT", 3, -1)
            f.amountbox.fontstring:SetPoint("BOTTOMRIGHT", -3, 1)
            f.amountbox.fontstring:SetFont(GameFontNormal:GetFont(), 13, "OUTLINE")
            f.amountbox.fontstring:SetWordWrap(true)
            f.amountbox.fontstring:SetJustifyH("RIGHT")
            f.amountbox.fontstring:SetJustifyV("MIDDLE")
            f.amountbox.fontstring:SetTextColor(0.95, 0.95, 0.95, 1)
            --设置TAB事件
            do
                local editboxList = {"BILLOVERVIEW_ITEMNAME"..v, "BILLOVERVIEW_AMOUNT"..v}
                local function OnTabPressed(self)
                    EditBox_HandleTabbing(self, editboxList)
                end
                f.itemNamebox:SetScript("OnTabPressed", OnTabPressed)
                -- f.playerNamebox:SetScript("OnTabPressed", OnTabPressed)
                f.amountbox:SetScript("OnTabPressed", OnTabPressed)
            end
            t[v] = f
            return f
        end
    })

    function BillOverviewFrame:Update(bill)
        bill = bill or ZL_CURRENT
        for _, f in ipairs(BillOverviewFrame.entries) do f:Hide() end
        local recordList = {}
        local itemLevelList = {}
        local profileName = ZL.opt.subsidyProfileList["profileKeys"][ZL.opt.subsidyProfileSelect]
        local subsidyData = ZL.opt.subsidyProfileList["profile"][profileName]["child"]
        local subsidyMoney = subsidyData["RL"]
        local isML = PlayerIsML()
        local numGroupMembers, RLBuTie, totalincome, totalpayout, totalamount, averageamount = GetAveWages()
        if bill.auctionlist and #bill.auctionlist > 0 then
            do
                local itemlink, spawnUID, bossName, playerName, counts, totalAmount, itemList
                for _, data in ipairs(bill.auctionlist) do
                    itemlink = data.itemlink
                    spawnUID = data.spawnUID
                    itemLevelList[itemlink] = data.itemLevel
                    itemList = data.itemList
                    if spawnUID and (not data.isPackage) then
                        for _, value in pairs(spawnUID) do
                            bossName = value["bossName"] or value["bossname"]
                            recordList[bossName] = recordList[bossName] or {}
                            recordList[bossName][itemlink] = recordList[bossName][itemlink] or {}
                            if (not value["successBidder"]) or (value["successBidder"] and (not next(value["successBidder"]))) then
                                counts = 1
                                if data.state == "waiting" then
                                    playerName = "待拍卖"
                                elseif data.state == "auctioning" then
                                    playerName = "拍卖中"
                                elseif data.state == "failed" or data.state == "success" then
                                    playerName = "流拍"
                                end
                                playerName = playerName or "流拍"
                                recordList[bossName][itemlink][playerName] = recordList[bossName][itemlink][playerName] or {}
                                recordList[bossName][itemlink][playerName].counts = counts + (recordList[bossName][itemlink][playerName].counts or 0)
                                recordList[bossName][itemlink][playerName].itemList = itemList
                                recordList[bossName][itemlink][playerName].itemindex = data.itemindex
                                recordList[bossName][itemlink][playerName].type = "auction"
                            else
                                for _palyer, value2 in pairs(value["successBidder"]) do
                                    playerName = _palyer
                                    totalAmount = value2.amount
                                    counts = value2.count
                                    recordList[bossName][itemlink][playerName] = recordList[bossName][itemlink][playerName] or {}
                                    recordList[bossName][itemlink][playerName].counts = counts + (recordList[bossName][itemlink][playerName].counts or 0)
                                    recordList[bossName][itemlink][playerName].totalAmount = totalAmount + (recordList[bossName][itemlink][playerName].totalAmount or 0)
                                    recordList[bossName][itemlink][playerName].itemList = itemList
                                    recordList[bossName][itemlink][playerName].itemindex = data.itemindex
                                    recordList[bossName][itemlink][playerName].type = "auction"
                                end
                            end
                        end
                    end
                end
            end
        end
        do
            local bossName = "手动添加"
            local playerName, notes
            if bill.IncomeList and #bill.IncomeList > 0 then
                for i, data in ipairs(bill.IncomeList) do
                    if not data["tradeId"] then
                        recordList[bossName] = recordList[bossName] or {}
                        notes = data["notes"]
                        while recordList[bossName][notes] do
                            notes = notes .. "§"
                        end
                        recordList[bossName][notes] = recordList[bossName][notes] or {}
                        playerName = data["player"] or "其它"
                        recordList[bossName][notes][playerName] = recordList[bossName][notes][playerName] or {}
                        recordList[bossName][notes][playerName].totalAmount = data["amount"]
                        recordList[bossName][notes][playerName].counts = data["itemCount"]
                        recordList[bossName][notes][playerName].type = "manualIncome"
                        recordList[bossName][notes][playerName].index = i
                    end
                end
            end
            if isML then
                notes = "|cff595959名称和金额为必填|r"
                recordList[bossName] = recordList[bossName] or {}
                while recordList[bossName][notes] do
                    notes = notes .. "§"
                end
                playerName = ""
                recordList[bossName][notes] = recordList[bossName][notes] or {}
                recordList[bossName][notes][playerName] = recordList[bossName][notes][playerName] or {}
                recordList[bossName][notes][playerName].totalAmount = ""
                recordList[bossName][notes][playerName].counts = 1
                recordList[bossName][notes][playerName].type = "manualIncome"
                recordList[bossName][notes][playerName].childType = "add"
                recordList[bossName][notes][playerName].index = #bill.IncomeList
            end
        end
        do
            local bossName = "补贴支出"
            local playerName
            local totalAmount
            recordList[bossName] = recordList[bossName] or {}
            local notes = "|cffffde00补贴配置 ▼|r"
            if ZL.opt.wagesSubsidyType == 1 then
                playerName = "无补贴"
                totalAmount = ""
            elseif ZL.opt.wagesSubsidyType == 2 then
                playerName = "父补贴金额"
                totalAmount = ZL.opt.subsidyProfileList.profileKeys[ZL.opt.subsidyProfileSelect]
            else
                playerName = "子补贴金额"
                totalAmount = ZL.opt.subsidyProfileList.profileKeys[ZL.opt.subsidyProfileSelect]
            end
            recordList[bossName][notes] = recordList[bossName][notes] or {}
            recordList[bossName][notes][playerName] = recordList[bossName][notes][playerName] or {}
            recordList[bossName][notes][playerName].totalAmount = totalAmount
            recordList[bossName][notes][playerName].counts = 1
            recordList[bossName][notes][playerName].type = "butie"
            if ZL.opt.wagesSubsidyType ~= 1 and subsidyMoney == "团双" then
                notes = "RL补贴"
                playerName = ""
                totalAmount = "已算到工资里"
                recordList[bossName][notes] = recordList[bossName][notes] or {}
                recordList[bossName][notes][playerName] = recordList[bossName][notes][playerName] or {}
                recordList[bossName][notes][playerName].totalAmount = totalAmount
                recordList[bossName][notes][playerName].counts = 1
                recordList[bossName][notes][playerName].type = "butie"
            end
            if bill["butie"] and #bill["butie"]  > 0 then
                for _, data in ipairs(bill["butie"]) do
                    notes = data["notes"]
                    if notes ~= "RL补贴(团双)" then
                        if notes:match("RL补贴") then
                            notes = "RL补贴"
                        end
                        recordList[bossName][notes] = recordList[bossName][notes] or {}
                        playerName = data["player"]
                        recordList[bossName][notes][playerName] = recordList[bossName][notes][playerName] or {}
                        recordList[bossName][notes][playerName].totalAmount = (recordList[bossName][notes][playerName].totalAmount or 0) + data["amount"]
                        recordList[bossName][notes][playerName].counts = (recordList[bossName][notes][playerName].counts or 0) + (data["itemCount"] or 1)
                        recordList[bossName][notes][playerName].type = "butie"
                    end
                end
            end
        end
        local playerBuyList = ZL.GetPlayerBuyList(bill)
        local debtList = {}
        for name, data in pairs(playerBuyList) do
            local balanceAmount = 0
            local playerPayToMLamount = 0
            if bill.playerPayToML and bill.playerPayToML[name] then
                playerPayToMLamount = bill.playerPayToML[name]
            end
            balanceAmount = playerPayToMLamount - data.totalAmount
            if PlayerIsML(name) then
                balanceAmount = 0
            end
            if balanceAmount < 0 then
                debtList[name] = balanceAmount
            end
        end
        if next(debtList) then
            local bossName = "欠款名单"
            recordList[bossName] = recordList[bossName] or {}
            if not recordList[bossName][" "] then recordList[bossName][" "] = {} end
            for name, debt in pairs(debtList) do
                if not recordList[bossName][" "][name] then recordList[bossName][" "][name] = {} end
                recordList[bossName][" "][name]["totalAmount"] = debt
                recordList[bossName][" "][name]["counts"] = 1
                recordList[bossName][" "][name].type = "qiankuan"
            end
        end
        if bill["aveWages"] then
            local zhanBi = " "
            if totalincome > 0 then
                zhanBi = format("%.2f%%", -totalpayout / totalincome * 100)
            end
            recordList["收支总览"] = {
                ["总收入"] = {
                    [" "] = {
                        ["totalAmount"] = totalincome,
                        ["counts"] = " ",
                        type = "overview",
                    },
                },
                ["总支出"] = {
                    [zhanBi] = {
                        ["totalAmount"] = totalpayout,
                        ["counts"] = " ",
                        type = "overview",
                    },
                },
                ["浄收入"] = {
                    [" "] = {
                        ["totalAmount"] = totalamount,
                        ["counts"] = " ",
                        type = "overview",
                    },
                },
            }
            recordList["工资分配"] = {
                [subsidyMoney == "团双" and "工资人数(团双)" or "工资人数"] = {
                    [" "] = {
                        ["totalAmount"] = numGroupMembers,
                        ["counts"] = " ",
                        type = "avewages",
                    },
                },
                ["人均工资"] = {
                    [" "] = {
                        ["totalAmount"] = averageamount,
                        ["counts"] = " ",
                        type = "avewages",
                    },
                },
                ["小队工资"] = {
                    [averageamount .. "×5"] = {
                        ["totalAmount"] = averageamount*5,
                        ["counts"] = " ",
                        type = "avewages",
                    },
                },
            }
        end
        wipe(debtList)
        wipe(playerBuyList)
        debtList = nil
        playerBuyList = nil
        if next(recordList) then
            BillOverviewFrame:SetSize(GetScreenWidth()-65, GetScreenHeight()-50)
            local maxrows = floor(BillOverviewFrame.scrollFrame:GetHeight() / (height+gapheight)) --全屏支持的最大行数
            local bossMaxRows = 0
            for bossName, value1 in pairs(recordList) do
                local rows = 0
                if type(value1) == "table" then
                    for _, value2 in pairs(value1) do
                        for _, value3 in pairs(value2) do
                            rows = rows + 1
                            bossMaxRows = bossMaxRows + 1
                            if bossName == "打包拍卖" then
                                for _ in pairs(value3["itemList"]) do
                                    rows = rows + 1
                                    bossMaxRows = bossMaxRows + 1
                                end
                            end
                        end
                    end
                    bossMaxRows = bossMaxRows + 1
                end
            end
            bossMaxRows = bossMaxRows - 1
            if bossMaxRows <= maxrows then
                maxrows = bossMaxRows
            else
                local minColumn = ceil(bossMaxRows/maxrows)
                minColumn = minColumn > 3 and 3 or minColumn
                maxrows = ceil(bossMaxRows/minColumn)
            end
            local index = 1  --总行数，用来计算BillOverviewFrame.entries[index]
            local bili = 1
            local bossindex = 0 -- 分类数
            local oldbossindex = 1
            local f, f2, f3
            local column = 0 --列
            local row = 1 --每一列中的行数
            local rowMax = 1 --取每列中最大的行
            local value1, value2, value3, index2, itemList, playerNameList, itemId
            for _, bossName in ipairs(ZL.encounterNameList) do
                value1 = recordList[bossName]
                if value1 and type(value1) == "table" then
                    bossindex = bossindex + 1
                    index2 = 1 --每一次分类中的行数
                    oldbossindex = index --重新初始化oldbossindex，用于设置f.bossfontstring的高度
                    if next(value1) then
                        itemList = {}
                        if bossName == "收支总览" then
                            itemList = {"总收入", "总支出", "浄收入"}
                        elseif bossName == "工资分配" then
                            itemList = { subsidyMoney == "团双" and "工资人数(团双)" or "工资人数", "人均工资", "小队工资"}
                        elseif bossName == "补贴支出" then
                            itemList = {"|cffffde00补贴配置 ▼|r", "RL补贴", "T补贴", "N补贴", "DPS补贴", "食物补贴", "工具人补贴", "其它补贴"}
                        elseif bossName == "拍卖合计" then
                            itemList = {"总收入", "预估人数", "人均预估"}
                        else
                            for itemlink in pairs(value1) do
                                tinsert(itemList, itemlink)
                            end
                            if bossName ~= "手动添加" then
                                sort(itemList)
                            else
                                sort(itemList, function (a, b)
                                    if a == "|cff595959名称和金额为必填|r" then
                                        return false
                                    end
                                    if b == "|cff595959名称和金额为必填|r" then
                                        return true
                                    end
                                    return a < b
                                end)
                            end
                        end
                        for _, itemlink in ipairs(itemList) do
                            value2 = value1[itemlink]
                            if value2 then
                                itemId = tonumber(itemlink:match("|Hitem:(%d+):"))
                                if next(value2) then
                                    playerNameList = {}
                                    for playerName in pairs(value2) do
                                        tinsert(playerNameList, playerName)
                                    end
                                    sort(playerNameList)
                                    for _, playerName in ipairs(playerNameList) do
                                        value3 = value2[playerName]
                                        f = BillOverviewFrame.entries[index]
                                        f.data = {
                                            type = recordList[bossName][itemlink][playerName].type,
                                            bossName = bossName,
                                            itemlink = itemlink:gsub("§", ""),
                                            playerName = playerName,
                                            totalAmount = recordList[bossName][itemlink][playerName].totalAmount,
                                            counts = value3.counts,
                                            itemindex = recordList[bossName][itemlink][playerName].itemindex,
                                            index = recordList[bossName][itemlink][playerName].index,
                                            childType = recordList[bossName][itemlink][playerName].childType,
                                        }
                                        f:ClearAllPoints()
                                        if index == 1 or row == maxrows + 1 then
                                            if index > 1 then
                                                f3 = BillOverviewFrame.entries[index-1]
                                                f3.itemNamebox.BorderBottom:Show()
                                                f3.playerNamebox.BorderBottom:Show()
                                                f3.amountbox.BorderBottom:Show()
                                            end
                                            --刚开始第一行或者每列最大行的时候增加一列
                                            f:SetPoint("TOPLEFT", content, "TOPLEFT", (totalColomnWidth+gapwidth)*column, 0)
                                            column = column + 1
                                            if row > rowMax then
                                                rowMax = row
                                            end
                                            row = 1
                                            index2 = 1
                                            oldbossindex = index
                                        else
                                            f:SetPoint("TOPLEFT", BillOverviewFrame.entries[index-1], "BOTTOMLEFT", 0, -gapheight)
                                            if row > rowMax then
                                                rowMax = row
                                            end
                                        end
                                        if index2 == 1 then
                                            if bossName == "打包拍卖" then
                                                f.bossfontstring:SetText(bossName)
                                            elseif bossName == "总览" or bossName == "工资" then
                                                f.bossfontstring:SetText("|cff00aaff" .. bossName .. "|r")
                                            elseif bossName == "欠款名单" then
                                                f.bossfontstring:SetText("|TInterface\\DialogFrame\\DialogAlertIcon.blp:20|t|cffff0000" .. bossName .. "|r")
                                            else
                                                if bossindex % 2 == 0 then
                                                    f.bossfontstring:SetText("|cffADDFAD" .. bossName .. "|r")
                                                else
                                                    f.bossfontstring:SetText("|cffFFD700" .. bossName .. "|r")
                                                end
                                            end
                                            f.bossfontstring:Show()
                                        else
                                            f.bossfontstring:SetText(bossName)
                                            f.bossfontstring:Hide()
                                        end
                                        f2 = BillOverviewFrame.entries[oldbossindex]
                                        f2.bossfontstring:SetHeight(index2*height + (index2-1)*gapheight)
                                        f.playerNamebox.fontstring:Show()
                                        f.amountbox.fontstring:Show()
                                        -- f.itemNamebox.BorderBottom:Hide()
                                        -- f.playerNamebox.BorderBottom:Hide()
                                        -- f.amountbox.BorderBottom:Hide()
                                        if f.data.type == "auction" and playerName == "拍卖中" then
                                            f.zlHighlight:Show()
                                        else
                                            f.zlHighlight:Hide()
                                        end
                                        if isML then
                                            if f.data.type == "manualIncome" then
                                                f.itemNamebox:Enable()
                                            else
                                                f.itemNamebox:Disable()
                                            end
                                        else
                                            f.itemNamebox:Disable()
                                        end
                                        f.playerNamebox:Disable()
                                        if isML then
                                            if f.data.type == "auction" then
                                                if f.data.playerName == "待拍卖" or f.data.playerName == "拍卖中" or f.data.playerName == "流拍" then
                                                    f.amountbox:Disable()
                                                else
                                                    f.amountbox:Enable()
                                                end
                                            elseif f.data.type == "overview" or f.data.type == "avewages" or f.data.type == "qiankuan" then
                                                f.amountbox:Disable()
                                            elseif f.data.type == "butie" then
                                                if itemlink == "|cffffde00补贴配置 ▼|r" then
                                                    f.amountbox:Disable()
                                                else
                                                    f.amountbox:Enable()
                                                end
                                            else
                                                f.amountbox:Enable()
                                            end
                                        else
                                            f.amountbox:Disable()
                                        end
                                        f:Show()
                                        index = index + 1
                                        index2 = index2 + 1
                                        row = row + 1
                                        if itemId then
                                            f.itemicon:SetNormalTexture(cGetItemIcon(itemlink))
                                            local itemTotalCount = select(4, ZL.GetItemNumbers(itemId))
                                            if itemTotalCount > 0 then
                                                f.itemicon.itemNumbersIcon:SetTexture([[interface/raidframe/readycheck-ready]])
                                            else
                                                f.itemicon.itemNumbersIcon:SetTexture()
                                            end
                                        elseif itemlink == "[打包拍卖]" then
                                            f.itemicon:SetNormalTexture(ZL.LogoPath)
                                            f.itemicon.itemNumbersIcon:SetTexture()
                                        else
                                            f.itemicon:ClearNormalTexture()
                                            f.itemicon.itemNumbersIcon:SetTexture()
                                        end
                                        if isML then
                                            if f.data.type == "manualIncome" then
                                                if f.data.childType == "add" then
                                                    f.itemicon:SetText("+")
                                                else
                                                    f.itemicon:SetText("-")
                                                end
                                            elseif f.data.type == "qiankuan" then
                                                f.itemicon:SetText("平")
                                            elseif f.data.type == "butie" then
                                                if itemlink == "|cffffde00补贴配置 ▼|r" then
                                                    f.itemicon:SetText("")
                                                else
                                                    f.itemicon:SetText("-")
                                                end
                                            else
                                                f.itemicon:SetText("")
                                            end
                                        else
                                            f.itemicon:SetText("")
                                        end
                                        f.level:SetTextScale(1)
                                        f.itemNamebox.fontstring:SetTextScale(1)
                                        f.playerNamebox.fontstring:SetTextScale(1)
                                        f.amountbox.fontstring:SetTextScale(1)
                                        if itemLevelList[itemlink] and itemLevelList[itemlink] >= 30 then
                                            f.level:SetText(itemLevelList[itemlink])
                                        else
                                            f.level:SetText("")
                                        end
                                        if type(value3["counts"]) == "number" and value3["counts"] > 1 then
                                            f.itemNamebox.fontstring:SetText(itemlink:gsub("§", "") .. "|cff00ff00×" .. value3["counts"] .. "|r")
                                        else
                                            if itemlink == "RL补贴" then
                                                if type(subsidyMoney) == "number" then
                                                    f.itemNamebox.fontstring:SetText(itemlink .. "(固定)")
                                                elseif subsidyMoney == "团双" then
                                                    f.itemNamebox.fontstring:SetText(itemlink .. "(团双)")
                                                    f.amountbox:Disable()
                                                elseif type(subsidyMoney) == "string" and subsidyMoney:match("(%d+%%)") then
                                                    f.itemNamebox.fontstring:SetText(itemlink .. "(" .. subsidyMoney:match("(%d+%%)") .. ")")
                                                end
                                            else
                                                f.itemNamebox.fontstring:SetText(itemlink:gsub("§", ""))
                                            end
                                        end
                                        if itemlink == "小队工资" then
                                            f.playerNamebox.fontstring:SetText(playerName)
                                        else
                                            f.playerNamebox.fontstring:SetText(ZL.GetNoRealmName(playerName, true))
                                        end
                                        if (f.data.type == "butie" or f.data.type == "manualIncome") and type(value3["totalAmount"]) == "string" then -- itemlink == "|cffffde00补贴配置 ▼|r"
                                            f.amountbox.fontstring:SetText(value3["totalAmount"])
                                        else
                                            f.amountbox.fontstring:SetText(value3["totalAmount"] and format("%.0f", value3["totalAmount"]) or "")
                                        end
                                        if bili < 1 then
                                            f.level:SetTextScale(bili)
                                        else
                                            f.level:SetTextScale(1)
                                        end
                                        bili = f.itemNamebox.fontstring:GetStringWidth()>0 and f.itemNamebox.fontstring:GetWidth()/(f.itemNamebox.fontstring:GetUnboundedStringWidth()+5) or 1
                                        if bili < 1 then
                                            f.itemNamebox.fontstring:SetTextScale(bili)
                                        else
                                            f.itemNamebox.fontstring:SetTextScale(1)
                                        end
                                        bili = f.playerNamebox.fontstring:GetStringWidth()>0 and f.playerNamebox.fontstring:GetWidth()/(f.playerNamebox.fontstring:GetUnboundedStringWidth()+5) or 1
                                        if bili < 1 then
                                            f.playerNamebox.fontstring:SetTextScale(bili)
                                        else
                                            f.playerNamebox.fontstring:SetTextScale(1)
                                        end
                                        bili = f.amountbox.fontstring:GetStringWidth()>0 and f.amountbox.fontstring:GetWidth()/(f.amountbox.fontstring:GetUnboundedStringWidth()+5) or 1
                                        if bili < 1 then
                                            f.amountbox.fontstring:SetTextScale(bili)
                                        else
                                            f.amountbox.fontstring:SetTextScale(1)
                                        end
                                        if bossName == "打包拍卖" and value3["itemList"] then
                                            for _itemlink, value4 in pairs(value3["itemList"]) do
                                                local _itemId = tonumber(_itemlink:match("|Hitem:(%d+):"))
                                                f = BillOverviewFrame.entries[index]
                                                f.data = {
                                                    type = "auctionzip",
                                                    itemlink = _itemlink,
                                                }
                                                f:ClearAllPoints()
                                                if index == 1 or row == maxrows + 1 then
                                                    if index > 1 then
                                                        f3 = BillOverviewFrame.entries[index-1]
                                                        f3.itemNamebox.BorderBottom:Show()
                                                        f3.playerNamebox.BorderBottom:Show()
                                                        f3.amountbox.BorderBottom:Show()
                                                    end
                                                    --刚开始第一行或者每列最大行的时候增加一列
                                                    f:SetPoint("TOPLEFT", content, "TOPLEFT", (totalColomnWidth+gapwidth)*column, 0)
                                                    column = column + 1
                                                    if row > rowMax then
                                                        rowMax = row
                                                    end
                                                    row = 1
                                                    index2 = 1
                                                    oldbossindex = index
                                                else
                                                    f:SetPoint("TOPLEFT", BillOverviewFrame.entries[index-1], "BOTTOMLEFT", 0, -gapheight)
                                                    if row > rowMax then
                                                        rowMax = row
                                                    end
                                                end
                                                f.bossfontstring:SetText(bossName)
                                                if index2 == 1 then
                                                    f.bossfontstring:Show()
                                                else
                                                    f.bossfontstring:Hide()
                                                end
                                                f2 = BillOverviewFrame.entries[oldbossindex]
                                                f2.bossfontstring:SetHeight(index2*height + (index2-1)*gapheight)
                                                f.playerNamebox.fontstring:SetText("")
                                                f.amountbox.fontstring:SetText("")
                                                f.playerNamebox.fontstring:Show()
                                                f.amountbox.fontstring:Show()
                                                -- f.itemNamebox.BorderBottom:Hide()
                                                -- f.playerNamebox.BorderBottom:Hide()
                                                -- f.amountbox.BorderBottom:Hide()
                                                f.itemNamebox:Disable()
                                                f.playerNamebox:Disable()
                                                f.amountbox:Disable()
                                                f:Show()
                                                index = index + 1
                                                index2 = index2 + 1
                                                row = row + 1

                                                if _itemId then
                                                    f.itemicon:SetNormalTexture(cGetItemIcon(_itemlink))
                                                else
                                                    f.itemicon:ClearNormalTexture()
                                                end
                                                f.level:SetTextScale(1)
                                                f.itemNamebox.fontstring:SetTextScale(1)
                                                f.playerNamebox.fontstring:SetTextScale(1)
                                                f.amountbox.fontstring:SetTextScale(1)
                                                if itemLevelList[_itemlink] and itemLevelList[_itemlink] >= 30 then
                                                    f.level:SetText(itemLevelList[_itemlink])
                                                else
                                                    f.level:SetText("")
                                                end
                                                if value4["itemCount"] > 1 then
                                                    f.itemNamebox.fontstring:SetText(_itemlink .. "|cff00ff00×" .. value4["itemCount"] .. "|r")
                                                else
                                                    f.itemNamebox.fontstring:SetText(_itemlink)
                                                end

                                                bili = f.level:GetStringWidth()>0 and (f.level:GetWidth())/(f.level:GetUnboundedStringWidth()+5) or 1
                                                if bili < 1 then
                                                    f.level:SetTextScale(bili)
                                                else
                                                    f.level:SetTextScale(1)
                                                end
                                                bili = f.itemNamebox.fontstring:GetStringWidth()>0 and f.itemNamebox.fontstring:GetWidth()/(f.itemNamebox.fontstring:GetUnboundedStringWidth()+5) or 1
                                                if bili < 1 then
                                                    f.itemNamebox.fontstring:SetTextScale(bili)
                                                else
                                                    f.itemNamebox.fontstring:SetTextScale(1)
                                                end
                                                bili = f.playerNamebox.fontstring:GetStringWidth()>0 and f.playerNamebox.fontstring:GetWidth()/(f.playerNamebox.fontstring:GetUnboundedStringWidth()+5) or 1
                                                if bili < 1 then
                                                    f.playerNamebox.fontstring:SetTextScale(bili)
                                                else
                                                    f.playerNamebox.fontstring:SetTextScale(1)
                                                end
                                                bili = f.amountbox.fontstring:GetStringWidth()>0 and f.amountbox.fontstring:GetWidth()/(f.amountbox.fontstring:GetUnboundedStringWidth()+5) or 1
                                                if bili < 1 then
                                                    f.amountbox.fontstring:SetTextScale(bili)
                                                else
                                                    f.amountbox.fontstring:SetTextScale(1)
                                                end
                                            end
                                        end
                                    end
                                end
                            end
                        end
                    end
                    f.itemNamebox.BorderBottom:Show()
                    f.playerNamebox.BorderBottom:Show()
                    f.amountbox.BorderBottom:Show()
                    if row <= maxrows then
                        f = BillOverviewFrame.entries[index]
                        f:SetPoint("TOPLEFT", BillOverviewFrame.entries[index-1], "BOTTOMLEFT", 0, 0)
                        f:Hide()
                        index = index + 1
                        row = row + 1
                        if row > rowMax then
                            rowMax = row
                        end
                    end
                end
            end
            rowMax = rowMax - 1
            rowMax = rowMax > 20 and rowMax or 20 --最低显示20行高度
            local contetHeight = (height+gapheight)*maxrows-gapheight
            content:SetHeight(contetHeight)
            if column == 1 then
                BOSSHeaderBtn2:Hide()
                itemNameHeaderBtn2:Hide()
                playerNameHeaderBtn2:Hide()
                amountHeaderBtn2:Hide()

                BOSSHeaderBtn3:Hide()
                itemNameHeaderBtn3:Hide()
                playerNameHeaderBtn3:Hide()
                amountHeaderBtn3:Hide()
            elseif column == 2 then
                BOSSHeaderBtn2:Show()
                itemNameHeaderBtn2:Show()
                playerNameHeaderBtn2:Show()
                amountHeaderBtn2:Show()
                
                BOSSHeaderBtn3:Hide()
                itemNameHeaderBtn3:Hide()
                playerNameHeaderBtn3:Hide()
                amountHeaderBtn3:Hide()
            elseif column == 3 then
                BOSSHeaderBtn2:Show()
                itemNameHeaderBtn2:Show()
                playerNameHeaderBtn2:Show()
                amountHeaderBtn2:Show()
                
                BOSSHeaderBtn3:Show()
                itemNameHeaderBtn3:Show()
                playerNameHeaderBtn3:Show()
                amountHeaderBtn3:Show()
            end
            local BillOverviewFrameHeight = contetHeight + BOSSHeaderBtn1:GetHeight() + 42
            BillOverviewFrameHeight = BillOverviewFrameHeight > (GetScreenHeight()-50) and (GetScreenHeight()-50) or BillOverviewFrameHeight
            BillOverviewFrame:SetSize(26+(column-1)*gapwidth+column*totalColomnWidth, BillOverviewFrameHeight)
            if bill and bill.name and bill.auctiondate then
                BillOverviewFrame.Title:SetText("拍卖账单总览|cffffffff—|r" .. bill.name .. "|cffffffff—|r" .. bill.auctiondate)
            else
                BillOverviewFrame.Title:SetText("拍卖账单总览")
            end
        else
            BOSSHeaderBtn2:Hide()
            itemNameHeaderBtn2:Hide()
            playerNameHeaderBtn2:Hide()
            amountHeaderBtn2:Hide()

            BOSSHeaderBtn3:Hide()
            itemNameHeaderBtn3:Hide()
            playerNameHeaderBtn3:Hide()
            amountHeaderBtn3:Hide()
            local BillOverviewFrameHeight = (height+gapheight)*20 + BOSSHeaderBtn1:GetHeight() + 42
            BillOverviewFrame:SetSize(26+totalColomnWidth, BillOverviewFrameHeight)
            BillOverviewFrame.Title:SetText("拍卖账单总览|cffffffff—|r没有记录")
            content:SetHeight(20 * height)
        end

    end
end