local addonName, ZLAUTO = ...
local ZL = ZLAUTO.mainFrame
local sleep = ZL.sleep
local ZLCreateFrame = ZL.ZLCreateFrame
local CreateEditBox = ZL.CreateEditBox
local CreateButton = ZL.CreateButton
local ScrollFrame_OnMouseWheel = ZL.ScrollFrame_OnMouseWheel
local GameTooltipShow = ZL.GameTooltipShow
local GameTooltipShowAnchor = ZL.GameTooltipShowAnchor
local GetClassColorName = ZL.GetClassColorName
local ParseClassColorName = ZL.ParseClassColorName
local PlayerIsML = ZL.PlayerIsML
local MyAddon = ZL.MyAddon
local cGetItemInfo = C_Item and C_Item.GetItemInfo or GetItemInfo
local cGetItemIcon = C_Item and C_Item.GetItemIconByID or GetItemIcon
local cGetItemInfoInstant = C_Item and C_Item.GetItemInfoInstant or GetItemInfoInstant
local GetActiveSpecGroup = C_SpecializationInfo and C_SpecializationInfo.GetActiveSpecGroup or GetActiveSpecGroup
local GetSpecialization = C_SpecializationInfo and C_SpecializationInfo.GetSpecialization or GetSpecialization
local GetSpecializationInfo = C_SpecializationInfo and C_SpecializationInfo.GetSpecializationInfo or GetSpecializationInfo
local Serializer = LibStub('AceSerializer-3.0')

local BUILD_DATA = floor(select(4, GetBuildInfo())/10000)
local subsidyParentTypeList = {
    "RL补贴", "T补贴", "N补贴", "DPS补贴", "食物补贴", "工具人补贴", "其它补贴"
}
--双休T：T和DPS
--双休：DPS和N
local subsidyTypeList = {
    "RL", "T", "主T", "副T", "双休T", "N", "NQ", "双休", "DPS", "DPS1", "DPS2", "DPS3",
    "DPS4", "DPS5", "DPS6", "DPS7", "DPS8", "DPS9", "DPS10", "鱼", "猪",
    "恶魔术", "战斗贼", "鸟德", "暗牧", "增强萨", "修星", "修理机器人", "橙锤", "橙斧", "其它"
}
local subsidyChildrenList = {
    ["RL补贴"] = {"RL"},
    ["T补贴"] = {"T", "副T", "双休T"},
    ["N补贴"] = {"N", "NQ", "双休"},
    ["DPS补贴"] = {"DPS", "DPS1", "DPS2", "DPS3", "DPS4", "DPS5", "DPS6", "DPS7", "DPS8", "DPS9", "DPS10"},
    ["食物补贴"] = {"鱼", "猪"},
    ["工具人补贴"] = {"恶魔术", "战斗贼", "鸟德", "暗牧", "增强萨", "修星"},
    ["其它补贴"] = {"修理机器人", "橙锤", "橙斧", "其它"},
}
local function singleMoneyboxTextChanged(self)
    local profileName = ZL.opt.subsidyProfileList["profileKeys"][ZL.opt.subsidyProfileSelect]
    local subsidyData = ZL.opt.subsidyProfileList["profile"][profileName]["child"]
    local subsidyName = self:GetParent().subsidyName
    local text = self:GetText()
    if text and #text > 0 then
        local subsidyMoney
        if subsidyName == "RL" then
            subsidyMoney = text:match("(团双)")
            if not subsidyMoney then
                subsidyMoney = text:match("(%d+%%)")
                if not subsidyMoney then
                    subsidyMoney = tonumber(text:match("^(%d+)$"))
                end
            end
            subsidyMoney = subsidyMoney or 0
        else
            subsidyMoney = self:GetNumber()
        end
        subsidyData[subsidyName] = subsidyMoney
    end
    self:ClearFocus()
    ZL.SubsidyFrame:Update()
end

local subsidyTypeFunc = {
    ["RL"] = {
        icon = "|T132062:13|t",
        parentType = "RL补贴",
        OnLeftButtonMouseDown = function (self)
            local function tempfunc(self)
                local menuList = {}
                local tempList = {"固定", "团双", "提成"}
                local RL = select(4, ZL.GetWagesGroupMembers())
                local subsidyName = "RL"
                if RL then
                    tinsert(menuList, {
                        text = RL,
                        checkable = 1,
                        keepShownOnClick = 1,
                        checked = ZL_CURRENT.subsidy and ZL_CURRENT.subsidy[subsidyName] and ZL_CURRENT.subsidy[subsidyName][RL],
                        func = function ()
                            ZL_CURRENT.subsidy = ZL_CURRENT.subsidy or {}
                            ZL_CURRENT.subsidy[subsidyName] = {}
                            ZL_CURRENT.subsidy[subsidyName][RL] = true
                            ZL.GUI:OpenMenu(self, tempfunc(self), 'TOPLEFT', self, 'BOTTOMRIGHT', 0, 0)
                            ZL.SubsidyFrame:Update()
                        end,
                    })
                    tinsert(menuList, {isSeparator = true})
                end
                for _, value in ipairs(tempList) do
                    tinsert(menuList, {
                        text = value,
                        func = function ()
                            if value == "团双" then
                                local profileName = ZL.opt.subsidyProfileList["profileKeys"][ZL.opt.subsidyProfileSelect]
                                local subsidyData = ZL.opt.subsidyProfileList["profile"][profileName]["child"]
                                subsidyData[subsidyName] = value
                                ZL.SubsidyFrame:Update()
                            end
                        end,
                        hasArrow = value ~= "团双" and true or false,
                        menuTable = function ()
                            local _menuList = {}
                            local _tempList
                            if value == "固定" then
                                _tempList = {100, 200, 300, 500, 1000, 2000, 3000, 5000, 10000}
                            else
                                _tempList = {"1%", "2%", "3%", "4%", "5%"}
                            end
                            for _, _value in ipairs(_tempList) do
                                tinsert(_menuList, {
                                    text = _value,
                                    func = function ()
                                        local profileName = ZL.opt.subsidyProfileList["profileKeys"][ZL.opt.subsidyProfileSelect]
                                        local subsidyData = ZL.opt.subsidyProfileList["profile"][profileName]["child"]
                                        subsidyData[subsidyName] = _value
                                        ZL.SubsidyFrame:Update()
                                        ZL.GUI:CloseMenu()
                                    end
                                })
                            end
                            return _menuList
                        end,
                    })
                end
                return menuList
            end
            ZL.GUI:ToggleMenu(self, tempfunc(self), 'TOPLEFT', self, 'BOTTOMRIGHT', 0, 0)
        end,
        toolTip = function (self)
            GameTooltipShow(self, "BOTTOMLEFT", "TOPRIGHT")
            GameTooltip:AddLine("RL补贴方式")
            GameTooltip:AddLine("固定：|cffffffff输入|r|cff4080FF不小于0的数|r")
            GameTooltip:AddLine("团双：|cffffffff输入|r|cff4080FF团双|r")
            GameTooltip:AddLine("提成：|cffffffff输入带%的数字，如|r|cff4080FF2%|r")
            GameTooltip:AddLine(" ")
            GameTooltip:AddLine("支持鼠标滚轮快速输入数字")
            GameTooltip:AddLine("输入后按|cff4080FFEnter|r或|cff4080FF右键|r保存！")
            GameTooltip:Show()
        end,
    },
    ["T"] = {
        icon = "|A:UI-LFG-RoleIcon-Tank:13:13|a",
        parentType = "T补贴",
    },
    ["主T"] = {
        icon = "|A:UI-LFG-RoleIcon-Tank:13:13|a",
        parentType = "T补贴",
    },
    ["副T"] = {
        icon = "|A:UI-LFG-RoleIcon-Tank:13:13|a",
        parentType = "T补贴",
    },
    ["双休T"] = {
        icon = "|A:UI-LFG-RoleIcon-Tank:13:13|a",
        parentType = "T补贴",
        OnLeftButtonMouseDown = function (self)
            local function tempfunc(self)
                local menuList = {}
                local subsidyName = "双休T"
                local WagesGroupMembers = ZL.GetWagesGroupMembers()
                if WagesGroupMembers then
                    for _, data in ipairs(WagesGroupMembers) do
                        for _, colorName in ipairs(data) do
                            local name = ParseClassColorName(colorName)
                            if name and ZL.opt.playerInfo and ZL.opt.playerInfo[name] and
                            ZL.opt.playerInfo[name]["T"] and ZL.opt.playerInfo[name]["DPS"] then
                                tinsert(menuList, {
                                    text = colorName,
                                    checkable = 1,
                                    checked = ZL_CURRENT.subsidy and ZL_CURRENT.subsidy[subsidyName] and ZL_CURRENT.subsidy[subsidyName][colorName],
                                    isNotRadio = 1,
                                    func = function ()
                                        ZL_CURRENT.subsidy = ZL_CURRENT.subsidy or {}
                                        ZL_CURRENT.subsidy[subsidyName] = ZL_CURRENT.subsidy[subsidyName] or {}
                                        if ZL_CURRENT.subsidy[subsidyName][colorName] then
                                            ZL_CURRENT.subsidy[subsidyName][colorName] = nil
                                        else
                                            ZL_CURRENT.subsidy[subsidyName][colorName] = true
                                        end
                                        ZL.GUI:OpenMenu(self, tempfunc(self), 'TOPLEFT', self, 'BOTTOMRIGHT', 0, 0)
                                        ZL.SubsidyFrame:Update()
                                    end,
                                })
                            end
                        end
                    end
                end
                if #menuList > 0 then
                    tinsert(menuList, 1, {
                        text = "|A:UI-LFG-RoleIcon-Tank:13:13|a" .. subsidyName .. "：",
                        isTitle = true,
                    })
                else
                    tinsert(menuList, {
                        text = "没有数据",
                        isTitle = true,
                    })
                end
                return menuList
            end
            ZL.GUI:ToggleMenu(self, tempfunc(self), 'TOPLEFT', self, 'BOTTOMRIGHT', 0, 0)
        end,
    },
    ["N"] = {
        icon = "|A:UI-LFG-RoleIcon-Healer:13:13|a",
        parentType = "N补贴",
        OnLeftButtonMouseDown = function (self)
            local function tempfunc(self)
                local menuList = {}
                local subsidyName = "N"
                local WagesGroupMembers = ZL.GetWagesGroupMembers()
                if WagesGroupMembers then
                    for _, data in ipairs(WagesGroupMembers) do
                        for _, colorName in ipairs(data) do
                            local name = ParseClassColorName(colorName)
                            if name and ZL.opt.playerInfo and ZL.opt.playerInfo[name]
                            and ZL.opt.playerInfo[name][subsidyName] then
                                tinsert(menuList, {
                                    text = function ()
                                        local text = colorName
                                        if ZL.opt.playerInfo[name]["DPS"] then
                                            text = text .. "(双休)"
                                        end
                                        return text
                                    end,
                                    checkable = 1,
                                    isNotRadio = 1,
                                    keepShownOnClick = 1,
                                    checked = ZL_CURRENT.subsidy and ZL_CURRENT.subsidy[subsidyName] and ZL_CURRENT.subsidy[subsidyName][colorName],
                                    func = function ()
                                        ZL_CURRENT.subsidy = ZL_CURRENT.subsidy or {}
                                        ZL_CURRENT.subsidy[subsidyName] = ZL_CURRENT.subsidy[subsidyName] or {}
                                        if ZL_CURRENT.subsidy[subsidyName][colorName] then
                                            ZL_CURRENT.subsidy[subsidyName][colorName] = nil
                                        else
                                            ZL_CURRENT.subsidy[subsidyName][colorName] = true
                                        end
                                        ZL.GUI:OpenMenu(self, tempfunc(self), 'TOPLEFT', self, 'BOTTOMRIGHT', 0, 0)
                                        ZL.SubsidyFrame:Update()
                                    end,
                                })
                            end
                        end
                    end
                end
                if #menuList > 0 then
                    tinsert(menuList, 1, {
                        text = "|A:UI-LFG-RoleIcon-Healer:13:13|a" .. subsidyName .. "：",
                        isTitle = true,
                    })
                else
                    tinsert(menuList, {
                        text = "没有数据",
                        isTitle = true,
                    })
                end
                return menuList
            end
            ZL.GUI:ToggleMenu(self, tempfunc(self), 'TOPLEFT', self, 'BOTTOMRIGHT', 0, 0)
        end,
    },
    ["NQ"] = {
        icon = "|T135920:13|t",
        parentType = "N补贴",
    },
    ["DPS"] = {
        icon = "|A:UI-LFG-RoleIcon-DPS:13:13|a",
        parentType = "DPS补贴",
    },
    ["猪"] = {
        icon = "|T132184:13|t",
        parentType = "食物补贴",
        OnLeftButtonMouseDown = function (self)
            local function tempfunc(self)
                local menuList = {}
                local WagesGroupMembers = ZL.GetWagesGroupMembers()
                if WagesGroupMembers then
                    local subsidyName = "猪"
                    for _, data in ipairs(WagesGroupMembers) do
                        for _, colorName in ipairs(data) do
                            local name = ParseClassColorName(colorName)
                            if name and ZL.opt.playerInfo and ZL.opt.playerInfo[name]
                            and ZL.opt.playerInfo[name][subsidyName] then
                                tinsert(menuList, {
                                    text = function ()
                                        local text = colorName .. " - " .. ZL.opt.playerInfo[name].pigCount .. "次"
                                        if ZL_CURRENT.subsidyPigFirst == name then
                                            text = text .. " - First"
                                        end
                                        return text
                                    end,
                                    checkable = 1,
                                    checked = ZL_CURRENT.subsidy and ZL_CURRENT.subsidy[subsidyName] and ZL_CURRENT.subsidy[subsidyName][colorName],
                                    func = function ()
                                        ZL_CURRENT.subsidy = ZL_CURRENT.subsidy or {}
                                        ZL_CURRENT.subsidy[subsidyName] = {}
                                        ZL_CURRENT.subsidy[subsidyName][colorName] = true
                                        ZL.GUI:OpenMenu(self, tempfunc(self), 'TOPLEFT', self, 'BOTTOMRIGHT', 0, 0)
                                        ZL.SubsidyFrame:Update()
                                    end,
                                })
                            end
                        end
                    end
                end
                if #menuList > 0 then
                    tinsert(menuList, 1, {
                        text = "|T132184:13|t猪：",
                        isTitle = true,
                    })
                else
                    tinsert(menuList, {
                        text = "没有数据",
                        isTitle = true,
                    })
                end
                return menuList
            end
            ZL.GUI:ToggleMenu(self, tempfunc(self), 'TOPLEFT', self, 'BOTTOMRIGHT', 0, 0)
        end,
    },
    ["鱼"] = {
        icon = "|T237303:13|t",
        parentType = "食物补贴",
        OnLeftButtonMouseDown = function (self)
            local function tempfunc(self)
                local menuList = {}
                local WagesGroupMembers = ZL.GetWagesGroupMembers()
                if WagesGroupMembers then
                    local subsidyName = "鱼"
                    for _, data in ipairs(WagesGroupMembers) do
                        for _, colorName in ipairs(data) do
                            local name = ParseClassColorName(colorName)
                            if name and ZL.opt.playerInfo and ZL.opt.playerInfo[name]
                            and ZL.opt.playerInfo[name][subsidyName] then
                                tinsert(menuList, {
                                    text = function ()
                                        local text = colorName .. " - " .. ZL.opt.playerInfo[name].fishCount .. "次"
                                        if ZL_CURRENT.subsidyFishFirst == name then
                                            text = text .. " - First"
                                        end
                                        return text
                                    end,
                                    checkable = 1,
                                    checked = ZL_CURRENT.subsidy and ZL_CURRENT.subsidy[subsidyName] and ZL_CURRENT.subsidy[subsidyName][colorName],
                                    func = function ()
                                        ZL_CURRENT.subsidy = ZL_CURRENT.subsidy or {}
                                        ZL_CURRENT.subsidy[subsidyName] = {}
                                        ZL_CURRENT.subsidy[subsidyName][colorName] = true
                                        ZL.GUI:OpenMenu(self, tempfunc(self), 'TOPLEFT', self, 'BOTTOMRIGHT', 0, 0)
                                        ZL.SubsidyFrame:Update()
                                    end,
                                })
                            end
                        end
                    end
                end
                if #menuList > 0 then
                    tinsert(menuList, 1, {
                        text = "|T237303:13|t鱼：",
                        isTitle = true,
                    })
                else
                    tinsert(menuList, {
                        text = "没有数据",
                        isTitle = true,
                    })
                end
                return menuList
            end
            ZL.GUI:ToggleMenu(self, tempfunc(self), 'TOPLEFT', self, 'BOTTOMRIGHT', 0, 0)
        end,
    },
    ["修理机器人"] = {
        icon = "|T132836:13|t",
        parentType = "其它补贴",
        OnLeftButtonMouseDown = function (self)
            local function tempfunc(self)
                local menuList = {}
                local WagesGroupMembers = ZL.GetWagesGroupMembers()
                if WagesGroupMembers then
                    local subsidyName = "修理机器人"
                    for _, data in ipairs(WagesGroupMembers) do
                        for _, colorName in ipairs(data) do
                            local name = ParseClassColorName(colorName)
                            if name and ZL.opt.playerInfo and ZL.opt.playerInfo[name]
                            and ZL.opt.playerInfo[name][subsidyName] then
                                tinsert(menuList, {
                                    text = function ()
                                        local text = colorName .. " - " .. ZL.opt.playerInfo[name].xiuLiCount .. "次"
                                        if ZL_CURRENT.subsidyXiuLiFirst == name then
                                            text = text .. " - First"
                                        end
                                        return text
                                    end,
                                    checkable = 1,
                                    checked = ZL_CURRENT.subsidy and ZL_CURRENT.subsidy[subsidyName] and ZL_CURRENT.subsidy[subsidyName][colorName],
                                    func = function ()
                                        ZL_CURRENT.subsidy = ZL_CURRENT.subsidy or {}
                                        ZL_CURRENT.subsidy[subsidyName] = {}
                                        ZL_CURRENT.subsidy[subsidyName][colorName] = true
                                        ZL.GUI:OpenMenu(self, tempfunc(self), 'TOPLEFT', self, 'BOTTOMRIGHT', 0, 0)
                                        ZL.SubsidyFrame:Update()
                                    end,
                                })
                            end
                        end
                    end
                end
                if #menuList > 0 then
                    tinsert(menuList, 1, {
                        text = "|T132836:13|t修理机器人：",
                        isTitle = true,
                    })
                else
                    tinsert(menuList, {
                        text = "没有数据",
                        isTitle = true,
                    })
                end
                return menuList
            end
            ZL.GUI:ToggleMenu(self, tempfunc(self), 'TOPLEFT', self, 'BOTTOMRIGHT', 0, 0)
        end,
    },
    ["恶魔术"] = {
        icon = "|T136172:13|t",
        parentType = "工具人补贴",
    },
    ["战斗贼"] = {
        icon = "|T132090:13|t",
        parentType = "工具人补贴",
    },
    ["鸟德"] = {
        icon = "|T136096:13|t",
        parentType = "工具人补贴",
    },
    ["暗牧"] = {
        icon = "|T136207:13|t",
        parentType = "工具人补贴",
    },
    ["增强萨"] = {
        icon = "|T136051:13|t",
        parentType = "工具人补贴",
    },
    ["双休"] = {
        icon = "|T236250:13|t",
        parentType = "N补贴",
        OnLeftButtonMouseDown = function (self)
            local function tempfunc(self)
                local menuList = {}
                local WagesGroupMembers = ZL.GetWagesGroupMembers()
                if WagesGroupMembers then
                    local subsidyName = "双休"
                    for _, data in ipairs(WagesGroupMembers) do
                        for _, colorName in ipairs(data) do
                            local name = ParseClassColorName(colorName)
                            if name and ZL.opt.playerInfo and ZL.opt.playerInfo[name] and
                            ZL.opt.playerInfo[name]["N"] and ZL.opt.playerInfo[name]["DPS"] then
                                tinsert(menuList, {
                                    text = colorName,
                                    isNotRadio = 1,
                                    checkable = 1,
                                    checked = ZL_CURRENT.subsidy and ZL_CURRENT.subsidy[subsidyName] and ZL_CURRENT.subsidy[subsidyName][colorName],
                                    func = function ()
                                        ZL_CURRENT.subsidy = ZL_CURRENT.subsidy or {}
                                        ZL_CURRENT.subsidy[subsidyName] = ZL_CURRENT.subsidy[subsidyName] or {}
                                        if ZL_CURRENT.subsidy[subsidyName][colorName] then
                                            ZL_CURRENT.subsidy[subsidyName][colorName] = nil
                                        else
                                            ZL_CURRENT.subsidy[subsidyName][colorName] = true
                                        end
                                        ZL.GUI:OpenMenu(self, tempfunc(self), 'TOPLEFT', self, 'BOTTOMRIGHT', 0, 0)
                                        ZL.SubsidyFrame:Update()
                                    end,
                                })
                            end
                        end
                    end
                end
                return menuList
            end
            local menuList = tempfunc(self)
            if #menuList > 0 then
                tinsert(menuList, 1, {
                    text = "|T236250:13|t双休：",
                    isTitle = true,
                })
            else
                tinsert(menuList, {
                    text = "没有数据",
                    isTitle = true,
                })
            end
            ZL.GUI:ToggleMenu(self, menuList, 'TOPLEFT', self, 'BOTTOMRIGHT', 0, 0)
        end,
    },
    ["修星"] = {
        icon = "|T135753:13|t",
        parentType = "工具人补贴",
        OnLeftButtonMouseDown = function (self)
            local function tempfunc(self)
                local menuList = {}
                local WagesGroupMembers = ZL.GetWagesGroupMembers()
                if WagesGroupMembers then
                    local subsidyName = "修星"
                    for _, data in ipairs(WagesGroupMembers) do
                        for _, colorName in ipairs(data) do
                            local name = ParseClassColorName(colorName)
                            if name and ZL.opt.playerInfo and ZL.opt.playerInfo[name]
                            and ZL.opt.playerInfo[name]["DPS"] then
                                tinsert(menuList, {
                                    text = colorName,
                                    checkable = 1,
                                    checked = ZL_CURRENT.subsidy and ZL_CURRENT.subsidy[subsidyName] and ZL_CURRENT.subsidy[subsidyName][colorName],
                                    func = function ()
                                        ZL_CURRENT.subsidy = ZL_CURRENT.subsidy or {}
                                        ZL_CURRENT.subsidy[subsidyName] = {}
                                        ZL_CURRENT.subsidy[subsidyName][colorName] = true
                                        ZL.GUI:OpenMenu(self, tempfunc(self), 'TOPLEFT', self, 'BOTTOMRIGHT', 0, 0)
                                        ZL.SubsidyFrame:Update()
                                    end,
                                })
                            end
                        end
                    end
                end
                return menuList
            end
            local menuList = tempfunc(self)
            if #menuList > 0 then
                tinsert(menuList, 1, {
                    text = "|T135753:13|t修星：",
                    isTitle = true,
                })
            else
                tinsert(menuList, {
                    text = "没有数据",
                    isTitle = true,
                })
            end
            ZL.GUI:ToggleMenu(self, menuList, 'TOPLEFT', self, 'BOTTOMRIGHT', 0, 0)
        end,
    },
    ["橙锤"] = {
        icon = "|T253399:13|t",
        parentType = "其它补贴",
    },
    ["橙斧"] = {
        icon = "|T313914:13|t",
        parentType = "其它补贴",
    },
    ["其它"] = {
        icon = "|T136815:13|t",
        parentType = "其它补贴",
        OnLeftButtonMouseDown = function (self)
            local function tempfunc(self)
                local menuList = {}
                local WagesGroupMembers = ZL.GetWagesGroupMembers()
                local subsidyName = "其它"
                if WagesGroupMembers then
                    for _, data in ipairs(WagesGroupMembers) do
                        for _, colorName in ipairs(data) do
                            local name = ParseClassColorName(colorName)
                            if name then
                                tinsert(menuList, {
                                    text = colorName,
                                    checkable = 1,
                                    isNotRadio = 1,
                                    keepShownOnClick = 1,
                                    checked = ZL_CURRENT.subsidy and ZL_CURRENT.subsidy[subsidyName] and ZL_CURRENT.subsidy[subsidyName][colorName],
                                    func = function ()
                                        ZL_CURRENT.subsidy = ZL_CURRENT.subsidy or {}
                                        ZL_CURRENT.subsidy[subsidyName] = ZL_CURRENT.subsidy[subsidyName] or {}
                                        if ZL_CURRENT.subsidy[subsidyName][colorName] then
                                            ZL_CURRENT.subsidy[subsidyName][colorName] = nil
                                        else
                                            ZL_CURRENT.subsidy[subsidyName][colorName] = true
                                        end
                                        ZL.GUI:OpenMenu(self, tempfunc(self), 'TOPLEFT', self, 'BOTTOMRIGHT', 0, 0)
                                        ZL.SubsidyFrame:Update()
                                    end,
                                })
                            end
                        end
                    end
                end
                if #menuList > 0 then
                    tinsert(menuList, 1, {
                        text = "|T136815:13|t" .. subsidyName .. "：",
                        isTitle = true,
                    })
                else
                    tinsert(menuList, {
                        text = "没有数据",
                        isTitle = true,
                    })
                end
                return menuList
            end
            ZL.GUI:ToggleMenu(self, tempfunc(self), 'TOPLEFT', self, 'BOTTOMRIGHT', 0, 0)
        end,
    },
}
local talentInfo = {
    ["鲜血坦克"] = {"T"},
    ["鲜血"] = {"T"},
    ["鲜血输出"] = {"DPS"},
    ["冰霜"] = {"DPS"},
    ["邪恶"] = {"DPS"},
    ["双休DKT"] = {"T"},
    ["野性坦克"] = {"T"},
    ["野性输出"] = {"DPS"},
    ["野性"] = {"DPS"},
    ["守护"] = {"T"},
    ["平衡"] = {"DPS", "鸟德"},
    ["双休德"] = {"N"},
    ["恢复"] = {"N"},
    ["野兽控制"] = {"DPS"},
    ["射击"] = {"DPS"},
    ["生存"] = {"DPS"},
    ["奥术"] = {"DPS"},
    ["火焰"] = {"DPS"},
    ["神圣"] = {"N"},
    ["防护"] = {"T"},
    ["惩戒"] = {"DPS"},
    ["双休防骑"] = {"T"},
    ["戒律"] = {"N"},
    ["暗影"] = {"DPS", "暗牧"},
    ["战斗"] = {"DPS", "战斗贼"},
    ["刺杀"] = {"DPS"},
    ["奇袭"] = {"DPS"},
    ["敏锐"] = {"DPS"},
    ["元素"] = {"DPS"},
    ["增强"] = {"DPS", "增强萨"},
    ["双休萨满"] = {"N"},
    ["武器"] = {"DPS"},
    ["狂怒"] = {"DPS"},
    ["双休防战"] = {"T"},
    ["痛苦"] = {"DPS"},
    ["恶魔学识"] = {"DPS", "恶魔术"},
    ["毁灭"] = {"DPS"},
    ["酒仙"] = {"T"},
    ["踏风"] = {"DPS"},
    ["织雾"] = {"N"},
}
ZL.talentRole = talentInfo
local talentSpellList = {"强化智慧祝福", "强化力量祝福", "庇护祝福", "神圣牺牲", "光环掌握", "痛苦压制"}

