Преглед на файлове

单位列表排序及增加类型

ellisran преди 1 година
родител
ревизия
386fd2b1fe
променени са 4 файла, в които са добавени 126 реда и са изтрити 27 реда
  1. 4 0
      app/const/account_group.js
  2. 30 25
      app/public/js/setting.js
  3. 82 0
      app/public/js/setting_unit_list_order.js
  4. 10 2
      app/view/setting/user_unit.ejs

+ 4 - 0
app/const/account_group.js

@@ -16,6 +16,8 @@ const accountGroup = {
     GZSJ: 6,
     ZBDW: 8,
     FBDW: 9,
+    HYZGBM: 10,
+    ZXSYS: 11,
     QT: 7,
 };
 
@@ -28,6 +30,8 @@ group[accountGroup.DJDW] = '代建单位';
 group[accountGroup.GZSJ] = '跟踪审计';
 group[accountGroup.ZBDW] = '总包单位';
 group[accountGroup.FBDW] = '分包单位';
+group[accountGroup.HYZGBM] = '行业主管部门';
+group[accountGroup.ZXSYS] = '中心试验室';
 group[accountGroup.QT] = '其他';
 
 module.exports = {

+ 30 - 25
app/public/js/setting.js

@@ -227,32 +227,12 @@ $(document).ready(() => {
     })
 
     // 参建单位页切换单位右侧显示
-    $('#unit_list tr').click(function () {
+    $('#unit_list tr').on('click', function () {
+        console.log('hello');
         const id = parseInt($(this).data('id'));
-        const one = _.find(unitList, { id });
-        if (one) {
-            $(this).siblings('tr').removeClass('table-warning');
-            $(this).addClass('table-warning');
-            $('#unit_name').val(one.name);
-            $('#unit_corporation').val(one.corporation);
-            $('#unit_credit_code').val(one.credit_code);
-            $('#unit_tel').val(one.tel);
-            $('#unit_website').val(one.website);
-            $('#unit_region').val(one.region);
-            $('#unit_address').val(one.address);
-            $('#unit_basic').val(one.basic);
-            $('#unit_type').val(one.type);
-            if(one.sign_path) {
-                $('#sign-show').html('<img src="' + fujianOssPath + one.sign_path + '" width="120">');
-                $('#delete-sign').show();
-                $('#upload-sign').hide();
-            } else {
-                $('#sign-show').html('');
-                $('#delete-sign').hide();
-                $('#upload-sign').show();
-            }
-            oneUnit = one;
-        }
+        $(this).siblings('tr').removeClass('table-warning');
+        $(this).addClass('table-warning');
+        setUnitRightHtml(id);
     });
 
     // 参建单位编辑
@@ -447,6 +427,31 @@ function checkPasswordForm() {
     }
 }
 
+function setUnitRightHtml(id) {
+    const one = _.find(unitList, { id });
+    if (one) {
+        $('#unit_name').val(one.name);
+        $('#unit_corporation').val(one.corporation);
+        $('#unit_credit_code').val(one.credit_code);
+        $('#unit_tel').val(one.tel);
+        $('#unit_website').val(one.website);
+        $('#unit_region').val(one.region);
+        $('#unit_address').val(one.address);
+        $('#unit_basic').val(one.basic);
+        $('#unit_type').val(one.type);
+        if(one.sign_path) {
+            $('#sign-show').html('<img src="' + fujianOssPath + one.sign_path + '" width="120">');
+            $('#delete-sign').show();
+            $('#upload-sign').hide();
+        } else {
+            $('#sign-show').html('');
+            $('#delete-sign').hide();
+            $('#upload-sign').show();
+        }
+        oneUnit = one;
+    }
+}
+
 /**
  * 表单检测
  */

+ 82 - 0
app/public/js/setting_unit_list_order.js

@@ -0,0 +1,82 @@
+'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'
+                ? '<i class="fa fa-sort-amount-asc" aria-hidden="true" onclick="unitListOrder.reOrderUnits(\'' + field + '|down' + '\')"></i>'
+                : '<i class="fa fa-sort-amount-desc" aria-hidden="true" onclick="unitListOrder.reOrderUnits(\'' + field + '|up' + '\')"></i>')
+            : '<i class="fa fa-sort" aria-hidden="true" onclick="unitListOrder.reOrderUnits(\'' + field + '|up' + '\')"></i>';
+        return '<a href="javascript:void(0)" class="btn btn-sm ml-1">' + button + '</a>';
+    }
+
+    function resetHeaderHtml() {
+        $('#unit_header').html(`<tr>
+                                        <th>序号</th>
+                                        <th>单位名称 ${unitListOrder.getOrderButton('name')}</th>
+                                        <th>账号数</th>
+                                        <th>类型 ${unitListOrder.getOrderButton('type')}</th>
+                                        <th class="text-center">备注</th></tr>`);
+    }
+
+    function getUnitsHtml() {
+        let html = '';
+        if (unitList.length > 0) {
+            for (const [index, u] of unitList.entries()) {
+                html += `<tr ${index === 0 ? 'class="table-warning"' : ''} data-id="${u.id}">
+                                        <td width="50px">${index+1}</td>
+                                        <td ><a href="javascript:void(0)">${u.name}</a></td>
+                                        <td width="80px">${u.account_num}</td>
+                                        <td width="100px">${accountGroup[u.type]}</td>
+                                        <td width="150px">${u.basic ? u.basic : ''}</td>
+                                    </tr>`;
+            }
+        }
+        return html;
+    }
+    return { reOrderUnits, getOrderButton, resetHeaderHtml }
+})();

+ 10 - 2
app/view/setting/user_unit.ejs

@@ -25,7 +25,7 @@
                         <div class="row">
                             <div class="col-6">
                                 <table class="table table-hover table-bordered table-sm">
-                                    <thead>
+                                    <thead id="unit_header">
                                     <tr>
                                         <th>序号</th>
                                         <th>单位名称</th>
@@ -129,6 +129,8 @@
 </div>
 <script>
 </script>
+<script src="/public/js/PinYinOrder.bundle.js"></script>
+<script src="/public/js/setting_unit_list_order.js"></script>
 <script src="/public/js/setting.js"></script>
 <script>
     const unitList = JSON.parse(unescape('<%- escape(JSON.stringify(unitList)) %>'));
@@ -136,4 +138,10 @@
     const fujianOssPath = JSON.parse(unescape('<%- escape(JSON.stringify(fujianOssPath)) %>'));
     let oneUnit = unitList.length > 0 ? unitList[0] : null;
 </script>
-<script>autoFlashHeight();</script>
+<script>
+    autoFlashHeight();
+    $(function () {
+        unitListOrder.resetHeaderHtml();
+        unitListOrder.reOrderUnits();
+    })
+</script>