张洋 4 лет назад
Родитель
Сommit
2ccc70c0cd

+ 2 - 0
bin/Win32/Debug/zhipuzi_pos_windows/skin/shangpin_create_page.xml

@@ -163,6 +163,8 @@
 					<Button name="shangpin_create_page_save_btn" width="400" height="60" text="保存" textcolor="#FFFFFFFF" normalimage="file='green_zhengchang.png' corner='5,5,5,5'" hotimage="file='green_xuanfu.png' corner='5,5,5,5'" pushedimage="file='green_dianji.png' corner='5,5,5,5'" />
 					<Control></Control>
 				</HorizontalLayout>
+				
+				<Label name="shangpin_create_page_save_result" textcolor="#FFFF0000" height="40" padding="0,20,0,20"></Label>
 			</VerticalLayout>
 			
 			<Control width="1" bkcolor="#FFEBE8E8"></Control>

+ 300 - 2
zhipuzi_pos_windows/page/CShangpinCreatePageUI.cpp

@@ -17,7 +17,16 @@ CShangpinCreatePageUI::~CShangpinCreatePageUI()
 //初始化当前页面的展示,处理默认展示效果,在页面被加载的时候调用
 void CShangpinCreatePageUI::InitShow()
 {
-	//一个个初始化新建商品的默认值
+	//一个个初始化新建商品的默认值(每次都要清空)
+
+	//商品名字
+	CEditUI* pName = static_cast<CEditUI*>(this->FindSubControl(L"shangpin_create_page_name_edit"));
+	pName->SetText(L"");
+	pName->SetFocus();
+
+	//商品序号
+	CEditUI* pXuhao = static_cast<CEditUI*>(this->FindSubControl(L"shangpin_create_page_xuhao_edit"));
+	pXuhao->SetText(L"");
 	
 	//初始化商品分类
 	CComboUI* com_fenlei = static_cast<CComboUI*>(this->FindSubControl(_T("shangpin_create_page_foodtype")));
@@ -51,6 +60,71 @@ void CShangpinCreatePageUI::InitShow()
 	}
 
 	com_fenlei->SetText(CLewaimaiString::UTF8ToUnicode(first_food_name).c_str());
+
+	//商品条码
+	CEditUI* pTiaoma = static_cast<CEditUI*>(this->FindSubControl(L"shangpin_create_page_barcode_edit"));
+	pXuhao->SetText(L"");
+
+	//商品价格
+	CEditUI* pPrice = static_cast<CEditUI*>(this->FindSubControl(L"shangpin_create_page_price_edit"));
+	pPrice->SetText(L"");
+
+	//商品单位
+	CEditUI* pDanwei = static_cast<CEditUI*>(this->FindSubControl(L"shangpin_create_page_unit_edit"));
+	pDanwei->SetText(L"");
+
+	//是否称重
+	CCheckBoxUI* pChengzhong = static_cast<CCheckBoxUI*>(this->FindSubControl(L"shangpin_create_page_chengzhong"));
+	pChengzhong->Selected(false, false);
+
+	//plu编码
+	CEditUI* pPlu = static_cast<CEditUI*>(this->FindSubControl(L"shangpin_create_page_plu"));
+	pPlu->SetText(L"");
+
+	//商品编码
+	CEditUI* pShangpin = static_cast<CEditUI*>(this->FindSubControl(L"shangpin_create_page_shangpinbianma"));
+	pShangpin->SetText(L"");
+
+	//库存类型
+	CCheckBoxUI* pKucuntype = static_cast<CCheckBoxUI*>(this->FindSubControl(L"shangpin_create_page_kucun_open"));
+	pKucuntype->Selected(true, false);
+
+	//当前库存
+	CEditUI* pDangqiankucun = static_cast<CEditUI*>(this->FindSubControl(L"shangpin_create_page_kucun_now"));
+	pDangqiankucun->SetText(L"");
+
+	//商品状态
+	CCheckBoxUI* pStatus = static_cast<CCheckBoxUI*>(this->FindSubControl(L"shangpin_create_page_status_normal"));
+	pStatus->Selected(true, false);
+
+	//进货价
+	CEditUI* pJinhuojia = static_cast<CEditUI*>(this->FindSubControl(L"shangpin_create_page_buyingprice_edit"));
+	pJinhuojia->SetText(L"");
+
+	//进货价模式
+	CCheckBoxUI* pJinhuomoshi = static_cast<CCheckBoxUI*>(this->FindSubControl(L"shangpin_create_page_jinhuojia_normal"));
+	pJinhuomoshi->Selected(true, false);
+
+	//在哪些地方显示
+	CCheckBoxUI* pShouyinji = static_cast<CCheckBoxUI*>(this->FindSubControl(L"shangpin_create_page_showplace_shouyinji"));
+	CCheckBoxUI* pWaimai = static_cast<CCheckBoxUI*>(this->FindSubControl(L"shangpin_create_page_showplace_waimai"));
+	CCheckBoxUI* pSaomaidancan = static_cast<CCheckBoxUI*>(this->FindSubControl(L"shangpin_create_page_showplace_saomadiancan"));
+
+	pShouyinji->Selected(true, false);
+	pWaimai->Selected(true, false);
+	pSaomaidancan->Selected(true, false);
+
+	//是否开启打包费
+	CCheckBoxUI* pDabao = static_cast<CCheckBoxUI*>(this->FindSubControl(L"shangpin_create_page_is_dabao"));
+	pDabao->Selected(false, false);
+
+	//打包费
+	CEditUI* pDaobaofei = static_cast<CEditUI*>(this->FindSubControl(L"shangpin_create_page_dabao_money"));
+	pDaobaofei->SetText(L"");
+
+	//商品加工方式
+	CCheckBoxUI* pJiagongfangshi = static_cast<CCheckBoxUI*>(this->FindSubControl(L"shangpin_create_page_fangan_1"));
+	pJiagongfangshi->Selected(true, false);
 }
 
 //处理按钮点击类事件
