CShangpinPageUI.cpp 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451
  1. #include "../pch/pch.h"
  2. #include "CShangpinPageUI.h"
  3. #include "../control/ControlEx.h"
  4. #include "../tool/CSqlite3.h"
  5. #include "../wnd/CMainWnd.h"
  6. #include "../wnd/CShangpinNewTypeWnd.h"
  7. CShangpinPageUI::CShangpinPageUI()
  8. {
  9. }
  10. CShangpinPageUI::~CShangpinPageUI()
  11. {
  12. }
  13. //初始化当前页面的展示,处理默认展示效果,在页面被加载的时候调用
  14. void CShangpinPageUI::InitShow()
  15. {
  16. //先初始化商品分类
  17. this->InitFoodtypeShow();
  18. //再初始化商品显示
  19. this->InitFoodShow();
  20. }
  21. void CShangpinPageUI::RefreshShow()
  22. {
  23. //初始化商品显示(因为这里要刷新商品库存状态)
  24. this->InitFoodShow();
  25. }
  26. void CShangpinPageUI::InitFoodtypeShow()
  27. {
  28. //初始化商品渲染相关的信息
  29. m_foodtype_mutex.lock();
  30. m_foodtypeLayout = static_cast<CHorizontalLayoutUI*>(this->FindSubControl(_T("shangpin_fenlei_layout")));
  31. m_foodtypeLayout->RemoveAll();
  32. CSqlite3 sqlite;
  33. m_types = sqlite.GetFoodtypes(); //只包含收银机显示的分类
  34. if (m_types.size() > 0)
  35. {
  36. m_cur_type_id = m_types[0].id;
  37. }
  38. m_curFoodtypeOption = NULL;
  39. //接下来开始处理商品分类
  40. for (std::vector<CFoodType>::iterator it = m_types.begin(); it != m_types.end(); it++)
  41. {
  42. CFoodType type = *it;
  43. CDialogBuilder builder;
  44. CDialogBuilderCallbackEx cb;
  45. CFoodtypeOptionUI* pItem = static_cast<CFoodtypeOptionUI*>(builder.Create(_T("foodtype_option.xml"), (UINT)0, &cb, m_pManager));
  46. pItem->SetName(CLewaimaiString::UTF8ToUnicode(type.name));
  47. pItem->SetTypeId(type.id);
  48. pItem->SetGroup(L"shangpin_foodtype");
  49. m_foodtypeLayout->Add(pItem);
  50. if (m_cur_type_id == type.id)
  51. {
  52. m_curFoodtypeOption = pItem;
  53. }
  54. }
  55. m_foodtype_mutex.unlock();
  56. if (m_curFoodtypeOption != NULL)
  57. {
  58. m_curFoodtypeOption->SetBkColor(0xFF3CB371);
  59. }
  60. //如果不是一个分类都没有,选中第一个分类
  61. if (m_cur_type_id != "")
  62. {
  63. CFoodtypeOptionUI* curTypeUI = static_cast<CFoodtypeOptionUI*>(m_foodtypeLayout->GetItemAt(0));
  64. curTypeUI->Selected(true, false);
  65. }
  66. UpdateFoodtypePos();
  67. }
  68. void CShangpinPageUI::UpdateFoodtypePos()
  69. {
  70. int nFoodtypeNum = m_types.size();
  71. //添加支付方式
  72. int nWidth = m_nPageWidth;
  73. if (nWidth == 0)
  74. {
  75. return;
  76. }
  77. //根据宽度计算每行显示的数量
  78. int nMeihangNum = (nWidth - 321) / 140;
  79. int num = 0;
  80. m_foodtype_mutex.lock();
  81. CHorizontalLayoutUI* pFenleiLayout = static_cast<CHorizontalLayoutUI*>(this->FindSubControl(_T("shangpin_fenlei_layout")));
  82. for (int i = 0; i < nFoodtypeNum; i++)
  83. {
  84. CButtonUI* curItem = static_cast<CButtonUI*>(pFenleiLayout->GetItemAt(i));
  85. int curRow = num / nMeihangNum + 1;
  86. int curCol = num % nMeihangNum + 1;
  87. RECT rect;
  88. rect.left = (curCol - 1) * 140 + 10;
  89. rect.right = rect.left + 130;
  90. rect.top = (curRow - 1) * 52 + 10;
  91. rect.bottom = rect.top + 42;
  92. curItem->SetFloat(true);
  93. curItem->SetPos(rect);
  94. num++;
  95. }
  96. m_foodtype_mutex.unlock();
  97. //调整区域高度
  98. int lastRow = (num - 1) / nMeihangNum + 1;
  99. pFenleiLayout->SetFixedHeight(lastRow * 52 + 10);
  100. //处理滚动条问题
  101. CVerticalLayoutUI* pFenleiScrollLayout = static_cast<CVerticalLayoutUI*>(this->FindSubControl(_T("shangpin_fenlei_layout_scrolllayout")));
  102. if (lastRow > 2)
  103. {
  104. lastRow = 2;
  105. }
  106. pFenleiScrollLayout->SetFixedHeight(lastRow * 52 + 10);
  107. SIZE size;
  108. size.cx = 0;
  109. size.cy = 0;
  110. pFenleiScrollLayout->SetScrollPos(size);
  111. }
  112. void CShangpinPageUI::InitFoodShow()
  113. {
  114. bool is_youtu;
  115. if (CSetting::GetInstance()->GetParam("setting_xianshi_is_youtu") == "1")
  116. {
  117. is_youtu = true;
  118. }
  119. else
  120. {
  121. is_youtu = false;
  122. }
  123. m_foodLayout = static_cast<CTileLayoutUI*>(this->FindSubControl(_T("shangpin_foodlist")));
  124. m_foodLayout->RemoveAll();
  125. std::wstring xml_name;
  126. if (is_youtu)
  127. {
  128. SIZE itemsize;
  129. itemsize.cx = 140;
  130. itemsize.cy = 230;
  131. m_foodLayout->SetItemSize(itemsize);
  132. xml_name = _T("shangpin_fooditem.xml");
  133. }
  134. else
  135. {
  136. SIZE itemsize;
  137. itemsize.cx = 140;
  138. itemsize.cy = 100;
  139. m_foodLayout->SetItemSize(itemsize);
  140. xml_name = _T("shangpin_fooditem_wutu.xml");
  141. }
  142. //如果当前一个分类都没有,那么就不处理了
  143. if (m_cur_type_id == "")
  144. {
  145. return;
  146. }
  147. else if (m_cur_type_id == "sousuo")
  148. {
  149. //展示的是商品搜索的结果
  150. CSqlite3 sqlite;
  151. std::vector<CFood> foodlist = sqlite.GetFoodByFoodname(m_sousuo_foodname);
  152. for (std::vector<CFood>::iterator it = foodlist.begin(); it != foodlist.end(); it++)
  153. {
  154. CFood food = *it;
  155. CDialogBuilder builder;
  156. CDialogBuilderCallbackEx cb;
  157. CShangpinFoodItemUI* pItem = static_cast<CShangpinFoodItemUI*>(builder.Create(xml_name.c_str(), (UINT)0, &cb, m_pManager));
  158. pItem->SetYoutuModel(is_youtu);
  159. pItem->SetFoodInfo(food);
  160. pItem->UpdateShow();
  161. m_foodLayout->Add(pItem);
  162. }
  163. }
  164. else
  165. {
  166. //选择的是普通商品分类
  167. CSqlite3 sqlite;
  168. std::vector<CFood> foodlist = sqlite.GetFoodByTypeid(m_cur_type_id);
  169. for (std::vector<CFood>::iterator it = foodlist.begin(); it != foodlist.end(); it++)
  170. {
  171. CFood food = *it;
  172. CDialogBuilder builder;
  173. CDialogBuilderCallbackEx cb;
  174. CShangpinFoodItemUI* pItem = static_cast<CShangpinFoodItemUI*>(builder.Create(xml_name.c_str(), (UINT)0, &cb, m_pManager));
  175. pItem->SetYoutuModel(is_youtu);
  176. pItem->SetFoodInfo(food);
  177. pItem->UpdateShow();
  178. m_foodLayout->Add(pItem);
  179. }
  180. }
  181. }
  182. //处理按钮点击类事件
  183. void CShangpinPageUI::HandleClickMsg(TNotifyUI& msg)
  184. {
  185. CDuiString name = msg.pSender->GetName();
  186. if (name == L"shangpin_fooditem")
  187. {
  188. CShangpinFoodItemUI* fooditemUI = static_cast<CShangpinFoodItemUI*>(msg.pSender);
  189. m_cur_click_food_item = fooditemUI;
  190. this->ClickFoodAction();
  191. }
  192. else if (name == L"shangpin_food_search_clear")
  193. {
  194. CEditUI* m_pEdit = static_cast<CEditUI*>(m_pManager->FindControl(_T("shangpin_food_search_edit")));
  195. m_pEdit->SetText(L"");
  196. StopSerachFood();
  197. }
  198. else if (name == L"shangpin_page_add_btn")
  199. {
  200. CShangpinCreatePageUI* page = static_cast<CShangpinCreatePageUI*>(m_pMainWnd->GetPage(CMainWnd::SHANGPIN_CREATE));
  201. m_pMainWnd->SwitchPage(CMainWnd::SHANGPIN_CREATE);
  202. }
  203. else if (name == L"shangpin_page_add_type_btn")
  204. {
  205. ShowNewtype();
  206. }
  207. }
  208. //处理option切换事件
  209. void CShangpinPageUI::HandleSelectChangeMsg(TNotifyUI& msg)
  210. {
  211. CDuiString name = msg.pSender->GetName();
  212. COptionUI* curOption = static_cast<COptionUI*>(msg.pSender);
  213. std::wstring groupname = curOption->GetGroup();
  214. if (groupname == L"shangpin_foodtype")
  215. {
  216. //商品分类切换
  217. CFoodtypeOptionUI* typeUI = static_cast<CFoodtypeOptionUI*>(curOption);
  218. std::string id = typeUI->GetTypeId();
  219. if (m_cur_type_id != id)
  220. {
  221. //切换了商品分类
  222. m_curFoodtypeOption->SetBkColor(0xFFECECEC);
  223. msg.pSender->SetBkColor(0xFF3CB371);
  224. m_curFoodtypeOption = static_cast<CControlUI*>(msg.pSender);
  225. m_cur_type_id = id;
  226. this->InitFoodShow();
  227. return;
  228. }
  229. }
  230. }
  231. //处理下拉框、radio的切换事件
  232. void CShangpinPageUI::HandleItemSelectMsg(TNotifyUI& msg)
  233. {
  234. }
  235. //处理编辑框输入内容改变事件
  236. void CShangpinPageUI::HandleTextChangedMsg(TNotifyUI& msg)
  237. {
  238. CDuiString name = msg.pSender->GetName();
  239. if (name == L"shangpin_food_search_edit")
  240. {
  241. //商品搜索框的输入事件
  242. CEditUI* m_pEdit = static_cast<CEditUI*>(m_pManager->FindControl(_T("shangpin_food_search_edit")));
  243. wstring ws_Value = m_pEdit->GetText();
  244. string strValue = CLewaimaiString::UnicodeToUTF8(ws_Value);
  245. if (strValue.length() == 0)
  246. {
  247. //搜索词被清空了,退出搜索
  248. this->StopSerachFood();
  249. }
  250. else
  251. {
  252. //搜索词没清空,进入搜索
  253. this->StartSearchFood(strValue);
  254. }
  255. }
  256. }
  257. //处理扫码枪捕捉到的扫码信息
  258. void CShangpinPageUI::HandleTextCapture(std::string content)
  259. {
  260. }
  261. void CShangpinPageUI::ClickFoodAction()
  262. {
  263. //点击普通商品之后的处理逻辑
  264. CFood foodinfo = m_cur_click_food_item->GetFoodInfo();
  265. //点击了这个商品,进入商品修改页面
  266. CShangpinUpdatePageUI* page = static_cast<CShangpinUpdatePageUI*>(m_pMainWnd->GetPage(CMainWnd::SHANGPIN_UPDATE));
  267. page->SetFoodinfo(foodinfo);
  268. m_pMainWnd->SwitchPage(CMainWnd::SHANGPIN_UPDATE);
  269. }
  270. //开始搜索某个商品名字
  271. void CShangpinPageUI::StartSearchFood(std::string foodname)
  272. {
  273. //展示删除按钮
  274. CButtonUI* pClear = static_cast<CButtonUI*>(this->FindSubControl(_T("shangpin_food_search_clear")));
  275. pClear->SetVisible(true);
  276. //隐藏商品分类展示
  277. CHorizontalLayoutUI* pFoodtype = static_cast<CHorizontalLayoutUI*>(this->FindSubControl(_T("shangpin_fenlei_layout")));
  278. pFoodtype->SetVisible(false);
  279. //隐藏新建分类按钮
  280. CHorizontalLayoutUI* pNewType = static_cast<CHorizontalLayoutUI*>(this->FindSubControl(_T("shangpin_page_add_type_layout")));
  281. pNewType->SetVisible(false);
  282. if (m_cur_type_id != "sousuo")
  283. {
  284. m_type_id_before_sousuo = m_cur_type_id;
  285. }
  286. m_cur_type_id = "sousuo";
  287. m_sousuo_foodname = foodname;
  288. CLabelUI* pTishi = static_cast<CLabelUI*>(this->FindSubControl(_T("shangpin_food_search_tishi")));
  289. pTishi->SetVisible(false);
  290. this->InitFoodShow();
  291. }
  292. //停止搜索商品
  293. void CShangpinPageUI::StopSerachFood()
  294. {
  295. //隐藏删除按钮
  296. CButtonUI* pClear = static_cast<CButtonUI*>(this->FindSubControl(_T("shangpin_food_search_clear")));
  297. pClear->SetVisible(false);
  298. //展示商品分类展示
  299. CHorizontalLayoutUI* pFoodtype = static_cast<CHorizontalLayoutUI*>(this->FindSubControl(_T("shangpin_fenlei_layout")));
  300. pFoodtype->SetVisible(true);
  301. //展示新建分类按钮
  302. CHorizontalLayoutUI* pNewType = static_cast<CHorizontalLayoutUI*>(this->FindSubControl(_T("shangpin_page_add_type_layout")));
  303. pNewType->SetVisible(true);
  304. m_cur_type_id = m_type_id_before_sousuo;
  305. CLabelUI* pTishi = static_cast<CLabelUI*>(this->FindSubControl(_T("shangpin_food_search_tishi")));
  306. pTishi->SetVisible(true);
  307. this->InitFoodShow();
  308. }
  309. void CShangpinPageUI::SetPos(RECT rc, bool bNeedInvalidate)
  310. {
  311. m_nPageWidth = rc.right - rc.left;
  312. //更新分类位置
  313. UpdateFoodtypePos();
  314. CContainerUI::SetPos(rc, bNeedInvalidate);
  315. }
  316. void CShangpinPageUI::ShowNewtype()
  317. {
  318. if (m_is_show_modal_wnd == true)
  319. {
  320. return;
  321. }
  322. CShangpinNewTypeWnd* pMemoDlg = new CShangpinNewTypeWnd();
  323. if (pMemoDlg != NULL)
  324. {
  325. m_is_show_modal_wnd = true;
  326. m_curModalWnd = pMemoDlg;
  327. pMemoDlg->Create(m_pManager->GetPaintWindow(), _T(""), UI_WNDSTYLE_DIALOG, WS_EX_WINDOWEDGE);
  328. pMemoDlg->SetIcon(IDI_ICON_DUILIB);
  329. pMemoDlg->CenterWindow();
  330. UINT ret = pMemoDlg->ShowModal();
  331. if (ret == IDOK)
  332. {
  333. //这里表示添加分类成功了,刷新分类显示
  334. InitFoodtypeShow();
  335. m_is_show_modal_wnd = false;
  336. delete pMemoDlg;
  337. }
  338. else
  339. {
  340. m_is_show_modal_wnd = false;
  341. delete pMemoDlg;
  342. return;
  343. }
  344. }
  345. }