#include "PayLogScene.h" #include "GlobalUserInfo.h" #include "WebReq.h" #include "Platform.h" #include "PopScene.h" PayLogScene::PayLogScene() { m_nCurPageIndex = 1; } PayLogScene::~PayLogScene() { } bool PayLogScene::init() { if (!Node::init()) { return false; }; auto rootPanel = CSLoader::createNode("Platform/PayLogScene.csb"); CC_ASSERT(rootPanel != nullptr); this->addChild(rootPanel); m_rootPanel = rootPanel->getChildByName("Image_bg"); CC_ASSERT(m_rootPanel != nullptr); //获取关闭按钮 auto btnClose = (Button*)m_rootPanel->getChildByName("btnClose"); CC_ASSERT(btnClose != nullptr); //注册关闭按钮事件 btnClose->addClickEventListener([this](Ref*){ YSAudioEngine::Instance().playBtnClickEffect(); //this->removeFromParent(); this->popScene(); }); m_txtPageDesc = (Text*)m_rootPanel->getChildByName("txtPageDesc"); CC_ASSERT(m_txtPageDesc != nullptr); m_btnLastPage = (Button*)m_rootPanel->getChildByName("btnLastPage"); CC_ASSERT(m_btnLastPage != nullptr); m_btnLastPage->addClickEventListener([this](Ref*){ getCurPageData(m_nCurPageIndex - 1); }); m_btnLastPage->setEnabled(false); m_btnNextPage = (Button*)m_rootPanel->getChildByName("btnNextPage"); CC_ASSERT(m_btnNextPage != nullptr); m_btnNextPage->addClickEventListener([this](Ref*){ getCurPageData(m_nCurPageIndex + 1); }); m_btnNextPage->setEnabled(false); m_listLogView = (ListView*)m_rootPanel->getChildByName("listPayLog"); CC_ASSERT(m_listLogView != nullptr); //获取List节点 m_listItem = (Layout*)rootPanel->getChildByName("ListItem"); CC_ASSERT(m_listItem != nullptr); return true; } void PayLogScene::onEnter() { Node::onEnter(); } void PayLogScene::onEnterTransitionDidFinish() { Node::onEnterTransitionDidFinish(); //for (int i = 0; i < 10; i++) //{ // Widget* pClone = m_listItem->clone(); // m_listLogView->pushBackCustomItem(pClone); //} getCurPageData(m_nCurPageIndex); } void PayLogScene::onExit() { Node::onExit(); } void PayLogScene::getCurPageData(int nPageIndex) { LoadingScene::Instance().show(); CGlobalUserInfo * pGlobalUserInfo = CGlobalUserInfo::GetInstance(); tagGlobalUserData * pGlobalUserData = pGlobalUserInfo->GetGlobalUserData(); std::string strUrl = StringUtils::format("%s?uid=%d&pageindex=%d", PAY_LOG_HTTP_ADDRESS, pGlobalUserData->dwUserID, nPageIndex); CWebReq::getInstance().sendRequestDocumentUrl(strUrl, CC_CALLBACK_1(PayLogScene::responseResult, this), nullptr); } //请求信息结果 void PayLogScene::responseResult(rapidjson::Document* pDoc) { LoadingScene::Instance().hide(); if (pDoc == nullptr) { PopScene::Instance().show(utility::a_u8("网络错误")); return; } int bSuccess = CWebReq::getDataValueInt(pDoc, "ret"); if (bSuccess == 1) { if (pDoc->HasMember("data")) { rapidjson::Value& infoArray = (*pDoc)["data"]; if (infoArray.IsArray()) { m_listLogView->removeAllChildren(); for (int i = 0; i < infoArray.Size(); i++) { const rapidjson::Value& object = infoArray[i]; Widget* pClone = m_listItem->clone(); Text* txtTime = (Text*)pClone->getChildByName("txtTime"); CC_ASSERT(txtTime != nullptr); std::string strInsertTime = CWebReq::getDataValueStr(&object, "InsertTime"); txtTime->setString(strInsertTime.substr(5, strInsertTime.size()-5)); Text* txtGameID = (Text*)pClone->getChildByName("txtGameID"); CC_ASSERT(txtGameID != nullptr); int nGameID = CWebReq::getDataValueInt(&object, "GameID"); txtGameID->setString(StringUtils::format("%d", nGameID)); Text* txtNickName = (Text*)pClone->getChildByName("txtNickName"); CC_ASSERT(txtNickName != nullptr); std::string strNickName = CWebReq::getDataValueStr(&object, "NickName"); txtNickName->setString(utility::getShortName(strNickName, 12)); Text* txtScore = (Text*)pClone->getChildByName("txtScore"); CC_ASSERT(txtScore != nullptr); int nScore = CWebReq::getDataValueInt(&object, "OperNum"); txtScore->setString(StringUtils::format("%d", nScore)); Text* txtCurScore = (Text*)pClone->getChildByName("txtCurScore"); CC_ASSERT(txtCurScore != nullptr); int nCurScore = CWebReq::getDataValueInt(&object, "CurNum"); txtCurScore->setString(StringUtils::format("%d", nCurScore)); m_listLogView->pushBackCustomItem(pClone); } } int nCurPageIndex = CWebReq::getDataValueInt(pDoc, "pageindex"); int nTotalCount = CWebReq::getDataValueInt(pDoc, "total"); int nPageCount = CWebReq::getDataValueInt(pDoc, "pagecount"); m_nCurPageIndex = nCurPageIndex; if (nCurPageIndexsetEnabled(true); } else { m_btnNextPage->setEnabled(false); } if (nCurPageIndex>1) { m_btnLastPage->setEnabled(true); } else { m_btnLastPage->setEnabled(false); } m_txtPageDesc->setString(StringUtils::format("%d/%d", nCurPageIndex, nPageCount)); } } }