12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667 |
- 'use strict';
- /**
- *
- *
- * @author Mai
- * @date
- * @version
- */
- const tenderListOrder = (function () {
- let orderSetting = getLocalCache('zh-calc-tender-list-order');
- if (!orderSetting) orderSetting = 'name|up';
- const pinyin = new PinYinOrder();
- 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', { sensitivity: 'base' });
- // }
- return pinyin.compareWord(x, y);
- }
- 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'
- ? '<i class="fa fa-sort-amount-asc" aria-hidden="true" onclick="tenderListOrder.reOrderTenders(\'' + field + '|down' + '\')"></i>'
- : '<i class="fa fa-sort-amount-desc" aria-hidden="true" onclick="tenderListOrder.reOrderTenders(\'' + field + '|up' + '\')"></i>')
- : '<i class="fa fa-sort" aria-hidden="true" onclick="tenderListOrder.reOrderTenders(\'' + field + '|up' + '\')"></i>';
- return '<a href="javascript:void(0)" class="btn btn-sm ml-1">' + button + '</a>';
- }
- return { reOrderTenders, getOrderButton }
- })();
|