CHuiyuanPageUI.cpp 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294
  1. #include "../pch/pch.h"
  2. #include "CHuiyuanPageUI.h"
  3. #include "../wnd/CHuiyuanChongzhiWnd.h"
  4. #include "../wnd/CHuiyuanAddWnd.h"
  5. CHuiyuanPageUI::CHuiyuanPageUI()
  6. {
  7. }
  8. CHuiyuanPageUI::~CHuiyuanPageUI()
  9. {
  10. }
  11. //初始化当前页面的展示,处理默认展示效果,在页面被加载的时候调用
  12. void CHuiyuanPageUI::InitShow()
  13. {
  14. CEditUI* pFukuanEdit = static_cast<CEditUI*>(this->FindSubControl(_T("huiyuan_page_shoujihao_edit")));
  15. pFukuanEdit->SetFocus();
  16. }
  17. //处理按钮点击类事件
  18. void CHuiyuanPageUI::HandleClickMsg(TNotifyUI& msg)
  19. {
  20. CDuiString name = msg.pSender->GetName();
  21. if (name == _T("huiiyuan_page_sousuo_btn"))
  22. {
  23. //如果是手动点击了,就重置这个搜索手机号
  24. CEditUI* m_pEdit = static_cast<CEditUI*>(this->FindSubControl(_T("huiyuan_page_shoujihao_edit")));
  25. wstring ws_Value = m_pEdit->GetText();
  26. m_sousuo_phone = CLewaimaiString::UnicodeToUTF8(ws_Value);
  27. StartHuiyuanSousuo();
  28. }
  29. else if (name == L"huiiyuan_page_chongzhi_btn")
  30. {
  31. StartHuiyuanChongzhi();
  32. }
  33. else if (name == L"huiyuan_page_add_btn")
  34. {
  35. StartAddHuiyuan();
  36. }
  37. }
  38. //处理option切换事件
  39. void CHuiyuanPageUI::HandleSelectChangeMsg(TNotifyUI& msg)
  40. {
  41. }
  42. //处理下拉框、radio的切换事件
  43. void CHuiyuanPageUI::HandleItemSelectMsg(TNotifyUI& msg)
  44. {
  45. }
  46. //处理编辑框输入内容改变事件
  47. void CHuiyuanPageUI::HandleTextChangedMsg(TNotifyUI& msg)
  48. {
  49. DuiLib::CDuiString senderName = msg.pSender->GetName();
  50. if (senderName == L"huiyuan_page_shoujihao_edit")
  51. {
  52. //只能输入数字,其他的全部删除
  53. CEditUI* m_pEdit = static_cast<CEditUI*>(this->FindSubControl(_T("huiyuan_page_shoujihao_edit")));
  54. if (!m_pEdit->GetText().IsEmpty())
  55. {
  56. wstring ws_Value = m_pEdit->GetText();
  57. string strValue = CLewaimaiString::UnicodeToUTF8(ws_Value);
  58. m_sousuo_phone = strValue;
  59. for (size_t nIndex = 0; nIndex < strValue.length(); nIndex++)
  60. {
  61. unsigned char tmp = strValue.at(nIndex);
  62. if (tmp > 57 || tmp < 48)
  63. {
  64. //ASCII码不是数字的都过滤掉
  65. strValue = strValue.substr(0, nIndex);
  66. m_sousuo_phone = strValue;
  67. m_pEdit->SetText(CLewaimaiString::UTF8ToUnicode(strValue).c_str());
  68. m_pEdit->SetSel(strValue.length(), strValue.length());//重设给光标设置位置
  69. break;
  70. }
  71. }
  72. }
  73. }
  74. }
  75. //处理扫码枪捕捉到的扫码信息
  76. void CHuiyuanPageUI::HandleTextCapture(std::string content)
  77. {
  78. if (m_is_show_modal_wnd == true)
  79. {
  80. m_curModalWnd->HandleTextCapture(content);
  81. }
  82. }
  83. void CHuiyuanPageUI::StartHuiyuanSousuo()
  84. {
  85. if (m_is_handle == true)
  86. {
  87. return;
  88. }
  89. std::wstring ws_phone = CLewaimaiString::UTF8ToUnicode(m_sousuo_phone);
  90. if (ws_phone.length() != 11)
  91. {
  92. //手机号格式错误
  93. ShowError(L"手机号格式不对!");
  94. }
  95. //手机号格式正确,开始处理
  96. m_is_handle = true;
  97. m_phone = CLewaimaiString::UnicodeToUTF8(ws_phone);
  98. std::map<string, string> params;
  99. params["phone"] = m_phone;
  100. std::string response;
  101. bool ret = CZhipuziHttpClient::Request("/member/membercheckbyphone", params, response);
  102. if (!ret)
  103. {
  104. ShowError(L"网络请求出错");
  105. m_is_handle = false;
  106. return;
  107. }
  108. rapidjson::Document document;
  109. document.Parse(response.c_str());
  110. if (document.HasParseError())
  111. {
  112. ShowError(L"服务器返回数据格式错误");
  113. m_is_handle = false;
  114. return;
  115. }
  116. else
  117. {
  118. if (!document.HasMember("errcode") || !document.HasMember("errmsg"))
  119. {
  120. ShowError(L"服务器返回数据格式错误");
  121. m_is_handle = false;
  122. return;
  123. }
  124. rapidjson::Value& v_errcode = document["errcode"];
  125. int errcode = v_errcode.GetInt();
  126. if (errcode != 0)
  127. {
  128. std::string errmsg = CLewaimaiString::UnicodeToUTF8(L"搜索结果:") + string(document["errmsg"].GetString());
  129. std::wstring m_errorInfo = CLewaimaiString::UTF8ToUnicode(errmsg);
  130. ShowError(m_errorInfo);
  131. m_is_handle = false;
  132. return;
  133. }
  134. rapidjson::Value& data = document["data"];
  135. rapidjson::Value& rows = data["rows"];
  136. if (rows.Size() < 1)
  137. {
  138. ShowError(L"会员信息为空");
  139. m_is_handle = false;
  140. return;
  141. }
  142. rapidjson::Value& rowinfo = rows[0];
  143. std::string member_name = rowinfo["name"].GetString();
  144. std::string phone = rowinfo["phone"].GetString();
  145. std::string sex = rowinfo["sex"].GetString();
  146. std::string birthday = rowinfo["birthday"].GetString();
  147. std::string balance = rowinfo["balance"].GetString();
  148. std::string member_level_name = rowinfo["member_level_name"].GetString();
  149. m_member_id = rowinfo["id"].GetString();
  150. m_balance = balance;
  151. m_member_card_no = rowinfo["card_no"].GetString();
  152. this->FindSubControl(L"huiyuan_name")->SetText((L"会员姓名:" + CLewaimaiString::UTF8ToUnicode(member_name)).c_str());
  153. this->FindSubControl(L"huiyuan_phone")->SetText((L"电话:" + CLewaimaiString::UTF8ToUnicode(phone)).c_str());
  154. this->FindSubControl(L"huiyuan_sex")->SetText((L"性别:" + CLewaimaiString::UTF8ToUnicode(sex)).c_str());
  155. this->FindSubControl(L"huiyuan_birthday")->SetText((L"生日:" + CLewaimaiString::UTF8ToUnicode(birthday)).c_str());
  156. this->FindSubControl(L"huiyuan_levelname")->SetText((L"会员级别:" + CLewaimaiString::UTF8ToUnicode(member_level_name)).c_str());
  157. this->FindSubControl(L"huiyuan_yue")->SetText((L"当前余额:" + CLewaimaiString::UTF8ToUnicode(balance)).c_str());
  158. this->FindSubControl(L"huiyuan_info_layout")->SetVisible(true);
  159. this->FindSubControl(L"huiyuan_page_no_layout")->SetVisible(false);
  160. m_is_handle = false;
  161. HideError();
  162. }
  163. }
  164. void CHuiyuanPageUI::ShowError(std::wstring err)
  165. {
  166. CLabelUI* m_pLabel= static_cast<CLabelUI*>(this->FindSubControl(_T("errorinfo")));
  167. m_pLabel->SetText(err.c_str());
  168. m_pLabel->SetVisible(true);
  169. this->FindSubControl(L"huiyuan_info_layout")->SetVisible(false);
  170. this->FindSubControl(L"huiyuan_page_no_layout")->SetVisible(true);
  171. }
  172. void CHuiyuanPageUI::StartAddHuiyuan()
  173. {
  174. if (m_is_show_modal_wnd == true)
  175. {
  176. return;
  177. }
  178. CHuiyuanAddWnd* pShoukuanWnd = new CHuiyuanAddWnd();
  179. if (pShoukuanWnd != NULL)
  180. {
  181. m_is_show_modal_wnd = true;
  182. m_curModalWnd = pShoukuanWnd;
  183. pShoukuanWnd->Create(m_pManager->GetPaintWindow(), _T(""), UI_WNDSTYLE_DIALOG, WS_EX_TOOLWINDOW);
  184. pShoukuanWnd->SetIcon(IDI_ICON_DUILIB);
  185. pShoukuanWnd->CenterWindow();
  186. UINT ret = pShoukuanWnd->ShowModal();
  187. if (ret == IDOK)
  188. {
  189. //会员开通成功
  190. m_pMainWnd->ShowToast(L"会员开通成功");
  191. m_sousuo_phone = pShoukuanWnd->m_phone;
  192. StartHuiyuanSousuo();
  193. }
  194. m_is_show_modal_wnd = false;
  195. delete pShoukuanWnd;
  196. }
  197. }
  198. void CHuiyuanPageUI::StartHuiyuanChongzhi()
  199. {
  200. if (m_is_show_modal_wnd == true)
  201. {
  202. return;
  203. }
  204. //充值之前,保存一下搜索电话,因为充值成功后要刷新的
  205. m_sousuo_phone = m_phone;
  206. CHuiyuanChongzhiWnd* pShoukuanWnd = new CHuiyuanChongzhiWnd();
  207. if (pShoukuanWnd != NULL)
  208. {
  209. m_is_show_modal_wnd = true;
  210. m_curModalWnd = pShoukuanWnd;
  211. pShoukuanWnd->Create(m_pManager->GetPaintWindow(), _T(""), UI_WNDSTYLE_DIALOG, WS_EX_TOOLWINDOW);
  212. pShoukuanWnd->SetIcon(IDI_ICON_DUILIB);
  213. pShoukuanWnd->CenterWindow();
  214. pShoukuanWnd->SetCurBalance(m_balance);
  215. pShoukuanWnd->m_member_id = m_member_id;
  216. pShoukuanWnd->m_member_card_no = m_member_card_no;
  217. UINT ret = pShoukuanWnd->ShowModal();
  218. if (ret == IDOK)
  219. {
  220. //这个表示充值成功了,这个时候刷新会员信息
  221. StartHuiyuanSousuo();
  222. }
  223. m_is_show_modal_wnd = false;
  224. delete pShoukuanWnd;
  225. }
  226. }
  227. void CHuiyuanPageUI::HideError()
  228. {
  229. CLabelUI* m_pLabel = static_cast<CLabelUI*>(this->FindSubControl(_T("errorinfo")));
  230. m_pLabel->SetVisible(true);
  231. }