agent-backend/contracts/Incentives/html/datatableSet.js

473 lines
17 KiB
JavaScript
Raw Permalink Normal View History

2021-09-26 04:49:24 +00:00
var dtLang = {
"sProcessing": "处理中...",
"lengthMenu": '显示 <select>' + '<option value="5">5</option>' + '<option value="20">20</option>' + '<option value="100">100</option>' + '<option value="-1">全部</option>' + '</select> 项结果',
"sZeroRecords": "没有匹配结果",
"sInfo": "显示第 _START_ 至 _END_ 项结果,共 _TOTAL_ 项",
"sInfoEmpty": "显示第 0 至 0 项结果,共 0 项",
"sInfoFiltered": "(由 _MAX_ 项结果过滤)",
"sInfoPostFix": "",
"sSearch": "搜索:",
"sUrl": "",
"sEmptyTable": "表中数据为空",
"sLoadingRecords": "载入中...",
"sInfoThousands": ",",
"oPaginate": {
"sFirst": "首页",
"sPrevious": "上页",
"sNext": "下页",
"sLast": "末页"
}
,
"oAria": {
"sSortAscending": ": 以升序排列此列",
"sSortDescending": ": 以降序排列此列"
}
};
var askListROHead = "<table id='askListROTab' class='table display row-border'><thead><tr><th>序号</th><th>资源</th><th>卖方</th><th>价格</th></tr></thead><tbody>";
var askListROTail = "</tbody></table>";
var fillAskListRO = function(data) {
var html = askListROHead;
var lines = data;
for (var i = 0; i < lines.length; i++) {
html += "<tr><td>";
html += (i + 1);
html += "</td><td>";
html += lines[i].item;
html += "</td><td>";
html += lines[i].seller;
html += "</td><td>";
html += lines[i].price;
html += "</td></tr>";
}
html += askListROTail;
$("#askListRODiv").html(html);
$("#askListROTab").DataTable({
"language": dtLang,
"rowCallback": function(row, data, displayNum, displayIndex, dataIndex) {
}
,
"headerCallback": function(thead, data, start, end, display) {
$(thead).css("background", primaryColor);
$(thead).css("color", "white");
$(thead).children().css("background", primaryColor);
$(thead).children().css("color", "white");
}
,
scrollCollapse: false,
searching: false,
paging: true,
pageLength: 5,
order: [[0, 'asc']],
"columnDefs": [
{
"targets": 1,
"render": function(data, type, row, meta) {
if (data.length > 30) {
return "<span title='" + data + "'>" + data.substring(0, 30) + " ...</span>";
} else {
return data;
}
}
},
{
"targets": 2,
"render": function(data, type, row, meta) {
return "<span title='" + data + "'>" + data.substring(0, 5) + " </span>";
}
}
]
}
);
};
var bidListAllHead = "<table id='bidListAllTab' class='table display row-border'><thead><tr><th>序号</th><th>资源</th><th>买方</th><th>价格</th></tr></thead><tbody>";
var bidListAllTail = "</tbody></table>";
var fillBidListAll = function(data) {
var html = bidListAllHead;
var lines = data;
for (var i = 0; i < lines.length; i++) {
html += "<tr><td>";
html += (i + 1);
html += "</td><td>";
html += lines[i].item;
html += "</td><td>";
html += lines[i].bidder;
html += "</td><td>";
html += lines[i].price;
html += "</td></tr>";
}
html += bidListAllTail;
$("#bidListAllDiv").html(html);
$("#bidListAllTab").DataTable({
"language": dtLang,
"rowCallback": function(row, data, displayNum, displayIndex, dataIndex) {
}
,
"headerCallback": function(thead, data, start, end, display) {
$(thead).css("background", primaryColor);
$(thead).css("color", "white");
$(thead).children().css("background", primaryColor);
$(thead).children().css("color", "white");
}
,
scrollCollapse: false,
searching: false,
paging: true,
pageLength: 5,
order: [[0, 'asc']],
"columnDefs": [
{
"targets": 1,
"render": function(data, type, row, meta) {
if (data.length > 30) {
return "<span title='" + data + "'>" + data.substring(0, 30) + " ...</span>";
} else {
return data;
}
}
},
{
"targets": 2,
"render": function(data, type, row, meta) {
return "<span title='" + data + "'>" + data.substring(0, 5) + " </span>";
}
}
]
}
);
};
var finalListOwnerHead = "<table id='finalListOwnerTab' class='table display row-border'><thead><tr><th>序号</th><th>资源</th><th>卖方</th><th>卖方价格</th><th>买方</th><th>买方价格</th><th>已使用</th><th>使用结果</th></tr></thead><tbody>";
var finalListOwnerTail = "</tbody></table>";
var fillFinalListOwner = function(data) {
var html = finalListOwnerHead;
var lines = data;
for (var i = 0; i < lines.length; i++) {
html += "<tr><td>";
html += (i + 1);
html += "</td><td>";
html += lines[i].item;
html += "</td><td>";
html += lines[i].seller;
html += "</td><td>";
html += lines[i].sellerPrice;
html += "</td><td>";
html += lines[i].bidder;
html += "</td><td>";
html += lines[i].bidderPrice;
html += "</td><td>";
html += lines[i].used;
html += "</td><td>";
html += lines[i].result;
html += "</td></tr>";
}
html += finalListOwnerTail;
$("#finalListOwnerDiv").html(html);
$("#finalListOwnerDiv").off("click", "tr").on(
"click",
"tr",
function(event) {
var pos = ($(this).closest("tr").find("td").eq(0)
.text() - 1) / 1;
if (pos != undefined) {
alert(global.finalListOwner[pos].item);
}
}
);
$("#finalListOwnerTab").DataTable({
"language": dtLang,
"rowCallback": function(row, data, displayNum, displayIndex, dataIndex) {
}
,
"headerCallback": function(thead, data, start, end, display) {
$(thead).css("background", primaryColor);
$(thead).css("color", "white");
$(thead).children().css("background", primaryColor);
$(thead).children().css("color", "white");
}
,
scrollCollapse: false,
searching: false,
paging: true,
pageLength: 5,
order: [[0, 'asc']],
"columnDefs": [
{
"targets": 1,
"render": function(data, type, row, meta) {
if (data.length > 20) {
return "<span title='" + data + "'>" + data.substring(0, 20) + " ...</span>";
} else {
return data;
}
}
},
{
"targets": 2,
"render": function(data, type, row, meta) {
return "<span title='" + data + "'>" + data.substring(0, 5) + " </span>";
}
},
{
"targets": 4,
"render": function(data, type, row, meta) {
return "<span title='" + data + "'>" + data.substring(0, 5) + " </span>";
}
},
{
"targets": 6,
"render": function(data, type, row, meta) {
if (data == "true") {
return "是";
} else {
return "否";
}
}
}
]
}
);
};
var askListRWHead = "<table id='askListRWTab' class='table display row-border'><thead><tr><th>序号</th><th>资源</th><th>卖方</th><th>卖方价格</th><th>出价</th><th>操作</th></tr></thead><tbody>";
var askListRWTail = "</tbody></table>";
var fillAskListRW = function(data) {
var html = askListRWHead;
var lines = data;
for (var i = 0; i < lines.length; i++) {
html += "<tr><td>";
html += (i + 1);
html += "</td><td>";
html += lines[i].item;
html += "</td><td>";
html += lines[i].seller;
html += "</td><td>";
html += lines[i].price;
html += "</td><td>";
html += "<input id='priceInput"+i+"'></input>";
html += "</td><td>";
html += "<button class='btn btn-outline-primary'>竞标</button>";
html += "</td></tr>";
}
html += askListRWTail;
$("#askListRWDiv").html(html);
$("#askListRWDiv").off("click", ":button").on(
"click",
":button",
function(event) {
var bidArg = {
};
var pos = ($(this).closest("tr").find("td").eq(0)
.text() - 1) / 1;
bidArg.item = global.askListRW[pos].item;
bidArg.price = $("#priceInput"+pos)[0].value;
if (bidArg.price/1!=bidArg.price || bidArg.price/1<=0){
alert("价格必须是大于0的整数");
return;
}
executeCurrentContract("bid",JSON.stringify(bidArg),function(data){
alert("竞标资源:"+data.result);
flushAllUserData();
});
}
);
$("#askListRWTab").DataTable({
"language": dtLang,
"rowCallback": function(row, data, displayNum, displayIndex, dataIndex) {
}
,
"headerCallback": function(thead, data, start, end, display) {
$(thead).css("background", primaryColor);
$(thead).css("color", "white");
$(thead).children().css("background", primaryColor);
$(thead).children().css("color", "white");
}
,
scrollCollapse: false,
searching: false,
paging: true,
pageLength: 5,
order: [[0, 'asc']],
"columnDefs": [
{
"targets": 1,
"render": function(data, type, row, meta) {
if (data.length > 30) {
return "<span title='" + data + "'>" + data.substring(0, 30) + " ...</span>";
} else {
return data;
}
}
},
{
"targets": 2,
"render": function(data, type, row, meta) {
if (data != "Anonymous") {
return "<span title='" + data + "'>" + data.substring(0, 5) + " </span>";;
} else {
return data;
}
}
}
]
}
);
};
var bidListPrivateHead = "<table id='bidListPrivateTab' class='table display row-border'><thead><tr><th>序号</th><th>资源</th><th>买方</th><th>价格</th></tr></thead><tbody>";
var bidListPrivateTail = "</tbody></table>";
var fillBidListPrivate = function(data) {
var html = bidListPrivateHead;
var lines = data;
for (var i = 0; i < lines.length; i++) {
html += "<tr><td>";
html += (i + 1);
html += "</td><td>";
html += lines[i].item;
html += "</td><td>";
html += lines[i].bidder;
html += "</td><td>";
html += lines[i].price;
html += "</td></tr>";
}
html += bidListPrivateTail;
$("#bidListPrivateDiv").html(html);
$("#bidListPrivateTab").DataTable({
"language": dtLang,
"rowCallback": function(row, data, displayNum, displayIndex, dataIndex) {
}
,
"headerCallback": function(thead, data, start, end, display) {
$(thead).css("background", primaryColor);
$(thead).css("color", "white");
$(thead).children().css("background", primaryColor);
$(thead).children().css("color", "white");
}
,
scrollCollapse: false,
searching: false,
paging: true,
pageLength: 5,
order: [[0, 'asc']],
"columnDefs": [
{
"targets": 1,
"render": function(data, type, row, meta) {
if (data.length > 30) {
return "<span title='" + data + "'>" + data.substring(0, 30) + " ...</span>";
} else {
return data;
}
}
},
{
"targets": 2,
"render": function(data, type, row, meta) {
return "<span title='" + data + "'>" + data.substring(0, 5) + " </span>";
}
}
]
}
);
};
var finalListPrivateHead = "<table id='finalListPrivateTab' class='table display row-border'><thead><tr><th>序号</th><th>资源</th><th>卖方</th><th>卖方价格</th><th>买方</th><th>买方价格</th><th>已使用</th><th>使用结果</th><th>操作</th></tr></thead><tbody>";
var finalListPrivateTail = "</tbody></table>";
var fillFinalListPrivate = function(data) {
var html = finalListPrivateHead;
var lines = data;
for (var i = 0; i < lines.length; i++) {
html += "<tr><td>";
html += (i + 1);
html += "</td><td>";
html += lines[i].item;
html += "</td><td>";
html += lines[i].seller;
html += "</td><td>";
html += lines[i].sellerPrice;
html += "</td><td>";
html += lines[i].bidder;
html += "</td><td>";
html += lines[i].bidderPrice;
html += "</td><td>";
html += lines[i].used;
html += "</td><td>";
html += lines[i].result;
html += "</td><td>";
html += "<button class='btn btn-outline-primary'>使用</button>";
html += "</td></tr>";
}
html += finalListPrivateTail;
$("#finalListPrivateDiv").html(html);
$("#finalListPrivateDiv").off("click", ":button").on(
"click",
":button",
function(event) {
var execArg = {
};
var pos = ($(this).closest("tr").find("td").eq(0)
.text() - 1) / 1;
execArg.item = global.finalListPrivate[pos].item;
executeCurrentContract("execute",JSON.stringify(execArg),function(data){
alert("使用资源:"+data.result);
flushAllUserData();
});
}
);
$("#finalListPrivateTab").DataTable({
"language": dtLang,
"rowCallback": function(row, data, displayNum, displayIndex, dataIndex) {
}
,
"headerCallback": function(thead, data, start, end, display) {
$(thead).css("background", primaryColor);
$(thead).css("color", "white");
$(thead).children().css("background", primaryColor);
$(thead).children().css("color", "white");
}
,
scrollCollapse: false,
searching: false,
paging: true,
pageLength: 5,
order: [[0, 'asc']],
"columnDefs": [
{
"targets": 1,
"render": function(data, type, row, meta) {
if (data.length > 20) {
return "<span title='" + data + "'>" + data.substring(0, 20) + " ...</span>";
} else {
return data;
}
}
},
{
"targets": 2,
"render": function(data, type, row, meta) {
if (data != "Anonymous") {
return "<span title='" + data + "'>" + data.substring(0, 5) + " </span>";;
} else {
return data;
}
}
},
{
"targets": 4,
"render": function(data, type, row, meta) {
if (data != "Anonymous") {
return "<span title='" + data + "'>" + data.substring(0, 5) + " </span>";;
} else {
return data;
}
}
},
{
"targets": 6,
"render": function(data, type, row, meta) {
if (data == "true") {
return "是";
} else {
return "否";
}
}
}
]
}
);
};