tender_list_order.js 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. 'use strict';
  2. /**
  3. *
  4. *
  5. * @author Mai
  6. * @date
  7. * @version
  8. */
  9. const tenderListOrder = (function () {
  10. let orderSetting = getLocalCache('zh-calc-tender-list-order');
  11. if (!orderSetting) orderSetting = 'name|up';
  12. const pinyin = new PinYinOrder();
  13. function CompareStr (x, y) {
  14. // 根据mysql的GBK
  15. // const regASC = /^[\x00-\x7F]/;
  16. // if (regASC.test(x) || regASC.test(y)) {
  17. // if (x > y) {
  18. // return 1
  19. // } else if (x < y) {
  20. // return -1
  21. // } else {
  22. // return 0;
  23. // }
  24. // } else {
  25. // return x.localeCompare(y, 'zh', { sensitivity: 'base' });
  26. // }
  27. return pinyin.compareWord(x, y);
  28. }
  29. function reOrderTenders (orderStr) {
  30. if (orderStr) {
  31. orderSetting = orderStr;
  32. setLocalCache('zh-calc-tender-list-order', orderStr);
  33. }
  34. const orders = orderSetting.split('|');
  35. if (orders[0] === 'name') {
  36. tenders.sort(function (a, b) {
  37. // return orders[1] === 'up'
  38. // ? a[orders[0]].localeCompare(b[orders[0]], 'zh')
  39. // : -a[orders[0]].localeCompare(b[orders[0]], 'zh');
  40. return orders[1] === 'up'
  41. ? CompareStr(a[orders[0]], b[orders[0]])
  42. : CompareStr(b[orders[0]], a[orders[0]]);
  43. });
  44. } else if (orders[0] === 'create_time') {
  45. tenders.sort(function (a, b){
  46. return orders[1] === 'up'
  47. ? Date.parse(a[orders[0]]) - Date.parse(b[orders[0]])
  48. : Date.parse(b[orders[0]]) - Date.parse(a[orders[0]]);
  49. })
  50. }
  51. initTenderTree();
  52. $('.c-body').html(getTenderTreeHtml());
  53. localHideList();
  54. }
  55. function getOrderButton(field) {
  56. const orders = orderSetting.split('|');
  57. const button = field === orders[0]
  58. ? (orders[1] === 'up'
  59. ? '<i class="fa fa-sort-amount-asc" aria-hidden="true" onclick="tenderListOrder.reOrderTenders(\'' + field + '|down' + '\')"></i>'
  60. : '<i class="fa fa-sort-amount-desc" aria-hidden="true" onclick="tenderListOrder.reOrderTenders(\'' + field + '|up' + '\')"></i>')
  61. : '<i class="fa fa-sort" aria-hidden="true" onclick="tenderListOrder.reOrderTenders(\'' + field + '|up' + '\')"></i>';
  62. return '<a href="javascript:void(0)" class="btn btn-sm ml-1">' + button + '</a>';
  63. }
  64. return { reOrderTenders, getOrderButton }
  65. })();