local addonName, ZLAUTO = ...

local ZL = ZLAUTO.mainFrame
-- if ZL.BUILD_DATA >= 4 then return end

local ScrollFrame_OnMouseWheel = ZL.ScrollFrame_OnMouseWheel
local ZLCreateFrame = ZL.ZLCreateFrame
local CreateButton = ZL.CreateButton
local CreateEditBox = ZL.CreateEditBox
local GameTooltipShow = ZL.GameTooltipShow
local emptytable = ZL.emptytable
local cGetItemInfo = C_Item and C_Item.GetItemInfo or GetItemInfo
local PickupContainerItem = C_Container and C_Container.PickupContainerItem or PickupContainerItem

local auctionBuyItemInfo = {} --用来缓存购买物品的信息itemId, count, buyoutPrice
local auctionFailed = {
    ERR_AUCTION_ALREADY_BID, --"你已经对该物品竞价了。"
    ERR_AUCTION_BID_INCREMENT, --"你的提价幅度太小了。"
    ERR_AUCTION_BID_OWN, --"你不能对自己拍卖的物品竞标"
    ERR_AUCTION_DATABASE_ERROR, --"内部拍卖错误"
    ERR_AUCTION_DOUBLE_BID, --"您已经是最高出价者"
    ERR_AUCTION_HIGHER_BID, --"已经有更高的出价了。"
    ERR_AUCTION_HOUSE_BUSY, --"拍卖行当前用户过多。"
    ERR_AUCTION_HOUSE_DISABLED, --"拍卖行目前暂时关闭。|n请稍后再试。"
    ERR_AUCTION_HOUSE_UNAVAILABLE, --"拍卖行当前不可用。"
    ERR_AUCTION_MIN_BID, --"你的出价必须不低于最低竞标价格。"
    ERR_ITEM_NOT_FOUND, --"未找到指定物品"
}
local function isAuctionBidFailed(msg)
    for _, v in ipairs(auctionFailed) do
        if msg == v then
            return true
        end
    end
    return false
end

local function SetCopper(money, frameType)
    if not money or type(money) ~= "number" then return end
    frameType = frameType or "UnitPrice"  --StackPrice
    local gold = floor(money / (COPPER_PER_GOLD))
	local silver = floor((money - (gold * COPPER_PER_GOLD)) / COPPER_PER_SILVER)
	local copper = mod(money, COPPER_PER_SILVER)
    HookAuctionFrame = ZL.HookAuctionFrame
    if frameType == "UnitPrice" then
        HookAuctionFrame.UnitGoldPrice:SetNumber(gold)
        HookAuctionFrame.UnitSilverPrice:SetNumber(silver)
        HookAuctionFrame.UnitCopperPrice:SetNumber(copper)
    elseif frameType == "StackPrice" then
        HookAuctionFrame.StackGoldPrice:SetNumber(gold)
        HookAuctionFrame.StackSilverPrice:SetNumber(silver)
        HookAuctionFrame.StackCopperPrice:SetNumber(copper)
    else
        return
    end
end
local function SetAuctionPriceDownCpper(money)
    if not money or type(money) ~= "number" then return end
    local gold = floor(money / (COPPER_PER_GOLD))
	local silver = floor((money - (gold * COPPER_PER_GOLD)) / COPPER_PER_SILVER)
	local copper = mod(money, COPPER_PER_SILVER)
    HookAuctionFrame = ZL.HookAuctionFrame
    HookAuctionFrame.glodPriceDown:SetNumber(gold)
    HookAuctionFrame.silverPriceDown:SetNumber(silver)
    HookAuctionFrame.copperPriceDown:SetNumber(copper)
end
local function GetAuctionSortColumn(sortTable)
	local existingSortColumn, existingSortReverse = GetAuctionSort(sortTable, 1);
    if (existingSortColumn == "totalbuyout" or existingSortColumn == "unitbid" or existingSortColumn == "unitprice") then
		existingSortColumn = "bid";
	end
	return existingSortColumn, existingSortReverse
end

local function Set_AuctionSort_Column(sortTable)
    SetCVar("auctionSortByBuyoutPrice", 1)
    SetCVar("auctionSortByUnitPrice", 1)
    AuctionFrame_SetSort(sortTable or "list", "bid", false)
end
local function IsCanDo()
    local existingSortColumn, existingSortReverse = GetAuctionSortColumn("list")
    if existingSortColumn ~= "bid" or existingSortReverse ~= false or
    GetCVar("auctionSortByBuyoutPrice") ~= "1" or GetCVar("auctionSortByUnitPrice") ~= "1" then
        return
    else
        return true
    end
end
local function MoneyInputEidtBox(parent, maxLetters, width, atlasName)
    -- local editBox = CreateFrame("EditBox", nil, parent or ZL.HookAuctionFrame, "InputBoxTemplate")
    local editBox = CreateEditBox(parent or ZL.HookAuctionFrame, width or 40, 20, 14, "RIGHT", true, nil, nil, nil, nil, nil)
    if maxLetters then
        editBox:SetMaxLetters(maxLetters)
    end
    if atlasName then
        editBox.Icon = editBox:CreateTexture(nil, "ARTWORK")
        editBox.Icon:SetSize(12, 14)
        editBox.Icon:SetPoint("RIGHT", 13, -2)
        editBox.Icon:SetAtlas(atlasName)
    end
    return editBox
end

local function UpdateSortAnim(isPlay)
    local sortBtn  = ZL.HookAuctionFrame.sortBtn
    if isPlay then
        sortBtn.SpellHighlightAnim:Play()
        sortBtn.SpellHighlightTexture:Show()
    else
        sortBtn.SpellHighlightAnim:Stop()
        sortBtn.SpellHighlightTexture:Hide()
    end
end
local function UpdateUnitPrice()
    local HookAuctionFrame = ZL.HookAuctionFrame
    local gold = HookAuctionFrame.StackGoldPrice:GetNumber()
    local silver = HookAuctionFrame.StackSilverPrice:GetNumber()
    local copper = HookAuctionFrame.StackCopperPrice:GetNumber()
    local count = HookAuctionFrame.StackCount:GetNumber()
    local stackMoney = gold*10000 + silver*100 + copper
    local unitMoney = floor(stackMoney/count)
    SetCopper(unitMoney)
end
local function UpdateStackPrice()
    local HookAuctionFrame = ZL.HookAuctionFrame
    local gold = HookAuctionFrame.UnitGoldPrice:GetNumber()
    local silver = HookAuctionFrame.UnitSilverPrice:GetNumber()
    local copper = HookAuctionFrame.UnitCopperPrice:GetNumber()
    local count = HookAuctionFrame.StackCount:GetNumber()
    local unitMoney = gold*10000 + silver*100 + copper
    local stackMoney = unitMoney*count
    SetCopper(stackMoney, "StackPrice")
end
local function UpdateAuctionPriceDown()
    local HookAuctionFrame = ZL.HookAuctionFrame
    local gold = HookAuctionFrame.glodPriceDown:GetNumber()
    local silver = HookAuctionFrame.silverPriceDown:GetNumber()
    local copper = HookAuctionFrame.copperPriceDown:GetNumber()
    ZL.opt.AucitonPriceDown = gold*10000 + silver*100 + copper
end
local function UpdateDepositMoney()
    local HookAuctionFrame = ZL.HookAuctionFrame
    local StackSize = HookAuctionFrame.StackCount:GetNumber()
    local NumStacks = HookAuctionFrame.NumStacks:GetNumber()
    local perDepositMoney = GetAuctionDeposit(1, 1, 1, StackSize, 1)
    -- HookAuctionFrame.depositMoneyLabel:SetText(format("单组保管费：|cffffffff%s|r", GetMoneyString(perDepositMoney)))
    HookAuctionFrame.totalDepositMoneyLabel:SetText(format("保管费：|cffffffff%s|r", GetMoneyString(perDepositMoney*NumStacks)))
end

local function UpdateStartAuctionCopperInfo(UnitPrice)
    local HookAuctionFrame = ZL.HookAuctionFrame
    SetCopper(UnitPrice)
    SetCopper(UnitPrice*HookAuctionFrame.StackCount:GetNumber(), "StackPrice")
end
local function UpdateStartAuctionStackInfo()
    local stackCount, numStack
    local HookAuctionFrame = ZL.HookAuctionFrame
    local _, _, _, _, _, _, _, _stackCount, _totalCount, itemID = GetAuctionSellItemInfo()
    if not itemID then
        stackCount = 1
        numStack = 1
    else
        if ZL.opt.defaultStackCountMax then
            stackCount = min(_stackCount, _totalCount)
        else
            stackCount = ZL.opt.DefaultStackCount
        end

        if ZL.opt.defaultNumStacksMax then
            numStack = _totalCount
        else
            numStack = ZL.opt.DefaultNumStacks
        end

        if stackCount * numStack > _totalCount then
            if ZL.opt.defaultStackCountOrdefaultNumStacksFirst == 1 then
                numStack = floor(_totalCount/stackCount)
            else
                stackCount = floor(_totalCount/numStack)
            end
        end
    end
    HookAuctionFrame.StackCount:SetNumber(stackCount)
    HookAuctionFrame.NumStacks:SetNumber(numStack)
end

local function BrowseButtonRightClickMenu()
    local menuList = {}
    local i = GetSelectedAuctionItem("list")
    local itemLink = GetAuctionItemLink("list", i)
    local name, _, selectcount, _, _, _, _, _, _, selectbuyoutPrice, selectbidAmount, _, _, owner, _, _, itemId = GetAuctionItemInfo("list", i)
    tinsert(menuList, {
        text = "取消拍卖",
        disabled = owner ~= UnitName("player"),
        func = function ()
            local selectItemLink = GetAuctionItemLink("list", i)
            local isExist, count, buyoutPrice, bidAmount, saleStatus, ownerItemLink, _
            for index = 1, GetNumAuctionItems("owner") do
                ownerItemLink = GetAuctionItemLink("owner", index)
                if ownerItemLink == selectItemLink then
                    _, _, count, _, _, _, _, _, _, buyoutPrice, bidAmount, _, _, _, _, saleStatus = GetAuctionItemInfo("owner", index)
                    if saleStatus ~= 1 and selectcount == count and selectbuyoutPrice == buyoutPrice and selectbidAmount == bidAmount then
                        isExist = true
                        CancelAuction(index)
                        break
                    end
                end
            end
            if not isExist then
                ZL.Print("没有符合要求的拍卖物品，请点搜索按钮刷新")
            end
        end
    })
    tinsert(menuList, {
        text = function ()
            if ZL.opt.AuctionConcern and ZL.opt.AuctionConcern[itemId] then
                return "取消收藏"
            else
                return "收藏"
            end
        end,
        func = function ()
            if ZL.opt.AuctionConcern and ZL.opt.AuctionConcern[itemId] then
                ZL.opt.AuctionConcern[itemId] = nil
                ZL.Print(format("已取消收藏 %s", itemLink), true, true)
            else
                ZL.opt.AuctionConcern = ZL.opt.AuctionConcern or {}
                ZL.opt.AuctionConcern[itemId] = name
                ZL.Print(format("已收藏 %s", itemLink), true, true)
            end
        end
    })
    return menuList
end

local function BrowseNameOnMouseUpMenu()
    local menuList = {}
    local ownerList = {}
    local concernList = {}
    local name, saleStatus, _
    for index = 1, GetNumAuctionItems("owner") do
        name, _, _, _, _, _, _, _, _, _, _, _, _, _, _, saleStatus = GetAuctionItemInfo("owner", index)
        if saleStatus ~= 1 and not tIndexOf(ownerList, name) then
            tinsert(ownerList, name)
        end
    end
    if #ownerList > 0 then
        table.sort(ownerList)
        tinsert(menuList, {text="拍卖中", isTitle=1})
        for _, key in ipairs(ownerList) do
            tinsert(menuList, {
                text = key,
                func = function ()
                    ChatEdit_ActivateChat(ChatEdit_ChooseBoxForSend())
                    ChatEdit_InsertLink(format('"%s"', key))
                    ChatEdit_ChooseBoxForSend():HighlightText()
                end
            })
        end
    end
    if ZL.opt.AuctionConcern and next(ZL.opt.AuctionConcern) then
        tinsert(menuList, {text="收藏", isTitle=1})
        for k, v in pairs(ZL.opt.AuctionConcern) do
            tinsert(concernList, v)
        end
        table.sort(concernList)
        for _, key in ipairs(concernList) do
            tinsert(menuList, {
                text = key,
                func = function ()
                    ChatEdit_ActivateChat(ChatEdit_ChooseBoxForSend())
                    if ZL.opt.AuctionPreciseSortKey then
                        ChatEdit_InsertLink(format('"%s"', key))
                    else
                        ChatEdit_InsertLink(format('%s', key))
                    end
                    ChatEdit_ChooseBoxForSend():HighlightText()
                end
            })
        end
    end
    local AuctionSortKeyList = ZL.opt.AuctionSortKeyList
    if AuctionSortKeyList and #AuctionSortKeyList > 0 then
        tinsert(menuList, {text="历史搜索词", isTitle=1})
        for _, key in ipairs(AuctionSortKeyList) do
            if not tIndexOf(ownerList, key) and not tIndexOf(concernList, key) then
                tinsert(menuList, {
                    text = key,
                    func = function ()
                        ChatEdit_ActivateChat(ChatEdit_ChooseBoxForSend())
                        if ZL.opt.AuctionPreciseSortKey then
                            ChatEdit_InsertLink(format('"%s"', key))
                        else
                            ChatEdit_InsertLink(format('%s', key))
                        end
                        ChatEdit_ChooseBoxForSend():HighlightText()
                    end
                })
            end
        end
    end
    ownerList = nil
    concernList = nil
    return menuList
