zhangyang 3 роки тому
батько
коміт
e92b2389ce

+ 12 - 0
bin/Win32/Debug/zhipuzi_pos_windows/skin/zhengcan_page.xml

@@ -15,6 +15,18 @@
 					<VerticalLayout name="zhengcan_tablelist" padding="0,0,0,0">
 					
 					</VerticalLayout>
+					
+					<HorizontalLayout name="loading">
+						<Control></Control>
+						<VerticalLayout width="24">
+							<Control></Control>
+							<HorizontalLayout height="24">
+								<GifAnim bkimage="loading.gif" autosize="true"></GifAnim>
+							</HorizontalLayout>
+							<Control></Control>
+						</VerticalLayout>
+						<Control></Control>
+					</HorizontalLayout>
 				</VerticalLayout>
 			</VerticalLayout>
 				

+ 41 - 57
zhipuzi_pos_windows/page/CZhengcanPageUI.cpp

@@ -21,7 +21,7 @@ void CZhengcanPageUI::InitShow()
 {
 	InitTabletypeShow();
 
-	InitTableShow();
+	RefreshTableShow();
 }
 
 //处理按钮点击类事件
@@ -64,7 +64,7 @@ void CZhengcanPageUI::HandleSelectChangeMsg(TNotifyUI& msg)
 
 			m_cur_type_id = id;
 
-			this->InitTableShow();
+			this->RefreshTableShow();
 
 			return;
 		}
@@ -108,53 +108,10 @@ 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"];
+	std::vector<TableType> tableTypes = CShopinfo::GetInstance()->m_tabletypes;
 
 	//计算总的桌子分类数量
-	m_tabletype_num = tabletype.Size() + 1;
+	m_tabletype_num = tableTypes.size() + 1;
 
 	m_cur_type_id = "all";
 
@@ -178,17 +135,15 @@ void CZhengcanPageUI::InitTabletypeShow()
 	}
 
 	//接下来开始处理商品分类
-	for (rapidjson::SizeType i = 0; i < tabletype.Size(); ++i)
+	for (std::vector<TableType>::iterator it = tableTypes.begin(); it != tableTypes.end(); it++)
 	{
-		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->SetName(CLewaimaiString::UTF8ToUnicode(it->name));
+		pItem->SetTypeId(it->id);
 		pItem->SetGroup(L"zhengcan_tabletype");
 
 		m_zhuozitypeLayout->Add(pItem);
@@ -270,8 +225,24 @@ void CZhengcanPageUI::UpdateTabletypePos()
 	pFenleiScrollLayout->SetScrollPos(size);
 }
 
-void CZhengcanPageUI::InitTableShow()
+void CZhengcanPageUI::RefreshTableShow()
+{
+	//开始转菊花
+	CVerticalLayoutUI* pTableLayout = static_cast<CVerticalLayoutUI*>(this->FindSubControl(_T("zhengcan_tablelist")));
+	pTableLayout->SetVisible(false);
+
+	this->FindSubControl(_T("loading"))->SetVisible(true);
+
+	//启动一个线程,进行网络请求操作
+
+	std::thread t(&CZhengcanPageUI::DoRefreshTable, this);
+	t.detach();
+}
+
+void CZhengcanPageUI::DoRefreshTable()
 {
+	m_is_refresh_table = true;
+
 	m_tableLayout = static_cast<CVerticalLayoutUI*>(this->FindSubControl(_T("zhengcan_tablelist")));
 	m_tableLayout->RemoveAll();
 
@@ -292,7 +263,7 @@ void CZhengcanPageUI::InitTableShow()
 	bool ret = CZhipuziHttpClient::GetInstance()->Request(url.c_str(), params, response);
 	if (ret == false)
 	{
-
+		m_is_refresh_table = false;
 		return;
 	}
 
@@ -302,13 +273,14 @@ void CZhengcanPageUI::InitTableShow()
 	if (document.HasParseError())
 	{
 		LOG_INFO("parse response error!");
+		m_is_refresh_table = false;
 		return;
 	}
 
 	if (!document.HasMember("errcode") || !document.HasMember("errmsg"))
 	{
 		LOG_INFO("json error!");
-
+		m_is_refresh_table = false;
 		return;
 	}
 
@@ -316,13 +288,13 @@ void CZhengcanPageUI::InitTableShow()
 	int errcode = v_errcode.GetInt();
 	if (errcode != 0)
 	{
-
+		m_is_refresh_table = false;
 		return;
 	}
 
 	if (!document.HasMember("data"))
 	{
-
+		m_is_refresh_table = false;
 		return;
 	}
 
@@ -349,11 +321,23 @@ void CZhengcanPageUI::InitTableShow()
 		m_table_num++;
 	}
 