@@ -307,7 +381,231 @@ void CShangpinCreatePageUI::SetPos(RECT rc, bool bNeedInvalidate)
 void CShangpinCreatePageUI::StartSave()
 {
 	//把参数一个个读出来
+
+	//商品名字
 	CEditUI* pName = static_cast<CEditUI*>(this->FindSubControl(L"shangpin_create_page_name_edit"));
 	std::wstring ws_name = pName->GetText();
-	std::string name = CLewaimaiString::UnicodeToUTF8(ws_name);
+	m_name = CLewaimaiString::UnicodeToUTF8(ws_name);
+
+	//商品序号
+	CEditUI* pXuhao = static_cast<CEditUI*>(this->FindSubControl(L"shangpin_create_page_xuhao_edit"));
+	std::wstring ws_xuhao = pXuhao->GetText();
+	m_xuhao = CLewaimaiString::UnicodeToUTF8(ws_xuhao);
+
+	//初始化商品分类
+	CComboUI* com_fenlei = static_cast<CComboUI*>(this->FindSubControl(_T("shangpin_create_page_foodtype")));
+	std::wstring ws_type = com_fenlei->GetText();
+	m_fenlei = CLewaimaiString::UnicodeToUTF8(ws_type);
+
+	//商品条码
+	CEditUI* pTiaoma = static_cast<CEditUI*>(this->FindSubControl(L"shangpin_create_page_barcode_edit"));
+	std::wstring ws_tiaoma = pTiaoma->GetText();
+	m_tiaoma = CLewaimaiString::UnicodeToUTF8(ws_tiaoma);
+
+	//商品价格
+	CEditUI* pPrice = static_cast<CEditUI*>(this->FindSubControl(L"shangpin_create_page_price_edit"));
+	std::wstring ws_price = pPrice->GetText();
+	m_price = CLewaimaiString::UnicodeToUTF8(ws_price);
+
+	//商品单位
+	CEditUI* pDanwei = static_cast<CEditUI*>(this->FindSubControl(L"shangpin_create_page_unit_edit"));
+	std::wstring ws_danwei = pDanwei->GetText();
+	m_danwei = CLewaimaiString::UnicodeToUTF8(ws_danwei);
+
+	//是否称重
+	CCheckBoxUI* pChengzhong = static_cast<CCheckBoxUI*>(this->FindSubControl(L"shangpin_create_page_chengzhong"));
+	m_is_chengzhong = pChengzhong->IsSelected();
+
+	//plu编码
+	CEditUI* pPlu = static_cast<CEditUI*>(this->FindSubControl(L"shangpin_create_page_plu"));
+	std::wstring ws_plu = pPlu->GetText();
+	m_plu = CLewaimaiString::UnicodeToUTF8(ws_plu);
+
+	//商品编码
+	CEditUI* pShangpin = static_cast<CEditUI*>(this->FindSubControl(L"shangpin_create_page_shangpinbianma"));
+	std::wstring ws_shangpin = pShangpin->GetText();
+	m_shangpinbianma = CLewaimaiString::UnicodeToUTF8(ws_shangpin);
+
+	//库存类型
+	CCheckBoxUI* pKucuntype = static_cast<CCheckBoxUI*>(this->FindSubControl(L"shangpin_create_page_kucun_open"));
+	if (pKucuntype->IsSelected())
+	{
+		m_kucuntype = 0;
+	}
+	else
+	{
+		m_kucuntype = 1;
+	}
+
+	//当前库存
+	CEditUI* pDangqiankucun = static_cast<CEditUI*>(this->FindSubControl(L"shangpin_create_page_kucun_now"));
+	std::wstring ws_dangqiankucun = pDangqiankucun->GetText();
+	m_dangqiankucun = CLewaimaiString::UnicodeToUTF8(ws_dangqiankucun);
+
+	//商品状态
+	CCheckBoxUI* pStatus = static_cast<CCheckBoxUI*>(this->FindSubControl(L"shangpin_create_page_status_normal"));
+	if (pStatus->IsSelected())
+	{
+		m_status = 0;
+	}
+	else
+	{
+		m_status = 1;
+	}
+
+	//进货价
+	CEditUI* pJinhuojia = static_cast<CEditUI*>(this->FindSubControl(L"shangpin_create_page_buyingprice_edit"));
+	std::wstring ws_jinhuojia = pJinhuojia->GetText();
+	m_jinhuojia = CLewaimaiString::UnicodeToUTF8(ws_jinhuojia);
+
+	//进货价模式
+	CCheckBoxUI* pJinhuomoshi = static_cast<CCheckBoxUI*>(this->FindSubControl(L"shangpin_create_page_jinhuojia_normal"));
+	if (pJinhuomoshi->IsSelected())
+	{
+		m_jinhuo_type = 0;
+	}
+	else
+	{
+		m_jinhuo_type = 1;
+	}
+
+	//在哪些地方显示
+	CCheckBoxUI* pShouyinji = static_cast<CCheckBoxUI*>(this->FindSubControl(L"shangpin_create_page_showplace_shouyinji"));
+	CCheckBoxUI* pWaimai = static_cast<CCheckBoxUI*>(this->FindSubControl(L"shangpin_create_page_showplace_waimai"));
+	CCheckBoxUI* pSaomaidancan = static_cast<CCheckBoxUI*>(this->FindSubControl(L"shangpin_create_page_showplace_saomadiancan"));
+
+	m_is_shouyinji_show = pShouyinji->IsSelected();
+	m_is_waimai_show = pWaimai->IsSelected();
+	m_is_saomadiancan_shou = pSaomaidancan->IsSelected();
+
+	//是否开启打包费
+	CCheckBoxUI* pDabao = static_cast<CCheckBoxUI*>(this->FindSubControl(L"shangpin_create_page_is_dabao"));
+	m_is_dabao_fei = pDabao->IsSelected();
+
+	//打包费
+	CEditUI* pDaobaofei = static_cast<CEditUI*>(this->FindSubControl(L"shangpin_create_page_dabao_money"));
+	std::wstring ws_dabaofei = pDaobaofei->GetText();
+	m_dabaofei = CLewaimaiString::UnicodeToUTF8(ws_dabaofei);
+
+	//商品加工方式
+	CCheckBoxUI* pJiagongfangshi_1 = static_cast<CCheckBoxUI*>(this->FindSubControl(L"shangpin_create_page_fangan_1"));
+	CCheckBoxUI* pJiagongfangshi_2 = static_cast<CCheckBoxUI*>(this->FindSubControl(L"shangpin_create_page_fangan_2"));
+	CCheckBoxUI* pJiagongfangshi_3 = static_cast<CCheckBoxUI*>(this->FindSubControl(L"shangpin_create_page_fangan_3"));
+	
+	if (pJiagongfangshi_1->IsSelected())
+	{
+		m_jiagong_type = 0;
+	}
+	else if (pJiagongfangshi_2->IsSelected())
+	{
+		m_jiagong_type = 1;
+	}
+	else if (pJiagongfangshi_3->IsSelected())
+	{
+		m_jiagong_type = 2;
+	}
+
+	ShowError(L"正在保存商品...");
+
+	std::thread(&CShangpinCreatePageUI::HandleSave, this).detach();
+}
+
+void CShangpinCreatePageUI::HandleSave()
+{
+	std::map<string, string> params;
+
+	params["goods_name"] = m_name;
+	params["goods_tag"] = m_xuhao;
+	params["stock"] = m_dangqiankucun;
+	params["goods_price"] = m_price;
+
+	if (m_status == 0)
+	{
+		params["goods_status"] = "OPEN";
+	}
+	else
+	{
+		params["goods_status"] = "CLOSED";
+	}
+
+	params["type_lv1_id"] = "";
+
+	if (m_kucuntype == 0)
+	{
+		params["stock_status"] = "1";
+	}
+	else
+	{
+		params["stock_status"] = "0";
+	}
+
+	params["unit"] = m_danwei;
+
+	if (m_is_dabao_fei)
+	{
+		params["is_dabao"] = "1";
+	}
+	else
+	{
+		params["is_dabao"] = "0";
+	}
+
+	params["dabao_money"] = m_dabaofei;
+
+	params["barcode"] = m_tiaoma;
+	params["buying_price"] = m_jinhuojia;
+
+	if (m_is_chengzhong)
+	{
+		params["is_weight"] = "1";
+	}
+	else
+	{
+		params["is_weight"] = "0";
+	}
+
+	std::string response;
+
+	std::string url = "/goods/addgoods";
+	bool ret = CZhipuziHttpClient::GetInstance()->Request(url.c_str(), params, response);
+
+	if (ret == false)
+	{
+		ShowError(L"请求服务器失败,请检查网络设置!");
+
+		return;
+	}
+
+	rapidjson::Document document;
+	document.Parse(response.c_str());
+
+	if (document.HasParseError())
+	{
+		ShowError(L"服务器错误");
+		return;
+	}
+
+	if (!document.HasMember("errcode") || !document.HasMember("errmsg") || !document.HasMember("data"))
+	{
+		ShowError(L"服务器错误");
+		return;
+	}
+
+	rapidjson::Value& v_errcode = document["errcode"];
+	int errcode = v_errcode.GetInt();
+	if (errcode != 0)
+	{
+		ShowError(L"服务器错误");
+		return;
+	}
+
+	rapidjson::Value& data = document["data"];
+
+
+}
+
+void CShangpinCreatePageUI::ShowError(std::wstring msg)
+{
+	CLabelUI* pResult = static_cast<CLabelUI*>(this->FindSubControl(L"shangpin_create_page_save_result"));
+	pResult->SetText(L"正在保存商品...");
 }