end

local function BuyItemsInfoFrame_Update(self)
    local batchAuctions = GetNumAuctionItems("list")
    if batchAuctions > 0 and self.index <= batchAuctions then
        local name, texture, count, _, _, _, _, _, _, buyoutPrice, _, _, _, _, _, _, itemId = GetAuctionItemInfo("list", self.index)
        self.itemId = itemId
        self.itemName = name
        self.currentBuyoutPrice = buyoutPrice
        self.currentCount = count
        self.currentItemName:SetText("|T" .. texture .. ":18:18:-2:0|t" .. self.itemLink)
        local unitPrice = floor(buyoutPrice/count)
        unitPrice = unitPrice == 0 and 1 or unitPrice
        self.currentBuyInfo:SetTextScale(1)
        self.totalBuyInfo:SetTextScale(1)
        self.currentBuyInfo:SetText(format("购买：%d |CFFFFDE00×|r %s |CFFFFDE00=|r %s", count, GetMoneyString(unitPrice), GetMoneyString(buyoutPrice)))
        local bili = self.currentBuyInfo:GetStringWidth()>0 and self.currentBuyInfo:GetWidth()/(self.currentBuyInfo:GetUnboundedStringWidth()+5) or 1
        if bili < 1 then
            self.currentBuyInfo:SetTextScale(bili)
        else
            self.currentBuyInfo:SetTextScale(1)
        end
        if self.totalMoney then
            self.totalBuyInfo:SetText(format("总计：%d |CFFFFDE00×|r %s |CFFFFDE00=|r %s", self.totalCount, GetMoneyString(floor(self.totalMoney/self.totalCount)), GetMoneyString(self.totalMoney)))
            bili = self.totalBuyInfo:GetStringWidth()>0 and self.totalBuyInfo:GetWidth()/(self.totalBuyInfo:GetUnboundedStringWidth()+5) or 1
            if bili < 1 then
                self.currentBuyInfo:SetTextScale(bili)
            else
                self.currentBuyInfo:SetTextScale(1)
            end
        else
            self.totalBuyInfo:SetText(" ")
        end

    else
        self:Hide()
    end
end

local function SaveAuctionItemsData()
    HookAuctionFrame = ZL.HookAuctionFrame
    local label = HookAuctionFrame.ScanAllInfoLabel
    label:SetText("缓存数据中，请稍后，不要关闭窗口...")
    -- ZL.Print("缓存数据中，请稍后，不要关闭窗口...", true, true, 1, 1, 1)
    local startIndex = 0
    local tempIndex = 0
    local stepSize = 500
    local currentAuctions = GetNumAuctionItems("list")
    local totalItems = 0
    if currentAuctions  == 0 then return end
    ZL.opt.AuctionPostItemsHistoryPrice = ZL.opt.AuctionPostItemsHistoryPrice or {}
    local priceList = ZL.opt.AuctionPostItemsHistoryPrice
    local itemId, count, buyoutPrice, unitPrice, _
    local tempList = {}
    local postDate = date("%Y-%m-%d", time())
    local function tempfunc()
        if startIndex >= currentAuctions then
            for k, v in pairs(tempList) do
                priceList[k] = priceList[k] or {}
                if priceList[k][1] and priceList[k][1][3] == postDate then  --1为当日最低价，2为当前扫描最低价， 3为扫描日期
                    if priceList[k][1][1] > v then
                        priceList[k][1][1] = floor(v)
                    end
                    priceList[k][1][2] = floor(v)
                else
                    tinsert(priceList[k], 1, {floor(v), floor(v), postDate})
                end
            end
            tempList = nil
            local txt = format("全局扫描完成，物品ID数：%d，用时:%s", totalItems, SecondsToTime(time() - HookAuctionFrame.scanAllStartTime))
            label:SetText(txt)
            ZL.Print(txt, true, true, 1, 1, 1)
            C_Timer.After(2, function ()
                HookAuctionFrame.SaveData = nil
                HookAuctionFrame.scanAllProcess = nil
                HookAuctionFrame.scanAllStartTime = nil
                HookAuctionFrame.ScanAllBtn:Enable()
            end)
            C_Timer.After(15, function ()
                label:SetText("")
            end)
        else
            tempIndex = startIndex
            for i = tempIndex+1, min(tempIndex+stepSize, currentAuctions) do
                label:SetText(format("缓存数据中:%.0f%%，请不要关闭窗口...", i*100/currentAuctions))
                _, _, count, _, _, _, _, _, _, buyoutPrice, _, _, _, _, _, _, itemId = GetAuctionItemInfo("list", i)
                -- itemLink = GetAuctionItemLink("list", i)
                if itemId and buyoutPrice > 0 then
                    unitPrice = buyoutPrice/count
                    if not tempList[itemId] then
                        totalItems = totalItems + 1
                        tempList[itemId] = unitPrice
                    else
                        if unitPrice < tempList[itemId] then
                            tempList[itemId] = unitPrice
                        end
                    end
                end
            end
            startIndex = min(tempIndex+stepSize, currentAuctions)
            C_Timer.After(0.01, tempfunc)
        end
    end
    tempfunc()
end

local function AuctionBuyItemsHistory(itemId, count, price)
    ZL.opt.BuyItemsHistoryList = ZL.opt.BuyItemsHistoryList or {}
    local list = ZL.opt.BuyItemsHistoryList
    list[itemId] = list[itemId] or {}
    local buyDate = date("%Y-%m-%d", time())
    list[itemId][buyDate] = list[itemId][buyDate] or {0, 0}
    list[itemId][buyDate][1] = list[itemId][buyDate][1] + count
    list[itemId][buyDate][2] = list[itemId][buyDate][2] + price
end

local function OtherSettingMenu()
    local menuList = {
        {
            text = "精准搜索",
            checkable = 1,
            isNotRadio = 1,
            checked = ZL.opt.AuctionPreciseSortKey,
            tooltipText = "|CFFFFDE00Shift+左键|r|CFFFFFFFF自动输入搜索关键词为原生功能，无论是否勾选都会以精准匹配方式输入，高频率精准搜索会加大卡顿的概率|r",
            tooltipTitle = "|CFFFFDE00精准搜索：带双引号的搜索关键词|r",
            tooltipOnButton = 1,
            keepShownOnClick = 1,
            func = function (owner, data)
                ZL.opt.AuctionPreciseSortKey = data.checked
            end
        },
        {
            text = "售出语音",
            checkable = 1,
            isNotRadio = 1,
            checked = ZL.opt.AuctionItemSold,
            keepShownOnClick = 1,
            func = function (owner, data)
                ZL.opt.AuctionItemSold = data.checked
            end
        },
        {
            text = "拍卖时长",
            hasArrow = 1,
            notClickable = 1,
            menuTable = function ()
                local tempList = {}
                for i, v in ipairs({"12小时", "24小时", "48小时"}) do
                    tinsert(tempList, {
                        text = v,
                        checkable = 1,
                        checked = ZL.opt.AuctionDefaultTime == i,
                        func = function ()
                            ZL.opt.AuctionDefaultTime = i
                            ZL.GUI:CloseMenu()
                        end
                    })
                end
                return tempList
            end
        },
        {
            text = "数据保存",
            hasArrow = 1,
            notClickable = 1,
            menuTable = {
                {
                    text = "扫描数据",
                    hasArrow = 1,
                    notClickable = 1,
                    menuTable = function ()
                        local scanList = {}
                        for i = 1, 14 do
                            tinsert(scanList, {
                                text = i,
                                checkable = 1,
                                checked = i == ZL.opt.AuctionPriceSaveDays,
                                func = function ()
                                    ZL.opt.AuctionPriceSaveDays = i
                                    ZL.GUI:CloseMenu()
                                end
                            })
                        end
                        return scanList
                    end
                },
                {
                    text = "购买数据",
                    hasArrow = 1,
                    notClickable = 1,
                    menuTable = function ()
                        local buyList = {}
                        for _, v in ipairs({7, 14, 21, 28}) do
                            tinsert(buyList, {
                                text = v,
                                checkable = 1,
                                checked = v == ZL.opt.BuyItemsHistorySaveDays,
                                func = function ()
                                    ZL.opt.BuyItemsHistorySaveDays = v
                                    ZL.GUI:CloseMenu()
                                end
                            })
                        end
                        return buyList
                    end
                },
            }
        },
        {
            text = "购买展示天数",
            hasArrow = 1,
            notClickable = 1,
            tooltipTitle = "|CFFFFDE00在鼠标提示中显示AH最近几天购买均价|r",
            tooltipOnButton = 1,
            menuTable = function ()
                local showList = {}
                for _, v in ipairs({1, 2, 3, 7, 14, 21, 28}) do
                    tinsert(showList, {
                        text = v,
                        checkable = 1,
                        checked = v == ZL.opt.ShowBuyItemsHistorySaveDays,
                        func = function ()
                            ZL.opt.ShowBuyItemsHistorySaveDays = v
                            ZL.GUI:CloseMenu()
                        end
                    })
                end
                return showList
            end
        },
        {
            text = "趋势图天数",
            hasArrow = 1,
            notClickable = 1,
            tooltipTitle = "|CFFFFDE00在鼠标提示中显示AH最近几天价格趋势图|r",
            tooltipOnButton = 1,
            menuTable = function ()
                local showList = {}
                for _, v in ipairs({7, 14}) do
                    tinsert(showList, {
                        text = v,
                        checkable = 1,
                        checked = v == ZL.opt.AHPriceChartDays,
                        func = function ()
                            ZL.opt.AHPriceChartDays = v
                            ZL.GUI:CloseMenu()
                        end
                    })
                end
                return showList
            end
        },
        {
            text = "鼠标提示",
            hasArrow = 1,
            notClickable = 1,
            menuTable = {
                {
                    text = "物品数量",
                    checkable = 1,
                    isNotRadio = 1,
                    checked = ZL.opt.showItemCounts,
                    keepShownOnClick = 1,
                    func = function (owner, data)
                        ZL.opt.showItemCounts = data.checked
                    end
                },
                {
                    text = "卖店价格",
                    checkable = 1,
                    isNotRadio = 1,
                    checked = ZL.opt.showSoldToNPC,
                    keepShownOnClick = 1,
                    func = function (owner, data)
                        ZL.opt.showSoldToNPC = data.checked
                    end
                },
                {
                    text = "扫描价格",
                    checkable = 1,
                    isNotRadio = 1,
                    checked = ZL.opt.showAuctionPostItemsHistoryPrice,
                    keepShownOnClick = 1,
                    func = function (owner, data)
                        ZL.opt.showAuctionPostItemsHistoryPrice = data.checked
                    end
                },
                {
                    text = "购买均价",
                    checkable = 1,
                    isNotRadio = 1,
                    checked = ZL.opt.showBuyItemsHistoryPrice,
                    keepShownOnClick = 1,
                    tooltipTitle = "|CFFFFDE00记录在AH购买物品的价格|r",
                    tooltipOnButton = 1,
                    func = function (owner, data)
                        ZL.opt.showBuyItemsHistoryPrice = data.checked
                    end
                },
                {
                    text = "价格趋势图",
                    checkable = 1,
                    isNotRadio = 1,
                    checked = ZL.opt.showAHPriceChartFrame,
                    keepShownOnClick = 1,
                    tooltipTitle = "|CFFFFDE00AH缓存最低价和购买均价趋势图|r",
                    tooltipOnButton = 1,
                    func = function (owner, data)
                        ZL.opt.showAHPriceChartFrame = data.checked
                    end
                },
--[[               
                {
                    text = "拍卖状态",
                    checkable = 1,
                    isNotRadio = 1,
                    checked = ZL.opt.auctionStateTip,
                    keepShownOnClick = 1,
                    func = function (owner, data)
                        ZL.opt.auctionStateTip = data.checked
                    end
                },
                {
                    text = "历史成交价",
                    checkable = 1,
                    isNotRadio = 1,
                    checked = ZL.opt.historyMaxAndMin,
                    keepShownOnClick = 1,
                    func = function (owner, data)
                        ZL.opt.historyMaxAndMin = data.checked
                    end
                },
                {
                    text = "成交趋势图",
                    checkable = 1,
                    isNotRadio = 1,
                    checked = ZL.opt.historyTrendChart,
                    keepShownOnClick = 1,
                    func = function (owner, data)
                        ZL.opt.historyTrendChart = data.checked
                    end
                },
]]
            }
        },
    }


    return menuList
