MVC登录跳转到显示


@{
ViewBag.Title = "OrdersInfoIndex";
Layout = "~/Views/Shared/_Layout.cshtml";
}

<h2>OrdersInfoIndex</h2>
<script src="~/Scripts/jquery-3.4.1.js"></script>
<script>
var UId = 0;

if (this.location.search.split("?")[1] == null) {
//判断是否登录
if (getCookie("UsersInfo") == null) {
this.location.href = '/Sale/LoginIndex';
}
else {
var list = JSON.parse(getCookie("UsersInfo"));
var obj = {
ACount: list[0].ACount,
Pwd: list[0].Pwd
}
UId = list[0].UId;
Aj(obj);
}
}
else {
UId = this.location.search.split("?")[1].split("=")[1];
}
DataBound();

function Aj(obj) {
$.ajax({
url: "http://localhost:57190/api/Sale/Login",
data: obj,
type: "get",
dataType: "json",
success: function (d) {
if (d != null) {
alert('登录成功');
UId = d.UId;
}
else {
alert('账号或密码输入错误');
}
}
})
}
/* cookie中存值
*/
function setCookie(name, value) {
if (value) {
var days = 1; //定义一天
var exp = new Date();
exp.setTime(exp.getTime() + days * 24 * 60 * 60 * 1000);
// 写入Cookie, toGMTString将时间转换成字符串
document.cookie = name + "=" + escape(value) + ";expires=" + exp.toGMTString;
}
};

/**
* cookie中取值
* */
function getCookie(name) {
var arr, reg = new RegExp("(^| )" + name + "=([^;]*)(;|$)"); //匹配字段
if (arr = document.cookie.match(reg)) {
return unescape(arr[2]);
} else {
return null;
}
};
//数据绑定
function DataBound() {
$.ajax({
url: "http://localhost:57190/api/Sale/GetOrdersInfos",
data: { UId: UId },
type: "get",
dataType: "json",
success: function (d) {
var str = "";
$("#DataRow").empty();
$(d).each(function (i, n) {
var State = "";
if (n.OState == 0) {
State = "待付款";
}
else if (n.OState == 1) {
State = "待发货";
}
else if (n.OState == 2) {
State = "已发货";
}
else if (n.OState == 3) {
State = "已退款";
}
str += "<tr>" +
"<td>" + n.OId + "</td>" +
"<td>" + n.GId + "</td>" +
"<td><img src='http://localhost:57190" + n.GoodsInfoGId.GImg + "' width='60px' height='60px'/></td>" +
"<td>" + n.GoodsInfoGId.GName + "</td>" +
"<td>" + State + "</td>" +
"<td><input type='button' value='退单' onclick='SkipSaleIndex(" + n.OId + ")'/></td>" +
"</tr>"
})
$("#DataRow").append(str);
}
})
}
//跳转页面
function SkipSaleIndex(OId) {
location.href = "/Sale/SaleIndex?UId=" + UId + "&OId=" + OId;
}

</script>
<table class="table">
<thead>
<tr>
<th>订单编号</th>
<th>商品编号</th>
<th>商品图片</th>
<th>商品名称</th>
<th>订单状态</th>
<th>操作</th>
</tr>
</thead>
<tbody id="DataRow">
</tbody>
</table>

 

posted @ 2020-07-09 19:02  N_o  阅读(143)  评论(0编辑  收藏  举报