+ 36 - 0
zhipuzi_pos_windows/page/CShangpinCreatePageUI.h

@@ -47,11 +47,47 @@ public:
 	//开始处理保存商品的逻辑
 	void StartSave();
 
+	void HandleSave();
+
+private:
+	void ShowError(std::wstring msg);
+
 private:
 	//模态对话框有关的
 	bool m_is_show_modal_wnd = false;
 	CModalWnd* m_curModalWnd;
 
+	//商品字段
+	std::string m_name;
+	std::string m_xuhao;
+	std::string m_fenlei;
+	std::string m_tiaoma;
+	std::string m_price;
+	std::string m_danwei;
+	bool m_is_chengzhong;
+	std::string m_plu;
+	std::string m_shangpinbianma;
+
+	//0 下单扣减库存 1 无限库存
+	int m_kucuntype;
+	std::string m_dangqiankucun;
+
+	//0正常 1下架
+	int m_status;
+	std::string m_jinhuojia;
+
+	//0 当前成本价 1:加权平均
+	int m_jinhuo_type;
+
+	bool m_is_shouyinji_show;
+	bool m_is_waimai_show;
+	bool m_is_saomadiancan_shou;
+	bool m_is_dabao_fei;
+	std::string m_dabaofei;
+
+	//0 方案1 1:方案2 2:方案3
+	int m_jiagong_type;
+
 	//当前控件的实际宽度
 	int m_nPageWidth;
 };