'use strict'; /** * * * @author Mai * @date * @version */ const unitListOrder = (function () { let orderSetting = getLocalCache('zh-calc-unit-list-order'); if (!orderSetting) orderSetting = 'create_time|up'; const pinyin = new PinYinOrder(); function CompareStr (x, y) { return pinyin.compareWord(x, y); } function reOrderUnits (orderStr, htmlClass = '#unit_list') { if (orderStr) { orderSetting = orderStr; setLocalCache('zh-calc-unit-list-order', orderStr); } const orders = orderSetting.split('|'); if (orders[0] === 'name') { unitList.sort(function (a, b) { return orders[1] === 'up' ? CompareStr(a[orders[0]], b[orders[0]]) : CompareStr(b[orders[0]], a[orders[0]]); }); } else if (orders[0] === 'create_time') { unitList.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]]); }) } else if (orders[0] === 'type') { unitList.sort(function (a, b){ return orders[1] === 'up' ? a[orders[0]] - b[orders[0]] : b[orders[0]] - a[orders[0]]; }) } resetHeaderHtml(); $(htmlClass).html(getUnitsHtml()); setUnitRightHtml(unitList[0].id); } function getOrderButton(field) { const orders = orderSetting.split('|'); const button = field === orders[0] ? (orders[1] === 'up' ? '' : '') : ''; return '' + button + ''; } function resetHeaderHtml() { $('#unit_header').html(` 序号 单位名称 ${unitListOrder.getOrderButton('name')} 账号数 类型 ${unitListOrder.getOrderButton('type')} 备注`); } function getUnitsHtml() { let html = ''; if (unitList.length > 0) { for (const [index, u] of unitList.entries()) { html += ` ${index+1} ${u.name} ${u.account_num} ${accountGroup[u.type]} ${u.basic ? u.basic : ''} `; } } return html; } return { reOrderUnits, getOrderButton, resetHeaderHtml } })();