end
local f = CreateFrame("Frame")
f:RegisterEvent("AUCTION_HOUSE_SHOW")
f:SetScript("OnEvent", function (slef, event, ...)
    if event == "AUCTION_HOUSE_SHOW" then
        if not ZL.HookAuctionFrame then
            if AuctionFrame and _G["BrowseButton1"] then
                ZL:CreateHookAuctionFrame()
                f:UnregisterEvent("AUCTION_HOUSE_SHOW")
                local id = 1
                local btn = _G["BrowseButton" .. id]
                local ownerTextur
                while btn do
                    ownerTextur = btn:CreateTexture(nil, "BACKGROUND")
                    ownerTextur:SetAllPoints()
                    ownerTextur:SetTexture([[Interface\QuestFrame\UI-QuestLogTitleHighlight]])
                    ownerTextur:Hide()
                    btn.ownerTextur = ownerTextur
                    btn:RegisterForClicks("LeftButtonUp", "RightButtonUp")
                    btn:HookScript("OnClick", function (self, button)
                        local index = mod(self.itemIndex,50) == 0 and 50 or mod(self.itemIndex,50)
                        local name, _, count, _, _, _, _, _, _, buyoutPrice, _, _, _, owner, _, saleStatus, _itemID = GetAuctionItemInfo("list", index)
                        auctionBuyItemInfo = {
                            itemId = _itemID,
                            count = count,
                            buyoutPrice = buyoutPrice,
                            itemName = name,
                        }
                        if button == "LeftButton" then
                            local itemID = select(10, GetAuctionSellItemInfo())
                            if itemID then
                                -- local _, _, count, _, _, _, _, _, _, buyoutPrice, _, _, _, owner, _, _, _itemID = GetAuctionItemInfo("list", index)
                                if itemID == _itemID and buyoutPrice > 0 then
                                    local UnitPrice = owner == UnitName("player") and floor(buyoutPrice/count) or (floor(buyoutPrice/count) - ZL.opt.AucitonPriceDown)
                                    UpdateStartAuctionCopperInfo(UnitPrice)
                                    UpdateStartAuctionStackInfo()
                                end
                            end
                        else
                            if IsModifierKeyDown() then
                                if IsShiftKeyDown() then
                                    if name and saleStatus ~=1 and buyoutPrice > 0 and owner ~= UnitName("player") then
                                        HookAuctionFrame.BuyItemsInfoFrame:Hide()
                                        PlaceAuctionBid("list", index, buyoutPrice)
                                    end
                                end
                            else
                                ZL.GUI:ToggleMenu(self, BrowseButtonRightClickMenu(), "cursor")
                            end
                        end
                    end)
                    id = id + 1
                    btn = _G["BrowseButton" .. id]
                end
                id = 1
                btn = _G["AuctionsButton" .. id]
                while btn do
                    btn:RegisterForClicks("LeftButtonUp", "RightButtonUp")
                    btn:HookScript("OnClick", function (self, button)
                        if button == "RightButton" then
                            local index = GetSelectedAuctionItem("owner")
                            local saleStatus = select(16, GetAuctionItemInfo("owner", index))
                            if saleStatus ~= 1 then
                                CancelAuction(index)
                            end
                        end
                    end)
                    id = id + 1
                    btn = _G["AuctionsButton" .. id]
                end
                _G["BrowseBuyoutButton"]:HookScript("OnEnable", function (self)
                    if not HookAuctionFrame.BuyItemsInfoFrame:IsShown() then
                        HookAuctionFrame.BuyAuctionBtn:Enable()
                    end
                end)
                _G["BrowseBuyoutButton"]:HookScript("OnDisable", function (self)
                    if not HookAuctionFrame.BuyItemsInfoFrame:IsShown() then
                        HookAuctionFrame.BuyAuctionBtn:Disable()
                    end
                end)
                _G["BrowseBuyoutButton"]:HookScript("OnClick", function ()
                    HookAuctionFrame.BuyItemsInfoFrame:Hide()
                end)
                _G["BrowseBidButton"]:HookScript("OnClick", function ()
                    HookAuctionFrame.BuyItemsInfoFrame:Hide()
                end)
                hooksecurefunc("AuctionFrameBrowse_Search", function ()
                    HookAuctionFrame.BuyItemsInfoFrame:Hide()
                end)
                hooksecurefunc("FauxScrollFrame_Update", function (frame)
                    if frame == _G["BrowseScrollFrame"] then
                        for i = 1, NUM_BROWSE_TO_DISPLAY do
                            btn = _G["BrowseButton" .. i]
                            if btn.itemIndex then
                                local index = mod(btn.itemIndex,50) == 0 and 50 or mod(btn.itemIndex,50)
                                local owner = select(14, GetAuctionItemInfo("list", index))
                                if owner == UnitName("player") then
                                    btn.ownerTextur:Show()
                                else
                                    btn.ownerTextur:Hide()
                                end
                            end
                        end
                    end
                end)
                hooksecurefunc("AuctionFrameBrowse_Search", function ()
                    -- _G["BrowseName"]:ClearFocus()
                    local txt = _G["BrowseName"]:GetText() or ""
                    txt = txt:gsub('"', "")
                    if #txt > 0 then
                        ZL.opt.AuctionSortKeyList = ZL.opt.AuctionSortKeyList or {}
                        local index = tIndexOf(ZL.opt.AuctionSortKeyList, txt)
                        if index then
                            tremove(ZL.opt.AuctionSortKeyList, index)
                        end
                        tinsert(ZL.opt.AuctionSortKeyList, 1, txt)
                        if #ZL.opt.AuctionSortKeyList > 20 then
                            for i = #ZL.opt.AuctionSortKeyList, 21, -1 do
                                tremove(ZL.opt.AuctionSortKeyList, i)
                            end
                        end
                    end
                end)
                btn = nil
                ownerTextur = nil
            end
        end
        Set_AuctionSort_Column()
    end
end)

