-
Notifications
You must be signed in to change notification settings - Fork 0
/
Search.html
133 lines (130 loc) · 6.05 KB
/
Search.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
<!DOCTYPE html>
<html>
<head>
<title>Index</title>
<meta charset="utf-8" />
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.6.4/angular.min.js"></script>
</head>
<body>
<div class="container">
<div>
<div class="well">
<h3>Tìm kiếm nâng cao, tìm theo các điều kiện:</h3>
Tên: <input class="input-sm" id="nameINPUT" type="text"> | Loại sản phẩm: <select id="loaisanphamSelectList"><option value="">Chọn</option></select> | Nhãn hiệu <select id="hangSelectList"><option value="">Chọn</option></select> | Giá tối thiểu: <input id="giatoithieuINPUT" class="input-sm" type="number"> | Giá tối đa: <input id="giatoidaINPUT" class="input-sm" type="number">
<button id="searchBUTTON" class="btn-primary btn-lg">Search</button>
</div>
<div class="bg-info">
<div id="newestProduct"></div>
</div>
<button onclick="previousNewestProductPage()">Trước</button> <button onclick="nextNewestProductPage()">Sau</button>
</div>
</div>
<script>
function getUrlVars() {
var vars = {};
var parts = window.location.href.replace(/[?&]+([^=&]+)=([^&]*)/gi,
function (m, key, value) {
vars[key] = value;
});
return vars;
}
var name = getUrlVars()["name"];
var parameter;
if (name != "undefined")
{
parameter = "?name=" + name;
alert(parameter);
}
else {
var productidTemp = ($('#loaisanphamSelectList').val() == null ? productidTemp = "" : productidTemp = $('#loaisanphamSelectList').val());
var brandidTemp = ($('#hangSelectList').val() == null ? brandidTemp = "" : brandidTemp = $('#hangSelectList').val());
var parameter = "?name=" + $('#nameINPUT').val() + "&productTypeid=" + productidTemp + "&brandId=" + brandidTemp + "&priceMin=" + $('#giatoithieuINPUT').val() + "&priceMax=" + $('#giatoidaINPUT').val();
}
var skip = 0;
var take = 10;
function previousNewestProductPage() {
if (skip >= 10) {
skip = skip - 10;
}
//parameter = "&skip=" + skip + "&take=" + take;
LoadNewestProducts()
}
function nextNewestProductPage() {
skip = skip + 10;
//parameter = "&skip=" + skip + "&take=" + take;
LoadNewestProducts()
}
function LoadNewestProducts() {
$('#newestProduct').empty();
alert(parameter);
$.ajax({
url: 'http://localhost:25225/api/Products/SearchProduct' + parameter +"&skip=" + skip + "&take=" + take,
method: 'GET',
contentType: 'application/json',
//headers: {
// 'Authorization': 'Bearer '
// + localStorage.accessToken
//},
success: function (response) {
$.each(response, function (index, val) {
$('#newestProduct').append('<div style="padding: 5px 5px 5px;"><a href="' + "http://localhost:33733/viewProduct.html?pid=" + val.ProductID + '"><img src="' + "http://localhost:25225/" + val.ProductImage + '" width = "40" height= "40"> Tên: ' + val.ProductName + ' | Giá: ' + val.Price + ' | SL còn: ' + val.Stock + '</a></div>');
});
},
error: function (jqXHR) {
alert(jqXHR.responseText);
}
});
}
function loadProducType() {
$.ajax({
url: 'http://localhost:25225/api/ProductTypes',
method: 'GET',
contentType: 'application/json',
headers: {
'Authorization': 'Bearer '
+ localStorage.accessToken
},
success: function (response) {
$.each(response, function (index, val) {
$('#loaisanphamSelectList').append(new Option(val.ProductTypeName, val.ProductTypeID));
});
},
error: function (jqXHR) {
alert(jqXHR.responseText);
}
});
$.ajax({
url: 'http://localhost:25225/api/Brands',
method: 'GET',
contentType: 'application/json',
headers: {
'Authorization': 'Bearer '
+ localStorage.accessToken
},
success: function (response) {
$.each(response, function (index, val) {
$('#hangSelectList').append(new Option(val.BrandName, val.BrandID));
});
},
error: function (jqXHR) {
alert(jqXHR.responseText);
}
});
}
$(document).ready(function () {
LoadNewestProducts();
loadProducType();
$('#searchBUTTON').click(function () {
productidTemp = ($('#loaisanphamSelectList').val() == null ? productidTemp = "" : productidTemp = $('#loaisanphamSelectList').val());
brandidTemp = ($('#hangSelectList').val() == null ? brandidTemp = "" : brandidTemp = $('#hangSelectList').val());
parameter = "?name=" + $('#nameINPUT').val() + "&productTypeid=" + productidTemp + "&brandId=" + brandidTemp + "&priceMin=" + $('#giatoithieuINPUT').val() + "&priceMax=" + $('#giatoidaINPUT').val();
alert(parameter);
LoadNewestProducts();
})
});
</script>
</body>
</html>