local FullMoonTaskCell = class("FullMoonTaskCell", BaseCell)

function FullMoonTaskCell:init()
    local uiMap = self:getUIMap()
    self.imgTaskBg = uiMap["full_moon_task_cell.img_task_bg"]
    self.imgTask = uiMap["full_moon_task_cell.img_task_bg.img_task"]
    self.txDesc = uiMap["full_moon_task_cell.tx_desc"]
    self.imgProg = uiMap["full_moon_task_cell.prog.img_prog"]:getComponent(GConst.TYPEOF_UNITY_CLASS.BF_SLIDER)
    self.txProg = uiMap["full_moon_task_cell.prog.tx_prog"]
    self.imgRewardIcon = uiMap["full_moon_task_cell.icon_reward"]
    self.txNum = uiMap["full_moon_task_cell.tx_num"]
    self.finish = uiMap["full_moon_task_cell.finish"]
    self.txFinish = uiMap["full_moon_task_cell.finish.bg.tx_finish"]

    self:addClickListener(function()
        if DataManager.FullMoonData:canGetTaskReward(self.taskId) and not DataManager.FullMoonData:isReceivedTaskReward(self.taskId) then
            ModuleManager.FullMoonManager:reqTaskReward(self.taskId)
        end
	end)
end

function FullMoonTaskCell:refresh(id)
    self.taskId = id
    local taskType = DataManager.FullMoonData:getTaskType(self.taskId)
    local total = DataManager.FullMoonData:getTaskTarget(self.taskId)
    local cur = DataManager.FullMoonData:getTaskProgress(self.taskId)
    local reward = DataManager.FullMoonData:getTaskReward(self.taskId)
    self.imgTask:setSprite(GConst.ATLAS_PATH.ICON_TASK, GFunc.getTaskIcon(taskType, total))
    self.txDesc:setText(GFunc.getTaskDesc(taskType, total))
    self.imgProg.value = cur / total
    self.txProg:setText(cur .. "/" .. total)
    self.imgRewardIcon:setSprite(GFunc.getRewardIconRes(reward.type, reward.id))
    self.txNum:setText(GFunc.getRewardNum(reward))
    self.txFinish:setText(I18N:getGlobalText(I18N.GlobalConst.STR_COMPLETED))

    self.finish:setActive(false)
    self.baseObject:removeRedPoint()
    if DataManager.FullMoonData:canGetTaskReward(self.taskId) then
        -- 已完成
        if DataManager.FullMoonData:isReceivedTaskReward(self.taskId) then
            -- 已领取
            self.baseObject:setSprite(GConst.ATLAS_PATH.ACT_COMMON, "act_common_bg_2")
            self.imgTaskBg:setSprite(GConst.ATLAS_PATH.ACT_COMMON, "act_common_board_3")
            self.finish:setActive(true)
        else
            -- 未领取
            self.baseObject:setSprite(GConst.ATLAS_PATH.ACT_COMMON, "act_common_bg_3")
            self.imgTaskBg:setSprite(GConst.ATLAS_PATH.ACT_COMMON, "act_common_board_4")
            self.baseObject:addRedPoint(260, 70, 0.8)
        end
    else
        --未完成
        self.baseObject:setSprite(GConst.ATLAS_PATH.ACT_COMMON, "act_common_bg_2")
        self.imgTaskBg:setSprite(GConst.ATLAS_PATH.ACT_COMMON, "act_common_board_3")
    end
end

return FullMoonTaskCell