function ZL:CreateHookAuctionFrame()
    ZL.HookAuctionFrame = ZLCreateFrame(nil, AuctionFrame, 300, AuctionFrame:GetHeight()-27, nil, nil, nil, "AutoAuction(" .. ZL.addonVersion .. "|cffffffff拍卖行|r)")
    local HookAuctionFrame = ZL.HookAuctionFrame
    HookAuctionFrame.Background:SetColorTexture(0.05, 0.05, 0.05, 1)
    HookAuctionFrame:SetPoint("TOPLEFT", AuctionFrame, "TOPRIGHT", 0, -15)
    HookAuctionFrame.resizeButton:Hide()
    HookAuctionFrame:SetScript("OnShow", function ()
        HookAuctionFrame.New_Auction_Update()
        UpdateDepositMoney()
        UpdateStartAuctionStackInfo()
    end)
    HookAuctionFrame:SetScript("OnMouseUp", function (self, button)
        if button == "LeftButton" then
            local infoType, itemID = GetCursorInfo()
            if infoType and infoType == "item" and itemID then
                ClickAuctionSellItemButton()
                ClearCursor()
                local name = cGetItemInfo(itemID)
                ChatEdit_ActivateChat(ChatEdit_ChooseBoxForSend())
                if ZL.opt.AuctionPreciseSortKey then
                    ChatEdit_InsertLink(format('"%s"', name))
                else
                    ChatEdit_InsertLink(format('%s', name))
                end
                ChatEdit_ChooseBoxForSend():HighlightText()
            else
                local edit = GetCurrentKeyBoardFocus()
                if edit then
                    edit:ClearFocus()
                end
            end
        end
    end)
    local showBtn = CreateButton(nil, _G["AuctionFrameBrowse"], ">>", "LEFT", BrowseSearchButton, "RIGHT", 13, 3, 30, BrowseSearchButton:GetHeight()-4, 14, true, 0)
    HookAuctionFrame.showBtn = showBtn
    showBtn:SetScript("OnClick", function ()
        if HookAuctionFrame:IsShown() then
            HookAuctionFrame:Hide()
        else
            HookAuctionFrame:Show()
        end
    end)
    local ScanAllBtn = CreateButton(nil, AuctionFrame, "扫描全部", "BOTTOMRIGHT", AuctionFrameCloseButton, "TOPRIGHT", 0, 0, 80, AuctionFrameCloseButton:GetHeight()-6, 13, true, 0)
    HookAuctionFrame.ScanAllBtn = ScanAllBtn
    local ScanAllInfoLabel = ScanAllBtn:CreateFontString(nil, "ARTWORK")
    ScanAllInfoLabel:SetFont(GameFontNormal:GetFont(), 13)
    ScanAllInfoLabel:SetPoint("LEFT", ScanAllBtn, "RIGHT", 5, 0)
    HookAuctionFrame.ScanAllInfoLabel = ScanAllInfoLabel
    -- ScanAllBtn:RegisterForClicks("LeftButtonUp", "RightButtonUp")
    ScanAllBtn:SetScript("OnClick", function (self, button)
        if button == "LeftButton" then
            local canQueryAll = select(2, CanSendAuctionQuery())
            if canQueryAll and (time() - (ZL.opt.LastSacnAllTime or 0) > 900) then
                HookAuctionFrame.scanAllProcess = true
                HookAuctionFrame.scanAllStartTime = time()
                _G["BrowseName"]:SetText("")
                QueryAuctionItems("", nil, nil, 0, nil, nil, true, false, nil)
                self:Disable()
                local txt = "请求数据中，可能有几分钟卡顿，请耐心等待，不要关闭窗口..."
                ScanAllInfoLabel:SetText(txt)
                ZL.Print(txt, true, true, 1, 1, 1)
            else
                local remainingTimeScanAll = SecondsToTime(900 - (time() - (ZL.opt.LastSacnAllTime or 0)))
                remainingTimeScanAll = #remainingTimeScanAll > 0 and remainingTimeScanAll or "0"
                ZL.Print(format("距离下次全局扫描还剩:%s", remainingTimeScanAll), true, nil, 1, 1, 1)
            end
        end
    end)
    ScanAllBtn:SetScript("OnEnter", function (self)
        GameTooltipShow(self, "BOTTOMLEFT", "TOPRIGHT")
        GameTooltip:AddLine("数据保存说明")
        GameTooltip:AddLine("1、为减少内存占用，缓存数据按照|CFFFFDE00物品ID|r统计；", 1, 1, 1)
        GameTooltip:AddLine("2、相同物品ID可能存在不同属性，造成价格不同，\n所以缓存价格仅供参考；", 1, 1, 1)
        GameTooltip:AddLine("3、缓存数据最大支持14天，天数越多，占用内存越大，\n请根据自己电脑配置在|CFFFFDE00更多设置|r选择保存天数", 1, 1, 1)
        GameTooltip:Show()
    end)
    ScanAllBtn:SetScript("OnLeave", function ()
        GameTooltip:Hide()
    end)
    local CancelAuctionBtn = CreateButton(nil, AuctionFrameBrowse, "取消有更低价的", "RIGHT", ScanAllBtn, "LEFT", -3, 0, 120, AuctionFrameCloseButton:GetHeight()-6, 13, true, 0)
    HookAuctionFrame.CancelAuctionBtn = CancelAuctionBtn
    CancelAuctionBtn:Disable()
    CancelAuctionBtn:SetScript("OnClick", function (self)
        if not IsCanDo() then
            ZL.Print("未按指定排序，无法操作！")
            return
        end
        local _, _, count, _, _, _, _, _, _, buyoutPrice, _, _, _, _, _, _, itemId = GetAuctionItemInfo("list", 1)
        if itemId and buyoutPrice > 0 then
            local itemLink = GetAuctionItemLink("list", 1)
            local ownerItemLink, ownercount, ownerbuyoutPrice, ownersaleStatus
            for index = 1, GetNumAuctionItems("owner") do
                ownerItemLink = GetAuctionItemLink("owner", index)
                if ownerItemLink == itemLink then
                    _, _, ownercount, _, _, _, _, _, _, ownerbuyoutPrice, _, _, _, _, _, ownersaleStatus = GetAuctionItemInfo("owner", index)
                    if ownersaleStatus ~= 1 and ownerbuyoutPrice > 0 and ownerbuyoutPrice/ownercount > buyoutPrice/count then
                        CancelAuction(index)
                        break
                    end
                end
            end
            local isExist
            for index = 1, GetNumAuctionItems("owner") do
                ownerItemLink = GetAuctionItemLink("owner", index)
                if ownerItemLink == itemLink then
                    _, _, ownercount, _, _, _, _, _, _, ownerbuyoutPrice, _, _, _, _, _, ownersaleStatus = GetAuctionItemInfo("owner", index)
                    if ownersaleStatus ~= 1 and ownerbuyoutPrice/ownercount > buyoutPrice/count then
                        isExist = true
                        break
                    end
                end
            end
            if not isExist then
                self:Disable()
                ZL.Print(itemLink .. "已全部取消有更低价的拍卖。")
            end
        end
    end)
    local BuyAuctionBtn = CreateButton(nil, AuctionFrameBrowse, "连续购买", "RIGHT", CancelAuctionBtn, "LEFT", -3, 0, 80, AuctionFrameCloseButton:GetHeight()-6, 13, true, 0)
    HookAuctionFrame.BuyAuctionBtn = BuyAuctionBtn
    BuyAuctionBtn:Disable()
    BuyAuctionBtn:SetScript("OnClick", function ()
        HookAuctionFrame.BuyItemsInfoFrame:Show()
    end)
    local BuyItemsInfoFrame = CreateFrame("Frame", nil, AuctionFrameBrowse, "BackdropTemplate")
    HookAuctionFrame.BuyItemsInfoFrame = BuyItemsInfoFrame
    BuyItemsInfoFrame:Hide()
    BuyItemsInfoFrame:SetSize(450, 200)
    BuyItemsInfoFrame:SetPoint("CENTER", AuctionFrameBrowse, "CENTER", 120, 0)
    BuyItemsInfoFrame:SetFrameStrata("DIALOG")
    BuyItemsInfoFrame:SetToplevel(true)
    BuyItemsInfoFrame:SetMovable(true)
    BuyItemsInfoFrame:SetHyperlinksEnabled(true)
    BuyItemsInfoFrame:SetScript("OnMouseUp", function (self)
        self:StopMovingOrSizing()
    end)
    BuyItemsInfoFrame:SetScript("OnMouseDown", function (self)
        self:StartMoving()
    end)
    BuyItemsInfoFrame:SetScript("OnHyperlinkEnter", function(self, link)
        local itemID = GetItemInfoInstant(link)
        if itemID then
            GameTooltip:SetOwner(self, "ANCHOR_CURSOR", 0, 0)
            GameTooltip:ClearLines()
            GameTooltip:SetHyperlink(link)
            GameTooltip:Show()
        end
    end)
    BuyItemsInfoFrame:SetScript("OnHyperlinkLeave", function(self)
        GameTooltip:Hide()
    end)
    BuyItemsInfoFrame:SetBackdrop({
        bgFile = "Interface\\DialogFrame\\UI-DialogBox-Background-Dark",
        edgeFile = "Interface\\DialogFrame\\UI-DialogBox-Border",
        tile = true,
        tileSize = 32,
        edgeSize = 32,
        insets = { left = 11, right = 12, top = 12, bottom = 11 }
    })
    BuyItemsInfoFrame:SetScript("OnShow", function (self)
        BuyAuctionBtn:Disable()
        self.BuyItemsInfoFrameBuyBtn:Enable()
        self.totalNeedBuyCount:SetText("")
        local index = GetSelectedAuctionItem("list")
        self.itemLink = GetAuctionItemLink("list", index)
        self.index = index
        self.itemId = nil
        self.totalMoney = nil
        self.totalCount = nil
        self.currentBuyoutPrice = nil
        self.currentCount = nil
        BuyItemsInfoFrame_Update(self)
    end)
    BuyItemsInfoFrame:SetScript("OnHide", function (self)
        if _G["BrowseBuyoutButton"]:IsEnabled() then
            BuyAuctionBtn:Enable()
        else
            BuyAuctionBtn:Disable()
        end
    end)
    local currentItemName = BuyItemsInfoFrame:CreateFontString(nil, "ARTWORK")
    currentItemName:SetSize(BuyItemsInfoFrame:GetWidth()-40, 24)
    currentItemName:SetFont(GameFontNormal:GetFont(), 20)
    currentItemName:SetPoint("TOP", 0, -20)
    BuyItemsInfoFrame.currentItemName = currentItemName

    local currentBuyInfo = BuyItemsInfoFrame:CreateFontString(nil, "ARTWORK")
    currentBuyInfo:SetFont(GameFontNormal:GetFont(), 16)
    currentBuyInfo:SetSize(BuyItemsInfoFrame:GetWidth()-40, 20)
    currentBuyInfo:SetJustifyH("LEFT")
    currentBuyInfo:SetPoint("TOPLEFT", BuyItemsInfoFrame, "TOPLEFT", 20, -(30+currentItemName:GetHeight()))
    BuyItemsInfoFrame.currentBuyInfo = currentBuyInfo
    local totalBuyInfo = BuyItemsInfoFrame:CreateFontString(nil, "ARTWORK")
    totalBuyInfo:SetFont(GameFontNormal:GetFont(), 16)
    totalBuyInfo:SetSize(BuyItemsInfoFrame:GetWidth()-40, 20)
    totalBuyInfo:SetJustifyH("LEFT")
    totalBuyInfo:SetPoint("TOPLEFT", currentBuyInfo, "BOTTOMLEFT", 0, -5)
    BuyItemsInfoFrame.totalBuyInfo = totalBuyInfo
    local totalNeedBuyCountLabel = BuyItemsInfoFrame:CreateFontString(nil, "ARTWORK")
    totalNeedBuyCountLabel:SetFont(GameFontNormal:GetFont(), 14)
    totalNeedBuyCountLabel:SetHeight(20)
    totalNeedBuyCountLabel:SetJustifyH("LEFT")
    totalNeedBuyCountLabel:SetPoint("TOPLEFT", totalBuyInfo, "BOTTOMLEFT", 0, -15)
    totalNeedBuyCountLabel:SetText("数量")
    local totalNeedBuyCount = MoneyInputEidtBox(BuyItemsInfoFrame, nil, 60)
    BuyItemsInfoFrame.totalNeedBuyCount = totalNeedBuyCount
    totalNeedBuyCount:SetPoint("LEFT", totalNeedBuyCountLabel, "RIGHT", 5, 0)

    -- local perBuyMoneyLabel = BuyItemsInfoFrame:CreateFontString(nil, "ARTWORK")
    -- perBuyMoneyLabel:SetFont(GameFontNormal:GetFont(), 14)
    -- perBuyMoneyLabel:SetHeight(20)
    -- perBuyMoneyLabel:SetJustifyH("LEFT")
    -- perBuyMoneyLabel:SetPoint("LEFT", totalNeedBuyCount, "RIGHT", 10, 0)
    -- perBuyMoneyLabel:SetText("均价")
    -- local perBuyMoney = MoneyInputEidtBox(BuyItemsInfoFrame, nil, 60)
    -- BuyItemsInfoFrame.perBuyMoney = perBuyMoney
    -- perBuyMoney:SetPoint("LEFT", perBuyMoneyLabel, "RIGHT", 5, 0)

    local BuyItemsInfoFrameCloseBtn = CreateFrame("Button", nil, BuyItemsInfoFrame, "UIPanelButtonTemplate")
    BuyItemsInfoFrame.BuyItemsInfoFrameCloseBtn = BuyItemsInfoFrameCloseBtn
    BuyItemsInfoFrameCloseBtn:SetSize(60, 25)
    BuyItemsInfoFrameCloseBtn:SetPoint("BOTTOMRIGHT", BuyItemsInfoFrame, "BOTTOMRIGHT", -20, 20)
    BuyItemsInfoFrameCloseBtn:SetText("关闭")
    BuyItemsInfoFrameCloseBtn:SetScript("OnClick", function ()
        BuyItemsInfoFrame:Hide()
    end)

    local BuyItemsInfoFrameBuyBtn = CreateFrame("Button", nil, BuyItemsInfoFrame, "UIPanelButtonTemplate")
    BuyItemsInfoFrame.BuyItemsInfoFrameBuyBtn = BuyItemsInfoFrameBuyBtn
    BuyItemsInfoFrameBuyBtn:SetSize(60, 25)
    BuyItemsInfoFrameBuyBtn:SetPoint("RIGHT", BuyItemsInfoFrameCloseBtn, "LEFT", -5, 0)
    BuyItemsInfoFrameBuyBtn:SetText("购买")
    BuyItemsInfoFrameBuyBtn:SetScript("OnClick", function (self)
        local needBuyCount = BuyItemsInfoFrame.totalNeedBuyCount:GetNumber()
        if needBuyCount > 0 and (BuyItemsInfoFrame.totalCount or 0 )>= needBuyCount then
            ZL.Print("已购买足够数量！")
            return
        end
        local batchAuctions = GetNumAuctionItems("list")
        if batchAuctions == 0 then
            ZL.Print("当前页没有拍卖物品！", true)
            return
        end
        local index = BuyItemsInfoFrame.index
        if index > batchAuctions then
            ZL.Print("已到末尾，如需购买，请关掉窗口后重新选择！", true)
            return
        end
        local isExsit = true
        local name, _, count, _, _, _, _, _, _, buyoutPrice, _, _, _, owner = GetAuctionItemInfo("list", index)
        if not name or buyoutPrice == 0 or owner == UnitName("player") or GetAuctionItemLink("list", index) ~= BuyItemsInfoFrame.itemLink then
            isExsit = false
            for i = index+1, batchAuctions do
                name, _, _, _, _, _, _, _, _, buyoutPrice, _, _, _, owner = GetAuctionItemInfo("list", i)
                if name and buyoutPrice > 0 and owner ~= UnitName("player") and GetAuctionItemLink("list", i) == BuyItemsInfoFrame.itemLink then
                    isExsit = true
                    BuyItemsInfoFrame.index = i
                    break
                end
            end
        end
        if not isExsit then
            ZL.Print("当前页未找到符合要求的拍卖物品，请关闭窗口后重新搜索！", true)
            return
        end
        index = BuyItemsInfoFrame.index
        buyoutPrice = select(10, GetAuctionItemInfo("list", index))
        if buyoutPrice > GetMoney() then
            ZL.Print("金币不足！", true)
        end
        PlaceAuctionBid("list", index, buyoutPrice)
        self:Disable()
    end)

    local lockBtnFrame = CreateFrame("Button", nil, _G["BrowsePriceOptionsButtonFrame"].Button)
    BuyItemsInfoFrame.lockBtnFrame = lockBtnFrame
    lockBtnFrame:SetPoint("TOPLEFT", _G["BrowseQualitySort"], "TOPLEFT")
    lockBtnFrame:SetPoint("BOTTOMRIGHT", _G["BrowsePriceOptionsButtonFrame"].Button, "BOTTOMRIGHT")
    lockBtnFrame:SetScript("OnClick", function ()
        if ZL.opt.AuctionSortLock then
            local link = "手动排序功能已锁定，点击" .. format("|cff87CEEB|Hgarrmission:%s:%s|h[%s]|h|r", "AutoAuction", "unAuctionSortLock", "解锁")
            ZL.Print(link)
        end
    end)
    local quicklyCancelAuctionLabel = _G["AuctionFrameAuctions"]:CreateFontString(nil, "ARTWORK", "GameFontHighlightSmall")
    quicklyCancelAuctionLabel:SetJustifyH("LEFT")
    quicklyCancelAuctionLabel:SetPoint("RIGHT", _G["AuctionsCancelAuctionButton"], "LEFT", -5, 0)
    quicklyCancelAuctionLabel:SetText("右键可快速取消拍卖")
    quicklyCancelAuctionLabel:SetTextColor(1, 0.82, 0)
    local soldMoneyAuctionLabel = _G["AuctionFrameAuctions"]:CreateFontString(nil, "ARTWORK", "GameFontHighlightSmall")
    soldMoneyAuctionLabel:SetJustifyH("LEFT")
    soldMoneyAuctionLabel:SetPoint("BOTTOMLEFT", _G["AuctionsTabText"], "TOPLEFT", 0, 4)
    soldMoneyAuctionLabel:SetPoint("BOTTOMRIGHT", _G["AuctionsBidSort"], "TOPRIGHT", 0, 4)
    soldMoneyAuctionLabel:SetTextColor(1, 0.82, 0)
    soldMoneyAuctionLabel:SetJustifyH("CENTER")

    local historySearchKeyBtn = CreateFrame("Frame", nil, _G["BrowseName"])
    historySearchKeyBtn:SetSize(25, 25)
    historySearchKeyBtn:SetPoint("RIGHT", _G["BrowseName"], "RIGHT", 3, 0)
    local historySearchKeyTexture = historySearchKeyBtn:CreateTexture(nil, "ARTWORK")
    historySearchKeyTexture:SetAllPoints()
    historySearchKeyTexture:SetTexture([[Interface\ChatFrame\UI-ChatIcon-ScrollDown-Up]])
    historySearchKeyBtn:SetScript("OnMouseDown", function (self, button)
        if button == "LeftButton" then
            local menuList = BrowseNameOnMouseUpMenu()
            if #menuList > 0 then
                ZL.GUI:ToggleMenu(self, BrowseNameOnMouseUpMenu(), "cursor")
            end
            menuList = nil
        end
    end)
    local quickBuyItemsRightBtn = CreateFrame("CheckButton", nil, _G["IsUsableCheckButton"], "UICheckButtonTemplate")
    quickBuyItemsRightBtn:SetPoint("LEFT", _G["IsUsableCheckButton"], "RIGHT", _G["IsUsableCheckButton"].Text:GetWidth()+5, 0)
    quickBuyItemsRightBtn:SetSize(24, 24)
    quickBuyItemsRightBtn:SetChecked(ZL.opt.QuickBuyItems)
    quickBuyItemsRightBtn.Text:SetText("快速购买")
    quickBuyItemsRightBtn:SetScript("OnEnter", function (self)
        GameTooltipShow(self, "TOPLEFT", "BOTTOMRIGHT")
        GameTooltip:AddLine("Shift+右键：快速购买单组物品")
        GameTooltip:Show()
    end)
    quickBuyItemsRightBtn:SetScript("OnLeave", function ()
        GameTooltip:Hide()
    end)
    quickBuyItemsRightBtn:SetScript("OnClick", function (self)
        ZL.opt.QuickBuyItems = self:GetChecked()
        if ZL.opt.QuickBuyItems then
            ZL.Print("已开启|cff4080FFShift+右键|r：快速购买单组物品")
        end
    end)

    local ItemName = HookAuctionFrame:CreateFontString(nil, "ARTWORK", "GameFontHighlightSmall")
    ItemName:SetSize(HookAuctionFrame:GetWidth() - 114, 20)
    ItemName:SetJustifyH("LEFT")
    ItemName:SetPoint("TOPLEFT", 5, -30)
    HookAuctionFrame.ItemName = ItemName

    local infoBtn = CreateFrame("Button", nil, HookAuctionFrame)
    HookAuctionFrame.infoBtn = infoBtn
    infoBtn:SetSize(30, 30)
    infoBtn:SetPoint("LEFT", ItemName, "RIGHT", 0, 0)
    infoBtn:SetNormalTexture(616343)
    infoBtn:SetHighlightTexture(616343)
    infoBtn:SetScript("OnClick", function ()
        ZL.Print("按Ctrl+V复制观看")
        ChatEdit_ActivateChat(ChatEdit_ChooseBoxForSend())
        ChatEdit_InsertLink("https://space.bilibili.com/476889394/lists")
        ChatEdit_ChooseBoxForSend():HighlightText()
    end)
    infoBtn:SetScript("OnEnter", function (self)
        GameTooltipShow(HookAuctionFrame, "TOPLEFT", "TOPRIGHT")
        GameTooltip:AddLine("第一种方法")
        GameTooltip:AddLine("1、禁用其他带有拍卖功能的插件，避免卡顿，如：TSM、Auctionator、Pig拍卖助手、金团助手，wim等；", 1, 1, 1, true)
        GameTooltip:AddLine("2、拍卖行选择搜索界面；", 1, 1, 1, true)
        GameTooltip:AddLine("3、背包|CFFFFDE00Shift+左键|r选择需要拍卖的物品；", 1, 1, 1, true)
        GameTooltip:AddLine("4、点击搜索", 1, 1, 1, true)
        GameTooltip:AddLine("5、确认单价、堆叠数和组数无误", 1, 1, 1, true)
        GameTooltip:AddLine("6、点击|CFFFFDE00开始拍卖|r", 1, 1, 1, true)
        GameTooltip:AddLine("第二种方法：不关闭其他插件")
        GameTooltip:AddLine("1、左键点击背包物品,将选择的物品拖到右侧拍卖窗口", 1, 1, 1, true)
        GameTooltip:AddLine("2、按Ctr+C、点击搜索框，按Ctr+V", 1, 1, 1, true)
        GameTooltip:AddLine("3、后面步骤跟第一种方法一样", 1, 1, 1, true)
        GameTooltip:AddLine(" ")
        GameTooltip:AddLine("注意事项")
        GameTooltip:AddLine("1、搜索文本只支持原生方法：", 1, 1, 1, true)
        GameTooltip:AddLine("如:手动输入、复制粘贴、Shift+左键点击物品或链接", 1, 1, 1, true)
        GameTooltip:AddLine("2、有些插件会污染原生Shift+左键点击功能，造成搜索卡顿", 1, 1, 1, true)
        GameTooltip:AddLine("3、只能手动点击搜索按钮，其他一切方法都会造成搜索卡顿", 1, 1, 1, true)
        GameTooltip:AddLine("4、就算不装任何插件，频繁使用Shift+左键输入，偶尔也会造成卡顿，并非插件原因，请控制好搜索频率；", nil, nil, nil, true)
        GameTooltip:AddLine("5、如出现搜索卡顿、内部错误，打开AH窗口，等到搜索按钮高亮后|CFFFFDE00/rl|r后再继续使用", 1, 1, 1, true)
        GameTooltip:AddLine("6、以上如果还频繁卡顿，切换小号，只保留这一个插件测试，如果不卡顿，说明有其他插件污染了Shift+左键功能或者存在自动搜索拍卖行", 1, 1, 1, true)
        GameTooltip:AddLine(" ")
        GameTooltip:AddLine("兼容alaTradeSkill查看利润方法")
        GameTooltip:AddLine([[1、打开\World of Warcraft\_classic_titan_\Interface\]], 1, 1, 1)
        GameTooltip:AddLine([[AddOns\|CFFFFDE00AutoAuction|r\plugin]], 1, 1, 1)
        GameTooltip:AddLine("2、复制里面的两个文件：AutoAuction.lua和plugin.xml", 1, 1, 1, true)
        GameTooltip:AddLine([[3、打开\World of Warcraft\_classic_titan_\Interface\]], 1, 1, 1)
        GameTooltip:AddLine([[AddOns\|CFFFFDE00alaTradeSkill|r\plugin]], 1, 1, 1)
        GameTooltip:AddLine("4、粘贴覆盖刚才的2个文件", 1, 1, 1, true)
        GameTooltip:AddLine("5、打开alaTradeSkill插件，将首选拍卖插件改成AutoAuction即可", 1, 1, 1, true)
        GameTooltip:AddLine(" ")
        GameTooltip:AddLine("点击复制观看使用视频")
        GameTooltip:SetMinimumWidth(370)
        GameTooltip:Show()
    end)
    infoBtn:SetScript("OnLeave", function ()
        GameTooltip:Hide()
    end)
    local lockBtn = CreateFrame("Button", nil, HookAuctionFrame)
    HookAuctionFrame.lockBtn = lockBtn
    lockBtn:SetSize(30, 30)
    lockBtn:SetPoint("LEFT", infoBtn, "RIGHT", -4, 0)
    local lockTexture = [[Interface\BUTTONS\LockButton-Locked-Up.blp]]
    local unlockTexture = [[Interface\BUTTONS\LockButton-Unlocked-Up.blp]]
    if ZL.opt.AuctionSortLock then
        lockBtn:SetNormalTexture(lockTexture)
        lockBtn:SetHighlightTexture(lockTexture)
        lockBtnFrame:Show()
    else
        lockBtn:SetNormalTexture(unlockTexture)
        lockBtn:SetHighlightTexture(unlockTexture)
        lockBtnFrame:Hide()
    end
    lockBtn:SetScript("OnClick", function ()
        if ZL.opt.AuctionSortLock then
            ZL.opt.AuctionSortLock = false
        else
            ZL.opt.AuctionSortLock = true
        end
        if ZL.opt.AuctionSortLock then
            Set_AuctionSort_Column()
            HookAuctionFrame.sortBtn.SpellHighlightAnim:Stop()
            HookAuctionFrame.sortBtn.SpellHighlightTexture:Hide()
            lockBtn:SetNormalTexture(lockTexture)
            lockBtn:SetHighlightTexture(lockTexture)
            lockBtnFrame:Show()
        else
            lockBtn:SetNormalTexture(unlockTexture)
            lockBtn:SetHighlightTexture(unlockTexture)
            lockBtnFrame:Hide()
        end
    end)
    lockBtn:SetScript("OnEnter", function (self)
        GameTooltipShow(self, "TOPLEFT", "BOTTOMRIGHT")
        if ZL.opt.AuctionSortLock then
            GameTooltip:AddLine("提示")
            GameTooltip:AddLine("左侧排序按钮已锁定，点击解锁", 1, 1, 1)
        else
            GameTooltip:AddLine("注意")
            GameTooltip:AddLine("排序未锁定，单价可能无法自动\n获取到最低价，点击锁定", 1, 0, 0)
        end
        GameTooltip:Show()
    end)
    lockBtn:SetScript("OnLeave", function ()
        GameTooltip:Hide()
    end)
    local sortBtn = CreateButton(nil, HookAuctionFrame, "排序", "LEFT", lockBtn, "RIGHT", 2, 0, 45, 20, 14, true, 0)
    sortBtn:SetScript("OnClick", function ()
        Set_AuctionSort_Column()
        UpdateSortAnim()
    end)
    sortBtn:SetScript("OnEnter", function (self)
        GameTooltipShow(self, "TOPLEFT", "BOTTOMRIGHT")
        GameTooltip:AddLine("提示")
        GameTooltip:AddLine("按钮如发光，表示未按指定要求排序;", 1, 1, 1)
        GameTooltip:AddLine("单价可能无法自动获取到最低一口价;", 1, 1, 1)
        GameTooltip:AddLine("点击左侧按钮可锁定排序", 1, 1, 1)
        GameTooltip:Show()
    end)
    sortBtn.SpellHighlightTexture = sortBtn:CreateTexture("SpellHighlightTexture1", "OVERLAY", nil, 1)
    local SpellHighlightTexture = sortBtn.SpellHighlightTexture
    SpellHighlightTexture:SetAtlas("bags-newitem")
    SpellHighlightTexture:SetSize(60, 26)
    SpellHighlightTexture:SetPoint("CENTER")
    SpellHighlightTexture:SetBlendMode("ADD")
    SpellHighlightTexture:Hide()
    -- 创建 SpellHighlightAnim 动画组（循环播放）
    sortBtn.SpellHighlightAnim = SpellHighlightTexture:CreateAnimationGroup() --"SpellHighlightAnim"
    local SpellHighlightAnim = sortBtn.SpellHighlightAnim
    SpellHighlightAnim:SetLooping("REPEAT")
    -- 第一个 Alpha 动画（淡入）
    local alpha1 = SpellHighlightAnim:CreateAnimation("Alpha")
    alpha1:SetChildKey("SpellHighlightTexture")
    alpha1:SetSmoothing("OUT")
    alpha1:SetDuration(0.75)
    alpha1:SetOrder(1)
    alpha1:SetFromAlpha(0)
    alpha1:SetToAlpha(1)
    -- 第二个 Alpha 动画（淡出）
    local alpha2 = SpellHighlightAnim:CreateAnimation("Alpha")
    alpha2:SetChildKey("SpellHighlightTexture")
    alpha2:SetSmoothing("IN")
    alpha2:SetDuration(0.75)
    alpha2:SetOrder(2)
    alpha2:SetFromAlpha(1)
    alpha2:SetToAlpha(0)
    HookAuctionFrame.sortBtn = sortBtn
    local ItemButton = CreateFrame("Button", nil, HookAuctionFrame)
    ItemButton:SetSize(40, 40)
    ItemButton:SetPoint("TOPLEFT", ItemName, "BOTTOMLEFT", 0, -5)
    ItemButton:SetHighlightTexture([[Interface\Buttons\ButtonHilight-Square]])
    ItemButton:SetPushedTexture([[Interface\Buttons\UI-Quickslot-Depress]])
    ItemButton:SetScript("OnEnter", function (self)
        if self.itemID then
            GameTooltipShow(self, "TOPLEFT", "BOTTOMRIGHT")
            GameTooltip:SetItemByID(self.itemID)
            GameTooltip:Show()
        end
    end)
    ItemButton:SetScript("OnLeave", function ()
        GameTooltip:Hide()
    end)
    ItemButton:SetScript("OnMouseUp", function (self, button)
        if button == "LeftButton" then
            local infoType, itemID = GetCursorInfo()
            if infoType and infoType == "item" and itemID then
                ClickAuctionSellItemButton()
                ClearCursor()
                local name = cGetItemInfo(itemID)
                ChatEdit_ActivateChat(ChatEdit_ChooseBoxForSend())
                if ZL.opt.AuctionPreciseSortKey then
                    ChatEdit_InsertLink(format('"%s"', name))
                else
                    ChatEdit_InsertLink(format('%s', name))
                end
                ChatEdit_ChooseBoxForSend():HighlightText()
            end
        end
    end)
    -- ItemButton:RegisterForDrag("LeftButton")
    -- ItemButton:EnableMouse(true)
    -- ItemButton:SetScript("OnReceiveDrag", function (self)
    --     print(11111)
    -- end)
    ItemButton.EmptySlot = ItemButton:CreateTexture(nil, "BACKGROUND")
    ItemButton.EmptySlot:SetTexture("Interface\\BUTTONS\\UI-Slot-Background")
    ItemButton.EmptySlot:SetDrawLayer("BACKGROUND", 1) -- 设置textureSubLevel
    ItemButton.EmptySlot:SetAllPoints()
    ItemButton.EmptySlot:SetTexCoord(0, 0.640625, 0, 0.640625)

    ItemButton.icon = ItemButton:CreateTexture(nil, "BACKGROUND")
    -- ItemButton.icon:SetTexture(132881)
    ItemButton.icon:SetDrawLayer("BACKGROUND", 2)
    ItemButton.icon:SetAllPoints()

    ItemButton.IconBorder = ItemButton:CreateTexture(nil, "BACKGROUND")
    ItemButton.IconBorder:SetTexture("Interface\\Common\\WhiteIconFrame")
    ItemButton.IconBorder:SetDrawLayer("BACKGROUND", 3)
    ItemButton.IconBorder:SetAllPoints()
    HookAuctionFrame.ItemButton = ItemButton

    local UnitPriceLabel = HookAuctionFrame:CreateFontString(nil, "ARTWORK", "GameFontHighlightSmall")
    UnitPriceLabel:SetText("单价")
    UnitPriceLabel:SetHeight(20)
    UnitPriceLabel:SetPoint("TOPLEFT", ItemButton, "TOPRIGHT", 5, 0)
    local UnitGoldPrice = MoneyInputEidtBox(HookAuctionFrame, 8, 90, "auctionhouse-icon-coin-gold")
    UnitGoldPrice:SetPoint("LEFT", UnitPriceLabel, "RIGHT", 8, 0)
    UnitGoldPrice:SetScript("OnTextChanged", function ()
        UpdateStackPrice()
    end)
    HookAuctionFrame.UnitGoldPrice = UnitGoldPrice
    local UnitSilverPrice = MoneyInputEidtBox(HookAuctionFrame, 2, 30, "auctionhouse-icon-coin-silver")
    UnitSilverPrice:SetPoint("LEFT", UnitGoldPrice, "RIGHT", 20, 0)
    UnitSilverPrice:SetScript("OnTextChanged", function ()
        UpdateStackPrice()
    end)
    HookAuctionFrame.UnitSilverPrice = UnitSilverPrice
    local UnitCopperPrice = MoneyInputEidtBox(HookAuctionFrame, 2, 30, "auctionhouse-icon-coin-copper")
    UnitCopperPrice:SetPoint("LEFT", UnitSilverPrice, "RIGHT", 20, 0)
    UnitCopperPrice:SetScript("OnTextChanged", function ()
        UpdateStackPrice()
    end)
    HookAuctionFrame.UnitCopperPrice = UnitCopperPrice

    local StackPriceLabel = HookAuctionFrame:CreateFontString(nil, "ARTWORK", "GameFontHighlightSmall")
    StackPriceLabel:SetText("堆叠")
    StackPriceLabel:SetHeight(20)
    StackPriceLabel:SetPoint("TOPLEFT", UnitPriceLabel, "BOTTOMLEFT", 0, -3)
    local StackGoldPrice = MoneyInputEidtBox(HookAuctionFrame, 8, 90, "auctionhouse-icon-coin-gold")
    StackGoldPrice:SetPoint("LEFT", StackPriceLabel, "RIGHT", 8, 0)
    StackGoldPrice:SetScript("OnTextChanged", function ()
        UpdateUnitPrice()
    end)
    HookAuctionFrame.StackGoldPrice = StackGoldPrice
    local StackSilverPrice = MoneyInputEidtBox(HookAuctionFrame, 2, 30, "auctionhouse-icon-coin-silver")
    StackSilverPrice:SetPoint("LEFT", StackGoldPrice, "RIGHT", 20, 0)
    StackSilverPrice:SetScript("OnTextChanged", function ()
        UpdateUnitPrice()
    end)
    HookAuctionFrame.StackSilverPrice = StackSilverPrice
    local StackCopperPrice = MoneyInputEidtBox(HookAuctionFrame, 2, 30, "auctionhouse-icon-coin-copper")
    StackCopperPrice:SetPoint("LEFT", StackSilverPrice, "RIGHT", 20, 0)
    StackCopperPrice:SetScript("OnTextChanged", function ()
        UpdateUnitPrice()
    end)
    HookAuctionFrame.StackCopperPrice = StackCopperPrice

    local StackCountLabel = HookAuctionFrame:CreateFontString(nil, "ARTWORK", "GameFontHighlightSmall")
    StackCountLabel:SetText("堆叠数")
    StackCountLabel:SetHeight(20)
    StackCountLabel:SetPoint("TOPLEFT", ItemButton, "BOTTOMLEFT", 0, -10)
    local StackCount = MoneyInputEidtBox(nil, nil, 42)
    StackCount:SetPoint("LEFT", StackCountLabel, "RIGHT", 8, 0)
    StackCount:SetNumber(1)
    StackCount:SetScript("OnTextChanged", function (self)
        local number = self:GetNumber()
        local name, _, _, _, _, _, _, stackCount, totalCount = GetAuctionSellItemInfo()
        if name then
            local maxStackCount = min(stackCount, totalCount)
            if number > maxStackCount then
                self:SetNumber(maxStackCount)
            elseif self:GetNumber() == 0 then
                self:SetNumber(1)
            end
            local oldNumStacks = HookAuctionFrame.NumStacks:GetNumber()
            local maxNumStacks = floor(totalCount/self:GetNumber())
            if oldNumStacks > maxNumStacks then
                HookAuctionFrame.NumStacks:SetNumber(maxNumStacks)
            end
            HookAuctionFrame.MaxNumStacksBtn:SetText("最大值:" .. totalCount)
        elseif self:GetNumber() == 0 then
            self:SetNumber(1)
        end
        UpdateStackPrice()
        UpdateDepositMoney()
    end)
    HookAuctionFrame.StackCount = StackCount
    local MaxStackCountBtn = CreateFrame("Button", nil, HookAuctionFrame)
    MaxStackCountBtn:SetSize(StackCountLabel:GetWidth() + 8 + StackCount:GetWidth(), 20)
    MaxStackCountBtn:SetNormalFontObject("GameFontNormalSmall")
    MaxStackCountBtn:SetHighlightFontObject("GameFontHighlightSmall")
    MaxStackCountBtn:SetHighlightTexture("UIPanelButtonHighlightTexture")
    MaxStackCountBtn:SetText("最大值:")
    do
        local fontString = MaxStackCountBtn:GetFontString()
        fontString:SetFont(GameFontNormal:GetFont(), 13)
        fontString:ClearAllPoints()
        fontString:SetPoint("LEFT")
        fontString:SetJustifyH("LEFT")
    end
    MaxStackCountBtn:SetPoint("TOPLEFT", StackCountLabel, "BOTTOMLEFT", 0, -3)
    MaxStackCountBtn:SetScript("OnClick", function ()
        local name, _, _, _, _, _, _, stackCount, totalCount = GetAuctionSellItemInfo()
        if name then
            StackCount:SetNumber(min(stackCount, totalCount))
        end
    end)
    HookAuctionFrame.MaxStackCountBtn = MaxStackCountBtn

    local NumStacksLabel = HookAuctionFrame:CreateFontString(nil, "ARTWORK", "GameFontHighlightSmall")
    NumStacksLabel:SetText("组数")
    NumStacksLabel:SetHeight(20)
    NumStacksLabel:SetPoint("LEFT", StackCount, "RIGHT", 10, 0)
    local NumStacks = MoneyInputEidtBox(nil, 3, 43)
    NumStacks:SetPoint("LEFT", NumStacksLabel, "RIGHT", 8, 0)
    NumStacks:SetNumber(1)
    NumStacks:SetScript("OnTextChanged", function (self)
        local number = self:GetNumber()
        local _stackCount = StackCount:GetNumber()
        local name, _, _, _, _, _, _, stackCount, totalCount = GetAuctionSellItemInfo()
        if name then
            if number > totalCount then
                self:SetNumber(totalCount)
            elseif number == 0 then
                self:SetNumber(1)
            end
            local maxStackCount = min(stackCount, totalCount, floor(totalCount/self:GetNumber()))
            if _stackCount > maxStackCount then
                StackCount:SetNumber(maxStackCount)
            end
            MaxStackCountBtn:SetText("最大值:" .. min(stackCount, totalCount))
        elseif self:GetNumber() == 0 then
            self:SetNumber(1)
        end
        UpdateDepositMoney()
    end)
    HookAuctionFrame.NumStacks = NumStacks
    local MaxNumStacksBtn = CreateFrame("Button", nil, HookAuctionFrame)
    MaxNumStacksBtn:SetSize(NumStacksLabel:GetWidth() + 8 + NumStacks:GetWidth(), 20)
    MaxNumStacksBtn:SetNormalFontObject("GameFontNormalSmall")
    MaxNumStacksBtn:SetHighlightFontObject("GameFontHighlightSmall")
    MaxNumStacksBtn:SetHighlightTexture("UIPanelButtonHighlightTexture")
    MaxNumStacksBtn:SetText("最大值:")
    do
        local fontString = MaxNumStacksBtn:GetFontString()
        fontString:SetFont(GameFontNormal:GetFont(), 13)
        fontString:ClearAllPoints()
        fontString:SetPoint("LEFT")
        fontString:SetJustifyH("LEFT")
    end
    MaxNumStacksBtn:SetPoint("TOPLEFT", NumStacksLabel, "BOTTOMLEFT", 0, -3)
    MaxNumStacksBtn:SetScript("OnClick", function ()
        local name, _, _, _, _, _, _, _, totalCount = GetAuctionSellItemInfo()
        if name then
            NumStacks:SetNumber(totalCount)
        end
    end)
    HookAuctionFrame.MaxNumStacksBtn = MaxNumStacksBtn
    HookAuctionFrame.StartAuctionBtn = CreateButton(nil, HookAuctionFrame, "开始拍卖", "TOPLEFT", NumStacks, "TOPRIGHT", 10, 0, 80, 43, 14, true, 0)
    local StartAuctionBtn = HookAuctionFrame.StartAuctionBtn
    StartAuctionBtn:SetScript("OnClick", function (self)
        local name, texture, _, quality, _, _, _, _, _, itemID = GetAuctionSellItemInfo()
        if itemID then
            local stackSize = StackCount:GetNumber()
            local numStacks = NumStacks:GetNumber()
            local unitPrice = (UnitGoldPrice:GetNumber()*10000 + UnitSilverPrice:GetNumber()*100 + UnitCopperPrice:GetNumber())
            local buyoutPrice = unitPrice * stackSize
            local minBid = buyoutPrice * ZL.opt.AuctionStartPrice/100
            if stackSize > 0 and numStacks > 0 and buyoutPrice > 0 then
                local _, itemLink, _, _, _, _, _, _, _, _, sellPrice = cGetItemInfo(itemID)
                if sellPrice > 0 and unitPrice*0.95 < sellPrice then
                    StaticPopup_Show(
                        "ZL_AUCTIONSCREATEAUCTIONWARNING",
                        format("%s税后低于卖店价(%s)，是否继续发布？", itemLink, GetMoneyString(sellPrice)), nil,
                        {minBid, buyoutPrice, ZL.opt.AuctionDefaultTime, stackSize, numStacks, false}
                    )
                    return
                end
                if IsCanDo() and AuctionFrameBrowse.page == 0 then
                    local currentAuctions = GetNumAuctionItems("list")
                    if currentAuctions > 0 then
                        local priceList = {}
                        local _count, _buyoutPrice, _owner, _itemId, _
                        for i = 1, currentAuctions do
                            _, _, _count, _, _, _, _, _, _, _buyoutPrice, _, _, _, _, _, _, _itemId = GetAuctionItemInfo("list", i)
                            if _itemId == itemID then
                                if #priceList > 3 then break end
                                if not tIndexOf(priceList, floor(_buyoutPrice/_count)) then
                                    tinsert(priceList, floor(_buyoutPrice/_count))
                                end
                            end
                        end
                        for i, _unitPrice in ipairs(priceList) do
                            if (i == 1 and (_unitPrice-unitPrice)/_unitPrice > 0.1) or (i == 2 and (_unitPrice-unitPrice)/_unitPrice > 0.15)
                            or (i == 3 and (_unitPrice-unitPrice)/_unitPrice > 0.2) then
                                StaticPopup_Show(
                                    "ZL_AUCTIONSCREATEAUCTIONWARNING",
                                    format("%s一口价与前面的幅度相差过大，是否继续发布？", itemLink, GetMoneyString(sellPrice)), nil,
                                    {minBid, buyoutPrice, ZL.opt.AuctionDefaultTime, stackSize, numStacks, false}
                                )
                                return
                            end
                        end
                    end
                end
                if PostAuction(minBid, buyoutPrice, ZL.opt.AuctionDefaultTime, stackSize, numStacks, false) then
                    AuctionsCreateAuctionButton:ClearPost();
                else
                    AuctionsCreateAuctionButton:CachePendingPost(minBid, buyoutPrice, ZL.opt.AuctionDefaultTime, stackSize, numStacks, false);
                end
            end
        end
    end)

    local depositMoneyLabel = HookAuctionFrame:CreateFontString(nil, "ARTWORK", "GameFontHighlightSmall")
    depositMoneyLabel:SetSize(HookAuctionFrame:GetWidth() - 10, 18)
    depositMoneyLabel:SetFont(GameFontNormal:GetFont(), 13)
    depositMoneyLabel:SetJustifyH("LEFT")
    depositMoneyLabel:SetTextColor(1, 0.82, 0)
    depositMoneyLabel:SetPoint("TOPLEFT", MaxStackCountBtn, "BOTTOMLEFT", 0, -5)
    HookAuctionFrame.depositMoneyLabel = depositMoneyLabel
    depositMoneyLabel:Hide()

    local totalDepositMoneyLabel = HookAuctionFrame:CreateFontString(nil, "ARTWORK")
    totalDepositMoneyLabel:SetSize(HookAuctionFrame:GetWidth() - 10, 18)
    totalDepositMoneyLabel:SetFont(GameFontNormal:GetFont(), 13)
    totalDepositMoneyLabel:SetJustifyH("LEFT")
    totalDepositMoneyLabel:SetTextColor(1, 0.82, 0)
    totalDepositMoneyLabel:SetPoint("TOPLEFT", MaxStackCountBtn, "BOTTOMLEFT", 0, -5)
    -- totalDepositMoneyLabel:SetPoint("TOPLEFT", depositMoneyLabel, "BOTTOMLEFT", 0, -3)
    HookAuctionFrame.totalDepositMoneyLabel = totalDepositMoneyLabel

    do
        local line = HookAuctionFrame:CreateTexture(nil, "OVERLAY")
        line:SetColorTexture(1, 1, 1, 0.5)
        line:SetPoint("TOPLEFT", totalDepositMoneyLabel, "BOTTOMLEFT", -5, -5)
        line:SetPoint("TOPRIGHT", totalDepositMoneyLabel ,"BOTTOMRIGHT", 5, -7)
    end
    local startPriceLabel = HookAuctionFrame:CreateFontString(nil, "ARTWORK", "GameFontHighlightSmall")
    startPriceLabel:SetText("起始价格")
    startPriceLabel:SetHeight(20)
    startPriceLabel:SetPoint("TOPLEFT", totalDepositMoneyLabel, "BOTTOMLEFT", 0, -11)
    local startPrice = MoneyInputEidtBox(HookAuctionFrame, 3, 60)
    startPrice:SetPoint("LEFT", startPriceLabel, "RIGHT", 8, 0)
    startPrice:SetNumber(ZL.opt.AuctionStartPrice)
    startPrice:SetScript("OnTextChanged", function (self)
        if self:GetNumber() == 0 then self:SetNumber(1) end
        ZL.opt.AuctionStartPrice = self:GetNumber()
    end)
    local startPriceLabel2 = HookAuctionFrame:CreateFontString(nil, "ARTWORK", "GameFontHighlightSmall")
    startPriceLabel2:SetText("%单价(一口价)")
    startPriceLabel2:SetHeight(20)
    startPriceLabel2:SetPoint("LEFT", startPrice, "RIGHT", 5, 0)

    local priceDownLabel = HookAuctionFrame:CreateFontString(nil, "ARTWORK", "GameFontHighlightSmall")
    priceDownLabel:SetText("压价金额")
    priceDownLabel:SetHeight(20)
    priceDownLabel:SetPoint("TOPLEFT", startPriceLabel, "BOTTOMLEFT", 0, -5)
    local glodPriceDown = MoneyInputEidtBox(HookAuctionFrame, 8, 90, "auctionhouse-icon-coin-gold")
    glodPriceDown:SetPoint("LEFT", priceDownLabel, "RIGHT", 8, 0)
    glodPriceDown:SetScript("OnTextChanged", function ()
        UpdateAuctionPriceDown()
    end)
    HookAuctionFrame.glodPriceDown = glodPriceDown
    local silverPriceDown = MoneyInputEidtBox(HookAuctionFrame, 2, 30, "auctionhouse-icon-coin-silver")
    silverPriceDown:SetPoint("LEFT", glodPriceDown, "RIGHT", 20, 0)
    silverPriceDown:SetScript("OnTextChanged", function ()
        UpdateAuctionPriceDown()
    end)
    HookAuctionFrame.silverPriceDown = silverPriceDown
    local copperPriceDown = MoneyInputEidtBox(HookAuctionFrame, 2, 30, "auctionhouse-icon-coin-copper")
    copperPriceDown:SetPoint("LEFT", silverPriceDown, "RIGHT", 20, 0)
    copperPriceDown:SetScript("OnTextChanged", function ()
        UpdateAuctionPriceDown()
    end)
    HookAuctionFrame.copperPriceDown = copperPriceDown
    SetAuctionPriceDownCpper(ZL.opt.AucitonPriceDown)

    local defaultStackCountLabel = HookAuctionFrame:CreateFontString(nil, "ARTWORK", "GameFontHighlightSmall")
    defaultStackCountLabel:SetText("默认堆叠")
    defaultStackCountLabel:SetHeight(20)
    defaultStackCountLabel:SetPoint("TOPLEFT", priceDownLabel, "BOTTOMLEFT", 0, -5)
    local defaultStackCount = MoneyInputEidtBox(nil, nil, 42)
    defaultStackCount:SetPoint("LEFT", defaultStackCountLabel, "RIGHT", 8, 0)
    defaultStackCount:SetNumber(ZL.opt.DefaultStackCount)
    defaultStackCount:SetScript("OnTextChanged", function (self)
        if self:GetNumber() == 0 then self:SetNumber(1) end
        ZL.opt.DefaultStackCount = self:GetNumber()
        UpdateStartAuctionStackInfo()
    end)
    if ZL.opt.defaultStackCountMax then
        defaultStackCount:Disable()
    else
        defaultStackCount:Enable()
    end
    local defaultStackCountMaxBtn = CreateFrame("CheckButton", nil, HookAuctionFrame, "UICheckButtonTemplate")
    defaultStackCountMaxBtn:SetPoint("LEFT", defaultStackCount, "RIGHT", 5, 0)
    defaultStackCountMaxBtn:SetSize(24, 24)
    defaultStackCountMaxBtn:SetChecked(ZL.opt.defaultStackCountMax)
    defaultStackCountMaxBtn.Text:SetText("最大值")
    defaultStackCountMaxBtn.Text:SetFontObject(GameFontHighlightSmall)
    defaultStackCountMaxBtn:SetScript("OnClick", function (self)
        ZL.opt.defaultStackCountMax = self:GetChecked()
        if ZL.opt.defaultStackCountMax then
            defaultStackCount:Disable()
        else
            defaultStackCount:Enable()
        end
        UpdateStartAuctionStackInfo()
    end)
    local defaultStackCountMaxFisrtBtn = CreateFrame("CheckButton", nil, HookAuctionFrame, "UICheckButtonTemplate")
    defaultStackCountMaxFisrtBtn:SetPoint("LEFT", defaultStackCountMaxBtn, "RIGHT", defaultStackCountMaxBtn.Text:GetWidth() + 5, 0)
    defaultStackCountMaxFisrtBtn:SetSize(24, 24)
    defaultStackCountMaxFisrtBtn:SetChecked(ZL.opt.defaultStackCountOrdefaultNumStacksFirst == 1 and true or false)
    defaultStackCountMaxFisrtBtn.Text:SetText("优先")
    defaultStackCountMaxFisrtBtn.Text:SetFontObject(GameFontHighlightSmall)
    defaultStackCountMaxFisrtBtn:SetScript("OnEnter", function (self)
        GameTooltipShow(self, "TOPLEFT", "BOTTOMRIGHT")
        GameTooltip:AddLine("堆叠数和组数冲突时：\n|cffffffff堆叠数|r优先")
        GameTooltip:Show()
    end)
    defaultStackCountMaxFisrtBtn:SetScript("OnLeave", function (self)
        GameTooltip:Hide()
    end)

    local defaultNumStacksLabel = HookAuctionFrame:CreateFontString(nil, "ARTWORK", "GameFontHighlightSmall")
    defaultNumStacksLabel:SetText("默认组数")
    defaultNumStacksLabel:SetHeight(20)
    defaultNumStacksLabel:SetPoint("TOPLEFT", defaultStackCountLabel, "BOTTOMLEFT", 0, -5)
    local defaultNumStacks = MoneyInputEidtBox(nil, nil, 42)
    defaultNumStacks:SetPoint("LEFT", defaultNumStacksLabel, "RIGHT", 8, 0)
    defaultNumStacks:SetNumber(ZL.opt.DefaultNumStacks)
    defaultNumStacks:SetScript("OnTextChanged", function (self)
        if self:GetNumber() == 0 then self:SetNumber(1) end
        ZL.opt.DefaultNumStacks = self:GetNumber()
        UpdateStartAuctionStackInfo()
    end)
    if ZL.opt.defaultNumStacksMax then
        defaultNumStacks:Disable()
    else
        defaultNumStacks:Enable()
    end
    local defaultNumStacksMaxBtn = CreateFrame("CheckButton", nil, HookAuctionFrame, "UICheckButtonTemplate")
    defaultNumStacksMaxBtn:SetPoint("LEFT", defaultNumStacks, "RIGHT", 5, 0)
    defaultNumStacksMaxBtn:SetSize(24, 24)
    defaultNumStacksMaxBtn:SetChecked(ZL.opt.defaultNumStacksMax)
    defaultNumStacksMaxBtn.Text:SetText("最大值")
    defaultNumStacksMaxBtn.Text:SetFontObject(GameFontHighlightSmall)
    defaultNumStacksMaxBtn:SetScript("OnClick", function (self)
        ZL.opt.defaultNumStacksMax= self:GetChecked()
        if ZL.opt.defaultNumStacksMax then
            defaultNumStacks:Disable()
        else
            defaultNumStacks:Enable()
        end
        UpdateStartAuctionStackInfo()
    end)

    local defaultNumStacksMaxFirstBtn = CreateFrame("CheckButton", nil, HookAuctionFrame, "UICheckButtonTemplate")
    defaultNumStacksMaxFirstBtn:SetPoint("LEFT", defaultNumStacksMaxBtn, "RIGHT", defaultNumStacksMaxBtn.Text:GetWidth() + 5, 0)
    defaultNumStacksMaxFirstBtn:SetSize(24, 24)
    defaultNumStacksMaxFirstBtn:SetChecked(ZL.opt.defaultStackCountOrdefaultNumStacksFirst == 2 and true or false)
    defaultNumStacksMaxFirstBtn.Text:SetText("优先")
    defaultNumStacksMaxFirstBtn.Text:SetFontObject(GameFontHighlightSmall)
    defaultNumStacksMaxFirstBtn:SetScript("OnClick", function (self)
        ZL.opt.defaultStackCountOrdefaultNumStacksFirst = 2
        self:SetChecked(true)
        defaultStackCountMaxFisrtBtn:SetChecked(false)
        UpdateStartAuctionStackInfo()
    end)
    defaultNumStacksMaxFirstBtn:SetScript("OnEnter", function (self)
        GameTooltipShow(self, "TOPLEFT", "BOTTOMRIGHT")
        GameTooltip:AddLine("堆叠数和组数冲突时：\n|cffffffff组数|r优先")
        GameTooltip:Show()
    end)
    defaultNumStacksMaxFirstBtn:SetScript("OnLeave", function (self)
        GameTooltip:Hide()
    end)
    defaultStackCountMaxFisrtBtn:SetScript("OnClick", function (self)
        ZL.opt.defaultStackCountOrdefaultNumStacksFirst = 1
        self:SetChecked(true)
        defaultNumStacksMaxFirstBtn:SetChecked(false)
        UpdateStartAuctionStackInfo()
    end)

    local otherSetting = CreateButton(nil, HookAuctionFrame, "更多设置", "BOTTOMRIGHT", HookAuctionFrame, "BOTTOMRIGHT", -5, 5, 80, 20, 14, true, 0)
    otherSetting:SetScript("OnClick", function (self)
        ZL.GUI:ToggleMenu(self, OtherSettingMenu(), "cursor")
    end)

    local QQGroupBtn = CreateFrame("Button", nil, HookAuctionFrame)
    QQGroupBtn:SetSize(80, 20)
    QQGroupBtn:SetPoint("BOTTOMLEFT", 5, 5)
    QQGroupBtn:SetNormalFontObject("GameFontNormalSmall")
    QQGroupBtn:SetHighlightFontObject("GameFontHighlightSmall")
    QQGroupBtn:SetHighlightTexture("UIPanelButtonHighlightTexture")
    QQGroupBtn:SetText("反馈Q群:599711083")
    do
        local fontString = QQGroupBtn:GetFontString()
        fontString:SetFont(GameFontNormal:GetFont(), 14)
        fontString:ClearAllPoints()
        fontString:SetPoint("LEFT")
        fontString:SetJustifyH("LEFT")
        QQGroupBtn:SetWidth(fontString:GetWidth())
    end
    QQGroupBtn:SetScript("OnClick", function ()
        ChatEdit_ActivateChat(ChatEdit_ChooseBoxForSend())
        ChatEdit_InsertLink("599711083")
        ChatEdit_ChooseBoxForSend():HighlightText()
    end)

    function HookAuctionFrame.New_Auction_Update()
        local name, texture, _, quality, _, _, _, stackCount, totalCount, itemID = GetAuctionSellItemInfo()
        if name then
            ItemButton.icon:SetTexture(texture)
            ItemButton.itemID = itemID
            ItemName:SetText(name)
            local color = ITEM_QUALITY_COLORS[quality]
            ItemName:SetVertexColor(color.r, color.g, color.b)
            local maxStackCount = min(stackCount, totalCount)
            if StackCount:GetNumber() > maxStackCount then
                StackCount:SetNumber(maxStackCount)
            end
            if NumStacks:GetNumber() > totalCount then
                NumStacks:SetNumber(totalCount)
            end
            MaxStackCountBtn:SetText("最大值:" .. min(stackCount, totalCount))
            MaxNumStacksBtn:SetText("最大值:" .. totalCount)
        else
            ItemButton.icon:SetTexture()
            ItemButton.itemID = nil
            ItemName:SetText("")
            UnitGoldPrice:SetNumber(0)
            UnitSilverPrice:SetNumber(0)
            UnitCopperPrice:SetNumber(0)
            StackGoldPrice:SetNumber(0)
            StackSilverPrice:SetNumber(0)
            StackCopperPrice:SetNumber(0)
            -- StackCount:SetNumber(1)
            -- NumStacks:SetNumber(1)
            MaxStackCountBtn:SetText("最大值:")
            MaxNumStacksBtn:SetText("最大值:")
        end
    end
    local New_Auction_Update = HookAuctionFrame.New_Auction_Update
    HookAuctionFrame:RegisterEvent("NEW_AUCTION_UPDATE")
    HookAuctionFrame:RegisterEvent("AUCTION_ITEM_LIST_UPDATE")
    HookAuctionFrame:RegisterEvent("AUCTION_OWNED_LIST_UPDATE")
    HookAuctionFrame:RegisterEvent("CHAT_MSG_SYSTEM")
    HookAuctionFrame:RegisterEvent("UI_ERROR_MESSAGE")
    HookAuctionFrame:RegisterEvent("AUCTION_HOUSE_CLOSED")
    HookAuctionFrame:SetScript("OnEvent", function (self, event, ...)
        local arg = emptytable(...)
        if event == "NEW_AUCTION_UPDATE" then
            New_Auction_Update()
            UpdateDepositMoney()
            UpdateStartAuctionStackInfo()
        elseif event == "AUCTION_HOUSE_CLOSED" then
            self.scanAllProcess = nil
            self.scanAllStartTime = nil
            self.SaveData = nil
            ScanAllBtn:Enable()
            self.ScanAllInfoLabel:SetText("")
        elseif event == "AUCTION_ITEM_LIST_UPDATE" then
            CancelAuctionBtn:Disable()
            if self.scanAllProcess then
                if not self.SaveData then
                    self.SaveData = true
                    ZL.opt.LastSacnAllTime = time()
                    SaveAuctionItemsData()
                end
                return
            end
            if IsCanDo() then
                UpdateSortAnim()
            else
                UpdateSortAnim(true)
                return
            end
            local currentAuctions, totalAuctions = GetNumAuctionItems("list")
            if totalAuctions == 0 then
                return
            elseif totalAuctions > 50 then
                if AuctionFrameBrowse.page and AuctionFrameBrowse.page > 0 then
                    return
                end
            end
            local itemID = select(10, GetAuctionSellItemInfo())
            local isExist, count, buyoutPrice, owner, itemId, UnitPrice, itemLink, _
            local postDate = date("%Y-%m-%d", time())
            self.historyPrice = self.historyPrice or {}
            for i = 1, currentAuctions do
                _, _, count, _, _, _, _, _, _, buyoutPrice, _, _, _, owner, _, _, itemId = GetAuctionItemInfo("list", 1)
                if itemId and buyoutPrice > 0 then
                    itemLink = GetAuctionItemLink("list", i)
                    UnitPrice = owner == UnitName("player") and floor(buyoutPrice/count) or (floor(buyoutPrice/count) - ZL.opt.AucitonPriceDown)
                    if itemID and itemId == itemID and not isExist then
                        isExist = true
                        UpdateStartAuctionCopperInfo(UnitPrice)
                        UpdateStartAuctionStackInfo()
                    end
                    if i == 1 then
                        --缓存历史价格
                        ZL.opt.AuctionPostItemsHistoryPrice = ZL.opt.AuctionPostItemsHistoryPrice or {}
                        local priceList = ZL.opt.AuctionPostItemsHistoryPrice
                        priceList[itemId] = priceList[itemId] or {}
                        local unitPrice = buyoutPrice/count
                        if priceList[itemId][1] and priceList[itemId][1][3] == postDate then  --1为当日最低价，2为当前扫描最低价， 3为扫描日期
                            if priceList[itemId][1][1] > unitPrice then
                                priceList[itemId][1][1] = floor(unitPrice)
                            end
                        priceList[itemId][1][2] = floor(unitPrice)
                        else
                            tinsert(priceList[itemId], 1, {floor(unitPrice), floor(unitPrice), postDate})
                        end
                        --判断是否有更低价的拍卖物品
                        local ownerItemLink, ownercount, ownerbuyoutPrice, ownersaleStatus
                        for index = 1, GetNumAuctionItems("owner") do
                            ownerItemLink = GetAuctionItemLink("owner", index)
                            if ownerItemLink == itemLink then
                                _, _, ownercount, _, _, _, _, _, _, ownerbuyoutPrice, _, _, _, _, _, ownersaleStatus = GetAuctionItemInfo("owner", index)
                                if ownersaleStatus ~= 1 and ownerbuyoutPrice > 0 and ownerbuyoutPrice/ownercount > buyoutPrice/count then
                                    CancelAuctionBtn:Enable()
                                    break
                                end
                            end
                        end
                    end
                end
            end
        elseif event == "AUCTION_OWNED_LIST_UPDATE" then
            do
                local ownerNum = GetNumAuctionItems("owner")
                if ownerNum > 0 then
                    local minBid, bidAmount, _
                    local totalMoney, soldMoney = 0, 0
                    for index = 1, GetNumAuctionItems("owner") do
                        _, _, _, _, _, _, _, minBid, _, _, bidAmount = GetAuctionItemInfo("owner", index)
                        if bidAmount > 0 then
                            totalMoney = totalMoney + bidAmount
                            soldMoney = soldMoney + bidAmount
                        else
                            totalMoney = totalMoney + minBid
                        end
                    end
                    soldMoneyAuctionLabel:SetText(format("税后总金额：|cffffffff%s|r  税后收入：|cffffffff%s|r", GetMoneyString(totalMoney*0.95), GetMoneyString(soldMoney*0.95)))
                else
                    soldMoneyAuctionLabel:SetText("")
                end
            end
            if not IsCanDo() then return end
            CancelAuctionBtn:Disable()
            if AuctionFrameBrowse.page and AuctionFrameBrowse.page > 0 then
                return
            end
            local isExist
            local _, _, count, _, _, _, _, _, _, buyoutPrice, _, _, _, _, _, _, itemId = GetAuctionItemInfo("list", 1)
            if itemId and buyoutPrice > 0 then
                local itemLink = GetAuctionItemLink("list", 1)
                local ownerItemLink, ownercount, ownerbuyoutPrice, ownersaleStatus, _
                for index = 1, GetNumAuctionItems("owner") do
                    ownerItemLink = GetAuctionItemLink("owner", index)
                    if ownerItemLink == itemLink then
                        _, _, ownercount, _, _, _, _, _, _, ownerbuyoutPrice, _, _, _, _, _, ownersaleStatus = GetAuctionItemInfo("owner", index)
                        if ownersaleStatus ~= 1 and ownerbuyoutPrice > 0 and ownerbuyoutPrice/ownercount > buyoutPrice/count then
                            isExist = true
                            break
                        end
                    end
                end
            end
            if isExist then
                CancelAuctionBtn:Enable()
            end
        elseif event == "CHAT_MSG_SYSTEM" then
            if strmatch(arg[1], ERR_AUCTION_WON_S:gsub("%%s", "(.+)")) then
                local name = strmatch(arg[1], ERR_AUCTION_WON_S:gsub("%%s", "(.+)"))
                if BuyItemsInfoFrame:IsShown() and name == BuyItemsInfoFrame.itemName then
                    AuctionBuyItemsHistory(BuyItemsInfoFrame.itemId, BuyItemsInfoFrame.currentCount, BuyItemsInfoFrame.currentBuyoutPrice)
                    BuyItemsInfoFrame.totalMoney = (BuyItemsInfoFrame.totalMoney or 0) + BuyItemsInfoFrame.currentBuyoutPrice
                    BuyItemsInfoFrame.totalCount = (BuyItemsInfoFrame.totalCount or 0) + BuyItemsInfoFrame.currentCount
                    BuyItemsInfoFrameBuyBtn:Enable()
                    BuyItemsInfoFrame_Update(BuyItemsInfoFrame)
                elseif name == auctionBuyItemInfo.itemName then
                    AuctionBuyItemsHistory(auctionBuyItemInfo.itemId, auctionBuyItemInfo.count, auctionBuyItemInfo.buyoutPrice)
                end
            elseif ZL.opt.AuctionItemSold and strmatch(arg[1], ERR_AUCTION_SOLD_S:gsub("%%s", "(.+)")) then
                ZL.SpeakText(arg[1])
            end
        elseif event == "UI_ERROR_MESSAGE" then
            if BuyItemsInfoFrame:IsShown() and isAuctionBidFailed(arg[2]) then
                BuyItemsInfoFrameBuyBtn:Enable()
                BuyItemsInfoFrame.index = BuyItemsInfoFrame.index + 1
                BuyItemsInfoFrame_Update(BuyItemsInfoFrame)
            end
        end
        arg:Release()
    end)