local function getSubsidyTypeFromTalentInfo(playerName, mainTalentName)
    if not mainTalentName then return end
    if talentInfo[mainTalentName] then
        for _, key in ipairs(talentInfo[mainTalentName]) do
            ZL.opt.playerInfo = ZL.opt.playerInfo or {}
            ZL.opt.playerInfo[playerName] = ZL.opt.playerInfo[playerName] or {}
            local playerData = ZL.opt.playerInfo[playerName]
            playerData[key] = true
            if playerData["T"] and playerData["DPS"] then
                playerData["双休T"] = true
            elseif playerData["N"] and playerData["DPS"] then
                playerData["双休"] = true
            end
        end
    end
end

function ZL.canInspect(unit)
    local isTrue = true
    UIErrorsFrame:UnregisterEvent("UI_ERROR_MESSAGE")
    if not unit or not CanInspect(unit) then-- or InCombatLockdown() or not CheckInteractDistance(unit, 1)-- or UnitIsDeadOrGhost("player") or UnitIsDeadOrGhost(unit)
        isTrue = false
    end
    UIErrorsFrame:RegisterEvent("UI_ERROR_MESSAGE")
    return isTrue
end
local canInspect = ZL.canInspect

local function getSubsidyProfileDropdownList()
    local subsidyProfileDropdownList = {}
    for index, profileName in ipairs(ZL.opt.subsidyProfileList.profileKeys) do
        tinsert(subsidyProfileDropdownList, {text=profileName, value=index})
    end
    return subsidyProfileDropdownList
end
function ZL.getSubsidyParent(totalincome, raidLeaderTiCheng)
    ZL_CURRENT.subsidyParent = {}
    if ZL_CURRENT.subsidy then
        local profileName = ZL.opt.subsidyProfileList["profileKeys"][ZL.opt.subsidyProfileSelect]
        local subsidyData = ZL.opt.subsidyProfileList["profile"][profileName]["child"]
        local subsidyParentName, subsidyNameGsub, subsidyMoney
        for subsidyName, value in pairs(ZL_CURRENT.subsidy) do
            subsidyMoney = subsidyData[subsidyName] or 0
            subsidyNameGsub = subsidyName:gsub("%d+", "")
            subsidyParentName = subsidyTypeFunc[subsidyNameGsub].parentType
            local subsidyCounts = 0
            for _ in pairs(value) do
                subsidyCounts = subsidyCounts + 1
            end
            if subsidyMoney == "团双" then
                ZL_CURRENT.subsidyParent[subsidyParentName] = ZL_CURRENT["aveWages"] or 0
            elseif type(subsidyMoney) == "string" and subsidyMoney:match("%d+%%") and totalincome and raidLeaderTiCheng then --RL提成
                ZL_CURRENT.subsidyParent[subsidyParentName] = floor(totalincome*raidLeaderTiCheng)
            else
                ZL_CURRENT.subsidyParent[subsidyParentName] = (ZL_CURRENT.subsidyParent[subsidyParentName] or 0) + subsidyMoney * subsidyCounts
            end
        end
    end
