| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294 |
- #include "../pch/pch.h"
- #include "CHuiyuanPageUI.h"
- #include "../wnd/CHuiyuanChongzhiWnd.h"
- #include "../wnd/CHuiyuanAddWnd.h"
- CHuiyuanPageUI::CHuiyuanPageUI()
- {
- }
- CHuiyuanPageUI::~CHuiyuanPageUI()
- {
- }
- //初始化当前页面的展示,处理默认展示效果,在页面被加载的时候调用
- void CHuiyuanPageUI::InitShow()
- {
- CEditUI* pFukuanEdit = static_cast<CEditUI*>(this->FindSubControl(_T("huiyuan_page_shoujihao_edit")));
- pFukuanEdit->SetFocus();
- }
- //处理按钮点击类事件
- void CHuiyuanPageUI::HandleClickMsg(TNotifyUI& msg)
- {
- CDuiString name = msg.pSender->GetName();
- if (name == _T("huiiyuan_page_sousuo_btn"))
- {
- //如果是手动点击了,就重置这个搜索手机号
- CEditUI* m_pEdit = static_cast<CEditUI*>(this->FindSubControl(_T("huiyuan_page_shoujihao_edit")));
- wstring ws_Value = m_pEdit->GetText();
- m_sousuo_phone = CLewaimaiString::UnicodeToUTF8(ws_Value);
- StartHuiyuanSousuo();
- }
- else if (name == L"huiiyuan_page_chongzhi_btn")
- {
- StartHuiyuanChongzhi();
- }
- else if (name == L"huiyuan_page_add_btn")
- {
- StartAddHuiyuan();
- }
- }
- //处理option切换事件
- void CHuiyuanPageUI::HandleSelectChangeMsg(TNotifyUI& msg)
- {
- }
- //处理下拉框、radio的切换事件
- void CHuiyuanPageUI::HandleItemSelectMsg(TNotifyUI& msg)
- {
- }
- //处理编辑框输入内容改变事件
- void CHuiyuanPageUI::HandleTextChangedMsg(TNotifyUI& msg)
- {
- DuiLib::CDuiString senderName = msg.pSender->GetName();
- if (senderName == L"huiyuan_page_shoujihao_edit")
- {
- //只能输入数字,其他的全部删除
- CEditUI* m_pEdit = static_cast<CEditUI*>(this->FindSubControl(_T("huiyuan_page_shoujihao_edit")));
- if (!m_pEdit->GetText().IsEmpty())
- {
- wstring ws_Value = m_pEdit->GetText();
- string strValue = CLewaimaiString::UnicodeToUTF8(ws_Value);
- m_sousuo_phone = strValue;
- for (size_t nIndex = 0; nIndex < strValue.length(); nIndex++)
- {
- unsigned char tmp = strValue.at(nIndex);
- if (tmp > 57 || tmp < 48)
- {
- //ASCII码不是数字的都过滤掉
- strValue = strValue.substr(0, nIndex);
- m_sousuo_phone = strValue;
- m_pEdit->SetText(CLewaimaiString::UTF8ToUnicode(strValue).c_str());
- m_pEdit->SetSel(strValue.length(), strValue.length());//重设给光标设置位置
- break;
- }
- }
- }
- }
- }
- //处理扫码枪捕捉到的扫码信息
- void CHuiyuanPageUI::HandleTextCapture(std::string content)
- {
- if (m_is_show_modal_wnd == true)
- {
- m_curModalWnd->HandleTextCapture(content);
- }
- }
- void CHuiyuanPageUI::StartHuiyuanSousuo()
- {
- if (m_is_handle == true)
- {
- return;
- }
- std::wstring ws_phone = CLewaimaiString::UTF8ToUnicode(m_sousuo_phone);
- if (ws_phone.length() != 11)
- {
- //手机号格式错误
- ShowError(L"手机号格式不对!");
- }
- //手机号格式正确,开始处理
- m_is_handle = true;
- m_phone = CLewaimaiString::UnicodeToUTF8(ws_phone);
- std::map<string, string> params;
- params["phone"] = m_phone;
- std::string response;
- bool ret = CZhipuziHttpClient::Request("/member/membercheckbyphone", params, response);
- if (!ret)
- {
- ShowError(L"网络请求出错");
- m_is_handle = false;
- return;
- }
- rapidjson::Document document;
- document.Parse(response.c_str());
- if (document.HasParseError())
- {
- ShowError(L"服务器返回数据格式错误");
- m_is_handle = false;
- return;
- }
- else
- {
- if (!document.HasMember("errcode") || !document.HasMember("errmsg"))
- {
- ShowError(L"服务器返回数据格式错误");
- m_is_handle = false;
- return;
- }
- rapidjson::Value& v_errcode = document["errcode"];
- int errcode = v_errcode.GetInt();
- if (errcode != 0)
- {
- std::string errmsg = CLewaimaiString::UnicodeToUTF8(L"搜索结果:") + string(document["errmsg"].GetString());
- std::wstring m_errorInfo = CLewaimaiString::UTF8ToUnicode(errmsg);
- ShowError(m_errorInfo);
- m_is_handle = false;
- return;
- }
- rapidjson::Value& data = document["data"];
- rapidjson::Value& rows = data["rows"];
- if (rows.Size() < 1)
- {
- ShowError(L"会员信息为空");
- m_is_handle = false;
- return;
- }
- rapidjson::Value& rowinfo = rows[0];
- std::string member_name = rowinfo["name"].GetString();
- std::string phone = rowinfo["phone"].GetString();
- std::string sex = rowinfo["sex"].GetString();
- std::string birthday = rowinfo["birthday"].GetString();
- std::string balance = rowinfo["balance"].GetString();
- std::string member_level_name = rowinfo["member_level_name"].GetString();
- m_member_id = rowinfo["id"].GetString();
- m_balance = balance;
- m_member_card_no = rowinfo["card_no"].GetString();
- this->FindSubControl(L"huiyuan_name")->SetText((L"会员姓名:" + CLewaimaiString::UTF8ToUnicode(member_name)).c_str());
- this->FindSubControl(L"huiyuan_phone")->SetText((L"电话:" + CLewaimaiString::UTF8ToUnicode(phone)).c_str());
- this->FindSubControl(L"huiyuan_sex")->SetText((L"性别:" + CLewaimaiString::UTF8ToUnicode(sex)).c_str());
- this->FindSubControl(L"huiyuan_birthday")->SetText((L"生日:" + CLewaimaiString::UTF8ToUnicode(birthday)).c_str());
- this->FindSubControl(L"huiyuan_levelname")->SetText((L"会员级别:" + CLewaimaiString::UTF8ToUnicode(member_level_name)).c_str());
- this->FindSubControl(L"huiyuan_yue")->SetText((L"当前余额:" + CLewaimaiString::UTF8ToUnicode(balance)).c_str());
- this->FindSubControl(L"huiyuan_info_layout")->SetVisible(true);
- this->FindSubControl(L"huiyuan_page_no_layout")->SetVisible(false);
- m_is_handle = false;
- HideError();
- }
- }
- void CHuiyuanPageUI::ShowError(std::wstring err)
- {
- CLabelUI* m_pLabel= static_cast<CLabelUI*>(this->FindSubControl(_T("errorinfo")));
- m_pLabel->SetText(err.c_str());
- m_pLabel->SetVisible(true);
- this->FindSubControl(L"huiyuan_info_layout")->SetVisible(false);
- this->FindSubControl(L"huiyuan_page_no_layout")->SetVisible(true);
- }
- void CHuiyuanPageUI::StartAddHuiyuan()
- {
- if (m_is_show_modal_wnd == true)
- {
- return;
- }
- CHuiyuanAddWnd* pShoukuanWnd = new CHuiyuanAddWnd();
- if (pShoukuanWnd != NULL)
- {
- m_is_show_modal_wnd = true;
- m_curModalWnd = pShoukuanWnd;
- pShoukuanWnd->Create(m_pManager->GetPaintWindow(), _T(""), UI_WNDSTYLE_DIALOG, WS_EX_TOOLWINDOW);
- pShoukuanWnd->SetIcon(IDI_ICON_DUILIB);
- pShoukuanWnd->CenterWindow();
- UINT ret = pShoukuanWnd->ShowModal();
- if (ret == IDOK)
- {
- //会员开通成功
- m_pMainWnd->ShowToast(L"会员开通成功");
- m_sousuo_phone = pShoukuanWnd->m_phone;
- StartHuiyuanSousuo();
- }
- m_is_show_modal_wnd = false;
- delete pShoukuanWnd;
- }
- }
- void CHuiyuanPageUI::StartHuiyuanChongzhi()
- {
- if (m_is_show_modal_wnd == true)
- {
- return;
- }
- //充值之前,保存一下搜索电话,因为充值成功后要刷新的
- m_sousuo_phone = m_phone;
- CHuiyuanChongzhiWnd* pShoukuanWnd = new CHuiyuanChongzhiWnd();
- if (pShoukuanWnd != NULL)
- {
- m_is_show_modal_wnd = true;
- m_curModalWnd = pShoukuanWnd;
- pShoukuanWnd->Create(m_pManager->GetPaintWindow(), _T(""), UI_WNDSTYLE_DIALOG, WS_EX_TOOLWINDOW);
- pShoukuanWnd->SetIcon(IDI_ICON_DUILIB);
- pShoukuanWnd->CenterWindow();
- pShoukuanWnd->SetCurBalance(m_balance);
- pShoukuanWnd->m_member_id = m_member_id;
- pShoukuanWnd->m_member_card_no = m_member_card_no;
- UINT ret = pShoukuanWnd->ShowModal();
- if (ret == IDOK)
- {
- //这个表示充值成功了,这个时候刷新会员信息
- StartHuiyuanSousuo();
- }
- m_is_show_modal_wnd = false;
- delete pShoukuanWnd;
- }
- }
- void CHuiyuanPageUI::HideError()
- {
- CLabelUI* m_pLabel = static_cast<CLabelUI*>(this->FindSubControl(_T("errorinfo")));
- m_pLabel->SetVisible(true);
- }
|