end

--创建AH相关价格趋势图
function ZL:CreateAHPriceChartFrame()
    ZL.AHPriceChartFrame = CreateFrame("Frame", "ZLAHPriceChartFrame", ZL)
    local AHPriceChartFrame = ZL.AHPriceChartFrame
    AHPriceChartFrame:SetSize(300, 50)
    -- ZL.CreateBorder(AHPriceChartFrame, 0.2, 0.6, 1, 0.5, "OVERLAY", 1)
    -- AHPriceChartFrame.Background = AHPriceChartFrame:CreateTexture(nil,"BACKGROUND")
    -- AHPriceChartFrame.Background:SetColorTexture(0, 0, 0, .7)
    -- AHPriceChartFrame.Background:SetAllPoints()
    AHPriceChartFrame.Title = AHPriceChartFrame:CreateFontString(nil, "OVERLAY")
    AHPriceChartFrame.Title:SetFont(GameFontNormal:GetFont(), 13, "")
    AHPriceChartFrame.Title:SetTextColor(0.2, 0.6, 1)
    AHPriceChartFrame.Title:SetWordWrap(false)
    AHPriceChartFrame.Title:SetJustifyH("CENTER")
    AHPriceChartFrame.Title:SetPoint("TOP", AHPriceChartFrame, "TOP")
    AHPriceChartFrame.Title:SetText("AH价格趋势图(|cffffffff柱形:扫描最低价  折线:购买均价|r)")
    -- AHPriceChartFrame:Hide()
    AHPriceChartFrame.scanEntries = setmetatable({}, {
        __index = function (t, v)
            local bar = CreateFrame("Frame", nil, AHPriceChartFrame)
            bar:SetSize(5, 5)
            bar:SetPoint("BOTTOMLEFT", AHPriceChartFrame, "BOTTOMLEFT", 5, 0)
            bar.texture = bar:CreateTexture()
            bar.texture:SetAllPoints()
            -- 添加柱子数值标签
            bar.label = bar:CreateFontString(nil, "OVERLAY", "GameFontHighlight")
            bar.label:SetPoint("TOP", bar, "BOTTOM", 0, -5)
            -- bar.label:SetText(weekList[v]:gsub("周", ""))
            bar.label:SetFont(GameFontNormal:GetFont(), 13, "")
            if v % 2 == 0 then
                bar.texture:SetColorTexture(0.2, 0.6, 1, 0.8) -- 蓝色柱子
                bar.label:SetTextColor(0.2, 0.6, 1, 0.8)
            else
                bar.texture:SetColorTexture(1, 1, 1, 1)
                bar.label:SetTextColor(1, 1, 1, 1)
            end
            t[v] = bar
            return bar
        end
    })
end