+	CVerticalLayoutUI* pTableLayout = static_cast<CVerticalLayoutUI*>(this->FindSubControl(_T("zhengcan_tablelist")));
+	pTableLayout->SetVisible(true);
+
+	this->FindSubControl(_T("loading"))->SetVisible(false);
+
+	m_is_refresh_table = false;
+
 	UpdateTablePos();
 }
 
 void CZhengcanPageUI::UpdateTablePos()
 {
+	if (m_is_refresh_table == true)
+	{
+		return;
+	}
+
 	int nTableNum = m_table_num;
 
 	//添加支付方式

+ 5 - 1
zhipuzi_pos_windows/page/CZhengcanPageUI.h

@@ -49,7 +49,7 @@ public:
 	void UpdateTabletypePos();
 
 	//根据当前选择的桌子分类,刷新桌位展示
-	void InitTableShow();
+	void RefreshTableShow();
 
 	void UpdateTablePos();
 
@@ -62,6 +62,8 @@ private:
 	//进入桌子
 	void EnterTable(std::string table_id);
 
+	void DoRefreshTable();
+
 private:
 	//当前控件的实际宽度
 	int m_nPageWidth;
@@ -80,4 +82,6 @@ private:
 	CControlUI* m_curZhuozitypeOption;
 
 	CZhengcanTableItemUI* m_cur_click_table_item;
+
+	bool m_is_refresh_table = false;
 };

+ 8 - 0
zhipuzi_pos_windows/wnd/CLoginWnd.cpp

@@ -563,6 +563,14 @@ void CLoginWnd::HandleLogin()
 			return;
 		}
 
+		ret = CShopinfo::GetInstance()->GetTabletypeInfo();
+		if (!ret)
+		{
+			m_wsLoginErrMsg = L"获取店铺桌子分类失败";
+			PostMessage(WM_LOGIN_ERROR);
+			return;
+		}
+
 		PostMessage(WM_LOGIN_SUCCESS);
 
 		return;

+ 59 - 0
zhipuzi_pos_windows/zhipuzi/CShopinfo.cpp

@@ -482,4 +482,63 @@ bool CShopinfo::GetLunboImages(std::vector<std::string>& images, std::wstring& e
 	}
 
 	return true;
+}
+
+bool CShopinfo::GetTabletypeInfo()
+{
+	std::map<string, string> params;
+
+	std::string response;
+
+	std::string url = "/dinnercash/gettabletypeinfo";
+	bool ret = CZhipuziHttpClient::GetInstance()->Request(url.c_str(), params, response);
+	if (ret == false)
+	{
+		return false;
+	}
+
+	rapidjson::Document document;
+	document.Parse(response.c_str());
+
+	if (document.HasParseError())
+	{
+		LOG_INFO("parse response error!");
+		return false;
+	}
+
+	if (!document.HasMember("errcode") || !document.HasMember("errmsg"))
+	{
+		LOG_INFO("json error!");
+
+		return false;
+	}
+
+	rapidjson::Value& v_errcode = document["errcode"];
+	int errcode = v_errcode.GetInt();
+	if (errcode != 0)
+	{
+		return false;
+	}
+
+	if (!document.HasMember("data"))
+	{
+		return false;
+	}
+
+	rapidjson::Value& data = document["data"];
+	rapidjson::Value& tabletype = data["type"];
+
+	for (rapidjson::SizeType i = 0; i < tabletype.Size(); ++i)
+	{
+		rapidjson::Value& typeinfo = tabletype[i];
+
+		TableType newTabletype;
+
+		newTabletype.id = CLewaimaiJson::ToString(typeinfo["id"]);
+		newTabletype.name = CLewaimaiJson::ToString(typeinfo["name"]);
+
+		m_tabletypes.push_back(newTabletype);
+	}
+
+	return true;
 }

+ 13 - 0
zhipuzi_pos_windows/zhipuzi/CShopinfo.h

@@ -36,6 +36,13 @@ public:
 	std::string channel_name;
 };
 
+class TableType
+{
+public:
+	std::string id;
+	std::string name;
+};
+
 //这个用来保存与当前登录的店铺相关的所有信息
 class CShopinfo
 {
@@ -61,6 +68,9 @@ public:
 
 	bool GetLunboImages(std::vector<std::string>& images, std::wstring& errmsg);
 
+	//获取店铺的桌位分类信息,保存起来,后续不用再重复获取了
+	bool GetTabletypeInfo();
+
 public:
 	//当前系统版本 1餐饮版 2零售版
 	std::string m_version_type;
@@ -184,4 +194,7 @@ public:
 
 	//这个存放的是轮播图副屏在本地对应的文件路径
 	std::vector<std::wstring> m_lunbo_img_paths;
+
+	//把桌位分类信息一起保存起来
+	std::vector<TableType> m_tabletypes;
 };