Jelajahi Sumber

继续做正餐功能

zhangyang 3 tahun lalu
induk
melakukan
4f3d0c7efc

+ 5 - 0
bin/Win32/Debug/zhipuzi_pos_windows/skin/tabletype_option.xml

@@ -0,0 +1,5 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<Window>
+	<TabletypeOption endellipsis="true" align="center" valign="center" width="120" height="42" float="true" padding="15,19,0,0" bkcolor="#FFECECEC" selectedtextcolor="#FFFFFFFF">
+	</TabletypeOption>
+</Window>

+ 1 - 1
bin/Win32/Debug/zhipuzi_pos_windows/skin/zhengcan_page.xml

@@ -5,7 +5,7 @@
 			<Control width="1" bkcolor="#FFD1D1D1"></Control>
 			
 			<VerticalLayout>
-				<VerticalLayout name="zhengcan_zhuozi_type_scrolllayout" vscrollbar="true">
+				<VerticalLayout name="zhengcan_zhuozi_type_layout_scrolllayout" vscrollbar="true">
 					<HorizontalLayout name="zhengcan_zhuozi_type_layout" padding="0,0,0,0" bkcolor="#FFFFFFFF">
 
 					</HorizontalLayout>

+ 28 - 0
zhipuzi_pos_windows/control/CTabletypeOptionUI.cpp

@@ -0,0 +1,28 @@
+#include "CTabletypeOptionUI.h"
+
+
+CTabletypeOptionUI::CTabletypeOptionUI()
+{
+}
+
+
+CTabletypeOptionUI::~CTabletypeOptionUI()
+{
+}
+
+void CTabletypeOptionUI::SetName(std::wstring name)
+{
+	m_name = name;
+
+	this->SetText(m_name.c_str());
+}
+
+void CTabletypeOptionUI::SetTypeId(std::string id)
+{
+	m_id = id;
+}
+
+std::string CTabletypeOptionUI::GetTypeId()
+{
+	return m_id;
+}

+ 21 - 0
zhipuzi_pos_windows/control/CTabletypeOptionUI.h

@@ -0,0 +1,21 @@
+#pragma once
+
+#include "../pch/pch.h"
+
+class CTabletypeOptionUI : public COptionUI
+{
+public:
+	CTabletypeOptionUI();
+	~CTabletypeOptionUI();
+
+	void SetName(std::wstring name);
+	void SetTypeId(std::string id);
+
+	std::string GetTypeId();
+
+private:
+	std::wstring m_name;
+
+	std::string m_id;
+};
+

+ 5 - 0
zhipuzi_pos_windows/control/ControlEx.h

@@ -26,6 +26,7 @@
 #include "CFoodtypeOptionUI.h"
 #include "CDiandanNatureItemUI.h"
 #include "CShangpinFoodItemUI.h"
+#include "CTabletypeOptionUI.h"
 
 class CDialogBuilderCallbackEx : public IDialogBuilderCallback
 {
@@ -127,6 +128,10 @@ public:
 		{
 			return new CShangpinFoodItemUI;
 		}
+		else if (_tcscmp(pstrClass, _T("TabletypeOption")) == 0)
+		{
+			return new CTabletypeOptionUI;
+		}
 
 		return NULL;
 	}

+ 185 - 0
zhipuzi_pos_windows/page/CZhengcanPageUI.cpp

@@ -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);
 }

+ 11 - 0
zhipuzi_pos_windows/page/CZhengcanPageUI.h

@@ -47,7 +47,18 @@ public:
 	//先初始化桌子分类
 	void InitTabletypeShow();
 
+	void UpdateTabletypePos();
+
 private:
 	//当前控件的实际宽度
 	int m_nPageWidth;
+
+	CHorizontalLayoutUI* m_zhuozitypeLayout;
+
+	//桌子分类的数量
+	int m_tabletype_num;
+
+	//当前选中的桌子分类ID,为空表示没选中任何分类,为all表示选中全部分类,如果选中普通分类就是分类ID
+	std::string m_cur_type_id = "";
+	CControlUI* m_curZhuozitypeOption;
 };

+ 2 - 0
zhipuzi_pos_windows/zhipuzi_pos_windows.vcxproj

@@ -229,6 +229,7 @@ copy $(ProjectDir)conf\ $(SolutionDir)bin\$(Platform)\$(Configuration)\conf\</Co
     </PostBuildEvent>
   </ItemDefinitionGroup>
   <ItemGroup>
+    <ClInclude Include="control\CTabletypeOptionUI.h" />
     <ClInclude Include="wnd\CFupingWnd.h" />
     <ClInclude Include="tool\CShuangpingTool.h" />
     <ClInclude Include="wnd\CShangpinSaomaluruWnd.h" />
@@ -328,6 +329,7 @@ copy $(ProjectDir)conf\ $(SolutionDir)bin\$(Platform)\$(Configuration)\conf\</Co
     <ClInclude Include="helper\CSystem.h" />
   </ItemGroup>
   <ItemGroup>
+    <ClCompile Include="control\CTabletypeOptionUI.cpp" />
     <ClCompile Include="wnd\CFupingWnd.cpp" />
     <ClCompile Include="tool\CShuangpingTool.cpp" />
     <ClCompile Include="wnd\CShangpinSaomaluruWnd.cpp" />

+ 6 - 0
zhipuzi_pos_windows/zhipuzi_pos_windows.vcxproj.filters

@@ -306,6 +306,9 @@
     <ClInclude Include="wnd\CFupingWnd.h">
       <Filter>头文件</Filter>
     </ClInclude>
+    <ClInclude Include="control\CTabletypeOptionUI.h">
+      <Filter>头文件</Filter>
+    </ClInclude>
   </ItemGroup>
   <ItemGroup>
     <ClCompile Include="pch\pch.cpp">
@@ -572,6 +575,9 @@
     <ClCompile Include="wnd\CFupingWnd.cpp">
       <Filter>源文件</Filter>
     </ClCompile>
+    <ClCompile Include="control\CTabletypeOptionUI.cpp">
+      <Filter>源文件</Filter>
+    </ClCompile>
   </ItemGroup>
   <ItemGroup>
     <Image Include="resource\zhipuzi.ico">