each ํ์ฉ, ๊ฐ ๋ฃ์ ๋, ๊ฐ ๋ฐ๋ ๋
๋ฉ๋ด ํด๋ฆญ ์ ์ฃผ๋ฌธ์ ๋ฃ๊ธฐ
//ํ์ฌ์ฃผ๋ฌธ ์ํฉ์ ๋ฃ๊ธฐ
$("body").on("click",".menu_btn",function(){
console.log(cnt);
if(cnt < 7){
$("#menuNo").val($(this).attr("mno"));
//์ฃผ๋ฌธ์ํฉ์ ๊ทธ๋ ค์ฃผ๋ ํจ์
reloadOrd();
cnt++;
}else{
ordPopup("", "๋์ด์ ํ๋ชฉ์ถ๊ฐ๋ ๋ถ๊ฐํฉ๋๋ค.",function(){
});
}
});
.menu_btn
์ด ๋ฉ๋ด์ด๋ฆ์ด ๋ค์ด๊ฐ ์๋ ๋ฒํผ์ด๋ค. ๊ทธ๋์ ๊ทธ๊ฒ์ ํด๋ฆญ ์
form ์์ ์๋ #menuNo๋ก ๋ฉ๋ด ๋ฒํธ๋ฅผ ๋ฃ์ด์ค๋ค.
<!-- ์ค๋๋ฉ๋ด -->
<select id="getMOrd" parameterType="hashmap" resultType="hashmap">
SELECT PM.MENU_NO AS MNO, PM.MENU_NAME AS MNAME, PC.CATE_NAME AS CNAME, PM.MENU_PRICE AS MPRICE, PM.MENU_IMG AS MIMG,PC.CATE_NO AS CNO
FROM POS_MENU PM INNER JOIN POS_CATE PC
ON PM.POS_CATE_NO = PC.CATE_NO
WHERE PM.MENU_NO = #{menuNo}
</select>
์์์ ์ฌ์ฉํ #menuNo๊ฐ xml์์ ํ์ฉ๋๋ค. ํ์ด์ ์ค๋ช ํด๋ณด๋ฉด ๋ง์ฝ DB์ ์ ์ฅ๋ ๋ฉ๋ด๋ฒํธ๊ฐ 2๋ฒ์ธ ๊ฒ์ ํฌ์ค์์ ํด๋ฆญ ์ xml์์๋ #{menuNo} ์ 2๊ฐ ๋ค์ด๊ฐ๊ฒ ๋๋ค.
<!-- ์ค๋๋ฉ๋ด -->
<select id="getMOrd" parameterType="hashmap" resultType="hashmap">
SELECT PM.MENU_NO AS MNO, PM.MENU_NAME AS MNAME, PC.CATE_NAME AS CNAME, PM.MENU_PRICE AS MPRICE, PM.MENU_IMG AS MIMG,PC.CATE_NO AS CNO
FROM POS_MENU PM INNER JOIN POS_CATE PC
ON PM.POS_CATE_NO = PC.CATE_NO
WHERE PM.MENU_NO = 2
</select>
์์ ์ฒ๋ผ ๋ฒํธ๊ฐ ๋ค์ด๊ฐ๊ฒ๋์ ๋ฐ์ดํฐ๊ฐ ์ถ๋ ฅ๋๋ค.
๊ทธ๋ค์ DB์์ ๋ฉ๋ด ๋ฒํธ 2๋ฒ์ ๋ฐ์ดํฐ๋ฅผ ๊บผ๋ด์์ ์ปจํธ๋กค๋ฌ์์ ORD ๋ผ๋ ํค ๊ฐ์ผ๋ก modelMap์ ๋ฃ์ด์ค๋ค.
@RequestMapping(value="/PosOrd",
method = RequestMethod.POST,
produces = "text/json;charset=UTF-8")
@ResponseBody
public String PosOrd(
@RequestParam HashMap<String, String> params) throws Throwable{
ObjectMapper mapper = new ObjectMapper();
Map<String, Object> modelMap = new HashMap<String, Object>();
System.out.println("์ค๋Params"+params);
// ์ค๋ ์ทจ๋
HashMap<String, String>ord= ijhService.getMOrd(params);
modelMap.put("ord", ord);
System.out.println("์ค๋ ๋ชฉ๋ก ๋ณด์"+ord);
return mapper.writeValueAsString(modelMap);
}
์ปจํธ๋กค๋ฌ์์ ord๋ก ๋ฉ๋ด๋ฒํธ 2๋ฒ์ ๋ฐ์ดํฐ๋ฅผ ๋ฐ๋๋ค.
๋ฐ์ ๋ฐ์ดํฐ๋ฅผ ๊ฐ์ง๊ณ reloadOrd()๋ก ๋ค์ ๊ทธ๋ ค์ค๋ค.
function reloadOrd(){
var params = $("#ord_form").serialize();
console.log(params);
$.ajax({
url: "PosOrd",
type: "post",
dataType: "json",
data: params,
success: function(res){
console.log(res.ord);
inputOrd(res.ord); //์ฃผ๋ฌธ์ ๋ฃ๊ณ ๊ทธ๋ ค์ฃผ๋ ํจ์
},
error: function(request, status, error){
console.log(error)
}
});
}
//ํ์ฌ ์ฃผ๋ฌธ ๋ฃ๊ธฐ
function inputOrd(ord){
var order ="";
//MNO๋ ๋ฉ๋ด ๋ฒํธ
// MIMG๋ ๋ฉ๋ด ์ด๋ฏธ์ง
// MNAME์ ๋ฉ๋ด ์ด๋ฆ
// MPRICE์ ๋ฉ๋ด ๊ฐ๊ฒฉ
order+= "<div class=\"ord_stat\">";
order+= "<div class=\"ord_img\" mNo=\""+ ord.MNO +"\">";
order+= "<img src=\"resources/upload/"+ord.MIMG+"\" class=\"choice_img\">";
order+= "</div>";
order+= "<div class=\"ord_div\">";
order+= "<input type=\"text\" value=\""+ ord.MNAME + "\" class=\"choice_menu\">";
order+= "</div>";
order+= "<div class=\"ord_div\">";
order+= "<input type=\"text\" value=\""+ ord.MPRICE + "\" class=\"choice_price\">";
order+= "</div >";
order+= "<div class=\"ord_div\">";
order+= "<select id=\"ord_cnt\" name=\"ord_cnt\">";
order+= "<option value=\"1\" selected=\"selected\">1</option>";
order+= "<option value=\"2\">2</option>";
order+= "<option value=\"3\">3</option>";
order+= "<option value=\"4\">4</option>";
order+= "<option value=\"5\">5</option>";
order+= "<option value=\"6\">6</option>";
order+= "<option value=\"7\">7</option>";
order+= "<option value=\"8\">8</option>";
order+= "<option value=\"9\">9</option>";
order+= "<option value=\"10\">10</option>";
order+= "</select>";
order+= "</div>";
order+= "<div class=\"ord_div\">";
order+= "<input type=\"button\" value=\"์ทจ์\" class=\"choice_cnl\">";
order+= "</div >";
order+= "</div>";
$(".ord_area").append(order);
ordRes();
ord_pay();
}
ord์์ ๋ฐ์ ๋ฐ์ดํฐ๋ฅผ ๊ฐ์ง๊ณ ๋ฉ๋ด๋ฅผ ๊ทธ๋ ค์ค๋ค.
๐๊ตํ : ์ค๋ ํฐ์ฐ์ ๋์ ๋๋์ด๋ค.