end
function ZL.GetTalent(isTarget, englishClass, playerName, isInventory)
    local colorPlayerName = GetClassColorName(playerName, englishClass)
    ZL.opt.playerInfo = ZL.opt.playerInfo or {}
    ZL.opt.playerInfo[playerName] = ZL.opt.playerInfo[playerName] or {}
    ZL.opt.playerInfo[playerName].talentName = nil
    ZL.opt.playerInfo[playerName].classFile = englishClass
    ZL.opt.playerInfo[playerName].colorName = colorPlayerName
    ZL.opt.playerInfo[playerName].updateTimestamp = time() --更新时间戳
    for _, talentSpellName in ipairs(talentSpellList) do
        ZL.opt.playerInfo[playerName][talentSpellName] = nil
    end
    if BUILD_DATA >= 5 then
        local specializationID = GetInspectSpecialization(playerName)
        if specializationID and specializationID ~= 0 then
            local _, mainTalentName, _,  mainTalenIcon, role = GetSpecializationInfoByID(specializationID)
            if mainTalentName then
                ZL.opt.playerInfo[playerName].talentName = ZL.opt.playerInfo[playerName].talentName or {}
                ZL.opt.playerInfo[playerName].talentName[mainTalentName] = mainTalenIcon
                ZL.opt.playerInfo[playerName].newTalentName = mainTalentName
                getSubsidyTypeFromTalentInfo(playerName, mainTalentName)
                if englishClass == "PALADIN" and mainTalentName == "神圣" then
                    ZL.opt.playerInfo[playerName]["NQ"] = true
                end
                if englishClass == "PRIEST" then
                    if mainTalentName == "戒律" then
                        ZL.opt.playerInfo[playerName]["痛苦压制"] = 1
                    elseif mainTalentName == "神圣" then
                        ZL.opt.playerInfo[playerName]["神圣赞美诗"] = 1
                    end
                end
            end
        end
    else
        -- 获取天赋 WLK及之前
        local activeTalentIndex = GetActiveTalentGroup(isTarget) --当前激活的天赋,true表示当前观察的人，false表示玩家自己
        local numTalentGroups = GetNumTalentGroups(isTarget) --天赋总数量
        local mainTalentName
        local mainTalenPointsSpent = 0
        local mainTalenIcon
        for talentIndex = 1, numTalentGroups do
            mainTalentName = nil
            mainTalenPointsSpent = 0
            mainTalenIcon = nil
            for i = 1, GetNumTalentTabs(isTarget) do --天赋种类，一般为3个，如戒律、神圣、暗影, true表示INSPECT_REDAY触发的对象，否则表示自己
                local _, talentName, _, talentIcon, pointsSpent = GetTalentTabInfo(i, isTarget, nil, talentIndex)
                if mainTalenPointsSpent >= pointsSpent then
                    mainTalentName = mainTalentName or talentName
                    mainTalenIcon = mainTalenIcon or talentIcon
                else
                    mainTalenPointsSpent = pointsSpent
                    mainTalentName = talentName
                    mainTalenIcon = talentIcon
                end
                if (mainTalentName == "鲜血" and talentName == "冰霜") or (mainTalentName == "野性战斗" and talentName == "野性战斗") then
                    for j = 1, GetNumTalents(i, isTarget) do --当前天赋种类里面有多少个天赋技能
                        --名称, iconID, 行， 列, 点了几点技能， 最大可以点的技能
                        local _name, _, _, _, rank = GetTalentInfo(i, j, isTarget, nil, talentIndex)
                        if _name == "坚韧" then --鲜血DK
                            if rank == 5 then
                                mainTalentName = "鲜血坦克"
                            else
                                mainTalentName = "鲜血输出"
                            end
                            break
                        elseif _name == "厚皮" then --德鲁伊
                            if rank > 0 then
                                mainTalentName = "野性坦克"
                            else
                                mainTalentName = "野性输出"
                            end
                            break
                        end
                    end
                end
                if (englishClass == "PALADIN" or englishClass == "PRIEST") and talentIndex == activeTalentIndex then
                    for j = 1, GetNumTalents(i, isTarget) do --当前天赋种类里面有多少个天赋技能
                        --名称, iconID, 行， 列, 点了几点技能， 最大可以点的技能
                        local _name, _, row, column, rank = GetTalentInfo(i, j, isTarget, nil, activeTalentIndex)
                        if tIndexOf(talentSpellList, _name) and rank > 0 then
                            ZL.opt.playerInfo[playerName][_name] = rank
                        end
                    end
                end
            end
            if mainTalentName then
                ZL.opt.playerInfo[playerName].talentName = ZL.opt.playerInfo[playerName].talentName or {}
                ZL.opt.playerInfo[playerName].talentName[mainTalentName] = mainTalenIcon
                if talentIndex == activeTalentIndex then
                    ZL.opt.playerInfo[playerName].newTalentName = mainTalentName
                    getSubsidyTypeFromTalentInfo(playerName, mainTalentName)
                    if englishClass == "PALADIN" and mainTalentName == "神圣" then
                        ZL.opt.playerInfo[playerName]["NQ"] = true
                    end
                end
            end
        end
    end
    if isInventory then
        -- 获取装备
        local itemId = GetInventoryItemID(playerName, 16)
        if itemId == 46017 then  -- 瓦兰奈尔，远古王者之锤
            ZL.opt.playerInfo[playerName]["橙锤"] = true
        elseif itemId == 49623 then
            ZL.opt.playerInfo[playerName]["橙斧"] = true
        end
    end
