'use strict';
/**
*
*
* @author Mai
* @date
* @version
*/
const tenderListOrder = (function () {
let orderSetting = getLocalCache('zh-calc-tender-list-order');
if (!orderSetting) orderSetting = 'name|up';
function CompareStr (x, y) {
// 根据mysql的GBK
const regASC = /^[\x00-\x7F]/;
if (regASC.test(x) || regASC.test(y)) {
if (x > y) {
return 1
} else if (x < y) {
return -1
} else {
return 0;
}
} else {
return x.localeCompare(y, 'zh-CN');
}
}
function reOrderTenders (orderStr) {
if (orderStr) {
orderSetting = orderStr;
setLocalCache('zh-calc-tender-list-order', orderStr);
}
const orders = orderSetting.split('|');
if (orders[0] === 'name') {
tenders.sort(function (a, b) {
// return orders[1] === 'up'
// ? a[orders[0]].localeCompare(b[orders[0]], 'zh')
// : -a[orders[0]].localeCompare(b[orders[0]], 'zh');
return orders[1] === 'up'
? CompareStr(a[orders[0]], b[orders[0]])
: CompareStr(b[orders[0]], a[orders[0]]);
});
} else if (orders[0] === 'create_time') {
tenders.sort(function (a, b){
return orders[1] === 'up'
? Date.parse(a[orders[0]]) - Date.parse(b[orders[0]])
: Date.parse(b[orders[0]]) - Date.parse(a[orders[0]]);
})
}
initTenderTree();
$('.c-body').html(getTenderTreeHtml());
localHideList();
}
function getOrderButton(field) {
const orders = orderSetting.split('|');
const button = field === orders[0]
? (orders[1] === 'up'
? ''
: '')
: '';
return '' + button + '';
}
return { reOrderTenders, getOrderButton }
})();