|
|
@@ -0,0 +1,367 @@
|
|
|
+#include "../pch/pch.h"
|
|
|
+#include "CShangpinPageUI.h"
|
|
|
+
|
|
|
+#include "../control/ControlEx.h"
|
|
|
+
|
|
|
+#include "../tool/CSqlite3.h"
|
|
|
+
|
|
|
+CShangpinPageUI::CShangpinPageUI()
|
|
|
+{
|
|
|
+}
|
|
|
+
|
|
|
+
|
|
|
+CShangpinPageUI::~CShangpinPageUI()
|
|
|
+{
|
|
|
+}
|
|
|
+
|
|
|
+//初始化当前页面的展示,处理默认展示效果,在页面被加载的时候调用
|
|
|
+void CShangpinPageUI::InitShow()
|
|
|
+{
|
|
|
+ //先初始化商品分类
|
|
|
+ this->InitFoodtypeShow();
|
|
|
+
|
|
|
+ //再初始化商品显示
|
|
|
+ this->InitFoodShow();
|
|
|
+}
|
|
|
+
|
|
|
+void CShangpinPageUI::RefreshShow()
|
|
|
+{
|
|
|
+ //初始化商品显示(因为这里要刷新商品库存状态)
|
|
|
+ this->InitFoodShow();
|
|
|
+}
|
|
|
+
|
|
|
+void CShangpinPageUI::InitFoodtypeShow()
|
|
|
+{
|
|
|
+ //初始化商品渲染相关的信息
|
|
|
+ m_foodtypeLayout = static_cast<CHorizontalLayoutUI*>(this->FindSubControl(_T("shangpin_fenlei_layout")));
|
|
|
+ m_foodtypeLayout->RemoveAll();
|
|
|
+
|
|
|
+ CSqlite3 sqlite;
|
|
|
+ m_types = sqlite.GetFoodtypes(); //只包含收银机显示的分类
|
|
|
+
|
|
|
+ if (m_types.size() > 0)
|
|
|
+ {
|
|
|
+ m_cur_type_id = m_types[0].id;
|
|
|
+ }
|
|
|
+
|
|
|
+ m_curFoodtypeOption = NULL;
|
|
|
+
|
|
|
+ //接下来开始处理商品分类
|
|
|
+ for (std::vector<CFoodType>::iterator it = m_types.begin(); it != m_types.end(); it++)
|
|
|
+ {
|
|
|
+ CFoodType type = *it;
|
|
|
+
|
|
|
+ CDialogBuilder builder;
|
|
|
+ CDialogBuilderCallbackEx cb;
|
|
|
+
|
|
|
+ CFoodtypeOptionUI* pItem = static_cast<CFoodtypeOptionUI*>(builder.Create(_T("foodtype_option.xml"), (UINT)0, &cb, m_pManager));
|
|
|
+
|
|
|
+ pItem->SetName(CLewaimaiString::UTF8ToUnicode(type.name));
|
|
|
+ pItem->SetTypeId(type.id);
|
|
|
+ pItem->SetGroup(L"shangpin_foodtype");
|
|
|
+
|
|
|
+ m_foodtypeLayout->Add(pItem);
|
|
|
+
|
|
|
+ if (m_cur_type_id == type.id)
|
|
|
+ {
|
|
|
+ m_curFoodtypeOption = pItem;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ if (m_curFoodtypeOption != NULL)
|
|
|
+ {
|
|
|
+ m_curFoodtypeOption->SetBkColor(0xFF3CB371);
|
|
|
+ }
|
|
|
+
|
|
|
+ //如果不是一个分类都没有,选中第一个分类
|
|
|
+ if (m_cur_type_id != "")
|
|
|
+ {
|
|
|
+ CFoodtypeOptionUI* curTypeUI = static_cast<CFoodtypeOptionUI*>(m_foodtypeLayout->GetItemAt(0));
|
|
|
+
|
|
|
+ curTypeUI->Selected(true, false);
|
|
|
+ }
|
|
|
+
|
|
|
+ UpdateFoodtypePos();
|
|
|
+}
|
|
|
+
|
|
|
+void CShangpinPageUI::UpdateFoodtypePos()
|
|
|
+{
|
|
|
+ int nFoodtypeNum = m_types.size();
|
|
|
+
|
|
|
+ //添加支付方式
|
|
|
+ int nWidth = m_nPageWidth;
|
|
|
+ if (nWidth == 0)
|
|
|
+ {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ //根据宽度计算每行显示的数量
|
|
|
+ int nMeihangNum = (nWidth - 521) / 135;
|
|
|
+
|
|
|
+ int num = 0;
|
|
|
+
|
|
|
+ CHorizontalLayoutUI* pFenleiLayout = static_cast<CHorizontalLayoutUI*>(this->FindSubControl(_T("shangpin_fenlei_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);
|
|
|
+}
|
|
|
+
|
|
|
+void CShangpinPageUI::InitFoodShow()
|
|
|
+{
|
|
|
+ bool is_youtu;
|
|
|
+ if (CSetting::GetInstance()->GetParam("setting_xianshi_is_youtu") == "1")
|
|
|
+ {
|
|
|
+ is_youtu = true;
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ is_youtu = false;
|
|
|
+ }
|
|
|
+
|
|
|
+ m_foodLayout = static_cast<CTileLayoutUI*>(this->FindSubControl(_T("shangpin_foodlist")));
|
|
|
+ m_foodLayout->RemoveAll();
|
|
|
+
|
|
|
+ std::wstring xml_name;
|
|
|
+
|
|
|
+ if (is_youtu)
|
|
|
+ {
|
|
|
+ SIZE itemsize;
|
|
|
+ itemsize.cx = 170;
|
|
|
+ itemsize.cy = 260;
|
|
|
+ m_foodLayout->SetItemSize(itemsize);
|
|
|
+
|
|
|
+ xml_name = _T("shangpin_fooditem.xml");
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ SIZE itemsize;
|
|
|
+ itemsize.cx = 170;
|
|
|
+ itemsize.cy = 105;
|
|
|
+ m_foodLayout->SetItemSize(itemsize);
|
|
|
+
|
|
|
+ xml_name = _T("shangpin_fooditem_wutu.xml");
|
|
|
+ }
|
|
|
+
|
|
|
+ //如果当前一个分类都没有,那么就不处理了
|
|
|
+ if (m_cur_type_id == "")
|
|
|
+ {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ else if (m_cur_type_id == "sousuo")
|
|
|
+ {
|
|
|
+ //展示的是商品搜索的结果
|
|
|
+ CSqlite3 sqlite;
|
|
|
+ std::vector<CFood> foodlist = sqlite.GetFoodByFoodname(m_sousuo_foodname);
|
|
|
+
|
|
|
+ for (std::vector<CFood>::iterator it = foodlist.begin(); it != foodlist.end(); it++)
|
|
|
+ {
|
|
|
+ CFood food = *it;
|
|
|
+
|
|
|
+ CDialogBuilder builder;
|
|
|
+ CDialogBuilderCallbackEx cb;
|
|
|
+
|
|
|
+ CDiandanFoodItemUI* pItem = static_cast<CDiandanFoodItemUI*>(builder.Create(xml_name.c_str(), (UINT)0, &cb, m_pManager));
|
|
|
+
|
|
|
+ pItem->SetYoutuModel(is_youtu);
|
|
|
+ pItem->SetFoodInfo(food);
|
|
|
+ pItem->UpdateShow();
|
|
|
+
|
|
|
+ m_foodLayout->Add(pItem);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ //选择的是普通商品分类
|
|
|
+ CSqlite3 sqlite;
|
|
|
+ std::vector<CFood> foodlist = sqlite.GetFoodByTypeid(m_cur_type_id);
|
|
|
+
|
|
|
+ for (std::vector<CFood>::iterator it = foodlist.begin(); it != foodlist.end(); it++)
|
|
|
+ {
|
|
|
+ CFood food = *it;
|
|
|
+
|
|
|
+ CDialogBuilder builder;
|
|
|
+ CDialogBuilderCallbackEx cb;
|
|
|
+
|
|
|
+ CDiandanFoodItemUI* pItem = static_cast<CDiandanFoodItemUI*>(builder.Create(xml_name.c_str(), (UINT)0, &cb, m_pManager));
|
|
|
+
|
|
|
+ pItem->SetYoutuModel(is_youtu);
|
|
|
+ pItem->SetFoodInfo(food);
|
|
|
+ pItem->UpdateShow();
|
|
|
+
|
|
|
+ m_foodLayout->Add(pItem);
|
|
|
+ }
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
+//处理按钮点击类事件
|
|
|
+void CShangpinPageUI::HandleClickMsg(TNotifyUI& msg)
|
|
|
+{
|
|
|
+ CDuiString name = msg.pSender->GetName();
|
|
|
+
|
|
|
+ if (name == L"shangpin_fooditem")
|
|
|
+ {
|
|
|
+ CDiandanFoodItemUI* fooditemUI = static_cast<CDiandanFoodItemUI*>(msg.pSender);
|
|
|
+
|
|
|
+ m_cur_click_food_item = fooditemUI;
|
|
|
+
|
|
|
+ this->ClickFoodAction();
|
|
|
+ }
|
|
|
+ else if (name == L"shangpin_food_search_clear")
|
|
|
+ {
|
|
|
+ CEditUI* m_pEdit = static_cast<CEditUI*>(m_pManager->FindControl(_T("shangpin_food_search_edit")));
|
|
|
+ m_pEdit->SetText(L"");
|
|
|
+
|
|
|
+ StopSerachFood();
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
+//处理option切换事件
|
|
|
+void CShangpinPageUI::HandleSelectChangeMsg(TNotifyUI& msg)
|
|
|
+{
|
|
|
+ CDuiString name = msg.pSender->GetName();
|
|
|
+
|
|
|
+ COptionUI* curOption = static_cast<COptionUI*>(msg.pSender);
|
|
|
+ std::wstring groupname = curOption->GetGroup();
|
|
|
+
|
|
|
+ if (groupname == L"shangpin_foodtype")
|
|
|
+ {
|
|
|
+ //商品分类切换
|
|
|
+ CFoodtypeOptionUI* typeUI = static_cast<CFoodtypeOptionUI*>(curOption);
|
|
|
+ std::string id = typeUI->GetTypeId();
|
|
|
+
|
|
|
+ if (m_cur_type_id != id)
|
|
|
+ {
|
|
|
+ //切换了商品分类
|
|
|
+ m_curFoodtypeOption->SetBkColor(0xFFECECEC);
|
|
|
+
|
|
|
+ msg.pSender->SetBkColor(0xFF3CB371);
|
|
|
+
|
|
|
+ m_curFoodtypeOption = static_cast<CControlUI*>(msg.pSender);
|
|
|
+
|
|
|
+ m_cur_type_id = id;
|
|
|
+
|
|
|
+ this->InitFoodShow();
|
|
|
+
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
+//处理下拉框、radio的切换事件
|
|
|
+void CShangpinPageUI::HandleItemSelectMsg(TNotifyUI& msg)
|
|
|
+{
|
|
|
+
|
|
|
+}
|
|
|
+
|
|
|
+//处理编辑框输入内容改变事件
|
|
|
+void CShangpinPageUI::HandleTextChangedMsg(TNotifyUI& msg)
|
|
|
+{
|
|
|
+ CDuiString name = msg.pSender->GetName();
|
|
|
+
|
|
|
+ if (name == L"shangpin_food_search_edit")
|
|
|
+ {
|
|
|
+ //商品搜索框的输入事件
|
|
|
+ CEditUI* m_pEdit = static_cast<CEditUI*>(m_pManager->FindControl(_T("shangpin_food_search_edit")));
|
|
|
+ wstring ws_Value = m_pEdit->GetText();
|
|
|
+ string strValue = CLewaimaiString::UnicodeToUTF8(ws_Value);
|
|
|
+
|
|
|
+ if (strValue.length() == 0)
|
|
|
+ {
|
|
|
+ //搜索词被清空了,退出搜索
|
|
|
+ this->StopSerachFood();
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ //搜索词没清空,进入搜索
|
|
|
+ this->StartSearchFood(strValue);
|
|
|
+ }
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
+//处理扫码枪捕捉到的扫码信息
|
|
|
+void CShangpinPageUI::HandleTextCapture(std::string content)
|
|
|
+{
|
|
|
+
|
|
|
+}
|
|
|
+
|
|
|
+void CShangpinPageUI::ClickFoodAction()
|
|
|
+{
|
|
|
+ bool is_taocan = m_cur_click_food_item->GetIsTaocan();
|
|
|
+
|
|
|
+ //点击普通商品之后的处理逻辑
|
|
|
+ CFood foodinfo = m_cur_click_food_item->GetFoodInfo();
|
|
|
+}
|
|
|
+
|
|
|
+//开始搜索某个商品名字
|
|
|
+void CShangpinPageUI::StartSearchFood(std::string foodname)
|
|
|
+{
|
|
|
+ //展示删除按钮
|
|
|
+ CButtonUI* pClear = static_cast<CButtonUI*>(this->FindSubControl(_T("shangpin_food_search_clear")));
|
|
|
+ pClear->SetVisible(true);
|
|
|
+
|
|
|
+ //隐藏商品分类展示
|
|
|
+ CHorizontalLayoutUI* pFoodtype = static_cast<CHorizontalLayoutUI*>(this->FindSubControl(_T("shangpin_fenlei_layout")));
|
|
|
+ pFoodtype->SetVisible(false);
|
|
|
+
|
|
|
+ if (m_cur_type_id != "sousuo")
|
|
|
+ {
|
|
|
+ m_type_id_before_sousuo = m_cur_type_id;
|
|
|
+ }
|
|
|
+
|
|
|
+ m_cur_type_id = "sousuo";
|
|
|
+
|
|
|
+ m_sousuo_foodname = foodname;
|
|
|
+
|
|
|
+ CLabelUI* pTishi = static_cast<CLabelUI*>(this->FindSubControl(_T("shangpin_food_search_tishi")));
|
|
|
+ pTishi->SetVisible(false);
|
|
|
+
|
|
|
+ this->InitFoodShow();
|
|
|
+}
|
|
|
+
|
|
|
+//停止搜索商品
|
|
|
+void CShangpinPageUI::StopSerachFood()
|
|
|
+{
|
|
|
+ //隐藏删除按钮
|
|
|
+ CButtonUI* pClear = static_cast<CButtonUI*>(this->FindSubControl(_T("shangpin_food_search_clear")));
|
|
|
+ pClear->SetVisible(false);
|
|
|
+
|
|
|
+ //展示商品分类展示
|
|
|
+ CHorizontalLayoutUI* pFoodtype = static_cast<CHorizontalLayoutUI*>(this->FindSubControl(_T("shangpin_fenlei_layout")));
|
|
|
+ pFoodtype->SetVisible(true);
|
|
|
+
|
|
|
+ m_cur_type_id = m_type_id_before_sousuo;
|
|
|
+
|
|
|
+ CLabelUI* pTishi = static_cast<CLabelUI*>(this->FindSubControl(_T("shangpin_food_search_tishi")));
|
|
|
+ pTishi->SetVisible(true);
|
|
|
+
|
|
|
+ this->InitFoodShow();
|
|
|
+}
|
|
|
+
|
|
|
+void CShangpinPageUI::SetPos(RECT rc, bool bNeedInvalidate)
|
|
|
+{
|
|
|
+ m_nPageWidth = rc.right - rc.left;
|
|
|
+
|
|
|
+ //更新分类位置
|
|
|
+ UpdateFoodtypePos();
|
|
|
+
|
|
|
+ CContainerUI::SetPos(rc, bNeedInvalidate);
|
|
|
+}
|