end
function ZL.updateFromtdInspect(name)
    local fullName = ZL.GetFullName(name)
    if TDDB_INSPECT2.global and TDDB_INSPECT2.global.userCache and TDDB_INSPECT2.global.userCache[fullName]
    and TDDB_INSPECT2.global.userCache[fullName].talents then
        local talentsDB = TDDB_INSPECT2.global.userCache[fullName]
        ZL.opt.playerInfo = ZL.opt.playerInfo or {}
        ZL.opt.playerInfo[name] = ZL.opt.playerInfo[name] or {}
        ZL.opt.playerInfo[name].talentName = nil
        local calssFile = select(2, GetClassInfo(talentsDB.class))
        local colorPlayerName = GetClassColorName(name, calssFile)
        ZL.opt.playerInfo[name].classFile = calssFile
        ZL.opt.playerInfo[name].classID = talentsDB.class
        ZL.opt.playerInfo[name].colorName = colorPlayerName
        ZL.opt.playerInfo[name].updateTimestamp = talentsDB.timestamp
        for talentIndex = 1, #talentsDB.talents do
            local activeTalent = talentsDB.talents[talentIndex] --talentsDB.activeGroup当前激活的天赋
            local activeTalentSpent = {}
            if type(activeTalent) == "string" then
                local startPos = 1
                for _, data in ipairs(ZL.ClassTalentDB[calssFile]) do
                    local length = #data.talentSpellName
                    -- 检查是否超出字符串长度
                    if startPos <= #activeTalent then
                        local endPos = math.min(startPos + length - 1, #activeTalent)
                        local substring = string.sub(activeTalent, startPos, endPos)
                        table.insert(activeTalentSpent, substring)
                        startPos = startPos + length
                    else
                        -- 如果超出字符串长度，插入空字符串或nil
                        table.insert(activeTalentSpent, "")
                    end
                end
            elseif type(activeTalent) == "table" then
                activeTalentSpent = activeTalent
            end
            if #activeTalentSpent > 0 then
                local mainTalentName
                local mainTalenPointsSpent = 0
                local mainTalenIcon
                for index, data in ipairs(ZL.ClassTalentDB[calssFile]) do
                    local talentName, talentIcon = data.talentName, data.talentIcon
                    local pointsSpent = 0
                    activeTalentSpent[index]:gsub("%d", function(d) pointsSpent = pointsSpent + tonumber(d) end)
                    if mainTalenPointsSpent >= pointsSpent then
                        mainTalentName = mainTalentName or talentName
                        mainTalenIcon = mainTalenIcon or talentIcon
                    else
                        mainTalenPointsSpent = pointsSpent
                        mainTalentName = talentName
                        mainTalenIcon = talentIcon
                    end
                    if (mainTalentName == "鲜血" and talentName == "冰霜") or (mainTalentName == "野性战斗" and talentName == "野性战斗") then
                        for spellIndex, _name in ipairs(data.talentSpellName) do
                            local rank = tonumber(activeTalentSpent[index]:sub(spellIndex, spellIndex)) or 0
                            if _name == "坚韧" then --鲜血DK
                                if rank == 5 then
                                    mainTalentName = "鲜血坦克"
                                else
                                    mainTalentName = "鲜血输出"
                                end
                                break
                            elseif _name == "厚皮" then --德鲁伊
                                if rank > 0 then
                                    mainTalentName = "野性坦克"
                                else
                                    mainTalentName = "野性输出"
                                end
                                break
                            end
                        end
                    end
                    if calssFile == "PALADIN" or calssFile == "PRIEST" and talentIndex == talentsDB.activeGroup then
                        for spellIndex, _name in ipairs(data.talentSpellName) do
                            local rank = tonumber(activeTalentSpent[index]:sub(spellIndex, spellIndex)) or 0
                            if tIndexOf(talentSpellList, _name) and rank > 0 then
                                ZL.opt.playerInfo[name][_name] = rank
                            end
                        end
                    end
                end
                if mainTalentName then
                    ZL.opt.playerInfo[name].talentName = ZL.opt.playerInfo[name].talentName or {}
                    ZL.opt.playerInfo[name].talentName[mainTalentName] = mainTalenIcon
                    if talentIndex == talentsDB.activeGroup then
                        ZL.opt.playerInfo[name].newTalentName = mainTalentName
                        getSubsidyTypeFromTalentInfo(name, mainTalentName)
                        if calssFile == "PALADIN" and mainTalentName == "神圣" then
                            ZL.opt.playerInfo[name]["NQ"] = true
                        end
                    end
                end
            end
        end
        return true
    end
end
local updateFromtdInspect = ZL.updateFromtdInspect
--需配合协程使用
function ZL.getPlayerTalent(colorName, frameUpdate)
    if not colorName then return end
    local name = ParseClassColorName(colorName)
    local isUpdate
    if canInspect(name) then
        NotifyInspect(name)
        sleep(1)
        if ZL.opt.playerInfo and ZL.opt.playerInfo[name] and ZL.opt.playerInfo[name].updateTimestamp and
        time() - ZL.opt.playerInfo[name].updateTimestamp <= 5 then
            isUpdate = true
        else
            ZL.getPlayerTalent(colorName)
        end
    else
        local istdInspectDB
        local fullName = ZL.GetFullName(name)
        if TDDB_INSPECT2 then
            MyAddon:SendCommMessage("tdInspect", Serializer:Serialize('Q', true, true, 2, false, false), 'WHISPER', name)
            sleep(1)
            if TDDB_INSPECT2.global and TDDB_INSPECT2.global.userCache and TDDB_INSPECT2.global.userCache[fullName]
            and TDDB_INSPECT2.global.userCache[fullName].talents and (time() - TDDB_INSPECT2.global.userCache[fullName].timestamp <= 5) then
                istdInspectDB = true
            end
            if not istdInspectDB then
                MyAddon:SendCommMessage("EMUCOM", '_q_tal', 'WHISPER', name)
                sleep(1)
                if TDDB_INSPECT2.global and TDDB_INSPECT2.global.userCache and TDDB_INSPECT2.global.userCache[fullName]
                and TDDB_INSPECT2.global.userCache[fullName].talents and (time() - TDDB_INSPECT2.global.userCache[fullName].timestamp <= 5) then
                    istdInspectDB = true
                end
            end
        end
        if istdInspectDB then
            updateFromtdInspect(name)
            isUpdate = true
        else
            MyAddon:TransmitAddonInfo2("AUTOAUC TALENT", {type="talent"}, 'WHISPER', name)
            sleep(2)
            if ZL.opt.playerInfo and ZL.opt.playerInfo[name] and ZL.opt.playerInfo[name].updateTimestamp and
            time() - ZL.opt.playerInfo[name].updateTimestamp <= 5 then
                isUpdate = true
            end
        end
    end
    if isUpdate then
        ZL.Print(colorName .. "天赋信息已更新。", true)
        if frameUpdate and ZL.SubsidyFrame:IsShown() then
            ZL.SubsidyFrame:Update()
        end
    else
        ZL.Print(colorName .. "获取天赋信息|cffff0000失败|r。", true)
    end
end
local getPlayerTalent = ZL.getPlayerTalent
function ZL.refreshAll()
    if IsInRaid(1) then
        local i = 1
        local name, fileName, online, colorName, _
        local function _tempfunc()
            if i <= MAX_RAID_MEMBERS then
                name, _, _, _, _, fileName, _, online = GetRaidRosterInfo(i)
                if name and online then
                    colorName = GetClassColorName(name, fileName)
                    getPlayerTalent(colorName)
                end
                i = i + 1
                _tempfunc()
            else
                ZL.Print("天赋信息更新完成！", true)
                C_Timer.After(1, function ()
                    if ZL.SubsidyFrame:IsShown() then
                        ZL.SubsidyFrame:Update()
                    end
                end)
            end
        end
        local co = coroutine.create(_tempfunc)
        coroutine.resume(co)
    else
        ZL.Print("不在团队中！")
    end
end
local refreshAll = ZL.refreshAll
function ZL:CreateSubsidyFrame()
    if type(ZL.opt.subsidyProfileSelect) ~= "number" then ZL.opt.subsidyProfileSelect = 1 end
    ZL.opt.subsidyProfileList = ZL.opt.subsidyProfileList or {
        ["profileKeys"] = {"默认"},
        ["profile"] = {
            ["默认"] = {
                ["parent"] = {
                    ["RL补贴"] = 0, ["T补贴"] = 0, ["N补贴"] = 0, ["DPS补贴"] = 0,
                    ["食物补贴"] = 0, ["工具人补贴"] = 0, ["其它补贴"] = 0
                },
                ["child"] = {},
            }
        }
    }
    ZL.SubsidyFrame = ZLCreateFrame("ZLSubsidyFrame", ZL, nil, nil, nil, true, true, "补贴设置")
    local SubsidyFrame = ZL.SubsidyFrame
    SubsidyFrame:Hide()
    SubsidyFrame.Background:SetColorTexture(0, 0, 0, 1)
    SubsidyFrame:SetScript("OnMouseUp", function (self)
        self:StopMovingOrSizing()
        if not ZL.glb.ZLSubsidyFrame then ZL.glb.ZLSubsidyFrame = {} end
        ZL.glb.ZLSubsidyFrame.point, _, ZL.glb.ZLSubsidyFrame.relative, ZL.glb.ZLSubsidyFrame.x, ZL.glb.ZLSubsidyFrame.y = self:GetPoint()
    end)
    SubsidyFrame:SetScript("OnMouseDown", function (self)
        self:StartMoving()
    end)
    SubsidyFrame:SetScript("OnShow", function (self)
        SubsidyFrame:Update()
    end)
    local resizeButton = SubsidyFrame.resizeButton
    -- 设置鼠标按下时开始调整大小
    resizeButton:SetScript("OnMouseDown", function(self, button)
        if button == "LeftButton" then
            SubsidyFrame:StartSizing("BOTTOMRIGHT")
        end
    end)
    -- 鼠标松开时停止调整大小
    resizeButton:SetScript("OnMouseUp", function(self, button)
        SubsidyFrame:StopMovingOrSizing()
        ZL.db.global.ZLSubsidyFrame = ZL.db.global.ZLSubsidyFrame or {}
        ZL.db.global.ZLSubsidyFrame.Width,  ZL.db.global.ZLSubsidyFrame.Height= SubsidyFrame:GetSize()
    end)
    SubsidyFrame:ClearAllPoints()
    if ZL.glb.ZLSubsidyFrame and ZL.glb.ZLSubsidyFrame.point then
        SubsidyFrame:SetPoint(ZL.glb.ZLSubsidyFrame.point, UIParent, ZL.glb.ZLSubsidyFrame.relative, ZL.glb.ZLSubsidyFrame.x, ZL.glb.ZLSubsidyFrame.y)
    else
        SubsidyFrame:SetPoint("CENTER")
    end

    --刷新界面数据
    SubsidyFrame.updateBtn = CreateFrame("Button", nil, SubsidyFrame)
    local updateBtn = SubsidyFrame.updateBtn
    updateBtn:SetPoint("RIGHT", SubsidyFrame.closeButton, "LEFT")
    updateBtn:SetSize(15, 15)
    updateBtn:SetNormalTexture(851904)
    updateBtn:SetHighlightTexture(851904)
    updateBtn:SetScript("OnClick", function (self)
        SubsidyFrame:Update()
    end)
    updateBtn:SetScript("OnEnter", function (self)
        GameTooltipShow(self, "BOTTOM", "TOP", 0, 5)
        GameTooltip:AddLine("刷新界面")
        GameTooltip:Show()
    end)
    updateBtn:SetScript("OnLeave", function ()
        GameTooltip:Hide()
    end)

    local subsidyTypeWidth, singleMoneyWidth, meetMembersWidth, actualMembersWidth, totalMoneyWidth, delWidth = 100, 80, 80, 80, 100, 20
    local totalWidth = subsidyTypeWidth + singleMoneyWidth + meetMembersWidth + actualMembersWidth + totalMoneyWidth + delWidth + 26
    SubsidyFrame:SetResizeBounds(totalWidth, 350, totalWidth, GetScreenHeight()-40)
    SubsidyFrame:SetWidth(totalWidth)
    if ZL.db.global.ZLSubsidyFrame and ZL.db.global.ZLSubsidyFrame.Height then
        SubsidyFrame:SetHeight(ZL.db.global.ZLSubsidyFrame.Height)
    end

    local lineHeight = 20
    local selectProfileFontString = SubsidyFrame:CreateFontString(nil, "OVERLAY")
    selectProfileFontString:SetPoint("TOPLEFT", SubsidyFrame.TitleBottom, "BOTTOMLEFT", 5, -8)
    selectProfileFontString:SetHeight(24)
    selectProfileFontString:SetFont(GameFontNormal:GetFont(), 14, "OUTLINE")
    selectProfileFontString:SetWordWrap(false)
    selectProfileFontString:SetJustifyH("LEFT")
    selectProfileFontString:SetTextColor(1, 0.82, 0, 1)
    selectProfileFontString:SetText("配置：")
    SubsidyFrame.historyProfileDropdown = CreateFrame("Button", nil, SubsidyFrame)
    local historyProfileDropdown = SubsidyFrame.historyProfileDropdown
    historyProfileDropdown:SetPoint("LEFT", selectProfileFontString, "RIGHT", 5, 0)
    historyProfileDropdown:SetSize(150, 24)
    ZL.GUI:GetClass('Dropdown'):Bind(historyProfileDropdown)
    historyProfileDropdown:SetMenuTable(getSubsidyProfileDropdownList())
    historyProfileDropdown:SetValue(ZL.opt.subsidyProfileSelect)
    historyProfileDropdown:SetCallback('OnSelectChanged', function (self)
        ZL.opt.subsidyProfileSelect = self.value
        ZL_CURRENT.subsidy = {}
        ZL_CURRENT.subsidyParent = {}
        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
    end)
    SubsidyFrame.delProfileBtn = CreateButton(nil, SubsidyFrame, "删除", "LEFT", historyProfileDropdown, "RIGHT", 3, 0, 45, 24)
    local delProfileBtn = SubsidyFrame.delProfileBtn
    delProfileBtn:SetScript("OnClick", function (self)
        local profileName = historyProfileDropdown:GetText()
        if profileName == "默认" then
            ZL.Print("|cffff0000【默认】|r配置不可删除！")
            return
        end
        for index, value in ipairs(ZL.opt.subsidyProfileList["profileKeys"]) do
            if value == profileName then
                tremove(ZL.opt.subsidyProfileList["profileKeys"], index)
            end
        end
        ZL.opt.subsidyProfileList["profile"][profileName] = nil
        historyProfileDropdown:SetMenuTable(getSubsidyProfileDropdownList())
        ZL.opt.subsidyProfileSelect = 1
        historyProfileDropdown:SetValue(ZL.opt.subsidyProfileSelect)
        ZL.Print("已删除：|cffff0000【" .. profileName .. "】|r配置")
    end)

    SubsidyFrame.addBtn = CreateButton(nil, SubsidyFrame, "补贴类型", "LEFT", delProfileBtn, "RIGHT", 3, 0, 75, 24)
    local addBtn = SubsidyFrame.addBtn
    addBtn:RegisterForClicks("LeftButtonUp", "RightButtonUp")
    addBtn:SetScript("OnClick", function (self)
        local function tempfunc()
            local menuList = {}
            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"]
            for _, subsidyParentName in ipairs(subsidyParentTypeList) do
                local childMenuList = {}
                for _, subsidyName in ipairs(subsidyChildrenList[subsidyParentName]) do
                    local subsidyNameGsub = subsidyName:gsub("%d+", "")
                    if subsidyName == "主T" or subsidyName == "副T" or subsidyName == "双休T" then
                        subsidyNameGsub = "T"
                    end
                    local icon = 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
                            SubsidyFrame:Update()
                            -- ZL.GUI:OpenMenu(self, tempfunc(), "TOPLEFT", self, "TOPRIGHT", 0, 0)
                        end
                    })
                end
                tinsert(menuList, {
                    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(subsidyChildrenList[subsidyParentName]) do
                                subsidyData[subsidyName] = nil
                                if ZL_CURRENT.subsidy then
                                    ZL_CURRENT.subsidy[subsidyName] = nil
                                end
                            end
                        else
                            subsidyParentData[subsidyParentName] = 0
                            if #subsidyChildrenList[subsidyParentName] == 1 then
                                subsidyData[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
                        SubsidyFrame:Update()
                        ZL.GUI:OpenMenu(self, tempfunc(), "TOPLEFT", self, "TOPRIGHT", 0, 0)
                    end,
                })
            end
            return menuList
        end
        ZL.GUI:ToggleMenu(self, tempfunc(), "TOPLEFT", self, "TOPRIGHT", 0, 0)
    end)

    SubsidyFrame.refreshBtn = CreateButton(nil, SubsidyFrame, "查看天赋", "LEFT", addBtn, "RIGHT", 3, 0, 75, 24)
    local refreshBtn = SubsidyFrame.refreshBtn
    refreshBtn:RegisterForClicks("LeftButtonUp", "RightButtonUp")
    refreshBtn:SetScript("OnClick", function (self, button)
        local function tempfunc()
            local menuList = {
                {
                    disabled = not IsInRaid(1),
                    text = "刷新所有天赋信息",
                    func = function ()
                        refreshAll()
                    end,
                    tooltipMore = function (tip)
                        tip:AddLine("刷新当前团员激活的天赋信息")
                    end,
                },
                {
                    disabled = not IsInRaid(1),
                    text = "重置所有天赋信息",
                    func = function ()
                        ZL.opt.playerInfo = {}
                        refreshAll()
                    end,
                    tooltipMore = function (tip)
                        tip:AddLine("重置所有天赋信息，含双天赋、食物等记录")
                    end,
                },
            }
            local WagesGroupMembers, msg = ZL.GetWagesGroupMembers()
            if WagesGroupMembers then
                if msg then
                    tinsert(menuList, 1, {text=msg, isTitle=1})
                end
                   local tempList = {}
                for _, data in ipairs(WagesGroupMembers) do
                    for _, colorName in ipairs(data) do
                        local name = ParseClassColorName(colorName)
                        local classFile = "未知"
                        if ZL.opt.playerInfo and ZL.opt.playerInfo[name] and ZL.opt.playerInfo[name].classFile then
                            classFile = ZL.opt.playerInfo[name].classFile
                        end
                        tempList[classFile] = tempList[classFile] or {}
                        tinsert(tempList[classFile], colorName)
                    end
                end
                if tempList["未知"] and #tempList["未知"] > 0 then
                    tinsert(menuList, {isSeparator = true})
                    tinsert(menuList, {text="未知天赋", isTitle=1})
                    for _, colorName in ipairs(tempList["未知"] ) do
                        local name = ParseClassColorName(colorName)
                        local text = colorName
                        local raidIndex = UnitInRaid(name)
                        local disabled
                        if raidIndex then
                            local online = UnitIsConnected(name)
                            if not online then
                                text = text .. "|cffff0000(离线)|r"
                                disabled = true
                            end
                        else
                            text = text .. "|cffff0000(离队)|r"
                            disabled = true
                        end
                        tinsert(menuList, {
                            text = text,
                            hasArrow = 1,
                            menuTable = {
                                {
                                    disabled = disabled,
                                    text = "刷新天赋",
                                    func = function ()
                                        local co = coroutine.create(getPlayerTalent)
                                        coroutine.resume(co, colorName, true)
                                        ZL.GUI:CloseMenu()
                                    end,
                                },
                            },
                        })
                    end
                end
                local isSeparator
                for _, classFile in ipairs(ZL.ClassFileList) do
                    if tempList[classFile] and #tempList[classFile] > 0 then
                        table.sort(tempList[classFile])
                        if not isSeparator then
                            tinsert(menuList, {isSeparator = true})
                            isSeparator = true
                        end
                        for _, colorName in ipairs(tempList[classFile] ) do
                            local name = ParseClassColorName(colorName)
                            local text = colorName
                            local raidIndex = UnitInRaid(name)
                            local disabled
                            if raidIndex then
                                local online = UnitIsConnected(name)
                                if not online then
                                    text = text .. "|cffff0000(离线)|r"
                                    disabled = true
                                end
                            else
                                text = text .. "|cffff0000(离队)|r"
                                disabled = true
                            end
                            if ZL.opt.playerInfo and ZL.opt.playerInfo[name] and ZL.opt.playerInfo[name].talentName then
                                local newTalentName = ZL.opt.playerInfo[name].newTalentName --当前天赋排前面
                                text = text .. " - |T" .. ZL.opt.playerInfo[name].talentName[newTalentName] .. ":12|t" .. newTalentName
                                for key, value in pairs(ZL.opt.playerInfo[name].talentName) do
                                    if key ~= newTalentName then
                                        text = text .. " - |T" .. value .. ":12|t" .. key
                                    end
                                end
                            end
                            tinsert(menuList, {
                                text = text,
                                hasArrow = 1,
                                menuTable = {
                                    {
                                        disabled = disabled,
                                        text = "刷新天赋",
                                        func = function ()
                                            local co = coroutine.create(getPlayerTalent)
                                            coroutine.resume(co, colorName, true)
                                            ZL.GUI:CloseMenu()
                                        end,
                                    },
                                    {
                                        disabled = disabled,
                                        text = "重置天赋",
                                        func = function ()
                                            local fish = ZL.opt.playerInfo[name]["鱼"]
                                            local fishCount = ZL.opt.playerInfo[name]["fishCount "]
                                            if fish and fishCount then
                                                ZL.opt.playerInfo[name] = {
                                                    ["鱼"] = fish,
                                                    fishCount = fishCount
                                                }
                                            else
                                                ZL.opt.playerInfo[name] = nil
                                            end
                                            local co = coroutine.create(getPlayerTalent)
                                            coroutine.resume(co, colorName, true)
                                            ZL.GUI:CloseMenu()
                                        end,
                                    },
                                },
                            })
                        end
                    end
                end
            end
            return menuList
        end
        ZL.GUI:ToggleMenu(self, tempfunc(), "TOPLEFT", self, "BOTTOMRIGHT")
    end)
    refreshBtn:SetScript("OnEnter", function (self)
        local notExistCounts = 0
        for i = 1, MAX_RAID_MEMBERS do
            local name, _, _, _, _, _, _, online = GetRaidRosterInfo(i)
            if online and not (name and ZL.opt.playerInfo and ZL.opt.playerInfo[name]
            and ZL.opt.playerInfo[name].newTalentName) then
                notExistCounts = notExistCounts + 1
            end
        end
        GameTooltipShow(self, "BOTTOMRIGHT", "TOPLEFT")
        GameTooltip:AddLine("说明")
        GameTooltip:AddLine("1、28码内会自动获取团队天赋信息；", 1, 1, 1)
        GameTooltip:AddLine("2、超出28码，如双方都装了|CFFFFDE00tdInspect|r\n插件，会获取这个插件的缓存数据", 1, 1, 1)
        GameTooltip:AddLine(" ")
        GameTooltip:AddLine("当前团员未获取到天赋数量(|cffffffff" .. notExistCounts .. "|r)")
        GameTooltip:Show()
    end)
    refreshBtn:SetScript("OnLeave", function (self)
        GameTooltip:Hide()
    end)

    SubsidyFrame.allocateBtn = CreateButton(nil, SubsidyFrame, "一键分配", "LEFT", refreshBtn, "RIGHT", 3, 0, 75, 24)
    local allocateBtn = SubsidyFrame.allocateBtn
    allocateBtn:SetScript("OnClick", function (self)
        if BUILD_DATA >= 5 then
            ZL.Print("当前版本不支持！")
            return
        end
        local profileName = ZL.opt.subsidyProfileList["profileKeys"][ZL.opt.subsidyProfileSelect]
        local subsidyData = ZL.opt.subsidyProfileList["profile"][profileName]["child"]
        ZL_CURRENT.subsidy = {}
        local filterSubsidyName = {"主T", "副T", "DPS", "修星"}
        local WagesGroupMembers, _, _, RL = ZL.GetWagesGroupMembers()
        for subsidyName in pairs(subsidyData) do
            local subsidyNameGsub = subsidyName:gsub("%d+", "")
            if not tIndexOf(filterSubsidyName, subsidyNameGsub) then
                if WagesGroupMembers then
                    if subsidyName == "RL" then
                        if RL then
                            ZL_CURRENT.subsidy[subsidyName] = {}
                            ZL_CURRENT.subsidy[subsidyName][RL] = true
                        end
                    elseif subsidyName == "鱼" then
                        if ZL_CURRENT.subsidyFishFirst then
                            local isExist
                            for _, _data in ipairs(WagesGroupMembers) do
                                for _, colorName in ipairs(_data) do
                                    local name = ParseClassColorName(colorName)
                                    if name == ZL_CURRENT.subsidyFishFirst then
                                        isExist = colorName
                                        break
                                    end
                                end
                                if isExist then break end
                            end
                            if isExist then
                                ZL_CURRENT.subsidy[subsidyName] = {}
                                ZL_CURRENT.subsidy[subsidyName][isExist] = true
                            end
                        end
                    elseif subsidyName == "猪" then
                        if ZL_CURRENT.subsidyPigFirst then
                            local isExist
                            for _, _data in ipairs(WagesGroupMembers) do
                                for _, colorName in ipairs(_data) do
                                    local name = ParseClassColorName(colorName)
                                    if name == ZL_CURRENT.subsidyPigFirst then
                                        isExist = colorName
                                        break
                                    end
                                end
                                if isExist then break end
                            end
                            if isExist then
                                ZL_CURRENT.subsidy[subsidyName] = {}
                                ZL_CURRENT.subsidy[subsidyName][isExist] = true
                            end
                        end
                    elseif subsidyName == "修理机器人" then
                        if ZL_CURRENT.subsidyXiuLiFirst then
                            local isExist
                            for _, _data in ipairs(WagesGroupMembers) do
                                for _, colorName in ipairs(_data) do
                                    local name = ParseClassColorName(colorName)
                                    if name == ZL_CURRENT.subsidyXiuLiFirst then
                                        isExist = colorName
                                        break
                                    end
                                end
                                if isExist then break end
                            end
                            if isExist then
                                ZL_CURRENT.subsidy[subsidyName] = {}
                                ZL_CURRENT.subsidy[subsidyName][isExist] = true
                            end
                        end
                    elseif subsidyName == "N" then
                        for playerName, data in pairs(ZL.opt.playerInfo) do
                            if data["N"] and (not data["双休"]) then
                                local isExist
                                for _, _data in ipairs(WagesGroupMembers) do
                                    for _, colorName in ipairs(_data) do
                                        local name = ParseClassColorName(colorName)
                                        if name == playerName then
                                            isExist = colorName
                                            break
                                        end
                                    end
                                    if isExist then break end
                                end
                                if isExist then
                                    ZL_CURRENT.subsidy[subsidyName] = ZL_CURRENT.subsidy[subsidyName] or {}
                                    ZL_CURRENT.subsidy[subsidyName][isExist] = true
                                end
                            end
                        end
                    elseif subsidyName == "鸟德" then
                        for playerName, data in pairs(ZL.opt.playerInfo) do
                            if data["鸟德"] and (not data["双休"]) then
                                local isExist
                                for _, _data in ipairs(WagesGroupMembers) do
                                    for _, colorName in ipairs(_data) do
                                        local name = ParseClassColorName(colorName)
                                        if name == playerName then
                                            isExist = colorName
                                            break
                                        end
                                    end
                                    if isExist then break end
                                end
                                if isExist then
                                    ZL_CURRENT.subsidy[subsidyName] = ZL_CURRENT.subsidy[subsidyName] or {}
                                    ZL_CURRENT.subsidy[subsidyName][isExist] = true
                                end
                            end
                        end
                    else
                        if ZL.opt.playerInfo then
                            for playerName, data in pairs(ZL.opt.playerInfo) do
                                if data[subsidyNameGsub] then
                                    local isExist
                                    for _, _data in ipairs(WagesGroupMembers) do
                                        for _, colorName in ipairs(_data) do
                                            local name = ParseClassColorName(colorName)
                                            if name == playerName then
                                                isExist = colorName
                                                break
                                            end
                                        end
                                        if isExist then break end
                                    end
                                    if isExist then
                                        ZL_CURRENT.subsidy[subsidyName] = ZL_CURRENT.subsidy[subsidyName] or {}
                                        ZL_CURRENT.subsidy[subsidyName][isExist] = true
                                    end
                                end
                            end
                        end
                    end
                end
            end
        end
        SubsidyFrame:Update()
    end)
    allocateBtn:SetScript("OnEnter", function (self)
        GameTooltipShow(SubsidyFrame, "TOPLEFT", "TOPRIGHT")
        GameTooltip:AddLine("分配补贴")
        GameTooltip:AddLine("1、按天赋类型一键分配子补贴类型；", 1, 1, 1)
        GameTooltip:AddLine("2、分配后请核对人数是否正确；", 1, 1, 1)
        GameTooltip:AddLine("3、DPS和部分子补贴类型需手动选择。", 1, 1, 1)
        GameTooltip:Show()
    end)
    allocateBtn:SetScript("OnLeave", function (self)
        GameTooltip:Hide()
    end)

    local saveProfileFontString = SubsidyFrame:CreateFontString(nil, "OVERLAY")
    saveProfileFontString:SetPoint("TOPLEFT", selectProfileFontString, "BOTTOMLEFT", 0, -5)
    saveProfileFontString:SetHeight(24)
    saveProfileFontString:SetFont(GameFontNormal:GetFont(), 14, "OUTLINE")
    saveProfileFontString:SetWordWrap(false)
    saveProfileFontString:SetJustifyH("LEFT")
    saveProfileFontString:SetTextColor(1, 0.82, 0, 1)
    saveProfileFontString:SetText("新建：")
    local function saveProfileName()
        local profileName = SubsidyFrame.saveProfileEditBox:GetText()
        local isExist
        for _, value in ipairs(ZL.opt.subsidyProfileList["profileKeys"]) do
            if value == profileName then
                isExist = true
                break
            end
        end
        if isExist then
            ZL.Print("配置名称已存在，请重新输入！")
        else
            ZL.opt.subsidyProfileList["profile"][profileName] = {
                ["child"] = {},
                ["parent"] = {},
            }
            for _, f in ipairs(SubsidyFrame.entries) do
                if f:IsShown() then
                    ZL.opt.subsidyProfileList["profile"][profileName]["child"][f.subsidyName] = f.subsidyMoney
                end
            end
            for _, f in ipairs(SubsidyFrame.parentEntries) do
                if f:IsShown() and f.subsidyName then
                    ZL.opt.subsidyProfileList["profile"][profileName]["parent"][f.subsidyName] = f.subsidyMoney
                end
            end
            tinsert(ZL.opt.subsidyProfileList["profileKeys"], profileName)
            historyProfileDropdown:SetMenuTable(getSubsidyProfileDropdownList())
            ZL.opt.subsidyProfileSelect = #ZL.opt.subsidyProfileList["profileKeys"]
            historyProfileDropdown:SetValue(ZL.opt.subsidyProfileSelect)
            SubsidyFrame.saveProfileEditBox:SetText("")
            SubsidyFrame.saveProfileEditBox:ClearFocus()
            ZL.Print("已创建新的配置文件：|cffffffff" .. profileName .. "|r")
        end
    end
    local saveProfileEditBoxWidth = selectProfileFontString:GetWidth() + historyProfileDropdown:GetWidth() - saveProfileFontString:GetWidth()
    SubsidyFrame.saveProfileEditBox = CreateEditBox(SubsidyFrame, saveProfileEditBoxWidth, 24, 14, "RIGHT")
    local saveProfileEditBox = SubsidyFrame.saveProfileEditBox
    saveProfileEditBox:SetPoint("LEFT", saveProfileFontString, "RIGHT", 5, 0)
    saveProfileEditBox:SetScript("OnTextChanged", function (self)
        if #self:GetText() > 0 then
            SubsidyFrame.saveProfileBtn:Enable()
        else
            SubsidyFrame.saveProfileBtn:Disable()
        end
    end)
    saveProfileEditBox:SetScript("OnEnterPressed", function (self)
        if #self:GetText() > 0 then
            saveProfileName()
        end
    end)
    SubsidyFrame.saveProfileBtn = CreateButton(nil, SubsidyFrame, "保存", "LEFT", saveProfileEditBox, "RIGHT", 3, 0, 45, 24)
    local saveProfileBtn = SubsidyFrame.saveProfileBtn
    saveProfileBtn:Disable()
    saveProfileBtn:SetScript("OnClick", function (self)
        saveProfileName()
    end)

    local wagesSubsidyTypeFontString = SubsidyFrame:CreateFontString(nil, "OVERLAY")
    wagesSubsidyTypeFontString:SetPoint("LEFT", saveProfileBtn, "RIGHT", 3, 0)
    wagesSubsidyTypeFontString:SetHeight(24)
    wagesSubsidyTypeFontString:SetFont(GameFontNormal:GetFont(), 14, "OUTLINE")
    wagesSubsidyTypeFontString:SetWordWrap(false)
    wagesSubsidyTypeFontString:SetJustifyH("LEFT")
    wagesSubsidyTypeFontString:SetTextColor(1, 0.82, 0, 1)
    wagesSubsidyTypeFontString:SetText("补贴方案：")
    SubsidyFrame.wagesSubsidyTypeDropdown = CreateFrame("Button", nil, SubsidyFrame)
    local wagesSubsidyTypeDropdown = SubsidyFrame.wagesSubsidyTypeDropdown
    wagesSubsidyTypeDropdown:SetPoint("LEFT", wagesSubsidyTypeFontString, "RIGHT", 5, 0)
    wagesSubsidyTypeDropdown:SetSize(150, 24)
    ZL.GUI:GetClass('Dropdown'):Bind(wagesSubsidyTypeDropdown)
    wagesSubsidyTypeDropdown:SetMenuTable({
        {text="无补贴", value=1},
        {text="|cfff58cba按父补贴金额|r", value=2},
        {text="|cff4080FF按子补贴金额|r", value=3},
    })
    wagesSubsidyTypeDropdown:SetValue(ZL.opt.wagesSubsidyType)
    wagesSubsidyTypeDropdown:SetCallback('OnSelectChanged', function (self)
        ZL.opt.wagesSubsidyType = self.value
        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
    end)
    --创建滚动条
    SubsidyFrame.scrollFrame = CreateFrame("ScrollFrame", nil, SubsidyFrame, "UIPanelScrollFrameTemplate")
    SubsidyFrame.scrollFrame:SetFrameLevel(SubsidyFrame:GetFrameLevel() + 1) -- 设置为比父框架高1级
    SubsidyFrame.scrollFrame:SetPoint("TOPLEFT", saveProfileFontString, "BOTTOMLEFT", -3, -10)
    SubsidyFrame.scrollFrame:SetPoint("BOTTOMRIGHT", SubsidyFrame, "BOTTOMRIGHT", 0, 3)
    SubsidyFrame.scrollFrame:SetClipsChildren(true) --必须设置为true，scrollFrame所有的子元素才会被剪切
    SubsidyFrame.scrollFrame:SetScript("OnMouseWheel", ScrollFrame_OnMouseWheel) --重设滑动条鼠标滚轮事件
    --重设ScrollBar位置，放置到scrollFrame内，防止被剪切掉
    SubsidyFrame.scrollFrame.ScrollBar:ClearAllPoints()
    SubsidyFrame.scrollFrame.ScrollBar:SetPoint("TOPLEFT", SubsidyFrame.scrollFrame, "TOPRIGHT", -20, -17)
    SubsidyFrame.scrollFrame.ScrollBar:SetPoint("BOTTOMRIGHT", SubsidyFrame.scrollFrame, "BOTTOMRIGHT", 0, 16)
    SubsidyFrame.scrollFrame.content = CreateFrame("Frame", nil, SubsidyFrame.scrollFrame)
    local content = SubsidyFrame.scrollFrame.content
    content:SetPoint("TOPLEFT", SubsidyFrame.scrollFrame, "TOPLEFT", 0, 0)
    content:SetSize(SubsidyFrame.scrollFrame:GetWidth()-20, 100)
    SubsidyFrame.scrollFrame:SetScrollChild(content)
    SubsidyFrame.scrollFrame.ScrollBar:SetFrameLevel(content:GetFrameLevel()+100)

    local btnTexture = [[Interface\ACHIEVEMENTFRAME\UI-Achievement-Parchment-Horizontal]]
    SubsidyFrame.subsidyParentTypeBtn = CreateButton(nil, content, "|cfff58cba父补贴类型|r", "TOPLEFT", content, "TOPLEFT", 0, 0, subsidyTypeWidth)
    local subsidyParentTypeBtn = SubsidyFrame.subsidyParentTypeBtn
    subsidyParentTypeBtn:GetFontString():SetFont(GameFontNormal:GetFont(), 13, "OUTLINE")
    subsidyParentTypeBtn:SetNormalTexture(btnTexture)
    subsidyParentTypeBtn:ClearHighlightTexture()
    subsidyParentTypeBtn:SetScript("OnClick", function (self)
        local function tempfunc()
            local menuList = {}
            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"]
            for _, subsidyParentName in ipairs(subsidyParentTypeList) do
                tinsert(menuList, {
                    text = subsidyParentName,
                    checkable = 1,
                    isNotRadio = 1,
                    checked = subsidyParentData[subsidyParentName],
                    keepShownOnClick = 1,
                    func = function ()
                        if subsidyParentData[subsidyParentName] then
                            subsidyParentData[subsidyParentName] = nil
                            if ZL_CURRENT.subsidyParent then
                                ZL_CURRENT.subsidyParent[subsidyParentName] = nil
                            end
                            for _, subsidyName in ipairs(subsidyChildrenList[subsidyParentName]) do
                                subsidyData[subsidyName] = nil
                                if ZL_CURRENT.subsidy then
                                    ZL_CURRENT.subsidy[subsidyName] = nil
                                end
                            end
                        else
                            subsidyParentData[subsidyParentName] = 0
                            if #subsidyChildrenList[subsidyParentName] == 1 then
                                subsidyData[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
                        SubsidyFrame:Update()
                        ZL.GUI:OpenMenu(self, tempfunc(), "TOPLEFT", self, "TOPRIGHT", 0, 0)
                    end,
                })
            end
            return menuList
        end
        ZL.GUI:ToggleMenu(self, tempfunc(), "TOPLEFT", self, "TOPRIGHT", 0, 0)
    end)

    SubsidyFrame.parentMoneyBtn = CreateButton(nil, content, "|cfff58cba父补贴金额|r", "LEFT", subsidyParentTypeBtn, "RIGHT", 0, 0, singleMoneyWidth+20)
    local parentMoneyBtn = SubsidyFrame.parentMoneyBtn
    parentMoneyBtn:GetFontString():SetFont(GameFontNormal:GetFont(), 13, "OUTLINE")
    parentMoneyBtn:SetNormalTexture(btnTexture)
    parentMoneyBtn:ClearHighlightTexture()
    parentMoneyBtn:SetScript("OnEnter", function (self)
        GameTooltipShow(self, "BOTTOM", "TOP")
        GameTooltip:AddLine("手动输入金额")
        GameTooltip:Show()
    end)
    parentMoneyBtn:SetScript("OnLeave", function (self)
        GameTooltip:Hide()
    end)

    SubsidyFrame.childMoneyBtn = CreateButton(nil, content, "|cff4080FF子补贴金额|r", "LEFT", parentMoneyBtn, "RIGHT", 0, 0, singleMoneyWidth+20)
    local childMoneyBtn = SubsidyFrame.childMoneyBtn
    childMoneyBtn:GetFontString():SetFont(GameFontNormal:GetFont(), 13, "OUTLINE")
    childMoneyBtn:SetNormalTexture(btnTexture)
    childMoneyBtn:ClearHighlightTexture()
    childMoneyBtn:SetScript("OnEnter", function (self)
        GameTooltipShow(self, "BOTTOM", "TOP")
        GameTooltip:AddLine("通过子补贴类型\n自动计算汇总金额")
        GameTooltip:Show()
    end)
    childMoneyBtn:SetScript("OnLeave", function (self)
        GameTooltip:Hide()
    end)

    SubsidyFrame.checkMoneyBtn = CreateButton(nil, content, "校对", "LEFT", childMoneyBtn, "RIGHT", 0, 0, 50)
    local checkMoneyBtn = SubsidyFrame.checkMoneyBtn
    checkMoneyBtn:GetFontString():SetFont(GameFontNormal:GetFont(), 13, "OUTLINE")
    checkMoneyBtn:SetNormalTexture(btnTexture)
    checkMoneyBtn:ClearHighlightTexture()

    SubsidyFrame.subsidyTypeBtn = CreateButton(nil, content, "|cff4080FF子补贴类型|r", "TOPLEFT", wagesSubsidyTypeFontString, "BOTTOMLEFT", 0, -50, subsidyTypeWidth)
    local subsidyTypeBtn = SubsidyFrame.subsidyTypeBtn
    subsidyTypeBtn:GetFontString():SetFont(GameFontNormal:GetFont(), 13, "OUTLINE")
    subsidyTypeBtn:SetNormalTexture(btnTexture)
    subsidyTypeBtn:ClearHighlightTexture()
    subsidyTypeBtn:SetScript("OnClick", function (self)
        local function tempfunc()
            local menuList = {}
            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"]
            for _, subsidyParentName in ipairs(subsidyParentTypeList) do
                tinsert(menuList, {text=subsidyParentName, isTitle=1})
                for _, subsidyName in ipairs(subsidyChildrenList[subsidyParentName]) do
                    local subsidyNameGsub = subsidyName:gsub("%d+", "")
                    if subsidyName == "主T" or subsidyName == "副T" or subsidyName == "双休T" then
                        subsidyNameGsub = "T"
                    end
                    local icon = subsidyTypeFunc[subsidyNameGsub].icon or "|T:13|t"
                    tinsert(menuList, {
                        text = icon .. subsidyName,
                        checkable = 1,
                        isNotRadio = 1,
                        checked = subsidyData[subsidyName],
                        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
                            SubsidyFrame:Update()
                            ZL.GUI:OpenMenu(self, tempfunc(), "TOPLEFT", self, "TOPRIGHT", 0, 0)
                        end
                    })
                end
                tinsert(menuList, {isSeparator=1})
            end
            tremove(menuList, #menuList)
            return menuList
        end
        ZL.GUI:ToggleMenu(self, tempfunc(), "TOPLEFT", self, "BOTTOMRIGHT", 0, 0)
    end)

    SubsidyFrame.singleMoneyBtn = CreateButton(nil, content, "单个补贴", "LEFT", subsidyTypeBtn, "RIGHT", 0, 0, singleMoneyWidth)
    local singleMoneyBtn = SubsidyFrame.singleMoneyBtn
    singleMoneyBtn:GetFontString():SetFont(GameFontNormal:GetFont(), 13, "OUTLINE")
    singleMoneyBtn:SetNormalTexture(btnTexture)
    singleMoneyBtn:ClearHighlightTexture()

    SubsidyFrame.meetMembersBtn = CreateButton(nil, content, "符合人数", "LEFT", singleMoneyBtn, "RIGHT", 0, 0, meetMembersWidth)
    local meetMembersBtn = SubsidyFrame.meetMembersBtn
    meetMembersBtn:GetFontString():SetFont(GameFontNormal:GetFont(), 13, "OUTLINE")
    meetMembersBtn:SetNormalTexture(btnTexture)
    meetMembersBtn:ClearHighlightTexture()

    SubsidyFrame.actualMembersBtn = CreateButton(nil, content, "实际人数", "LEFT", meetMembersBtn, "RIGHT", 0, 0, actualMembersWidth)
    local actualMembersBtn = SubsidyFrame.actualMembersBtn
    actualMembersBtn:GetFontString():SetFont(GameFontNormal:GetFont(), 13, "OUTLINE")
    actualMembersBtn:SetNormalTexture(btnTexture)
    actualMembersBtn:ClearHighlightTexture()

    SubsidyFrame.totalMoneyBtn = CreateButton(nil, content, "合计补贴", "LEFT", actualMembersBtn, "RIGHT", 0, 0, totalMoneyWidth)
    local totalMoneyBtn = SubsidyFrame.totalMoneyBtn
    totalMoneyBtn:GetFontString():SetFont(GameFontNormal:GetFont(), 13, "OUTLINE")
    totalMoneyBtn:SetNormalTexture(btnTexture)
    totalMoneyBtn:ClearHighlightTexture()

    local function OnEnter(self)
        self:GetParent():SetNormalTexture("Interface\\FriendsFrame\\UI-FriendsFrame-HighlightBar")
    end
    local function OnLeave(self)
        self:GetParent():ClearNormalTexture()
    end
    local board_r, board_g, board_b, board_a = 0.24, 0.25, 0.3, 1
    SubsidyFrame.parentEntries = setmetatable({}, {
        __index = function (t, v)
            local f = CreateFrame("Button", nil, content)
            f:Hide()
            f:SetSize(subsidyTypeWidth+singleMoneyWidth+20+singleMoneyWidth+lineHeight+50, lineHeight)
            if v == 1 then
                f:SetPoint("TOPLEFT", subsidyParentTypeBtn, "BOTTOMLEFT", 0, -1)
            else
                f:SetPoint("TOPLEFT", t[v-1], "BOTTOMLEFT")
            end
            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)
                self:SetNormalTexture("Interface\\FriendsFrame\\UI-FriendsFrame-HighlightBar")
            end)
            f:SetScript("OnLeave", function (self)
                self:ClearNormalTexture()
            end)
            f.subsidyParentTypebox = CreateEditBox(f, subsidyTypeWidth, lineHeight, 13, "CENTER", nil, nil, board_r, board_g, board_b, board_a)
            f.subsidyParentTypebox:SetPoint("LEFT", f, "LEFT", 0, 0)
            f.subsidyParentTypebox.Background:SetColorTexture(0,0,0,0)
            f.subsidyParentTypebox.fontstring = f.subsidyParentTypebox:CreateFontString(nil, "OVERLAY")
            f.subsidyParentTypebox.fontstring:SetPoint("TOPLEFT", 3, -1)
            f.subsidyParentTypebox.fontstring:SetPoint("BOTTOMRIGHT", -3, 1)
            f.subsidyParentTypebox.fontstring:SetFont(GameFontNormal:GetFont(), 13, "OUTLINE")
            f.subsidyParentTypebox.fontstring:SetWordWrap(false)
            f.subsidyParentTypebox.fontstring:SetJustifyH("LEFT")
            f.subsidyParentTypebox.fontstring:SetJustifyV("MIDDLE")
            f.subsidyParentTypebox.fontstring:SetTextColor(0.95, 0.95, 0.95, 1)
            f.subsidyParentTypebox:Disable()
            f.subsidyParentTypebox:SetScript("OnEnter", function(self)
                OnEnter(self)
            end)
            f.subsidyParentTypebox:SetScript("OnLeave", function(self)
                OnLeave(self)
            end)
            f.subsidyParentTypebox:SetScript("OnMouseDown", function (self, button)
                if button == "LeftButton" then
                    local function tempfunc()
                        local menuList = {}
                        local subsidyParentName = f.subsidyName
                        if subsidyParentName and subsidyChildrenList[subsidyParentName] 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"]
                            for _, subsidyName in ipairs(subsidyChildrenList[subsidyParentName]) do
                                local subsidyNameGsub = subsidyName:gsub("%d+", "")
                                if subsidyName == "主T" or subsidyName == "副T" or subsidyName == "双休T" then
                                    subsidyNameGsub = "T"
                                end
                                local icon = subsidyTypeFunc[subsidyNameGsub].icon or "|T:13|t"
                                tinsert(menuList, {
                                    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
                                            end
                                        end
                                        SubsidyFrame:Update()
                                    end,
                                })
                            end
                        end
                        return menuList
                    end
                    local menuList = tempfunc()
                    if #menuList > 0 then
                        ZL.GUI:ToggleMenu(self, menuList, "TOPLEFT", self, "BOTTOMRIGHT", 0, 0)
                    end
                end
            end)

            f.singleParentMoneybox = CreateEditBox(f, singleMoneyWidth+20, lineHeight, 13, "CENTER", nil, nil, board_r, board_g, board_b, board_a)
            f.singleParentMoneybox:SetPoint("LEFT", f.subsidyParentTypebox, "RIGHT", 0, 0)
            f.singleParentMoneybox.Background:SetColorTexture(0,0,0,0)
            f.singleParentMoneybox.fontstring = f.singleParentMoneybox:CreateFontString(nil, "OVERLAY")
            f.singleParentMoneybox.fontstring:SetPoint("TOPLEFT", 3, -1)
            f.singleParentMoneybox.fontstring:SetPoint("BOTTOMRIGHT", -3, 1)
            f.singleParentMoneybox.fontstring:SetFont(GameFontNormal:GetFont(), 13, "OUTLINE")
            f.singleParentMoneybox.fontstring:SetWordWrap(false)
            f.singleParentMoneybox.fontstring:SetJustifyH("RIGHT")
            f.singleParentMoneybox.fontstring:SetTextColor(0.95, 0.95, 0.95, 1)
            f.singleParentMoneybox:SetScript("OnEnter", function(self)
                OnEnter(self)
                if f.subsidyName then
                    if f.subsidyName == "RL补贴" then
                        subsidyTypeFunc["RL"].toolTip(self)
                    else
                        GameTooltipShow(self, "BOTTOMLEFT", "TOPRIGHT")
                        GameTooltip:AddLine("输入|cff4080FF不小于0的数|r")
                        GameTooltip:AddLine("支持鼠标滚轮快速输入数字")
                        GameTooltip:AddLine("输入后按|cff4080FFEnter|r或|cff4080FF右键|r保存！")
                        GameTooltip:Show()
                    end
                end
            end)
            f.singleParentMoneybox:SetScript("OnLeave", function(self)
                OnLeave(self)
                GameTooltip:Hide()
            end)
            f.singleParentMoneybox:SetScript("OnEditFocusGained", function (self)
                self.fontstring:Hide()
                local profileName = ZL.opt.subsidyProfileList["profileKeys"][ZL.opt.subsidyProfileSelect]
                local subsidyParentData = ZL.opt.subsidyProfileList["profile"][profileName]["parent"]
                local subsidyParentName = f.subsidyName
                if subsidyParentName == "RL补贴" then
                    local subsidyData = ZL.opt.subsidyProfileList["profile"][profileName]["child"]
                    self:SetText(subsidyData["RL"])
                else
                    self:SetText(subsidyParentData[subsidyParentName])
                end
                self:HighlightText()
            end)
            f.singleParentMoneybox:SetScript("OnEditFocusLost", function (self)
                self.fontstring:Show()
                local profileName = ZL.opt.subsidyProfileList["profileKeys"][ZL.opt.subsidyProfileSelect]
                local subsidyParentData = ZL.opt.subsidyProfileList["profile"][profileName]["parent"]
                local subsidyParentName = f.subsidyName
                if subsidyParentName == "RL补贴" then
                    local _, RLBuTie = ZL.GetAveWages()
                    local subsidyData = ZL.opt.subsidyProfileList["profile"][profileName]["child"]
                    local subsidyMoney = subsidyData["RL"]
                    local text
                    if subsidyMoney == "团双" then
                        text = "团双：" .. (ZL_CURRENT["aveWages"] or 0)
                    elseif type(subsidyMoney) == "string" and subsidyMoney:match("%d+%%") then --RL提成
                        text = subsidyMoney:match("%d+%%") .. "：" .. (RLBuTie or 0)
                    else
                        text = "固定：" .. subsidyMoney
                    end
                    self.fontstring:SetText(text)
                else
                    self.fontstring:SetText(subsidyParentData[subsidyParentName])
                end
                self:SetText("")
                self:HighlightText(0, 0)
            end)
            f.singleParentMoneybox:SetScript("OnMouseWheel", function(self, delta)
                if self:HasFocus() then
                    local number = self:GetNumber()
                    if delta > 0 then
                        number = number + 100
                    else
                        number = number - 100
                    end
                    if number < 0 then
                        number = 0
                    end
                    self:SetNumber(number)
                end
            end)
            local function singleParentMoneyboxTextChanged(self)
                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 = self:GetParent().subsidyName
                local text = self:GetText()
                if text and #text > 0 then
                    local subsidyMoney
                    if subsidyName == "RL补贴" then
                        subsidyMoney = text:match("(团双)")
                        if not subsidyMoney then
                            subsidyMoney = text:match("(%d+%%)")
                            if not subsidyMoney then
                                subsidyMoney = tonumber(text:match("^(%d+)$"))
                            end
                        end
                        subsidyMoney = subsidyMoney or 0
                    else
                        subsidyMoney = self:GetNumber()
                    end
                    if subsidyName == "RL补贴" then
                        subsidyData["RL"] = subsidyMoney
                    else
                        subsidyParentData[subsidyName] = subsidyMoney
                    end
                end
                self:ClearFocus()
                ZL.SubsidyFrame:Update()
            end
            f.singleParentMoneybox:SetScript("OnEnterPressed", function (self)
                singleParentMoneyboxTextChanged(self)
            end)
            f.singleParentMoneybox:SetScript("OnMouseDown", function (self, button)
                if button == "RightButton" and self:HasFocus() then
                    C_Timer.After(0.5, function ()
                        singleParentMoneyboxTextChanged(self)
                    end)
                elseif button == "LeftButton" then
                    local subsidyParentName = f.subsidyName
                    if subsidyParentName and subsidyParentName == "RL补贴" then
                        subsidyTypeFunc["RL"].OnLeftButtonMouseDown(self)
                    end
                end
            end)

            f.totalChildMoneybox = CreateEditBox(f, singleMoneyWidth+20, lineHeight, 13, "CENTER", nil, nil, board_r, board_g, board_b, board_a)
            f.totalChildMoneybox:SetPoint("LEFT", f.singleParentMoneybox, "RIGHT", 0, 0)
            f.totalChildMoneybox.Background:SetColorTexture(0,0,0,0)
            f.totalChildMoneybox.fontstring = f.totalChildMoneybox:CreateFontString(nil, "OVERLAY")
            f.totalChildMoneybox.fontstring:SetPoint("TOPLEFT", 3, -1)
            f.totalChildMoneybox.fontstring:SetPoint("BOTTOMRIGHT", -3, 1)
            f.totalChildMoneybox.fontstring:SetFont(GameFontNormal:GetFont(), 13, "OUTLINE")
            f.totalChildMoneybox.fontstring:SetWordWrap(false)
            f.totalChildMoneybox.fontstring:SetJustifyH("RIGHT")
            f.totalChildMoneybox.fontstring:SetJustifyV("MIDDLE")
            f.totalChildMoneybox.fontstring:SetTextColor(0.95, 0.95, 0.95, 1)
            f.totalChildMoneybox:Disable()
            f.totalChildMoneybox:SetScript("OnEnter", function(self)
                OnEnter(self)
            end)
            f.totalChildMoneybox:SetScript("OnLeave", function(self)
                OnLeave(self)
            end)

            f.moneyCheckbox = CreateEditBox(f, 50, lineHeight, 13, "CENTER", nil, nil, board_r, board_g, board_b, board_a)
            f.moneyCheckbox:SetPoint("LEFT", f.totalChildMoneybox, "RIGHT", 0, 0)
            f.moneyCheckbox.Background:SetColorTexture(0,0,0,0)
            f.moneyCheckbox.fontstring = f.moneyCheckbox:CreateFontString(nil, "OVERLAY")
            f.moneyCheckbox.fontstring:SetPoint("TOPLEFT", 3, -1)
            f.moneyCheckbox.fontstring:SetPoint("BOTTOMRIGHT", -3, 1)
            f.moneyCheckbox.fontstring:SetFont(GameFontNormal:GetFont(), 13, "OUTLINE")
            f.moneyCheckbox.fontstring:SetWordWrap(false)
            f.moneyCheckbox.fontstring:SetJustifyH("CENTER")
            f.moneyCheckbox.fontstring:SetJustifyV("MIDDLE")
            f.moneyCheckbox.fontstring:SetTextColor(0.95, 0.95, 0.95, 1)
            f.moneyCheckbox:Disable()
            f.moneyCheckbox:SetScript("OnEnter", function(self)
                OnEnter(self)
            end)
            f.moneyCheckbox:SetScript("OnLeave", function(self)
                OnLeave(self)
            end)

            f.delBtn = CreateButton(nil, f, "-", "LEFT", f.moneyCheckbox, "RIGHT", 0, 0, delWidth, lineHeight)
            f.delBtn:SetScript("OnEnter", function(self)
                OnEnter(self)
            end)
            f.delBtn:SetScript("OnLeave", function(self)
                OnLeave(self)
            end)
            f.delBtn:SetScript("OnClick", function (self)
                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.subsidyName
                subsidyParentData[subsidyParentName] = nil
                if ZL_CURRENT.subsidyParent then
                    ZL_CURRENT.subsidyParent[subsidyParentName] = nil
                end
                for _, subsidyName in ipairs(subsidyChildrenList[subsidyParentName]) do
                    subsidyData[subsidyName] = nil
                    if ZL_CURRENT.subsidy then
                        ZL_CURRENT.subsidy[subsidyName] = nil
                    end
                end
                SubsidyFrame:Update()
            end)
            t[v] = f
            return f
        end
    })
    SubsidyFrame.entries = setmetatable({}, {
        __index = function (t, v)
            local f = CreateFrame("Button", nil, content)
            f:Hide()
            f:SetSize(totalWidth-26, lineHeight)
            if v == 1 then
                f:SetPoint("TOPLEFT", subsidyTypeBtn, "BOTTOMLEFT", 0, -1)
            else
                f:SetPoint("TOPLEFT", t[v-1], "BOTTOMLEFT")
            end
            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)
                self:SetNormalTexture("Interface\\FriendsFrame\\UI-FriendsFrame-HighlightBar")
            end)
            f:SetScript("OnLeave", function (self)
                self:ClearNormalTexture()
            end)
            f.subsidyTypebox = CreateEditBox(f, subsidyTypeWidth, lineHeight, 13, "CENTER", nil, nil, board_r, board_g, board_b, board_a, "SubsidyFrameSubsidyTypeAddBoxChild" .. v)
            f.subsidyTypebox:SetPoint("LEFT", f, "LEFT", 0, 0)
            f.subsidyTypebox.Background:SetColorTexture(0,0,0,0)
            f.subsidyTypebox.fontstring = f.subsidyTypebox:CreateFontString(nil, "OVERLAY")
            f.subsidyTypebox.fontstring:SetPoint("TOPLEFT", 3, -1)
            f.subsidyTypebox.fontstring:SetPoint("BOTTOMRIGHT", -3, 1)
            f.subsidyTypebox.fontstring:SetFont(GameFontNormal:GetFont(), 13, "OUTLINE")
            f.subsidyTypebox.fontstring:SetWordWrap(false)
            f.subsidyTypebox.fontstring:SetJustifyH("LEFT")
            f.subsidyTypebox.fontstring:SetJustifyV("MIDDLE")
            f.subsidyTypebox.fontstring:SetTextColor(0.95, 0.95, 0.95, 1)
            f.subsidyTypebox:Disable()
            f.subsidyTypebox:SetScript("OnEnter", function(self)
                OnEnter(self)
            end)
            f.subsidyTypebox:SetScript("OnLeave", function(self)
                OnLeave(self)
            end)

            f.singleMoneybox = CreateEditBox(f, singleMoneyWidth, lineHeight, 13, "CENTER", nil, nil, board_r, board_g, board_b, board_a, "SubsidyFrameSingleMoneyAddBoxChild" .. v)
            f.singleMoneybox:SetPoint("LEFT", f.subsidyTypebox, "RIGHT", 0, 0)
            f.singleMoneybox.Background:SetColorTexture(0,0,0,0)
            f.singleMoneybox.fontstring = f.singleMoneybox:CreateFontString(nil, "OVERLAY")
            f.singleMoneybox.fontstring:SetPoint("TOPLEFT", 3, -1)
            f.singleMoneybox.fontstring:SetPoint("BOTTOMRIGHT", -3, 1)
            f.singleMoneybox.fontstring:SetFont(GameFontNormal:GetFont(), 13, "OUTLINE")
            f.singleMoneybox.fontstring:SetWordWrap(false)
            f.singleMoneybox.fontstring:SetJustifyH("RIGHT")
            f.singleMoneybox.fontstring:SetTextColor(0.95, 0.95, 0.95, 1)
            f.singleMoneybox:SetScript("OnLeave", function(self)
                OnLeave(self)
                GameTooltip:Hide()
            end)
            f.singleMoneybox:SetScript("OnEditFocusGained", function (self)
                self.fontstring:Hide()
                local profileName = ZL.opt.subsidyProfileList["profileKeys"][ZL.opt.subsidyProfileSelect]
                local subsidyData = ZL.opt.subsidyProfileList["profile"][profileName]["child"]
                local subsidyName = f.subsidyName
                self:SetText(subsidyData[subsidyName])
                self:HighlightText()
            end)
            f.singleMoneybox:SetScript("OnEditFocusLost", function (self)
                self.fontstring:Show()
                local profileName = ZL.opt.subsidyProfileList["profileKeys"][ZL.opt.subsidyProfileSelect]
                local subsidyData = ZL.opt.subsidyProfileList["profile"][profileName]["child"]
                local subsidyName = f.subsidyName
                self.fontstring:SetText(subsidyData[subsidyName])
                self:SetText("")
                self:HighlightText(0, 0)
            end)
            f.singleMoneybox:SetScript("OnMouseWheel", function(self, delta)
                if self:HasFocus() then
                    local number = self:GetNumber()
                    if delta > 0 then
                        number = number + 100
                    else
                        number = number - 100
                    end
                    if number < 0 then
                        number = 0
                    end
                    self:SetNumber(number)
                end
            end)
            f.singleMoneybox:SetScript("OnEnterPressed", function (self)
                singleMoneyboxTextChanged(self)
            end)

            f.meetMembersbox = CreateEditBox(f, meetMembersWidth, lineHeight, 13, "CENTER", nil, nil, board_r, board_g, board_b, board_a, "SubsidyFramemeetMembersAddBoxChild" .. v)
            f.meetMembersbox:SetPoint("LEFT", f.singleMoneybox, "RIGHT", 0, 0)
            f.meetMembersbox.Background:SetColorTexture(0,0,0,0)
            f.meetMembersbox.fontstring = f.meetMembersbox:CreateFontString(nil, "OVERLAY")
            f.meetMembersbox.fontstring:SetPoint("TOPLEFT", 3, -1)
            f.meetMembersbox.fontstring:SetPoint("BOTTOMRIGHT", -3, 1)
            f.meetMembersbox.fontstring:SetFont(GameFontNormal:GetFont(), 13, "OUTLINE")
            f.meetMembersbox.fontstring:SetWordWrap(false)
            f.meetMembersbox.fontstring:SetJustifyH("RIGHT")
            f.meetMembersbox.fontstring:SetJustifyV("MIDDLE")
            f.meetMembersbox.fontstring:SetTextColor(0.95, 0.95, 0.95, 1)
            f.meetMembersbox:Disable()
            f.meetMembersbox:SetScript("OnEnter", function(self)
                OnEnter(self)
            end)
            f.meetMembersbox:SetScript("OnLeave", function(self)
                OnLeave(self)
            end)

            f.actualMembersbox = CreateEditBox(f, actualMembersWidth, lineHeight, 12, "CENTER", nil, nil, board_r, board_g, board_b, board_a, "SubsidyFrameactualMembersAddBoxChild" .. v)
            f.actualMembersbox:SetPoint("LEFT", f.meetMembersbox, "RIGHT", 0, 0)
            f.actualMembersbox.Background:SetColorTexture(0,0,0,0)
            f.actualMembersbox.fontstring = f.actualMembersbox:CreateFontString(nil, "OVERLAY")
            f.actualMembersbox.fontstring:SetPoint("TOPLEFT", 3, -1)
            f.actualMembersbox.fontstring:SetPoint("BOTTOMRIGHT", -3, 1)
            f.actualMembersbox.fontstring:SetFont(GameFontNormal:GetFont(), 13, "OUTLINE")
            f.actualMembersbox.fontstring:SetWordWrap(false)
            f.actualMembersbox.fontstring:SetJustifyH("RIGHT")
            f.actualMembersbox.fontstring:SetJustifyV("MIDDLE")
            f.actualMembersbox.fontstring:SetTextColor(0.95, 0.95, 0.95, 1)
            f.actualMembersbox:Disable()
            f.actualMembersbox:SetScript("OnEnter", function(self)
                OnEnter(self)
            end)
            f.actualMembersbox:SetScript("OnLeave", function(self)
                OnLeave(self)
            end)

            f.totalMoneybox = CreateEditBox(f, totalMoneyWidth, lineHeight, 12, "CENTER", true, nil, board_r, board_g, board_b, board_a, "SubsidyFrameTotalMoneyAddBoxChild" .. v)
            f.totalMoneybox:SetPoint("LEFT", f.actualMembersbox, "RIGHT", 0, 0)
            f.totalMoneybox.Background:SetColorTexture(0,0,0,0)
            f.totalMoneybox.fontstring = f.totalMoneybox:CreateFontString(nil, "OVERLAY")
            f.totalMoneybox.fontstring:SetPoint("TOPLEFT", 3, -1)
            f.totalMoneybox.fontstring:SetPoint("BOTTOMRIGHT", -3, 1)
            f.totalMoneybox.fontstring:SetFont(GameFontNormal:GetFont(), 13, "OUTLINE")
            f.totalMoneybox.fontstring:SetWordWrap(false)
            f.totalMoneybox.fontstring:SetJustifyH("RIGHT")
            f.totalMoneybox.fontstring:SetTextColor(0.95, 0.95, 0.95, 1)
            f.totalMoneybox:Disable()
            f.totalMoneybox:SetScript("OnEnter", function(self)
                OnEnter(self)
            end)
            f.totalMoneybox:SetScript("OnLeave", function(self)
                OnLeave(self)
            end)
            --设置TAB事件
            do
                local editboxList = {"SubsidyFrameSubsidyTypeAddBoxChild" .. v, "SubsidyFrameSingleMoneyAddBoxChild" .. v, "SubsidyFrameTotalMoneyAddBoxChild" .. v}
                local function OnTabPressed(self)
                    EditBox_HandleTabbing(self, editboxList)
                end
                f.subsidyTypebox:SetScript("OnTabPressed", OnTabPressed)
                f.singleMoneybox:SetScript("OnTabPressed", OnTabPressed)
                f.totalMoneybox:SetScript("OnTabPressed", OnTabPressed)
            end

            f.delBtn = CreateButton(nil, f, "-", "LEFT", f.totalMoneybox, "RIGHT", 0, 0, delWidth, lineHeight)
            f.delBtn:SetScript("OnEnter", function(self)
                OnEnter(self)
            end)
            f.delBtn:SetScript("OnLeave", function(self)
                OnLeave(self)
            end)
            f.delBtn:SetScript("OnClick", function (self)
                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"]
                subsidyData[f.subsidyName] = nil
                if ZL_CURRENT.subsidy then
                    ZL_CURRENT.subsidy[f.subsidyName] = nil
                end
                if f.subsidyName == "RL" then
                    subsidyParentData["RL补贴"] = nil
                    if ZL_CURRENT.subsidyParent then
                        ZL_CURRENT.subsidyParent["RL补贴"] = nil
                    end
                end
                SubsidyFrame:Update()
            end)

            t[v] = f
            return f
        end
    })
    function SubsidyFrame:Update()
        for _, f in ipairs(SubsidyFrame.entries) do f:Hide() end
        for _, f in ipairs(SubsidyFrame.parentEntries) do f:Hide() end
        local _, RLBuTie = ZL.GetAveWages()
        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 totalParentMoney = 0
        local totalChildMoney = 0
        local index2 = 1
        for _, subsidyParentName in ipairs(subsidyParentTypeList) do
            local subsidyParentMoney = subsidyParentData[subsidyParentName]
            local singleParentMoneyboxText = subsidyParentMoney
            if subsidyParentName == "RL补贴" and subsidyData["RL"] then
                local subsidyMoney = subsidyData["RL"]
                if subsidyMoney == "团双" then
                    subsidyParentMoney = ZL_CURRENT["aveWages"] or 0
                    singleParentMoneyboxText = "团双：" .. subsidyParentMoney
                elseif type(subsidyMoney) == "string" and subsidyMoney:match("%d+%%") then --RL提成
                    subsidyParentMoney = RLBuTie or 0
                    singleParentMoneyboxText = subsidyMoney:match("%d+%%") .. "：" .. subsidyParentMoney
                else
                    subsidyParentMoney = subsidyMoney
                    singleParentMoneyboxText = "固定：" .. subsidyParentMoney
                end
            end
            if subsidyParentMoney then
                totalParentMoney = totalParentMoney + subsidyParentMoney
                local childMoney = (ZL_CURRENT.subsidyParent and ZL_CURRENT.subsidyParent[subsidyParentName]) and ZL_CURRENT.subsidyParent[subsidyParentName] or 0
                totalChildMoney = totalChildMoney + childMoney
                local f = SubsidyFrame.parentEntries[index2]
                f.subsidyName = subsidyParentName
                f.subsidyMoney = subsidyParentMoney
                f.singleParentMoneybox.Background:SetColorTexture(0.78,0.93,0.8,0.1)
                f.subsidyParentTypebox.fontstring:SetText(subsidyParentName)
                f.singleParentMoneybox:Enable()
                f.singleParentMoneybox.fontstring:SetText(singleParentMoneyboxText)
                f.totalChildMoneybox.fontstring:SetText(childMoney)
                if subsidyParentMoney == 0 or childMoney == 0 then
                    f.moneyCheckbox.fontstring:SetText("|T136815:13:0:0|t")
                elseif subsidyParentMoney == childMoney then
                    f.moneyCheckbox.fontstring:SetText("|T136814:13:0:0|t")
                else
                    f.moneyCheckbox.fontstring:SetText("|T136813:13:0:0|t")
                end
                f.delBtn:Enable()
                f:Show()
                index2 = index2 + 1
            end
        end
        if index2 > 1 then
            local f = SubsidyFrame.parentEntries[index2]
            f.singleParentMoneybox:Disable()
            f.singleParentMoneybox.Background:SetColorTexture(0,0,0,0)
            f.subsidyParentTypebox.fontstring:SetText("|cfff58cba合计|r")
            f.singleParentMoneybox.fontstring:SetText("|cfff58cba" .. totalParentMoney .. "|r")
            f.totalChildMoneybox.fontstring:SetText("|cff4080FF" .. totalChildMoney .. "|r")
            if totalParentMoney == 0 or totalChildMoney == 0 then
                f.moneyCheckbox.fontstring:SetText("|T136815:13:0:0|t")
            elseif totalParentMoney == totalChildMoney then
                f.moneyCheckbox.fontstring:SetText("|T136814:13:0:0|t")
            else
                f.moneyCheckbox.fontstring:SetText("|T136813:13:0:0|t")
            end
            f.delBtn:Disable()
            f:Show()
        end

        subsidyTypeBtn:ClearAllPoints()
        subsidyTypeBtn:SetPoint("TOPLEFT", subsidyParentTypeBtn, "BOTTOMLEFT", 0, -index2*lineHeight-11)
        local index = 1
        for _, subsidyName in ipairs(subsidyTypeList) do
            local subsidyMoney = subsidyData[subsidyName]
            if subsidyMoney then
                local f = SubsidyFrame.entries[index]
                f.subsidyName = subsidyName
                f.subsidyMoney = subsidyMoney
                local subsidyNameGsub = subsidyName:gsub("%d+", "")
                if subsidyName == "主T" or subsidyName == "副T" then
                    subsidyNameGsub = "T"
                end
                local icon = subsidyTypeFunc[subsidyNameGsub].icon or "|T:13|t"
                f.subsidyTypebox.fontstring:SetText(icon .. subsidyName)
                f.singleMoneybox.Background:SetColorTexture(0.78,0.93,0.8,0.1)
                f.singleMoneybox.fontstring:SetText(subsidyMoney)
                if subsidyName == "RL" then
                    f.singleMoneybox:SetScript("OnMouseDown", function (self, button)
                        if button == "RightButton" and self:HasFocus() then
                            C_Timer.After(0.5, function ()
                                singleMoneyboxTextChanged(self)
                            end)
                        elseif button == "LeftButton" then
                            subsidyTypeFunc[subsidyName].OnLeftButtonMouseDown(self)
                        end
                    end)
                else
                    f.singleMoneybox:SetScript("OnMouseDown", function (self, button)
                        if button == "RightButton"  and self:HasFocus() then
                            C_Timer.After(0.5, function ()
                                singleMoneyboxTextChanged(self)
                            end)
                        end
                    end)
                end
                if subsidyTypeFunc[subsidyNameGsub].OnLeftButtonMouseDown then
                    f.meetMembersbox:SetScript("OnMouseDown", function (self, button)
                        if button == "LeftButton" then
                            subsidyTypeFunc[subsidyNameGsub].OnLeftButtonMouseDown(self)
                        end
                    end)
                else
                    f.meetMembersbox:SetScript("OnMouseDown", function (self, button)
                        if button == "LeftButton" then
                            local function tempfunc(self)
                                local menuList = {}
                                local WagesGroupMembers = ZL.GetWagesGroupMembers()
                                if WagesGroupMembers then
                                    for _, data in ipairs(WagesGroupMembers) do
                                        for _, colorName in ipairs(data) do
                                            local name = ParseClassColorName(colorName)
                                            if name and ZL.opt.playerInfo and ZL.opt.playerInfo[name]
                                            and ZL.opt.playerInfo[name][subsidyNameGsub] then
                                                tinsert(menuList, {
                                                    text = function ()
                                                        local text = colorName
                                                        if ZL.opt.playerInfo[name]["DPS"] and ZL.opt.playerInfo[name]["N"] then
                                                            text = text .. "(双休)"
                                                        elseif ZL.opt.playerInfo[name]["DPS"] and ZL.opt.playerInfo[name]["T"] then
                                                            text = text .. "(双休T)"
                                                        end
                                                        return text
                                                    end,
                                                    checkable = 1,
                                                    isNotRadio = 1,
                                                    keepShownOnClick = 1,
                                                    checked = ZL_CURRENT.subsidy and ZL_CURRENT.subsidy[subsidyName] and ZL_CURRENT.subsidy[subsidyName][colorName],
                                                    func = function ()
                                                        ZL_CURRENT.subsidy = ZL_CURRENT.subsidy or {}
                                                        ZL_CURRENT.subsidy[subsidyName] = ZL_CURRENT.subsidy[subsidyName] or {}
                                                        if ZL_CURRENT.subsidy[subsidyName][colorName] then
                                                            ZL_CURRENT.subsidy[subsidyName][colorName] = nil
                                                        else
                                                            ZL_CURRENT.subsidy[subsidyName][colorName] = true
                                                        end
                                                        ZL.GUI:OpenMenu(self, tempfunc(self), 'TOPLEFT', self, 'BOTTOMRIGHT', 0, 0)
                                                        SubsidyFrame:Update()
                                                    end,
                                                })
                                            end
                                        end
                                    end
                                end
                                if #menuList > 0 then
                                    tinsert(menuList, 1, {
                                        text = icon .. subsidyName .. "：",
                                        isTitle = true,
                                    })
                                else
                                    tinsert(menuList, {
                                        text = "没有数据",
                                        isTitle = true,
                                    })
                                end
                                return menuList
                            end
                            ZL.GUI:ToggleMenu(self, tempfunc(self), 'TOPLEFT', self, 'BOTTOMRIGHT', 0, 0)
                        end
                    end)
                end
                f.actualMembersbox:SetScript("OnMouseDown", f.meetMembersbox:GetScript("OnMouseDown"))
                if subsidyTypeFunc[subsidyNameGsub].toolTip then
                    f.singleMoneybox:SetScript("OnEnter", function (self)
                        OnEnter(self)
                        subsidyTypeFunc[subsidyNameGsub].toolTip(self)
                    end)
                else
                    f.singleMoneybox:SetScript("OnEnter", function (self)
                        OnEnter(self)
                        GameTooltipShow(self, "BOTTOMLEFT", "TOPRIGHT")
                        GameTooltip:AddLine("输入|cff4080FF不小于0的数|r")
                        GameTooltip:AddLine("支持鼠标滚轮快速输入数字")
                        GameTooltip:AddLine("输入后按|cff4080FFEnter|r或|cff4080FF右键|r保存！")
                        GameTooltip:Show()
                    end)
                end
                local subsidyNameNumbers = 0
                local subsidyNameActualNumbers = 0
                local WagesGroupMembers, _, _, RL = ZL.GetWagesGroupMembers()
                if WagesGroupMembers then
                    if subsidyName == "RL" then
                        if RL then
                            subsidyNameNumbers = subsidyNameNumbers + 1
                        end
                    elseif subsidyName == "修星" then
                        for _, data in ipairs(WagesGroupMembers) do
                            for _, colorName in ipairs(data) do
                                local name = ParseClassColorName(colorName)
                                if name and ZL.opt.playerInfo and ZL.opt.playerInfo[name]
                                and ZL.opt.playerInfo[name]["DPS"] then
                                    subsidyNameNumbers = subsidyNameNumbers + 1
                                end
                            end
                        end
                    elseif subsidyName == "其它" then
                        for _, data in ipairs(WagesGroupMembers) do
                            for _, colorName in ipairs(data) do
                                local name = ParseClassColorName(colorName)
                                if name then
                                    subsidyNameNumbers = subsidyNameNumbers + 1
                                end
                            end
                        end
                    else
                        if ZL.opt.playerInfo then
                            for playerName, data in pairs(ZL.opt.playerInfo) do
                                local isExist
                                local isBreak
                                for _, _data in ipairs(WagesGroupMembers) do
                                    for _, colorName in ipairs(_data) do
                                        local name = ParseClassColorName(colorName)
                                        if name == playerName then
                                            isExist = true
                                            isBreak = true
                                            break
                                        end
                                    end
                                    if isBreak then break end
                                end
                                if isExist and data[subsidyNameGsub] then
                                    subsidyNameNumbers = subsidyNameNumbers + 1
                                end
                            end
                        end
                    end
                    if ZL_CURRENT.subsidy and ZL_CURRENT.subsidy[subsidyName] then
                        for playerName in pairs(ZL_CURRENT.subsidy[subsidyName]) do
                            local isExist
                            local isBreak
                            for _, _data in ipairs(WagesGroupMembers) do
                                for _, colorName in ipairs(_data) do
                                    if playerName == colorName then
                                        isExist = true
                                        isBreak = true
                                        break
                                    end
                                end
                                if isBreak then break end
                            end
                            if isExist then
                                subsidyNameActualNumbers = subsidyNameActualNumbers + 1
                            end
                        end
                    end
                end
                f.meetMembersbox.fontstring:SetText(subsidyNameNumbers)
                f.actualMembersbox.fontstring:SetText(subsidyNameActualNumbers)
                if subsidyNameActualNumbers > 0 then
                    if subsidyMoney == "团双" then
                        f.totalMoneybox.fontstring:SetText(ZL_CURRENT["aveWages"] or 0)
                    elseif type(subsidyMoney) == "string" and subsidyMoney:match("%d+%%") then --RL提成
                        f.totalMoneybox.fontstring:SetText(RLBuTie)
                    else
                        f.totalMoneybox.fontstring:SetText(subsidyNameActualNumbers*subsidyMoney)
                    end
                else
                    f.totalMoneybox.fontstring:SetText(0)
                end
                f:Show()
                index = index + 1
            end
        end
        if ZL.opt.autoInputSubsidy then
            ZL.inputSubsidy()
        end
    end

    SubsidyFrame:RegisterEvent("PLAYER_ENTERING_WORLD")
    SubsidyFrame:RegisterEvent("COMBAT_LOG_EVENT_UNFILTERED")
    SubsidyFrame:RegisterEvent("INSPECT_READY")
    SubsidyFrame:SetScript("OnEvent", function (self, event, ...)
        local arg = ZL.emptytable(...)
        if event == "COMBAT_LOG_EVENT_UNFILTERED" then
            if IsInRaid(1) and IsInInstance() and (select(2, IsInInstance()) == "raid") then -- and IsInInstance() and (select(2, IsInInstance()) == "raid")
                local _, subevent, _, sourceGUID, _, _, _, _, _, _, _, spellId = CombatLogGetCurrentEventInfo()
                if subevent == "SPELL_CAST_SUCCESS" then
                    if spellId == 57426 or spellId == 57301 or spellId == 22700 or spellId == 443894 or spellId == 67826 then -- or spellId == 48168
                        local _, englishClass, _, _, _, playerName = GetPlayerInfoByGUID(sourceGUID)
                        local colorPlayerName = GetClassColorName(playerName, englishClass)
                        ZL.opt.playerInfo = ZL.opt.playerInfo or {}
                        ZL.opt.playerInfo[playerName] = ZL.opt.playerInfo[playerName] or {}
                        ZL.opt.playerInfo[playerName].classFile = englishClass
                        ZL.opt.playerInfo[playerName].colorName = colorPlayerName
                        ZL_CURRENT.subsidyFoodFirst = ZL_CURRENT.subsidyFoodFirst or sourceGUID
                        local msgStr, msgStr2
                        if spellId == 57426 then -- or spellId == 48168 
                            ZL.opt.playerInfo[playerName]["鱼"] = true
                            ZL.opt.playerInfo[playerName].fishCount = (ZL.opt.playerInfo[playerName].fishCount or 0) + 1
                            ZL_CURRENT.subsidyFishFirst = ZL_CURRENT.subsidyFishFirst or playerName
                            msgStr = format(
                                ">>>%s<<<释放了%s，记录次数%d，请文明就餐，不要遮挡。",
                                playerName, GetSpellLink(spellId), ZL.opt.playerInfo[playerName].fishCount
                            )
                            msgStr2 = format(
                                ">>>%s<<<释放了%s，记录次数%d，请文明就餐，不要遮挡。",
                                colorPlayerName, GetSpellLink(spellId), ZL.opt.playerInfo[playerName].fishCount
                            )
                        elseif spellId == 57301 then
                            ZL.opt.playerInfo[playerName]["猪"] = true
                            ZL.opt.playerInfo[playerName].pigCount = (ZL.opt.playerInfo[playerName].pigCount or 0) + 1
                            ZL_CURRENT.subsidyPigFirst = ZL_CURRENT.subsidyPigFirst or playerName
                            msgStr = format(
                                ">>>%s<<<释放了%s，记录次数%d，请文明就餐，不要遮挡。",
                                playerName, GetSpellLink(spellId), ZL.opt.playerInfo[playerName].pigCount
                            )
                            msgStr2 = format(
                                ">>>%s<<<释放了%s，记录次数%d，请文明就餐，不要遮挡。",
                                colorPlayerName, GetSpellLink(spellId), ZL.opt.playerInfo[playerName].fishCount
                            )
                        elseif spellId == 22700 or spellId == 44389 then
                            ZL.opt.playerInfo[playerName]["修理机器人"] = true
                            ZL.opt.playerInfo[playerName].xiuLiCount = (ZL.opt.playerInfo[playerName].xiuLiCount or 0) + 1
                            ZL_CURRENT.subsidyXiuLiFirst = ZL_CURRENT.subsidyXiuLiFirst or playerName
                            msgStr = format(
                                ">>>%s<<<释放了%s，记录次数%d，有需要修理的尽快修理。",
                                playerName, GetSpellLink(spellId), ZL.opt.playerInfo[playerName].xiuLiCount
                            )
                            msgStr2 = format(
                                ">>>%s<<<释放了%s，记录次数%d，有需要修理的尽快修理。",
                                colorPlayerName, GetSpellLink(spellId), ZL.opt.playerInfo[playerName].xiuLiCount
                            )
                        elseif spellId == 67826 then --基维斯
                            msgStr = format(">>>%s<<<释放了%s，请及时修理和补充材料。", playerName, GetSpellLink(spellId))
                            msgStr2 = format(">>>%s<<<释放了%s，请及时修理和补充材料。", colorPlayerName, GetSpellLink(spellId))
                        end
                        local reporter
                        if ZL_PLAYERLIST.autoNotice and next(ZL_PLAYERLIST.autoNotice) then
                            local tempList = {}
                            for i = 1, MAX_RAID_MEMBERS do
                                local name, _, _, _, _, _, _, online = GetRaidRosterInfo(i)
                                if name and online and ZL_PLAYERLIST.autoNotice[name] and ZL_PLAYERLIST.autoNotice[name].autoNoticeFoodInRaid then
                                    tinsert(tempList, name)
                                end
                            end
                            if #tempList > 1 then
                                table.sort(tempList, function (a, b)
                                    local aIsML = PlayerIsML(a)
                                    local bIsML = PlayerIsML(b)
                                    if aIsML and not bIsML then
                                        return true
                                    elseif not aIsML and bIsML then
                                        return false
                                    end
                                    local aIsLeader = UnitIsGroupLeader(a)
                                    local bIsLeader = UnitIsGroupLeader(b)
                                    if aIsLeader and not bIsLeader then
                                        return true
                                    elseif not aIsLeader and bIsLeader then
                                        return false
                                    end
                                    return a < b
                                end)
                            end
                            reporter = tempList[1]
                            tempList = nil
                        end
                        if reporter == UnitName("player") then
                            SendChatMessage("[AutoAuction]提醒：" .. msgStr, "RAID")
                            local _link = format("|cff87CEEB|Hgarrmission:%s:%s|h[%s]|h|r", "AutoAuction", "CLOSENOTICEFOOD", "关闭提醒")
                            ZL.Print(msgStr2 .. _link)
                        end
                    end
                end
                subevent = nil
                sourceGUID = nil
                spellId = nil
            end
        elseif event == "INSPECT_READY" then
            local _, englishClass, _, _, _, playerName = GetPlayerInfoByGUID(arg[1])
            if not (UnitInRaid(playerName) or UnitInParty(playerName)) then return end
            ZL.GetTalent(true, englishClass, playerName, true)
            local classID = select(3, UnitClass(playerName))
            ZL.opt.playerInfo[playerName].classID = classID
        elseif event == "PLAYER_ENTERING_WORLD" then
            if arg[1] or arg[2] then
                C_Timer.After(10, function ()
                    local i, interval = 1, 120
                    local name, online, _, fullName, istdInspectDB, isSync
                    local function temfunc()
                        if IsInRaid(1) or IsInGroup(1) then
                            name, _, _, _, _, _, _, online = GetRaidRosterInfo(i)
                            i = i + 1
                            i = i > MAX_RAID_MEMBERS and 1 or i
                            if name and online then
                                if canInspect(name) then
                                    NotifyInspect(name)
                                    sleep(1)
                                    temfunc()
                                elseif UnitIsGroupLeader("player") or PlayerIsML() then --只有团长和ML才检测天赋信息，防止过渡占用插件通信资源，其他成员可以通过手动刷新来获取
                                    fullName = ZL.GetFullName(name)
                                    istdInspectDB = nil
                                    ZL.opt.playerInfo = ZL.opt.playerInfo or {}
                                    ZL.opt.playerInfo[name] = ZL.opt.playerInfo[name] or {}
                                    --如果tdInspect插件存在更新的缓存数据，则直接读取
                                    if TDDB_INSPECT2 and TDDB_INSPECT2.global and TDDB_INSPECT2.global.userCache and TDDB_INSPECT2.global.userCache[fullName] and
                                    TDDB_INSPECT2.global.userCache[fullName].talents and (time() - TDDB_INSPECT2.global.userCache[fullName].timestamp <= interval) and
                                    (not (ZL.opt.playerInfo and ZL.opt.playerInfo[name] and ZL.opt.playerInfo[name].updateTimestamp) or (ZL.opt.playerInfo[name].updateTimestamp < TDDB_INSPECT2.global.userCache[fullName].timestamp)) then
                                        istdInspectDB = true
                                    else
                                        if (not (ZL.opt.playerInfo and ZL.opt.playerInfo[name] and ZL.opt.playerInfo[name].updateTimestamp)) or (time() - ZL.opt.playerInfo[name].updateTimestamp > interval) then
                                            if TDDB_INSPECT2 then
                                                --先用tdInspect插件通信，安装人数更多
                                                isSync = nil
                                                if TDDB_INSPECT2.global and TDDB_INSPECT2.global.userCache and TDDB_INSPECT2.global.userCache[fullName] and
                                                TDDB_INSPECT2.global.userCache[fullName].talents then
                                                    if time() - TDDB_INSPECT2.global.userCache[fullName].timestamp > interval then
                                                        isSync = true
                                                    end
                                                else
                                                    isSync = true
                                                end
                                                if isSync then
                                                    MyAddon:SendCommMessage("tdInspect", Serializer:Serialize('Q', true, true, 2, false, false), 'WHISPER', name)
                                                    sleep(1)
                                                    if TDDB_INSPECT2.global and TDDB_INSPECT2.global.userCache and TDDB_INSPECT2.global.userCache[fullName]
                                                    and TDDB_INSPECT2.global.userCache[fullName].talents and (time() - TDDB_INSPECT2.global.userCache[fullName].timestamp <= interval) then
                                                        istdInspectDB = true
                                                    end
                                                    if not istdInspectDB then
                                                        MyAddon:SendCommMessage("EMUCOM", '_q_tal', 'WHISPER', name)
                                                        sleep(1)
                                                        if TDDB_INSPECT2.global and TDDB_INSPECT2.global.userCache and TDDB_INSPECT2.global.userCache[fullName]
                                                        and TDDB_INSPECT2.global.userCache[fullName].talents and (time() - TDDB_INSPECT2.global.userCache[fullName].timestamp <= interval) then
                                                            istdInspectDB = true
                                                        end
                                                    end
                                                end
                                            end
                                            if not istdInspectDB then
                                                MyAddon:TransmitAddonInfo2("AUTOAUC TALENT", {type="talent"}, 'WHISPER', name)
                                                --不管是否能获取到天赋信息，每120秒都只检测一次
                                                ZL.opt.playerInfo[name].updateTimestamp = time()
                                            end
                                        end
                                    end
                                    if istdInspectDB then
                                        updateFromtdInspect(name)
                                    end
                                    temfunc()
                                end
                            else
                                sleep(0.1)
                                temfunc()
                            end
                        else
                            i = 1
                            sleep(10)
                            temfunc()
                        end
                    end
                    local co = coroutine.create(temfunc)
                    coroutine.resume(co)
                end)
            end
        end
        arg:Release()
    end)
end