local _, ZLAUTO = ...

local ZL = ZLAUTO.mainFrame
local Prefix = ZL.Prefix
local tableSort = ZL.tableSort
local autoBid = ZL.autoBid
local GameTooltipShow = ZL.GameTooltipShow
local GetStartAndIncrementBid = ZL.GetStartAndIncrementBid
local GetCurrentRoster = ZL.GetCurrentRoster
local LoadItemDataByID = ZL.LoadItemDataByID
local InportToStatistics = ZL.InportToStatistics
local cGetItemInfo = C_Item and C_Item.GetItemInfo or GetItemInfo
local cGetItemIcon = C_Item and C_Item.GetItemIconByID or GetItemIcon


--定义静态弹出对话框
--重置当前拍卖记录
StaticPopupDialogs["ZL_RESETCURRENT"] = {
	text = "%s",
	button1 = "重置",
	button2 = "取消",
    hasEditBox = true,
    EditBoxOnEnterPressed = function(self) self:GetParent().button1:Click() end,
    -- EditBoxOnTextChanged = function(self)
	-- 	if strlen(self:GetText()) > 0 then
	-- 		self:GetParent().button1:Enable()
	-- 	else
	-- 		self:GetParent().button1:Disable()
	-- 	end
	-- end,
    OnShow = function(self)
		-- self.button1:Disable()
        self.editBox:SetNumeric(false)
        self.editBox:SetAutoFocus(false)
        if self.editBox2 then self.editBox2:Hide() end
        if self.editBox3 then self.editBox3:Hide() end
        if self.editBox4 then self.editBox4:Hide() end
        if self.editBox5 then self.editBox5:Hide() end
        if self.editBox6 then self.editBox6:Hide() end
        if self.editBox7 then self.editBox7:Hide() end
        if self.dropDown then self.dropDown:Hide() end
    end,
	OnAccept = function(self)
        if ZL_CURRENT["auctionlist"] and (#ZL_CURRENT["auctionlist"] > 0) then
            for num, data in ipairs(ZL_CURRENT["auctionlist"]) do
                local f = ZL.AuctionFrame2.entries[num]
                if data.state == "auctioning" then
                    ZL_CURRENT.auctionlist[num].state = "waiting"
                    ZL_CURRENT.auctionlist[num].countdownremaining = 0
                    ZL_CURRENT.auctionlist[num].isPaused = false
                    ZL_CURRENT.auctionlist[num].bidderlist = {}
                    f:SetValues(num)
                end
                f:Hide()
            end
            --将收入导入到Statistics
            InportToStatistics(ZL_CURRENT)
            local numGroupMembers, RLBuTie, totalincome, totalpayout, totalamount, averageamount = ZL.GetAveWages()
            ZL_CURRENT.totalincome = totalincome
            if (not ZL_CURRENT.name) and (strlen(self.editBox:GetText()) == 0) then
                ZL_CURRENT.name = GetInstanceInfo()
            elseif strlen(self.editBox:GetText()) > 0 then
                ZL_CURRENT.name = self.editBox:GetText()
            end
            if not ZL_CURRENT.auctiondate then ZL_CURRENT.auctiondate = date("%Y-%m-%d %H:%M:%S", time()) end
            table.insert(ZL_HISTORY, ZL_CURRENT)
            ZL_CURRENT = {}
            ZL.AuctionFrame2:Update()
            ZL.AuctionRecordFrame.historyFrame:Update()
            ZL.AuctionRecordFrame.currentIncomeFrame:Update()
            ZL.AuctionRecordFrame.playerBalanceFrame:Update()
            ZL.TransmitAddonInfo_Pro()
        end
	end,
	OnCancel = function(self)
	end,
    timeout = 0,
    whileDead = true,
    hideOnEscape = false,
    preferredIndex = 3,  -- 避免与其他弹出窗口冲突
}

--流拍物品申请重拍确认
StaticPopupDialogs["ZL_RETAKE"] = {
	text = "%s",
	button1 = "重拍",
	button2 = "取消",
    hasEditBox = false,
    OnShow = function(self)
        if self.editBox2 then self.editBox2:Hide() end
        if self.editBox3 then self.editBox3:Hide() end
        if self.editBox4 then self.editBox4:Hide() end
        if self.editBox5 then self.editBox5:Hide() end
        if self.editBox6 then self.editBox6:Hide() end
        if self.editBox7 then self.editBox7:Hide() end
        if self.dropDown then self.dropDown:Hide() end
    end,
	OnAccept = function(self, data)
		if ZL.retake and #ZL.retake > 0 then
            local retake = ZL.retake
            local function linshi()
                if #retake > 0 then
                    local fdata = retake[1]
                    local AuctioningCount = ZL.GetAuctioningCount()
                    if (not ZL_CURRENT.globalConfig.allowMultipleAuctions) and AuctioningCount > 0 then
                        C_Timer.After(2, linshi)
                    else
                        local _, _index = ZL.FetchDataFromItemId(fdata.itemlink, fdata.itemindex)
                        if _index then
                            local f = ZL.AuctionFrame2.entries[_index]
                            f.MLframe.functionFrame.CancelBtn:Click()
                            tremove(ZL.retake, 1)
                            C_Timer.After(2, linshi)
                        end
                    end
                end
            end
            linshi()
        end
	end,
	OnCancel = function(self, data)
        SendChatMessage("因暂时不方便拍卖，请稍后重新提交重拍申请", "RAID")
        ZL.retake = {}
	end,
    timeout = 0,
    whileDead = true,
    hideOnEscape = false,
    -- preferredIndex = 3,  -- 避免与其他弹出窗口冲突
}

--拾取绑定物品加入到打包拍卖确认提醒
StaticPopupDialogs["ZL_ISPACKAGE"] = {
	text = "%s",
	button1 = "打包拍卖",
	button2 = "取消",
    hasEditBox = false,
    OnShow = function(self)
        if self.editBox2 then self.editBox2:Hide() end
        if self.editBox3 then self.editBox3:Hide() end
        if self.editBox4 then self.editBox4:Hide() end
        if self.editBox5 then self.editBox5:Hide() end
        if self.editBox6 then self.editBox6:Hide() end
        if self.editBox7 then self.editBox7:Hide() end
        if self.dropDown then self.dropDown:Hide() end
    end,
	OnAccept = function(self, data)
		ZL.AddToPackage(data)
	end,
	OnCancel = function(self)
	end,
    timeout = 0,
    whileDead = true,
    hideOnEscape = false,
    preferredIndex = 3,  -- 避免与其他弹出窗口冲突
}
--保存当前团员名单信息警告按钮----已弃用
StaticPopupDialogs["ZL_SAVEGROUPMEMBERS"] = {
	text = "警告！警告！确定覆盖之前的团队名单信息么？",
	button1 = "确定",
    button2 = "取消",
    OnShow = function(self)
		if self.editBox2 then self.editBox2:Hide() end
        if self.editBox3 then self.editBox3:Hide() end
        if self.editBox4 then self.editBox4:Hide() end
        if self.editBox5 then self.editBox5:Hide() end
        if self.editBox6 then self.editBox6:Hide() end
        if self.editBox7 then self.editBox7:Hide() end
        if self.dropDown then self.dropDown:Hide() end
    end,
	OnAccept = function(self, data)
        ZL_CURRENT.GroupMembersList = ZL.GetCurrentRoster()
        ZL.AuctionRecordFrame.playerBalanceFrame:Update()
        print(Prefix("团员名单保存成功！"))
	end,
    timeout = 0,
    whileDead = true,
    hideOnEscape = false,
    preferredIndex = 3,  -- 避免与其他弹出窗口冲突
}
--进入全新副本时提醒是否重置拍卖记录
StaticPopupDialogs["ZL_RESETCURRENTINFO"] = {
	text = "%s",
	button1 = "确定",
    button2 = "取消",
    OnShow = function(self)
		if self.editBox2 then self.editBox2:Hide() end
        if self.editBox3 then self.editBox3:Hide() end
        if self.editBox4 then self.editBox4:Hide() end
        if self.editBox5 then self.editBox5:Hide() end
        if self.editBox6 then self.editBox6:Hide() end
        if self.editBox7 then self.editBox7:Hide() end
        if self.dropDown then self.dropDown:Hide() end
    end,
	OnAccept = function(self, data)
        ZL.AuctionFrame2.MLFrame.reset:Click()
	end,
    timeout = 0,
    whileDead = true,
    hideOnEscape = false,
    preferredIndex = 3,  -- 避免与其他弹出窗口冲突
}
--手动添加收支记录
StaticPopupDialogs["ZL_ADDINCOME"] = {
    text = "【|cffffd100%s|r】请输入必填项目",
    button1 = "确定",
    button2 = "取消",
    -- hasEditBox2 = true, -- 玩家名字
	-- hasEditBox3 = true, -- 收支金额
    -- hasEditBox4 = true, -- 名称
    OnShow = function(self, data)
		self.button1:Disable()
        -- self.text:SetJustifyH("LEFT")
        local xSize = 130 --self.editBox:GetWidth()
        local ySize = 30 --self.editBox:GetHeight()
        if not self.editBox2 then
			self.editBox2 = CreateFrame("EditBox", "StaticPopupDialogsEditBox2", self, "InputBoxTemplate")
			self.editBox2:SetSize(xSize, ySize)
			self.editBox2:SetPoint("TOP", self.text, "BOTTOM", 10, -10)
			self.editBox2:SetAutoFocus(false)
			self.editBox2:SetMaxLetters(150)
			self.editBox2.text = self.editBox2:CreateFontString(nil, "OVERLAY")
			self.editBox2.text:SetFontObject(GameFontWhite)
			self.editBox2.text:SetPoint("RIGHT", self.editBox2, "LEFT", -15, 0)
			self.editBox2.text:SetText("玩家名：")
            self.editBox2.text2 = self.editBox2:CreateFontString(nil, "OVERLAY")
			self.editBox2.text2:SetFontObject(GameFontWhite)
			self.editBox2.text2:SetPoint("LEFT", self.editBox2, "RIGHT", 5, 0)
		end
        if not self.editBox3 then
			self.editBox3 = CreateFrame("EditBox", "StaticPopupDialogsEditBox3", self, "InputBoxTemplate")
			self.editBox3:SetSize(xSize, ySize)
			self.editBox3:SetPoint("TOP", self.editBox2, "BOTTOM", 0, 8)
			self.editBox3:SetAutoFocus(false)
			self.editBox3:SetMaxLetters(9)
            self.editBox3:SetNumeric(true)
            self.editBox3:SetScript("OnEnter", function (self)
                GameTooltip:ClearAllPoints()
                GameTooltip:ClearLines()
                GameTooltip:SetOwner(self, "ANCHOR_NONE")
                GameTooltip:AddLine("输入大于0的数，最大9个字符！")
                GameTooltip:SetPoint("LEFT", self, "RIGHT")
                GameTooltip:Show()
            end)
            self.editBox3:SetScript("OnLeave", function (self) GameTooltip:Hide() end)
			self.editBox3.text = self.editBox3:CreateFontString(nil, "OVERLAY")
			self.editBox3.text:SetFontObject(GameFontWhite)
			self.editBox3.text:SetPoint("RIGHT", self.editBox3, "LEFT", -15, 0)
			self.editBox3.text:SetText("单　价：")
            self.editBox3.text2 = self.editBox3:CreateFontString(nil, "OVERLAY")
			self.editBox3.text2:SetFontObject(GameFontWhite)
			self.editBox3.text2:SetPoint("LEFT", self.editBox3, "RIGHT", 5, 0)
			self.editBox3.text2:SetText("(必填)")
		end
        if not self.editBox4 then
			self.editBox4 = CreateFrame("EditBox", "StaticPopupDialogsEditBox4", self, "InputBoxTemplate")
			self.editBox4:SetSize(xSize, ySize)
			self.editBox4:SetPoint("TOP", self.editBox3, "BOTTOM", 0, 8)
			self.editBox4:SetAutoFocus(false)
			self.editBox4:SetMaxLetters(150)
            self.editBox4:SetScript("OnLeave", function (self) GameTooltip:Hide() end)
            self.editBox4:SetScript("OnMouseUp", function (self)
                if (select(1, GetCursorInfo())) == "item" then
                    self:SetText(select(3, GetCursorInfo()))
                    ClearCursor()
                end
            end)
            self.editBox4:SetScript("OnEditFocusGained", function ()
                ZL.focusEditBox = self.editBox4
            end)
            self.editBox4:SetScript("OnEditFocusLost", function ()
                if ZL.focusEditBox == self.editBox4 then
                    ZL.focusEditBox = nil
                end
            end)
			self.editBox4.text = self.editBox4:CreateFontString(nil, "OVERLAY")
			self.editBox4.text:SetFontObject(GameFontWhite)
			self.editBox4.text:SetPoint("RIGHT", self.editBox4, "LEFT", -15, 0)
			self.editBox4.text:SetText("名　称：")
            self.editBox4.text2 = self.editBox4:CreateFontString(nil, "OVERLAY")
			self.editBox4.text2:SetFontObject(GameFontWhite)
			self.editBox4.text2:SetPoint("LEFT", self.editBox4, "RIGHT", 5, 0)
			self.editBox4.text2:SetText("(必填)")
		end
        if not self.editBox7 then
			self.editBox7 = CreateFrame("EditBox", "StaticPopupDialogseditBox7", self, "InputBoxTemplate")
			self.editBox7:SetSize(xSize, ySize)
			self.editBox7:SetPoint("TOP", self.editBox4, "BOTTOM", 0, 8)
			self.editBox7:SetAutoFocus(false)
            self.editBox7:SetNumeric(true)
            self.editBox7:SetNumber(1)
            self.editBox7:SetScript("OnEnter", function (self)
                GameTooltip:ClearAllPoints()
                GameTooltip:ClearLines()
                GameTooltip:SetOwner(self, "ANCHOR_NONE")
                GameTooltip:AddLine("输入大于0的数，默认为1")
                GameTooltip:SetPoint("LEFT", self, "RIGHT")
                GameTooltip:Show()
            end)
            self.editBox7:SetScript("OnLeave", function (self) GameTooltip:Hide() end)
			self.editBox7.text = self.editBox7:CreateFontString(nil, "OVERLAY")
			self.editBox7.text:SetFontObject(GameFontWhite)
			self.editBox7.text:SetPoint("RIGHT", self.editBox7, "LEFT", -15, 0)
			self.editBox7.text:SetText("数　量：")
            self.editBox7.text2 = self.editBox7:CreateFontString(nil, "OVERLAY")
			self.editBox7.text2:SetFontObject(GameFontWhite)
			self.editBox7.text2:SetPoint("LEFT", self.editBox7, "RIGHT", 5, 0)
			self.editBox7.text2:SetText("(必填)")
		end
        local function CreateMenu(self, level, menuList)
            local currentRoster = ZL.GetWagesGroupMembers()
            if not currentRoster then return end
            local info = UIDropDownMenu_CreateInfo()
            if (level or 1) == 1 then
                for i = 1, #currentRoster do
                    if #currentRoster[i] > 0 then
                        info.notCheckable = 1
                        info.text = "小队 " .. i
                        info.hasArrow = true
                        info.menuList = currentRoster[i]
                        UIDropDownMenu_AddButton(info, level)
                    end
                end
            else
                for _, name in ipairs(menuList) do
                    info.text = name
                    info.hasArrow = false
                    info.func = function()
                        self:GetParent().editBox2:SetText(name)
                        info.checked = true
                        CloseDropDownMenus()
                    end
                    UIDropDownMenu_AddButton(info, level)
                end
            end
        end
        if not self.dropDown then
            self.dropDown = CreateFrame("FRAME", "WPDemoDropDown", self, "UIDropDownMenuTemplate")
            self.dropDown:SetPoint("RIGHT", self.editBox2, "RIGHT", 17, -1)
            self.dropDown:SetScale(0.8)
            UIDropDownMenu_SetWidth(self.dropDown, 8)
            UIDropDownMenu_Initialize(self.dropDown, CreateMenu)
        end
        self.dropDown:Show()
        self.editBox2:SetScript("OnTextChanged", function (self)
            if data.type == "收入" or data.type == "指定人员" or data.type == "罚款" then
                if strlen(self:GetParent().editBox2:GetText()) > 0 and self:GetParent().editBox3:GetNumber() > 0 and
                    strlen(self:GetParent().editBox4:GetText()) > 0 then
                    self:GetParent().button1:Enable()
                else
                    self:GetParent().button1:Disable()
                end
            elseif data.type == "支出" then
                if self:GetParent().editBox3:GetNumber() > 0 and strlen(self:GetParent().editBox4:GetText()) > 0 then
                    self:GetParent().button1:Enable()
                else
                    self:GetParent().button1:Disable()
                end
            end
        end)
        self.editBox3:SetScript("OnTextChanged", function (self)
            if data.type == "收入" or data.type == "指定人员" or data.type == "罚款" then
                if strlen(self:GetParent().editBox2:GetText()) > 0 and self:GetParent().editBox3:GetNumber() > 0 and
                    strlen(self:GetParent().editBox4:GetText()) > 0 then
                    self:GetParent().button1:Enable()
                else
                    self:GetParent().button1:Disable()
                end
            elseif data.type == "支出" then
                if self:GetParent().editBox3:GetNumber() > 0 and strlen(self:GetParent().editBox4:GetText()) > 0 then
                    self:GetParent().button1:Enable()
                else
                    self:GetParent().button1:Disable()
                end
            end
        end)
        self.editBox4:SetScript("OnTextChanged", function (self)
            if data.type == "收入" or data.type == "指定人员" or data.type == "罚款" then
                if strlen(self:GetParent().editBox2:GetText()) > 0 and self:GetParent().editBox3:GetNumber() > 0 and
                    strlen(self:GetParent().editBox4:GetText()) > 0 then
                    self:GetParent().button1:Enable()
                else
                    self:GetParent().button1:Disable()
                end
            elseif data.type == "支出" then
                if self:GetParent().editBox3:GetNumber() > 0 and strlen(self:GetParent().editBox4:GetText()) > 0 then
                    self:GetParent().button1:Enable()
                else
                    self:GetParent().button1:Disable()
                end
            end
        end)
        self.editBox4:SetScript("OnEnter", function (self)
            GameTooltip:ClearAllPoints()
            GameTooltip:ClearLines()
            GameTooltip:SetOwner(self, "ANCHOR_NONE")
            if data.type == "收入" or data.type == "指定人员" or data.type == "罚款" then
                GameTooltip:AddLine("如：罚款，垃圾或其他收入")
            elseif data.type == "支出" then
                GameTooltip:AddLine("如：补贴，物资消耗支出等")
            end
            GameTooltip:AddLine("如需输入物品名，|cffffd100Shift+左键|r点击\n背包物品或拍卖图标", 1, 1, 1)
            GameTooltip:SetPoint("LEFT", self, "RIGHT")
            GameTooltip:Show()
        end)
        self.editBox2:SetText("")
		self.editBox3:SetText("")
        self.editBox4:SetText("")
        self.editBox2:Show()
        self.editBox3:Show()
        self.editBox4:Show()
        self.editBox7:Show()
        if self.editBox5 then self.editBox5:Hide() end
        if self.editBox6 then self.editBox6:Hide() end
		self:SetHeight(90 + self.editBox2:GetHeight() + self.editBox3:GetHeight() + self.editBox4:GetHeight() + self.editBox7:GetHeight())
        do
            local editboxList = {"StaticPopupDialogsEditBox2", "StaticPopupDialogsEditBox3", "StaticPopupDialogsEditBox4", "StaticPopupDialogseditBox7"}
            local function OnTabPressed(self)
                EditBox_HandleTabbing(self, editboxList)
            end
            self.editBox2:SetScript("OnTabPressed", OnTabPressed)
            self.editBox3:SetScript("OnTabPressed", OnTabPressed)
            self.editBox4:SetScript("OnTabPressed", OnTabPressed)
            self.editBox7:SetScript("OnTabPressed", OnTabPressed)
        end
        if data.type == "收入" then
            self.editBox2.text2:SetText("(必填)")
            self.editBox7.text2:SetText("(必填)")
        elseif data.type == "支出" then
            self.editBox2.text2:SetText("(可选)")
            self.editBox7.text2:SetText("(可选)")
        elseif data.type == "指定人员" then
            self.editBox2.text2:SetText("(必填)")
            self.editBox7.text2:SetText("(必填)")
            self.editBox3:SetNumber(data.data.startbidamount)
            self.editBox4:SetText(data.data.itemlink)
            self.editBox7:SetNumber(data.data.itemCount)
        elseif data.type == "罚款" then
            self.editBox2.text2:SetText("(必填)")
            self.editBox7.text2:SetText("(必填)")
            self.editBox2:SetText(ZL.GetClassColorName(data.name))
            self.editBox3:SetNumber(data.amount)
            self.editBox4:SetText("罚款")
        end
    end,
    OnUpdate = function(self)
		-- 确保高度保持不变
		self:SetHeight(85 + self.editBox2:GetHeight() + self.editBox3:GetHeight() + self.editBox4:GetHeight())
	end,
    OnAccept = function (self, data)
        local itemList
        local tradeId
        local player = ZL.GetClassColorName(self.editBox2:GetText())
        local notes = self.editBox4:GetText()
        local itemId = tonumber(notes:match("|Hitem:(%d+):"))
        if itemId then
            tradeId = tostring(itemId) .. tostring(time())
        end
        local amount = 0
        local itemCount = self.editBox7:GetNumber()
        if ((not itemCount) or itemCount <= 0) then
            itemCount = 1
        end
        if not ZL_CURRENT.IncomeList then ZL_CURRENT.IncomeList = {} end
        if data.type == "收入" or data.type == "支出" or data.type == "罚款" then
            if data.type == "收入" or data.type == "罚款" then
                amount = self.editBox3:GetNumber() * itemCount
            elseif data.type == "支出" then
                amount = -self.editBox3:GetNumber() * itemCount
            end
            table.insert(ZL_CURRENT.IncomeList, {
                player = player,
                amount = amount,
                notes = notes,
                itemCount = itemCount,
                itemList = itemList,
                -- tradeId = tradeId,
            })
            if ZL.PlayerIsML(player) and amount > 0 then
                --ML自己拍到的物品直接记录到已支付
                if not ZL_CURRENT.playerPayToML then ZL_CURRENT.playerPayToML = {} end
                local oldPayToML = ZL_CURRENT.playerPayToML[player] and ZL_CURRENT.playerPayToML[player] or 0
                ZL_CURRENT.playerPayToML[player] = oldPayToML + amount
                ZL.AuctionRecordFrame.playerBalanceFrame:Update()
            end
            ZL.AuctionRecordFrame.currentIncomeFrame:Update()
            ZL.AuctionRecordFrame.playerBalanceFrame:Update()
        elseif data.type == "指定人员" then
            local ddate = data.data
            ddate.bidderlist = {}
            table.insert(ddate.bidderlist, {
                bidder = player,
                bidamount = self.editBox3:GetNumber(),
                bidCount = itemCount,
                time = GetTime()*1000,
            })
            ZL.AuctionFrame2:CountDown(ddate.index)
        end
        local fdata = {
            type = "添加收支",
            data = ZL_CURRENT.IncomeList,
        }
        MyAddon:TransmitAddonInfo("AUTOAUC SYNC11", fdata)

    end,
    timeout = 0,
    whileDead = true,
    hideOnEscape = false,
    preferredIndex = 3,  -- 避免与其他弹出窗口冲突
}
--清除所有历史记录警告
StaticPopupDialogs["ZL_CLEARHISTORYWARNING"] = {
	text = "警告！警告！将清空所有历史拍卖记录，并且无法恢复！是否确定清空？",
	button1 = "确定",
    button2 = "取消",
    OnShow = function(self)
		if self.editBox2 then self.editBox2:Hide() end
        if self.editBox3 then self.editBox3:Hide() end
        if self.editBox4 then self.editBox4:Hide() end
        if self.editBox5 then self.editBox5:Hide() end
        if self.editBox6 then self.editBox6:Hide() end
        if self.editBox7 then self.editBox7:Hide() end
        if self.dropDown then self.dropDown:Hide() end
    end,
	OnAccept = function(self, data)
        for _, f in ipairs(ZL.AuctionRecordFrame.historyFrame.entries) do
            f:Hide()
        end
        ZL_HISTORY = {}
	end,
    timeout = 0,
    whileDead = true,
    hideOnEscape = false,
    preferredIndex = 3,  -- 避免与其他弹出窗口冲突
}
--删除历史拍卖记录警告
StaticPopupDialogs["ZL_DELETEHISTORYWARNING"] = {
	text = "删除后无法恢复，确认删除该拍卖记录？",
	button1 = "确定",
    button2 = "取消",
    OnShow = function(self)
		if self.editBox2 then self.editBox2:Hide() end
        if self.editBox3 then self.editBox3:Hide() end
        if self.editBox4 then self.editBox4:Hide() end
        if self.editBox5 then self.editBox5:Hide() end
        if self.editBox6 then self.editBox6:Hide() end
        if self.editBox7 then self.editBox7:Hide() end
        if self.dropDown then self.dropDown:Hide() end
    end,
	OnAccept = function(self, data)
        table.remove(ZL_HISTORY, data)
        ZL.AuctionRecordFrame.historyFrame:Update()
	end,
    timeout = 0,
    whileDead = true,
    hideOnEscape = false,
    preferredIndex = 3,  -- 避免与其他弹出窗口冲突
}
--删除拍卖警告
StaticPopupDialogs["ZL_DELETEAUCTIONWARNING"] = {
	text = "%s",
	button1 = "确定",
    button2 = "取消",
    OnShow = function(self)
		if self.editBox2 then self.editBox2:Hide() end
        if self.editBox3 then self.editBox3:Hide() end
        if self.editBox4 then self.editBox4:Hide() end
        if self.editBox5 then self.editBox5:Hide() end
        if self.editBox6 then self.editBox6:Hide() end
        if self.editBox7 then self.editBox7:Hide() end
        if self.dropDown then self.dropDown:Hide() end
    end,
	OnAccept = function(self, data)
        local curAuctionList = ZL_CURRENT.auctionlist[data]
        local itemlink = curAuctionList.itemlink
        if curAuctionList["spawnUID"] and ZL_CURRENT.itemGUIDUsed then
            for _, value in pairs(curAuctionList["spawnUID"]) do
                if value["itemGUID"] then
                    for itemGUID in pairs(value["itemGUID"]) do
                        ZL_CURRENT.itemGUIDUsed[itemGUID] = nil
                    end
                end
            end
        end
        if itemlink == "[打包拍卖]" then
            local itemList = curAuctionList["itemList"]
            if itemList and next(itemList, nil) then
                for _itemlink, _data in pairs(itemList) do
                    for _, __itemindex in ipairs (_data.itemindex) do
                        local _, __index = ZL.FetchDataFromItemId(_itemlink, __itemindex)
                        if __index then ZL_CURRENT.auctionlist[__index].isPackage = nil end
                    end
                end
            end
        end
        --将需要删除的拍卖物品发送给其他成员
        local fdata = {
            type = "删除拍卖物品",
            itemindex = curAuctionList.itemindex,
            itemlink = itemlink,
        }
        MyAddon:TransmitAddonInfo("AUTOAUC SYNC10", fdata)
        --ML开始删除自己的拍卖物品
        table.remove(ZL_CURRENT.auctionlist, data)
        ZL.AuctionFrame2:Update()
        print(Prefix("注意：已删除拍卖物品" .. itemlink))
        ZL.ScrollingMessageFrame:AddMessage("注意：已删除拍卖物品" .. itemlink)
	end,
    timeout = 0,
    whileDead = true,
    hideOnEscape = false,
    preferredIndex = 3,  -- 避免与其他弹出窗口冲突
}
--自动出价
StaticPopupDialogs["ZL_AUTOBID"] = {
    text = "输入%s的最大心里价位(g):",
	button1 = "开始",
	button2 = "取消",
    hasEditBox = true,
    EditBoxOnEnterPressed = function(self) self:GetParent().button1:Click() end,
    EditBoxOnTextChanged = function(self)
		if self:GetNumber() > 0 then
			self:GetParent().button1:Enable()
		else
			self:GetParent().button1:Disable()
		end
	end,
    OnShow = function(self)
		self.button1:Disable()
        self.editBox:SetNumeric(false)
        self.editBox:SetAutoFocus(false)
        if self.editBox2 then self.editBox2:Hide() end
        if self.editBox3 then self.editBox3:Hide() end
        if self.editBox4 then self.editBox4:Hide() end
        if self.editBox5 then self.editBox5:Hide() end
        if self.editBox6 then self.editBox6:Hide() end
        if self.editBox7 then self.editBox7:Hide() end
        if self.dropDown then self.dropDown:Hide() end
    end,
	OnAccept = function(self, data)
		data.f.maxAutoBid = self.editBox:GetNumber() or 0
        if data.f.maxAutoBid > 0 then
            data.f.bidFrame.bidEditBox:Disable()
            data.f.bidFrame.bidBtn:SetText("停止")
            data.f.bidFrame.lgnoreBtn:Disable()
            local itemCount = ZL_CURRENT.auctionlist[data.index].itemCount
            local bidCount = data.f.bidFrame.bidCounts:GetNumber()
            bidCount = bidCount > 0 and bidCount or 1
            bidCount = bidCount > itemCount and itemCount or bidCount
            autoBid(data.index, data.f.maxAutoBid, bidCount)
            if data.f.autoBid then
                if (not data.f.autoBid:IsCancelled()) then
                    data.f.autoBid:Cancel()
                end
                data.f.autoBid = nil
            end
            data.f.autoBid = C_Timer.NewTicker(2, function (self)
                autoBid(data.index, data.f.maxAutoBid, bidCount)
            end)
        end
        self.editBox:ClearFocus()
	end,
	OnCancel = function(self, data)
	end,
    timeout = 0,
    whileDead = true,
    hideOnEscape = false,
    preferredIndex = 3,  -- 避免与其他弹出窗口冲突
}
--撤销指定玩家的出价
StaticPopupDialogs["ZL_REVOKEBID"] = {
    text = "输入你想撤销出价的玩家名字:",
	button1 = "确定",
	button2 = "取消",
    hasEditBox = true,
    EditBoxOnEnterPressed = function(self) self:ClearFocus();self:GetParent().button1:Click() end,
    EditBoxOnTextChanged = function(self)
		if strlen(self:GetText()) > 0 then
			self:GetParent().button1:Enable()
		else
			self:GetParent().button1:Disable()
		end
	end,
    OnShow = function(self)
		self.button1:Disable()
        self.editBox:SetNumeric(false)
        if self.editBox2 then self.editBox2:Hide() end
        if self.editBox3 then self.editBox3:Hide() end
        if self.editBox4 then self.editBox4:Hide() end
        if self.editBox5 then self.editBox5:Hide() end
        if self.editBox6 then self.editBox6:Hide() end
        if self.editBox7 then self.editBox7:Hide() end
        if self.dropDown then self.dropDown:Hide() end
    end,
	OnAccept = function(self, data)
		local playerName = self.editBox:GetText()
        MyAddon:TransmitAddonInfo("AUTOAUC REVOKE", {itemId=data.itemId, itemindex=data.itemindex, playerName=playerName})
	end,
	OnCancel = function(self, data)
	end,
    timeout = 0,
    whileDead = true,
    hideOnEscape = false,
    preferredIndex = 3,  -- 避免与其他弹出窗口冲突
}
--增加玩家收入金额
StaticPopupDialogs["ZL_ADDTOPLAYER"] = {
    text = "输入你想|cffffd100增加|r[|cffffd100%s|r]的收入金额：",
	button1 = "确定",
	button2 = "取消",
    hasEditBox = true,
    EditBoxOnEnterPressed = function(self) self:GetParent().button1:Click() end,
    EditBoxOnTextChanged = function(self)
		if self:GetNumber() > 0 then
			self:GetParent().button1:Enable()
		else
			self:GetParent().button1:Disable()
		end
	end,
    OnShow = function(self)
		self.button1:Disable()
        self.editBox:SetNumeric(false)
        self.editBox:SetAutoFocus(false)
        if self.editBox2 then self.editBox2:Hide() end
        if self.editBox3 then self.editBox3:Hide() end
        if self.editBox4 then self.editBox4:Hide() end
        if self.editBox5 then self.editBox5:Hide() end
        if self.editBox6 then self.editBox6:Hide() end
        if self.editBox7 then self.editBox7:Hide() end
        if self.dropDown then self.dropDown:Hide() end
    end,
	OnAccept = function(self, data)
		local addamount = self.editBox:GetNumber() or 0
        if (not ZL_CURRENT.playerPayToML) then ZL_CURRENT.playerPayToML = {} end
        ZL_CURRENT.playerPayToML[data]= (ZL_CURRENT.playerPayToML[data] or 0 )+ addamount
        ZL.AuctionRecordFrame.playerBalanceFrame:Update()
	end,
	OnCancel = function(self, data)
	end,
    timeout = 0,
    whileDead = true,
    hideOnEscape = false,
    preferredIndex = 3,  -- 避免与其他弹出窗口冲突
}
--扣除玩家收入金额
StaticPopupDialogs["ZL_REMFROMPLAYER"] = {
    text = "输入你想|cffffd100扣除|r[|cffffd100%s|r]的收入金额：",
	button1 = "确定",
	button2 = "取消",
    hasEditBox = true,
    EditBoxOnEnterPressed = function(self) self:GetParent().button1:Click() end,
    EditBoxOnTextChanged = function(self)
		if self:GetNumber() > 0 then
			self:GetParent().button1:Enable()
		else
			self:GetParent().button1:Disable()
		end
	end,
    OnShow = function(self)
		self.button1:Disable()
        self.editBox:SetNumeric(false)
        self.editBox:SetAutoFocus(false)
        if self.editBox2 then self.editBox2:Hide() end
        if self.editBox3 then self.editBox3:Hide() end
        if self.editBox4 then self.editBox4:Hide() end
        if self.editBox5 then self.editBox5:Hide() end
        if self.editBox6 then self.editBox6:Hide() end
        if self.editBox7 then self.editBox7:Hide() end
        if self.dropDown then self.dropDown:Hide() end
    end,
	OnAccept = function(self, data)
		local addamount = self.editBox:GetNumber() or 0
        if (not ZL_CURRENT.playerPayToML) then ZL_CURRENT.playerPayToML = {} end
        ZL_CURRENT.playerPayToML[data] = (ZL_CURRENT.playerPayToML[data] or 0) - addamount
        ZL.AuctionRecordFrame.playerBalanceFrame:Update()
	end,
	OnCancel = function(self, data)
	end,
    timeout = 0,
    whileDead = true,
    hideOnEscape = false,
    preferredIndex = 3,  -- 避免与其他弹出窗口冲突
}
--手动创建拍卖物品
StaticPopupDialogs["ZL_ADDAUCTIONITEM"] = {
    text = "请填写需要拍卖的物品ID和数量：",
    button1 = "确定",
    button2 = "取消",
    OnShow = function(self)
		self.button1:Disable()
        local xSize = 130 --self.editBox:GetWidth()
        local ySize = 30 --self.editBox:GetHeight()
         if not self.editBox5 then
			self.editBox5 = CreateFrame("EditBox", "StaticPopupDialogseditBox5", self, "InputBoxTemplate")
			self.editBox5:SetSize(xSize, ySize)
			self.editBox5:SetPoint("TOP", self.text, "BOTTOM", 10, -10)
			self.editBox5:SetAutoFocus(false)
            self.editBox5:SetNumeric(true)
            self.editBox5:SetScript("OnTextChanged", function (self)
                if self:GetParent().editBox5:GetNumber() > 0 and self:GetParent().editBox6:GetNumber() > 0 then
                    self:GetParent().button1:Enable()
                else
                    self:GetParent().button1:Disable()
                end
            end)
            self.editBox5:SetScript("OnMouseUp", function (self)
                if (select(1, GetCursorInfo())) == "item" then
                    self:SetText(select(2, GetCursorInfo()))
                    ClearCursor()
                end
            end)
            self.editBox5:SetScript("OnEnter", function (self)
                GameTooltipShow(self, "LEFT", "RIGHT")
                GameTooltip:AddLine("提示")
                GameTooltip:AddLine("鼠标点击物品，移动到这里，\n释放鼠标后可以自动获取到物品ID", 1, 1, 1)
                GameTooltip:Show()
            end)
            self.editBox5:SetScript("OnLeave", function ()
                GameTooltip:Hide()
            end)
			self.editBox5.text = self.editBox5:CreateFontString(nil, "OVERLAY")
			self.editBox5.text:SetFontObject(GameFontWhite)
			self.editBox5.text:SetPoint("RIGHT", self.editBox5, "LEFT", -15, 0)
			self.editBox5.text:SetText("物品ID：")
            self.editBox5.text2 = self.editBox5:CreateFontString(nil, "OVERLAY")
			self.editBox5.text2:SetFontObject(GameFontWhite)
			self.editBox5.text2:SetPoint("LEFT", self.editBox5, "RIGHT", 5, 0)
            self.editBox5.text2:SetText("(必填)")
		end
        if not self.editBox6 then
			self.editBox6 = CreateFrame("EditBox", "StaticPopupDialogseditBox6", self, "InputBoxTemplate")
			self.editBox6:SetSize(xSize, ySize)
			self.editBox6:SetPoint("TOP", self.editBox5, "BOTTOM", 0, 5)
			self.editBox6:SetAutoFocus(false)
            self.editBox6:SetNumeric(true)
            self.editBox6:SetScript("OnTextChanged", function (self)
                if self:GetParent().editBox5:GetNumber() > 0 and self:GetParent().editBox6:GetNumber() > 0 then
                    self:GetParent().button1:Enable()
                else
                    self:GetParent().button1:Disable()
                end
            end)
            -- self.editBox6:SetScript("OnEnter", function (self)
            --     GameTooltipShow(self, "LEFT", "RIGHT")
            --     GameTooltip:AddLine("注意")
            --     GameTooltip:AddLine("如是拍卖打包的物品，数量填|cffffd1001|r", 1, 1, 1)
            --     GameTooltip:Show()
            -- end)
            -- self.editBox6:SetScript("OnLeave", function (self) GameTooltip:Hide() end)
			self.editBox6.text = self.editBox6:CreateFontString(nil, "OVERLAY")
			self.editBox6.text:SetFontObject(GameFontWhite)
			self.editBox6.text:SetPoint("RIGHT", self.editBox6, "LEFT", -15, 0)
			self.editBox6.text:SetText("数　量：")
            self.editBox6.text2 = self.editBox6:CreateFontString(nil, "OVERLAY")
			self.editBox6.text2:SetFontObject(GameFontWhite)
			self.editBox6.text2:SetPoint("LEFT", self.editBox6, "RIGHT", 5, 0)
			self.editBox6.text2:SetText("(必填)")
		end
        self.editBox5:SetText("")
		self.editBox6:SetText("")
        if self.editBox2 then self.editBox2:Hide() end
        if self.editBox3 then self.editBox3:Hide() end
        if self.editBox4 then self.editBox4:Hide() end
        if self.dropDown then self.dropDown:Hide() end
        if self.editBox7 then self.editBox7:Hide() end
        self.editBox5:Show()
        self.editBox6:Show()
        if self.data then
            self.editBox5:SetNumber(self.data.itemId)
        end
		self:SetHeight(85 + self.editBox5:GetHeight() + self.editBox6:GetHeight() + self.editBox5:GetHeight())
        do
            local editboxList = {"StaticPopupDialogseditBox5", "StaticPopupDialogseditBox6"}
            local function OnTabPressed(self)
                EditBox_HandleTabbing(self, editboxList)
            end
            self.editBox5:SetScript("OnTabPressed", OnTabPressed)
            self.editBox6:SetScript("OnTabPressed", OnTabPressed)
        end
    end,
    OnUpdate = function(self)
		-- 确保高度保持不变
		self:SetHeight(85 + self.editBox5:GetHeight() + self.editBox6:GetHeight() + self.editBox5:GetHeight())
	end,
    OnAccept = function (self, data)
        local itemId = self.editBox5:GetNumber()
        local itemCount = self.editBox6:GetNumber()
        -- if data and data.itemGuid then
        --     ZL_CURRENT["itemGUIDUsed"][data.itemGuid] = "其他"
        -- end
        local function func(itemlink)
            ZL.ManualCreateAuctionItem(itemlink, itemCount or 1, data and data.itemGuid)
            print(Prefix("已创建拍卖物品：" .. itemlink))
        end
        LoadItemDataByID(itemId, func, self.editBox5)
     end,
    timeout = 0,
    whileDead = true,
    hideOnEscape = false,
    preferredIndex = 3,  -- 避免与其他弹出窗口冲突
}

--首次提醒
StaticPopupDialogs["ZL_FIRSTNOTICE"] = {
    text = "|cff0000ff【AutoAuction】|r提醒：新增了鼠标提示功能开关：拍卖状态、历史成交价、历史成交趋势图，默认为展示状态，如需隐藏，可到设置里面修改",
	button1 = "修改",
    button2 = "取消",
    OnShow = function(self)
		if self.editBox2 then self.editBox2:Hide() end
        if self.editBox3 then self.editBox3:Hide() end
        if self.editBox4 then self.editBox4:Hide() end
        if self.editBox5 then self.editBox5:Hide() end
        if self.editBox6 then self.editBox6:Hide() end
        if self.editBox7 then self.editBox7:Hide() end
        if self.dropDown then self.dropDown:Hide() end
    end,
	OnAccept = function(self, data)
        ZL.OpenAceConfigDialog("金团拍卖助手", "tooltip")
	end,
    OnCancel = function(self)
        local msgStr = "后续可到设置——鼠标提示里取消展示"
        print(Prefix(msgStr))
        ZL.ScrollingMessageFrame:AddMessage(msgStr)
	end,
    timeout = 0,
    whileDead = true,
    hideOnEscape = false,
    preferredIndex = 3,  -- 避免与其他弹出窗口冲突
}

--同步不同战网子账号之间数据弹窗确认
StaticPopupDialogs["ZL_SYNCROLES"] = {
	text = "%s",
	button1 = "同意",
	button2 = "拒绝",
    timeout = 0,
    OnShow = function(self)
		self.editBox:SetNumeric(false)
        self.editBox:SetAutoFocus(false)
        if self.editBox2 then self.editBox2:Hide() end
        if self.editBox3 then self.editBox3:Hide() end
        if self.editBox4 then self.editBox4:Hide() end
        if self.editBox5 then self.editBox5:Hide() end
        if self.editBox6 then self.editBox6:Hide() end
        if self.editBox7 then self.editBox7:Hide() end
        if self.dropDown then self.dropDown:Hide() end
        -- print(self.data, self.data.timeout)
        self.timeout = nil
    end,
	OnAccept = function(self, data)
        ZL.SaveRoles(data)
        RolesOverView["syncKeyUnBind"][data.OwnRolesSyncKey] = nil --从新绑定的从这里面移除
        local _data = {
            type = "addnewAgree",
            playerName = ZL.GetClassColorName(UnitName("player")),
            rolesData = RolesOverView.owner,
            syncData = RolesOverView.sync,
            OwnRolesSyncKey = select(3, ZL.GetOwnRolesSyncKey()),
        }
        MyAddon:TransmitAddonInfo2("AUTOAUC ROLES", _data, "WHISPER", ZL.ParseClassColorName(data.playerName))
        local msgStr = "已成功与" .. data.playerName .. "绑定同步角色数据！"
        print(Prefix(msgStr))
        ZL.ScrollingMessageFrame:AddMessage(msgStr)
	end,
	OnCancel = function(self, data)
        local _data = {
            type = "addnewRefuse",
            data = ZL.GetClassColorName(UnitName("player")),
        }
        MyAddon:TransmitAddonInfo2("AUTOAUC ROLES", _data, "WHISPER", ZL.ParseClassColorName(data.playerName))
	end,
    OnUpdate = function(self, elapsed)
        -- 每帧更新时触发
        if not self.timeout then self.timeout = self.data.timeout - GetTime() end
        self.timeout = self.timeout - elapsed
        if self.timeout <= 0 then
            self.timeout = 0
            self:Hide()  -- 倒计时结束后关闭对话框
        else
            self.text:SetText(self.data.playerName .. "请求与你共享角色数据，是否同意？倒数：" .. "|cff00ff00" .. ceil(self.timeout) .. "|r")
        end
    end,
    whileDead = true,
    hideOnEscape = false,
    preferredIndex = 3,  -- 避免与其他弹出窗口冲突
}

--修改子账号名字
StaticPopupDialogs["ZL_MODIFYBNCHILD"] = {
	text = "%s",
	button1 = "修改",
	button2 = "取消",
    hasEditBox = true,
    EditBoxOnEnterPressed = function(self) self:GetParent().button1:Click() end,
    EditBoxOnTextChanged = function(self)
		if #self:GetText() > 0 then
			self:GetParent().button1:Enable()
		else
			self:GetParent().button1:Disable()
		end
	end,
    OnShow = function(self)
		self.editBox:SetNumeric(false)
        self.editBox:SetAutoFocus(false)
        self.button1:Disable()
        if self.editBox2 then self.editBox2:Hide() end
        if self.editBox3 then self.editBox3:Hide() end
        if self.editBox4 then self.editBox4:Hide() end
        if self.editBox5 then self.editBox5:Hide() end
        if self.editBox6 then self.editBox6:Hide() end
        if self.editBox7 then self.editBox7:Hide() end
        if self.dropDown then self.dropDown:Hide() end
    end,
	OnAccept = function(self, data)
        local _, _, BNChild = strsplit(":", data)
        local BNChildNewName = self.editBox:GetText()
        BNChildNewName = BNChildNewName:gsub(":", "")
        RolesOverView["BNChildNewName"][BNChild] = self.editBox:GetText()
        if ZL.LgnoreRolesFrame:IsShown() then
            ZL.LgnoreRolesFrame:Update()
        end
	end,
	OnCancel = function(self, data)
	end,
    whileDead = true,
    hideOnEscape = false,
    preferredIndex = 3,  -- 避免与其他弹出窗口冲突
}
--删除角色数据
StaticPopupDialogs["ZL_DELETEROLES"] = {
	text = "%s",
	button1 = "删除",
	button2 = "取消",
    OnShow = function(self)
		self.editBox:SetNumeric(false)
        self.editBox:SetAutoFocus(false)
        if self.editBox2 then self.editBox2:Hide() end
        if self.editBox3 then self.editBox3:Hide() end
        if self.editBox4 then self.editBox4:Hide() end
        if self.editBox5 then self.editBox5:Hide() end
        if self.editBox6 then self.editBox6:Hide() end
        if self.editBox7 then self.editBox7:Hide() end
        if self.dropDown then self.dropDown:Hide() end
    end,
	OnAccept = function(self, data)
        if not ZL.glb.rolesDel then ZL.glb.rolesDel = {} end
        ZL.glb.rolesDel[data] = true
        local playerName, realmName, BNChild, battleTag = strsplit(":", data)
        local parsePlayerName = ZL.ParseClassColorName(playerName)
        local factionGroup = select(2, UnitFactionGroup("player"))
        if RolesOverView["owner"][battleTag] and RolesOverView["owner"][battleTag][BNChild] and RolesOverView["owner"][battleTag][BNChild][realmName]
        and RolesOverView["owner"][battleTag][BNChild][realmName][factionGroup] then
            RolesOverView["owner"][battleTag][BNChild][realmName][factionGroup][parsePlayerName] = nil
        end
        if RolesOverView["sync"][battleTag] and RolesOverView["sync"][battleTag][BNChild] and RolesOverView["sync"][battleTag][BNChild][realmName]
        and RolesOverView["sync"][battleTag][BNChild][realmName][factionGroup] then
            RolesOverView["sync"][battleTag][BNChild][realmName][factionGroup][parsePlayerName] = nil
        end
        RolesOverView["syncKey"][realmName .. ":" .. factionGroup .. ":" .. parsePlayerName] = nil
        ZL.glb["rolesLgnore"][data] = nil
        ZL.RolesOverViewFrame:Update()
        ZL.LgnoreRolesFrame:Update()
	end,
	OnCancel = function(self, data)
	end,
    whileDead = true,
    hideOnEscape = false,
    preferredIndex = 3,  -- 避免与其他弹出窗口冲突
}
--删除绑定子账号
StaticPopupDialogs["ZL_DELETEBNCHILD"] = {
	text = "%s",
	button1 = "解除绑定",
	button2 = "取消",
    OnShow = function(self)
		self.editBox:SetNumeric(false)
        self.editBox:SetAutoFocus(false)
        if self.editBox2 then self.editBox2:Hide() end
        if self.editBox3 then self.editBox3:Hide() end
        if self.editBox4 then self.editBox4:Hide() end
        if self.editBox5 then self.editBox5:Hide() end
        if self.editBox6 then self.editBox6:Hide() end
        if self.editBox7 then self.editBox7:Hide() end
        if self.dropDown then self.dropDown:Hide() end
    end,
	OnAccept = function(self, data)
        RolesOverView["syncKeyUnBind"][data] = nil
        local battleTag, BNChild = strsplit(":", data)
        if RolesOverView["sync"] and RolesOverView["sync"][battleTag] then
            RolesOverView["sync"][battleTag][BNChild] = nil
        end
        local accountPlayer = {}
        local myRealm, myFactiongroup = GetRealmName(), select(2, UnitFactionGroup("player"))
        for key, value in pairs(RolesOverView["syncKey"]) do
            if value == data then
                local realm, factiongroup, player = strsplit(":", key)
                if realm == myRealm and factiongroup == myFactiongroup then
                    tinsert(accountPlayer, player)
                end
                RolesOverView["syncKey"][key] = nil
            end
        end
        if ZL.glb["rolesLgnore"] then
            for key in pairs(ZL.glb["rolesLgnore"]) do
                local _, _, _BNChild, _battleTag = strsplit(":", key)
                if BNChild == _BNChild and battleTag == _battleTag then
                    ZL.glb["rolesLgnore"][key] = nil
                end
            end
        end
        if ZL.glb["rolesDel"] then
            for key in pairs(ZL.glb["rolesDel"]) do
                local _, _, _BNChild, _battleTag = strsplit(":", key)
                if BNChild == _BNChild and battleTag == _battleTag then
                    ZL.glb["rolesDel"][key] = nil
                end
            end
        end
        local msgStr = "已解除[|cffffff00" .. battleTag .. ":" .. (RolesOverView["BNChildNewName"][BNChild] or BNChild) .. "|r]绑定！"
        print(Prefix(msgStr))
        ZL.ScrollingMessageFrame:AddMessage(msgStr)
        -- RolesOverView["BNChildNewName"][BNChild] = nil
        ZL.RolesOverViewFrame.battleTagDropdown:SetMenuTable(ZL.GetBattleTagDropdownList())
        ZL.RolesOverViewFrame.battleTagDropdown:SetDefaultText("全部")
        ZL.RolesOverViewFrame.BNChildDropdown:SetMenuTable(ZL.GetBNChildDropdownList())
        ZL.RolesOverViewFrame.BNChildDropdown:SetDefaultText("全部")
        ZL.RolesOverViewFrame.BNChildDropdown:SetValue("全部")
        ZL.RolesOverViewFrame.realmDropdown:SetMenuTable(ZL.GetRealmDropdownList())
        ZL.RolesOverViewFrame.realmDropdown:SetDefaultText(GetRealmName())
        ZL.RolesOverViewFrame:Update()
        ZL.LgnoreRolesFrame:Update()

        --发送解除消息
        if #accountPlayer > 0 then
            --先判断是否有在线好友
            local isOnline
            for _, player in ipairs(accountPlayer) do
                if ZL.IsOnline(player, nil, nil, true) then
                    --发送解绑信息
                    local _, _, ownSyncKey = ZL.GetOwnRolesSyncKey()
                    local _data = {
                        type = "unBind",
                        playerName = ZL.GetClassColorName(UnitName("player")),
                        rolesData = "已解绑",
                        accountSyncKey = ownSyncKey,
                    }
                    MyAddon:TransmitAddonInfo2("AUTOAUC ROLES", _data, "WHISPER", ZL.ParseClassColorName(player))
                    isOnline = true
                    wipe(accountPlayer)
                    accountPlayer = nil
                    break
                end
            end
            --没有在线好友，则先全部添加, 最多添加2次
            if not isOnline then
                ChatFrame_AddMessageEventFilter("CHAT_MSG_SYSTEM", ZL.AddFriendFilterFunc)
                for _, player in ipairs(accountPlayer) do
                    local info = C_FriendList.GetFriendInfo(player)
                    if (not info) and C_FriendList.GetNumFriends() < 100 then
                        C_FriendList.AddFriend(player)
                    end
                end
                --1秒后再添加一次
                C_Timer.After(1, function ()
                    for _, player in ipairs(accountPlayer) do
                        local info = C_FriendList.GetFriendInfo(player)
                        if (not info) and C_FriendList.GetNumFriends() < 100 then
                            C_FriendList.AddFriend(player)
                        end
                    end
                    --1秒后判断是否有在线好友
                    C_Timer.After(1, function ()
                        ChatFrame_RemoveMessageEventFilter("CHAT_MSG_SYSTEM", ZL.AddFriendFilterFunc)
                        for _, player in ipairs(accountPlayer) do
                            if ZL.IsOnline(player, nil, nil, true) then
                                --发送解绑信息
                                local _, _, ownSyncKey = ZL.GetOwnRolesSyncKey()
                                local _data = {
                                    type = "unBind",
                                    playerName = ZL.GetClassColorName(UnitName("player")),
                                    rolesData = "已解绑",
                                    accountSyncKey = ownSyncKey,
                                }
                                MyAddon:TransmitAddonInfo2("AUTOAUC ROLES", _data, "WHISPER", ZL.ParseClassColorName(player))
                                wipe(accountPlayer)
                                accountPlayer = nil
                                break
                            end
                        end
                    end)
                end)
            end
            
        end

	end,
	OnCancel = function(self, data)
	end,
    whileDead = true,
    hideOnEscape = false,
    preferredIndex = 3,  -- 避免与其他弹出窗口冲突
}