.dian {
width: 230px;
display: block;
text-overflow: ellipsis;
overflow: hidden;
white-space: nowrap;
}
.alert {
display: none;
}
.pagination {
margin: 0 20px 10px;
float: right;
}
# | 商品名称 | 商品价格 | 商品数量 | 商品重量 | 商品状态 | 操作 |
---|
function filterPrice(that) {
filterData($(that).val())
}
function handlePrice(that) {
console.log($(that).val());
init($(that).val())
}
init(0);
let goodsList = []
function init(flag) {
let params = { pagenum: 1, pagesize: 10 }
$.ajax({
url: "http://timemeetyou.com:8889/api/private/v1/goods",
headers: {
/* 最新的token token过一段时间会失效 失效需要重新获取 */
Authorization: 'Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1aWQiOjUwMCwicmlkIjowLCJpYXQiOjE2NDQ4MDQyNjIsImV4cCI6MTY0NDg5MDY2Mn0.JyAB5ngwtiJSx-Rb4_VrQ3WnfkmAKGXrTduLqsOGAlU'
},
data: params,
success: function (res) {
// let str = '';
let { data: { goods } } = res;
showTable(flag, goods);
goodsList = goods;
}
})
}
function showTable(flag, goods) {
if (flag == 0) {
goods.sort(function (item1, item2) {
return item1.goods_price - item2.goods_price
})
}
if (flag == 1) {
goods.sort(function (item1, item2) {
return item2.goods_price - item1.goods_price
})
}
showCase(goods)
}
function filterData(flag2) {
if (flag2 == 0) {
showCase(goodsList)
}
if (flag2 == 1) {
let goods1 = goodsList.filter(function (item) {
return item.goods_price > 500
})
showCase(goods1)
}
if (flag2 == 2) {
let goods2 = goodsList.filter(function (item) {
return item.goods_price < 500
})
showCase(goods2)
}
}
function showCase(arr) {
let str = '';
arr.forEach(function (r, i) {
str += `
`
})
$('tbody').html(str)
}
/* function sendId(goods_name,goods_price,goods_number,goods_weight,goods_state,goods_id) {
console.log(goods_name,goods_price,goods_number,goods_weight,goods_state,goods_id);
$('#goods_name').val( goods_name )
$('#goods_price').val( goods_price )
$('#goods_number').val( goods_number )
$('#goods_weight').val( goods_weight )
$('#goods_state').val( goods_state )
} */
function sendId(id) {
// console.log(id);
let str = goodsList.find(function (r) {
console.log(r.goods_id,r.goods_name);
return r.goods_id==id
})
// console.log(str);
$('#goods_name').val( str.goods_name )
$('#goods_price').val( str.goods_price )
$('#goods_number').val( str.goods_number )
$('#goods_weight').val( str.goods_weight )
$('#goods_state').val( str.goods_state )
}