|
|
@@ -17,6 +17,8 @@ CZhengcanPageUI::~CZhengcanPageUI()
|
|
|
//初始化当前页面的展示,处理默认展示效果,在页面被加载的时候调用
|
|
|
void CZhengcanPageUI::InitShow()
|
|
|
{
|
|
|
+ InitTabletypeShow();
|
|
|
+
|
|
|
|
|
|
}
|
|
|
|
|
|
@@ -35,6 +37,28 @@ void CZhengcanPageUI::HandleSelectChangeMsg(TNotifyUI& msg)
|
|
|
COptionUI* curOption = static_cast<COptionUI*>(msg.pSender);
|
|
|
std::wstring groupname = curOption->GetGroup();
|
|
|
|
|
|
+ if (groupname == L"zhengcan_tabletype")
|
|
|
+ {
|
|
|
+ //商品分类切换
|
|
|
+ CTabletypeOptionUI* typeUI = static_cast<CTabletypeOptionUI*>(curOption);
|
|
|
+ std::string id = typeUI->GetTypeId();
|
|
|
+
|
|
|
+ if (m_cur_type_id != id)
|
|
|
+ {
|
|
|
+ //切换了商品分类
|
|
|
+ m_curZhuozitypeOption->SetBkColor(0xFFECECEC);
|
|
|
+
|
|
|
+ msg.pSender->SetBkColor(0xFF3CB371);
|
|
|
+
|
|
|
+ m_curZhuozitypeOption = static_cast<CControlUI*>(msg.pSender);
|
|
|
+
|
|
|
+ m_cur_type_id = id;
|
|
|
+
|
|
|
+ //this->InitFoodShow();
|
|
|
+
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
//处理下拉框、radio的切换事件
|
|
|
@@ -59,10 +83,171 @@ void CZhengcanPageUI::SetPos(RECT rc, bool bNeedInvalidate)
|
|
|
{
|
|
|
m_nPageWidth = rc.right - rc.left;
|
|
|
|
|
|
+ //更新分类位置
|
|
|
+ UpdateTabletypePos();
|
|
|
+
|
|
|
CContainerUI::SetPos(rc, bNeedInvalidate);
|
|
|
}
|
|
|
|
|
|
void CZhengcanPageUI::InitTabletypeShow()
|
|
|
{
|
|
|
+ //初始化商品渲染相关的信息
|
|
|
+ m_zhuozitypeLayout = static_cast<CHorizontalLayoutUI*>(this->FindSubControl(_T("zhengcan_zhuozi_type_layout")));
|
|
|
+ m_zhuozitypeLayout->RemoveAll();
|
|
|
+
|
|
|
+ std::map<string, string> params;
|
|
|
+
|
|
|
+ std::string response;
|
|
|
+
|
|
|
+ std::string url = "/dinnercash/gettableinfo";
|
|
|
+ bool ret = CZhipuziHttpClient::GetInstance()->Request(url.c_str(), params, response);
|
|
|
+ if (ret == false)
|
|
|
+ {
|
|
|
+
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ rapidjson::Document document;
|
|
|
+ document.Parse(response.c_str());
|
|
|
+
|
|
|
+ if (document.HasParseError())
|
|
|
+ {
|
|
|
+ LOG_INFO("parse response error!");
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ if (!document.HasMember("errcode") || !document.HasMember("errmsg"))
|
|
|
+ {
|
|
|
+ LOG_INFO("json error!");
|
|
|
+
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ rapidjson::Value& v_errcode = document["errcode"];
|
|
|
+ int errcode = v_errcode.GetInt();
|
|
|
+ if (errcode != 0)
|
|
|
+ {
|
|
|
+
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ if (!document.HasMember("data"))
|
|
|
+ {
|
|
|
+
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ rapidjson::Value& data = document["data"];
|
|
|
+ rapidjson::Value& tabletype = data["type"];
|
|
|
+
|
|
|
+ //计算总的桌子分类数量
|
|
|
+ m_tabletype_num = tabletype.Size() + 1;
|
|
|
+
|
|
|
+ m_cur_type_id = "all";
|
|
|
+
|
|
|
+ m_curZhuozitypeOption = NULL;
|
|
|
+
|
|
|
+ //先添加全部分类
|
|
|
+ CDialogBuilder builder;
|
|
|
+ CDialogBuilderCallbackEx cb;
|
|
|
+
|
|
|
+ CFoodtypeOptionUI* pItem = static_cast<CFoodtypeOptionUI*>(builder.Create(_T("tabletype_option.xml"), (UINT)0, &cb, m_pManager));
|
|
|
+
|
|
|
+ pItem->SetName(L"全部桌子");
|
|
|
+ pItem->SetTypeId("all");
|
|
|
+ pItem->SetGroup(L"zhengcan_tabletype");
|
|
|
+
|
|
|
+ m_zhuozitypeLayout->Add(pItem);
|
|
|
+
|
|
|
+ if (m_cur_type_id == "all")
|
|
|
+ {
|
|
|
+ m_curZhuozitypeOption = pItem;
|
|
|
+ }
|
|
|
+
|
|
|
+ //接下来开始处理商品分类
|
|
|
+ for (rapidjson::SizeType i = 0; i < tabletype.Size(); ++i)
|
|
|
+ {
|
|
|
+ rapidjson::Value& typeinfo = tabletype[i];
|
|
|
+
|
|
|
+ CDialogBuilder builder;
|
|
|
+ CDialogBuilderCallbackEx cb;
|
|
|
+
|
|
|
+ CFoodtypeOptionUI* pItem = static_cast<CFoodtypeOptionUI*>(builder.Create(_T("tabletype_option.xml"), (UINT)0, &cb, m_pManager));
|
|
|
+
|
|
|
+ pItem->SetName(CLewaimaiString::UTF8ToUnicode(CLewaimaiJson::ToString(typeinfo["name"])));
|
|
|
+ pItem->SetTypeId(CLewaimaiJson::ToString(typeinfo["id"]));
|
|
|
+ pItem->SetGroup(L"zhengcan_tabletype");
|
|
|
+
|
|
|
+ m_zhuozitypeLayout->Add(pItem);
|
|
|
+ }
|
|
|
+
|
|
|
+ if (m_curZhuozitypeOption != NULL)
|
|
|
+ {
|
|
|
+ m_curZhuozitypeOption->SetBkColor(0xFF3CB371);
|
|
|
+ }
|
|
|
+
|
|
|
+ //如果不是一个分类都没有,选中第一个分类
|
|
|
+ if (m_cur_type_id != "")
|
|
|
+ {
|
|
|
+ CFoodtypeOptionUI* curTypeUI = static_cast<CFoodtypeOptionUI*>(m_zhuozitypeLayout->GetItemAt(0));
|
|
|
+
|
|
|
+ curTypeUI->Selected(true, false);
|
|
|
+ }
|
|
|
+
|
|
|
+ UpdateTabletypePos();
|
|
|
+}
|
|
|
+
|
|
|
+void CZhengcanPageUI::UpdateTabletypePos()
|
|
|
+{
|
|
|
+ int nFoodtypeNum = m_tabletype_num;
|
|
|
+
|
|
|
+ //添加支付方式
|
|
|
+ int nWidth = m_nPageWidth;
|
|
|
+ if (nWidth == 0)
|
|
|
+ {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ //根据宽度计算每行显示的数量
|
|
|
+ int nMeihangNum = (nWidth - 20) / 135;
|
|
|
+
|
|
|
+ int num = 0;
|
|
|
+
|
|
|
+ CHorizontalLayoutUI* pFenleiLayout = static_cast<CHorizontalLayoutUI*>(this->FindSubControl(_T("zhengcan_zhuozi_type_layout")));
|
|
|
+ for (int i = 0; i < nFoodtypeNum; i++)
|
|
|
+ {
|
|
|
+ CButtonUI* curItem = static_cast<CButtonUI*>(pFenleiLayout->GetItemAt(i));
|
|
|
+
|
|
|
+ int curRow = num / nMeihangNum + 1;
|
|
|
+ int curCol = num % nMeihangNum + 1;
|
|
|
+
|
|
|
+ RECT rect;
|
|
|
+ rect.left = (curCol - 1) * 135 + 15;
|
|
|
+ rect.right = rect.left + 120;
|
|
|
+ rect.top = (curRow - 1) * 61 + 19;
|
|
|
+ rect.bottom = rect.top + 42;
|
|
|
+
|
|
|
+ curItem->SetFloat(true);
|
|
|
+ curItem->SetPos(rect);
|
|
|
+
|
|
|
+ num++;
|
|
|
+ }
|
|
|
+
|
|
|
+ //调整区域高度
|
|
|
+ int lastRow = (num - 1) / nMeihangNum + 1;
|
|
|
+ pFenleiLayout->SetFixedHeight(lastRow * 61 + 19);
|
|
|
+
|
|
|
+ //处理滚动条问题
|
|
|
+ CVerticalLayoutUI* pFenleiScrollLayout = static_cast<CVerticalLayoutUI*>(this->FindSubControl(_T("zhengcan_zhuozi_type_layout_scrolllayout")));
|
|
|
+ if (lastRow > 2)
|
|
|
+ {
|
|
|
+ lastRow = 2;
|
|
|
+ }
|
|
|
+
|
|
|
+ pFenleiScrollLayout->SetFixedHeight(lastRow * 61 + 19);
|
|
|
|
|
|
+ SIZE size;
|
|
|
+ size.cx = 0;
|
|
|
+ size.cy = 0;
|
|
|
+ pFenleiScrollLayout->SetScrollPos(size);
|
|
|
}
|