OrderListUI.cpp 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176
  1. #include "../pch/pch.h"
  2. #include "OrderListUI.h"
  3. #include "CWaimaiOrderItemUI.h"
  4. #include "ControlEx.h"
  5. void OrderListUI::Refresh()
  6. {
  7. std::string url;
  8. if (m_status == 1)
  9. {
  10. url = "/waimaiorder/getopenlist";
  11. }
  12. else if (m_status == 2)
  13. {
  14. url = "/waimaiorder/getconfirmedlist";
  15. }
  16. else if (m_status == 3)
  17. {
  18. url = "/waimaiorder/getdeliverylist";
  19. }
  20. else if (m_status == 4)
  21. {
  22. url = "/waimaiorder/getsucceededlist";
  23. }
  24. else if (m_status == 5)
  25. {
  26. url = "/waimaiorder/getfailedlist";
  27. }
  28. else if (m_status == 6)
  29. {
  30. url = "/waimaiorder/getcancelledlist";
  31. }
  32. else if (m_status == 7)
  33. {
  34. url = "/waimaiorder/getrefundlist";
  35. }
  36. //请求外卖的未处理订单,直接用当前的page值去请求
  37. std::map<string, string> params;
  38. params["page"] = to_string(m_page);
  39. std::string response;
  40. CZhipuziHttpClient::RequestOld(url.c_str(), params, response);
  41. //请求成功之后,清空之前的数据
  42. this->RemoveAll();
  43. rapidjson::Document document;
  44. document.Parse(response.c_str());
  45. if (document.HasParseError())
  46. {
  47. LOG_INFO("parse response error!");
  48. return;
  49. }
  50. if (!document.HasMember("errcode") || !document.HasMember("errmsg") || !document.HasMember("data"))
  51. {
  52. LOG_INFO("json error!");
  53. return;
  54. }
  55. rapidjson::Value& v_errcode = document["errcode"];
  56. int errcode = v_errcode.GetInt();
  57. if (errcode != 0)
  58. {
  59. LOG_INFO("response failed! message:" << document["errmsg"].GetString());
  60. return;
  61. }
  62. //获得数据成功
  63. rapidjson::Value& data = document["data"];
  64. rapidjson::Value& v_count = data["count"];
  65. string count = v_count.GetString();
  66. //处理页数
  67. int nCount = atoi(count.c_str());
  68. m_total_page = (int)ceil(nCount / 20.0);
  69. if (m_total_page < 1)
  70. {
  71. m_total_page = 1;
  72. }
  73. if (m_page <= 1)
  74. {
  75. m_page = 1;
  76. CButtonUI* pControl = static_cast<CButtonUI*>(m_pManager->FindControl(_T("waimai_order_list_last")));
  77. pControl->SetEnabled(false);
  78. }
  79. if (m_page >= m_total_page)
  80. {
  81. m_page = m_total_page;
  82. CButtonUI* pControl = static_cast<CButtonUI*>(m_pManager->FindControl(_T("waimai_order_list_next")));
  83. pControl->SetEnabled(false);
  84. }
  85. CLabelUI* pControl = static_cast<CLabelUI*>(m_pManager->FindControl(_T("waimai_order_list_page")));
  86. wstring pageinfo = _T("第 ") + CLewaimaiString::ANSIToUnicode(to_string(m_page)) + _T("页/共 ") + CLewaimaiString::ANSIToUnicode(to_string(m_total_page)) + _T("页");
  87. pControl->SetText(pageinfo.c_str());
  88. rapidjson::Value& v_rows = data["rows"];
  89. for (rapidjson::SizeType i = 0; i < v_rows.Size(); ++i)
  90. {
  91. rapidjson::Value& v_row_i = v_rows[i];
  92. //创建一个对象
  93. CDialogBuilder builder;
  94. CDialogBuilderCallbackEx cb;
  95. CWaimaiOrderItemUI* pItem = static_cast<CWaimaiOrderItemUI*>(builder.Create(_T("waimai_order_item.xml"), (UINT)0, &cb, m_pManager));
  96. if (pItem != NULL)
  97. {
  98. //初始化该对应的数据
  99. pItem->SetStatus(m_status);
  100. pItem->SetData(v_row_i);
  101. this->Add(pItem);
  102. pItem = NULL;
  103. }
  104. else
  105. {
  106. LOG_INFO("create waimai_order_item fail!");
  107. }
  108. }
  109. //重置滚动条的位置
  110. tagSIZE size;
  111. size.cx = 0;
  112. size.cy = 0;
  113. this->SetScrollPos(size);
  114. }
  115. void OrderListUI::LastPage()
  116. {
  117. m_page--;
  118. if (m_page < 1)
  119. {
  120. m_page = 1;
  121. }
  122. if (m_page == 1)
  123. {
  124. CButtonUI* pControl = static_cast<CButtonUI*>(m_pManager->FindControl(_T("waimai_order_list_last")));
  125. pControl->SetEnabled(false);
  126. }
  127. Refresh();
  128. }
  129. void OrderListUI::NextPage()
  130. {
  131. m_page++;
  132. if (m_page > m_total_page)
  133. {
  134. m_page = m_total_page;
  135. }
  136. if (m_page == m_total_page)
  137. {
  138. CButtonUI* pControl = static_cast<CButtonUI*>(m_pManager->FindControl(_T("waimai_order_list_next")));
  139. pControl->SetEnabled(false);
  140. }
  141. Refresh();
  142. }
  143. void OrderListUI::DoEvent(TEventUI& event)
  144. {
  145. CVerticalLayoutUI::DoEvent(event);
  146. }