mirror of
https://gitee.com/coder-xiaomo/flashsale
synced 2025-09-11 14:31:40 +08:00
商品模型-商品创建实现
This commit is contained in:
119
frontend/createitem.html
Normal file
119
frontend/createitem.html
Normal file
@@ -0,0 +1,119 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<title>Title</title>
|
||||
<link href="static/assets/global/plugins/bootstrap/css/bootstrap.min.css" rel="stylesheet" type="text/css"/>
|
||||
<link href="static/assets/global/css/components.css" rel="stylesheet" type="text/css"/>
|
||||
<link href="static/assets/admin/pages/css/login.css" rel="stylesheet" type="text/css"/>
|
||||
<script src="./static/assets/global/plugins/jquery-1.11.0.min.js" type="text/javascript"></script>
|
||||
</head>
|
||||
<body class="login">
|
||||
<div class="content">
|
||||
<h3 class="form-title">创建商品</h3>
|
||||
<div class="from-group">
|
||||
<label class="control-label">商品名</label>
|
||||
<div>
|
||||
<input class="form-control" type="text" placeholder="商品名" name="title" id="title">
|
||||
</div>
|
||||
</div>
|
||||
<div class="from-group">
|
||||
<label class="control-label">商品描述</label>
|
||||
<div>
|
||||
<input class="form-control" type="text" placeholder="商品描述" name="description" id="description">
|
||||
</div>
|
||||
</div>
|
||||
<div class="from-group">
|
||||
<label class="control-label">价格</label>
|
||||
<div>
|
||||
<input class="form-control" type="text" placeholder="价格" name="price" id="price">
|
||||
</div>
|
||||
</div>
|
||||
<div class="from-group">
|
||||
<label class="control-label">图片</label>
|
||||
<div>
|
||||
<input class="form-control" type="text" placeholder="图片" name="imgUrl" id="imgUrl">
|
||||
</div>
|
||||
</div>
|
||||
<div class="from-group">
|
||||
<label class="control-label">库存</label>
|
||||
<div>
|
||||
<input class="form-control" type="text" placeholder="库存" name="stock" id="stock">
|
||||
</div>
|
||||
</div>
|
||||
<div class="form-actions">
|
||||
<button class="btn blue" id="create" type="submit">
|
||||
创建商品
|
||||
</button>
|
||||
<a href="getotp.html?quickDebug">获取验证码</a>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<script>
|
||||
jQuery(document).ready(function () {
|
||||
$("#create").on("click", function () {
|
||||
var title = $("#title").val();
|
||||
var description = $("#description").val();
|
||||
var imgUrl = $("#imgUrl").val();
|
||||
var price = $("#price").val();
|
||||
var stock = $("#stock").val();
|
||||
|
||||
if (title == null || title == "") {
|
||||
alert("商品名不能为空");
|
||||
return false; // 捕获onclick事件,不让他传递到上一层
|
||||
}
|
||||
if (description == null || description == "") {
|
||||
alert("商品描述不能为空");
|
||||
return false; // 捕获onclick事件,不让他传递到上一层
|
||||
}
|
||||
if (imgUrl == null || imgUrl == "") {
|
||||
alert("图片Url不能为空");
|
||||
return false; // 捕获onclick事件,不让他传递到上一层
|
||||
}
|
||||
if (price == null || price == "") {
|
||||
alert("价格不能为空");
|
||||
return false; // 捕获onclick事件,不让他传递到上一层
|
||||
}
|
||||
if (stock == null || stock == "") {
|
||||
alert("库存不能为空");
|
||||
return false; // 捕获onclick事件,不让他传递到上一层
|
||||
}
|
||||
$.ajax({
|
||||
type: "POST",
|
||||
contentType: "application/x-www-form-urlencoded",
|
||||
url: "http://localhost:8090/item/create",
|
||||
data: {
|
||||
"title": title,
|
||||
"description": description,
|
||||
"imgUrl": imgUrl,
|
||||
"price": price,
|
||||
"stock": stock,
|
||||
},
|
||||
xhrFields: {withCredentials: true},
|
||||
success: function (data) {
|
||||
if (data.status == "success") {
|
||||
alert("创建成功");
|
||||
} else {
|
||||
alert("创建失败,原因为" + data.data.errMsg);
|
||||
}
|
||||
},
|
||||
error: function (data) {
|
||||
alert("创建失败,原因为" + data.responseText);
|
||||
}
|
||||
})
|
||||
})
|
||||
|
||||
function filldata() {
|
||||
const date = new Date();
|
||||
$("#title").val("item-" + Math.random().toString(36).slice(-6) + "-" + date.getSeconds() + date.getMilliseconds());
|
||||
$("#description").val(Math.random().toString(36).slice(-6) + Math.random().toString(36).slice(-6) + Math.random().toString(36).slice(-6) + Math.random().toString(36).slice(-6));
|
||||
$("#imgUrl").val("https://domain.com/pic/" + Math.random().toString(36).slice(-6) + ".jpg");
|
||||
$("#price").val(Math.round(Math.random() * (500 - 1) + 1));
|
||||
$("#stock").val(Math.round(Math.random() * (1000 - 1) + 1));
|
||||
}
|
||||
|
||||
filldata();
|
||||
})
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
Reference in New Issue
Block a user