local addonName, ZLAUTO = ...
local ZL = ZLAUTO.mainFrame
local background = ZL.background
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 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 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_CURRENT.playerInfo and ZL_CURRENT.playerInfo[name] and
                            ZL_CURRENT.playerInfo[name]["T"] and ZL_CURRENT.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_CURRENT.playerInfo and ZL_CURRENT.playerInfo[name]
                            and ZL_CURRENT.playerInfo[name][subsidyName] then
                                tinsert(menuList, {
                                    text = function ()
                                        local text = colorName
                                        if ZL_CURRENT.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_CURRENT.playerInfo and ZL_CURRENT.playerInfo[name]
                            and ZL_CURRENT.playerInfo[name][subsidyName] then
                                tinsert(menuList, {
                                    text = function ()
                                        local text = colorName .. " - " .. ZL_CURRENT.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_CURRENT.playerInfo and ZL_CURRENT.playerInfo[name]
                            and ZL_CURRENT.playerInfo[name][subsidyName] then
                                tinsert(menuList, {
                                    text = function ()
                                        local text = colorName .. " - " .. ZL_CURRENT.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_CURRENT.playerInfo and ZL_CURRENT.playerInfo[name]
                            and ZL_CURRENT.playerInfo[name][subsidyName] then
                                tinsert(menuList, {
                                    text = function ()
                                        local text = colorName .. " - " .. ZL_CURRENT.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_CURRENT.playerInfo and ZL_CURRENT.playerInfo[name] and
                            ZL_CURRENT.playerInfo[name]["N"] and ZL_CURRENT.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_CURRENT.playerInfo and ZL_CURRENT.playerInfo[name]
                            and ZL_CURRENT.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"},
    ["冰霜"] = {"DPS"},
    ["邪恶"] = {"DPS"},
    ["野性坦克"] = {"T"},
    ["野性输出"] = {"DPS"},
    ["平衡"] = {"DPS", "鸟德"},
    ["恢复"] = {"N"},
    ["野兽控制"] = {"DPS"},
    ["射击"] = {"DPS"},
    ["生存"] = {"DPS"},
    ["奥术"] = {"DPS"},
    ["火焰"] = {"DPS"},
    ["神圣"] = {"N"},
    ["防护"] = {"T"},
    ["惩戒"] = {"DPS"},
    ["戒律"] = {"N"},
    ["暗影"] = {"DPS", "暗牧"},
    ["战斗"] = {"DPS", "战斗贼"},
    ["刺杀"] = {"DPS"},
    ["奇袭"] = {"DPS"},
    ["敏锐"] = {"DPS"},
    ["元素"] = {"DPS"},
    ["增强"] = {"DPS", "增强萨"},
    ["武器"] = {"DPS"},
    ["狂怒"] = {"DPS"},
    ["痛苦"] = {"DPS"},
    ["恶魔学识"] = {"DPS", "恶魔术"},
    ["毁灭"] = {"DPS"},
}

local function getSubsidyTypeFromTalentInfo(playerName, mainTalentName)
    if not mainTalentName then return end
    if talentInfo[mainTalentName] then
        for _, key in ipairs(talentInfo[mainTalentName]) do
            ZL_CURRENT.playerInfo = ZL_CURRENT.playerInfo or {}
            ZL_CURRENT.playerInfo[playerName] = ZL_CURRENT.playerInfo[playerName] or {}
            local playerData = ZL_CURRENT.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

local function canInspect(unit)
    if not unit or UnitIsDeadOrGhost("player") or UnitIsDeadOrGhost(unit) or InCombatLockdown()
    or not CheckInteractDistance(unit, 1) or not CanInspect(unit) then
        return false
    end
    return true
end

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:CreateSubsidyFrame()
    if ZL.opt.subsidyProfileSelect == "默认" 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: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

    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()
    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)
        if button == "LeftButton" then
            if IsInRaid(1) then
                self:Disable()
                local i = 1
                local delay
                local function tempfunc()
                    if i <= MAX_RAID_MEMBERS then
                        local name, _, _, _, _, fileName = GetRaidRosterInfo(i)
                        if name then
                            if canInspect(name) then
                                if ZL.inspectUnit == true then
                                    ZL.inspectUnit = nil
                                    i = i + 1
                                    delay = 0
                                else
                                    ZL.inspectUnit = name
                                    NotifyInspect(name)
                                    delay = 0.3
                                end
                            else
                                i = i + 1
                                delay = 0
                                ZL.Print(GetClassColorName(name, fileName) .. "获取天赋信息|cffff0000失败|r。", true)
                            end
                        else
                            i = i + 1
                            delay = 0
                        end
                        C_Timer.After(delay, tempfunc)
                    else
                        self:Enable()
                        ZL.Print("天赋信息更新完成！", true)
                    end
                end
                tempfunc()
            else
                ZL.Print("不在团队中！")
            end
        elseif button == "RightButton" then
            local function tempfunc()
                local function getPlayerTalent(colorName)
                    C_Timer.NewTicker(0.2, function (self)
                        local name = ParseClassColorName(colorName)
                        if canInspect(name) then
                            if ZL.inspectUnit == true then
                                ZL.Print(colorName .. "天赋信息已更新。")
                                ZL.inspectUnit = nil
                                self:Cancel()
                            else
                                ZL.inspectUnit = name
                                NotifyInspect(name)
                            end
                        else
                            ZL.Print(colorName .. "获取天赋信息|cffff0000失败|r。")
                            self:Cancel()
                        end
                    end)
                end
                local menuList = {
                    {text="当前团队成员", isTitle=1},
                    {
                        disabled = not IsInRaid(1),
                        text = "重置团队天赋信息",
                        func = function ()
                            ZL_CURRENT.playerInfo = {}
                            self:Click()
                        end
                    },
                    {isSeparator = true},
                }
                local notTalentCounts = 0
                local WagesGroupMembers, msg = ZL.GetWagesGroupMembers()
                if WagesGroupMembers then
                    if msg then
                        tinsert(menuList, {text=msg, isTitle=1})
                    end
                    for _, data in ipairs(WagesGroupMembers) do
                        for _, colorName in ipairs(data) do
                            local name = ParseClassColorName(colorName)
                            local text = colorName
                            local isExist
                            if ZL_CURRENT.playerInfo and ZL_CURRENT.playerInfo[name] and ZL_CURRENT.playerInfo[name].talentName then
                                for key, value in pairs(ZL_CURRENT.playerInfo[name].talentName) do
                                    text = text .. " - |T" .. value .. ":12|t" .. key
                                    isExist = true
                                end
                            end
                            if (not isExist) and IsInRaid(1) and UnitInRaid(name) then
                                notTalentCounts = notTalentCounts + 1
                            end
                            tinsert(menuList, {
                                text = text,
                                hasArrow = 1,
                                menuTable = {
                                    {
                                        text = "刷新天赋",
                                        func = function ()
                                            getPlayerTalent(colorName)
                                            ZL.GUI:CloseMenu()
                                        end,
                                    },
                                    {
                                        text = "重置天赋",
                                        func = function ()
                                            ZL_CURRENT.playerInfo[name] = nil
                                            getPlayerTalent(colorName)
                                            ZL.GUI:CloseMenu()
                                        end,
                                    },
                                },
                            })
                        end
                    end
                end
                tinsert(menuList, 3, {
                    disabled = (not IsInRaid(1)) or notTalentCounts == 0,
                    text = "刷新未获取到天赋成员(" .. notTalentCounts .. ")",
                    func = function ()
                        local i = 1
                        local delay
                        local function _tempfunc()
                            if i <= MAX_RAID_MEMBERS then
                                local name, _, _, _, _, fileName = GetRaidRosterInfo(i)
                                if name then
                                    if ZL_CURRENT.playerInfo and ZL_CURRENT.playerInfo[name] and ZL_CURRENT.playerInfo[name].talentName then
                                        i = i + 1
                                        delay = 0
                                    else
                                        if canInspect(name) then
                                            if ZL.inspectUnit == true then
                                                ZL.inspectUnit = nil
                                                i = i + 1
                                                delay = 0
                                            else
                                                ZL.inspectUnit = name
                                                NotifyInspect(name)
                                                delay = 0.3
                                            end
                                        else
                                            i = i + 1
                                            delay = 0
                                            ZL.Print(GetClassColorName(name, fileName) .. "获取天赋信息|cffff0000失败|r。", true)
                                        end
                                    end
                                else
                                    i = i + 1
                                    delay = 0
                                end
                                C_Timer.After(delay, _tempfunc)
                            else
                                self:Enable()
                                ZL.Print("天赋信息更新完成！", true)
                            end
                        end
                        _tempfunc()
                    end
                })
                return menuList
            end
            ZL.GUI:ToggleMenu(self, tempfunc(), "TOPLEFT", self, "BOTTOMRIGHT")
        end
    end)
    refreshBtn:SetScript("OnEnter", function (self)
        GameTooltipShow(self, "BOTTOMLEFT", "TOPRIGHT")
        GameTooltip:AddLine("功能")
        GameTooltip:AddLine("左键：|cffffffff更新全团天赋|r")
        GameTooltip:AddLine("右键：|cffffffff更多功能|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)
        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_CURRENT.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_CURRENT.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_CURRENT.playerInfo then
                            for playerName, data in pairs(ZL_CURRENT.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)

    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
    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_CURRENT.playerInfo and ZL_CURRENT.playerInfo[name]
                                            and ZL_CURRENT.playerInfo[name][subsidyNameGsub] then
                                                tinsert(menuList, {
                                                    text = function ()
                                                        local text = colorName
                                                        if ZL_CURRENT.playerInfo[name]["DPS"] and ZL_CURRENT.playerInfo[name]["N"] then
                                                            text = text .. "(双休)"
                                                        elseif ZL_CURRENT.playerInfo[name]["DPS"] and ZL_CURRENT.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_CURRENT.playerInfo and ZL_CURRENT.playerInfo[name]
                                and ZL_CURRENT.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_CURRENT.playerInfo then
                            for playerName, data in pairs(ZL_CURRENT.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("CHAT_MSG_SYSTEM")
    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 -- and IsMasterLooter()
            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 == 22864 or spellId == 443894 then -- or spellId == 48168
                        local _, englishClass, _, _, _, playerName = GetPlayerInfoByGUID(sourceGUID)
                        local colorPlayerName = GetClassColorName(playerName, englishClass)
                        ZL_CURRENT.playerInfo = ZL_CURRENT.playerInfo or {}
                        ZL_CURRENT.playerInfo[playerName] = ZL_CURRENT.playerInfo[playerName] or {}
                        ZL_CURRENT.playerInfo[playerName].classFile = englishClass
                        ZL_CURRENT.playerInfo[playerName].colorName = colorPlayerName
                        ZL_CURRENT.subsidyFoodFirst = ZL_CURRENT.subsidyFoodFirst or sourceGUID
                        local msgStr, msgStr2
                        if spellId == 57426 then -- or spellId == 48168 
                            ZL_CURRENT.playerInfo[playerName]["鱼"] = true
                            ZL_CURRENT.playerInfo[playerName].fishCount = (ZL_CURRENT.playerInfo[playerName].fishCount or 0) + 1
                            ZL_CURRENT.subsidyFishFirst = ZL_CURRENT.subsidyFishFirst or playerName
                            msgStr = format(
                                ">>>%s<<<释放了%s，记录次数%d次，请文明就餐，不要遮挡。",
                                playerName, GetSpellLink(spellId), ZL_CURRENT.playerInfo[playerName].fishCount
                            )
                            msgStr2 = format(
                                ">>>%s<<<释放了%s，记录次数%d次，请文明就餐，不要遮挡。",
                                colorPlayerName, GetSpellLink(spellId), ZL_CURRENT.playerInfo[playerName].fishCount
                            )
                        elseif spellId == 57301 then
                            ZL_CURRENT.playerInfo[playerName]["猪"] = true
                            ZL_CURRENT.playerInfo[playerName].pigCount = (ZL_CURRENT.playerInfo[playerName].pigCount or 0) + 1
                            ZL_CURRENT.subsidyPigFirst = ZL_CURRENT.subsidyPigFirst or playerName
                            msgStr = format(
                                ">>>%s<<<释放了%s，记录次数%d次，请文明就餐，不要遮挡。",
                                playerName, GetSpellLink(spellId), ZL_CURRENT.playerInfo[playerName].pigCount
                            )
                            msgStr2 = format(
                                ">>>%s<<<释放了%s，记录次数%d次，请文明就餐，不要遮挡。",
                                colorPlayerName, GetSpellLink(spellId), ZL_CURRENT.playerInfo[playerName].fishCount
                            )
                        elseif spellId == 22864 or spellId == 44389 then
                            ZL_CURRENT.playerInfo[playerName]["修理机器人"] = true
                            ZL_CURRENT.playerInfo[playerName].xiuLiCount = (ZL_CURRENT.playerInfo[playerName].xiuLiCount or 0) + 1
                            ZL_CURRENT.subsidyXiuLiFirst = ZL_CURRENT.subsidyXiuLiFirst or playerName
                            msgStr = format(
                                ">>>%s<<<释放了%s，记录次数%d次，有需要修理的尽快修理。",
                                playerName, GetSpellLink(spellId), ZL_CURRENT.playerInfo[playerName].xiuLiCount
                            )
                            msgStr2 = format(
                                ">>>%s<<<释放了%s，记录次数%d次，有需要修理的尽快修理。",
                                colorPlayerName, GetSpellLink(spellId), ZL_CURRENT.playerInfo[playerName].xiuLiCount
                            )
                        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, true)
                        end
                    end
                end
                subevent = nil
                sourceGUID = nil
                spellId = nil
            end
        elseif event == "INSPECT_READY" then
            local _, englishClass, _, _, _, playerName = GetPlayerInfoByGUID(arg[1])
            if ZL.inspectUnit and ZL.inspectUnit == playerName then
                ZL.inspectUnit = true
            end
            if not UnitInRaid(playerName) then return end
            local colorPlayerName = GetClassColorName(playerName, englishClass)
            ZL_CURRENT.playerInfo = ZL_CURRENT.playerInfo or {}
            ZL_CURRENT.playerInfo[playerName] = ZL_CURRENT.playerInfo[playerName] or {}
            ZL_CURRENT.playerInfo[playerName].classFile = englishClass
            ZL_CURRENT.playerInfo[playerName].colorName = colorPlayerName
            -- 获取装备
            local itemId = GetInventoryItemID(playerName, 16)
            if itemId == 46017 then  -- 瓦兰奈尔，远古王者之锤
                ZL_CURRENT.playerInfo[playerName]["橙锤"] = true
            elseif itemId == 49623 then
                ZL_CURRENT.playerInfo[playerName]["橙斧"] = true
            end
            -- 获取天赋
            local activeTalentIndex = GetActiveTalentGroup(true) --当前激活的天赋
            local mainTalentName
            local mainTalenPointsSpent = 0
            local mainTalenIcon
            for i = 1, GetNumTalentTabs(true) do --天赋种类，一般为3个，如戒律、神圣、暗影
                local _, talentName, _, talentIcon, pointsSpent = GetTalentTabInfo(i, true, nil, activeTalentIndex)
                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, true) do --当前天赋种类里面有多少个天赋技能
                        --名称, iconID, 行， 列, 点了几点技能， 最大可以点的技能
                        local _name, _, _, _, rank = GetTalentInfo(i, j, true, nil, activeTalentIndex)
                        if _name == "坚韧" then --鲜血DK
                            if rank == 5 then
                                mainTalentName = "鲜血坦克"
                            else
                                mainTalentName = "鲜血输出"
                            end
                            break
                        elseif _name == "厚皮" then --德鲁伊
                            if rank > 0 then
                                mainTalentName = "野性坦克"
                            else
                                mainTalentName = "野性输出"
                            end
                        end
                    end
                end
            end
            if mainTalentName then
                -- print(colorPlayerName .. "主天赋是：".. "|T" .. mainTalenIcon .. ":14|t" .. mainTalentName)
                ZL_CURRENT.playerInfo[playerName].talentName = ZL_CURRENT.playerInfo[playerName].talentName or {}
                ZL_CURRENT.playerInfo[playerName].talentName[mainTalentName] = mainTalenIcon
                getSubsidyTypeFromTalentInfo(playerName, mainTalentName)
                if englishClass == "PALADIN" and mainTalentName == "神圣" then
                    ZL_CURRENT.playerInfo[playerName]["NQ"] = true
                end
            end
            if SubsidyFrame:IsShown() then
                SubsidyFrame:Update()
            end
        end
        arg:Release()
    end)
end