Browse Source

金额与进度列表更新

laiguoran 5 years ago
parent
commit
6c9aa9a775

+ 8 - 8
app/public/js/category.js

@@ -45,9 +45,9 @@ function getCategoryHtml(category) {
         }
         html.push('</td>');
         html.push('<td>');
-        html.push('<a href="javasrcipt: void(0);" name="add" class="btn btn-sm btn-outline-primary"', 'cid="' + d.id, '">添加值</a>\n');
-        html.push('<a href="javasrcipt: void(0);" name="edit-cate" class="btn btn-sm btn-outline-primary"', 'cid="' + d.id + '">编辑</a>\n');
-        html.push('<a href="javasrcipt: void(0);" name="del" class="btn btn-sm btn-outline-danger"', 'cid="' + d.id + '">删除</a> ');
+        html.push('<a href="javascript: void(0);" name="add" class="btn btn-sm btn-outline-primary"', 'cid="' + d.id, '">添加值</a>\n');
+        html.push('<a href="javascript: void(0);" name="edit-cate" class="btn btn-sm btn-outline-primary"', 'cid="' + d.id + '">编辑</a>\n');
+        html.push('<a href="javascript: void(0);" name="del" class="btn btn-sm btn-outline-danger"', 'cid="' + d.id + '">删除</a> ');
         html.push('</td>');
         html.push('<tr>');
     }
@@ -60,7 +60,7 @@ function getValueHtml(value) {
         html.push('<tr name="value" vid="' + v.id + '">');
         html.push('<td><input class="form-control form-control-sm" name="value" placeholder="请输入值" value="' + v.value + '" vid ="' + v.id +  '"></td>');
         html.push('<td>', v.relaTenders.length + v.newTenders.length ,'</td>');
-        html.push('<td><a href="javasrcipt: void(0);" class="text-danger" name="del-value" vid="' + v.id + '">删除</a></td>');
+        html.push('<td><a href="javascript: void(0);" class="text-danger" name="del-value" vid="' + v.id + '">删除</a></td>');
         html.push('</tr>');
     }
     return html.join('');
@@ -108,7 +108,7 @@ function getEditCate(category) {
 }
 // 绑定编辑值、删除值
 function bindCategoryValueControl() {
-    $('a[name="del-value"]').click(function () {
+    $('body').on('click', 'a[name="del-value"]', function () {
         const vid = $(this).attr('vid');
         const value = _.find(editCate.value, function (v) {
             return v.id == vid;
@@ -152,7 +152,7 @@ function bindCategoryValueControl() {
 // 绑定分类控制等(添加值、编辑、删除)
 function bindCategoryControl() {
     // 弹出添加值
-    $('a[name=add]').bind('click', function () {
+    $('body').on('click', 'a[name=add]', function () {
         const id = parseInt($(this).attr('cid'));
         const category = findCategory(id);
         getEditCate(category);
@@ -178,7 +178,7 @@ function bindCategoryControl() {
         }
     });
     // 弹出 编辑
-    $('a[name=edit-cate]').bind('click', function () {
+    $('body').on('click', 'a[name=edit-cate]', function () {
         const id = parseInt($(this).attr('cid'));
         const category = findCategory(id);
         $('input[name=name]', '#edit-cate').val(category.name);
@@ -188,7 +188,7 @@ function bindCategoryControl() {
         $('#edit-cate').modal('show');
     });
     // 弹出 删除类别
-    $('a[name=del]').bind('click', function () {
+    $('body').on('click', 'a[name=del]', function () {
         $('#del-cate-ok').attr('cid', $(this).attr('cid'));
         $('#del-cate').modal('show');
     });

+ 0 - 1
app/public/js/tender_list.js

@@ -254,7 +254,6 @@ function initTenderTree () {
             tenderTree.push(t);
         }
     }
-    console.log(tenderTree);
 }
 function recursiveGetTenderNodeHtml (node, arr, pid) {
     const html = [];

+ 75 - 17
app/public/js/tender_list_info.js

@@ -45,6 +45,7 @@ const levelTreeSetting = {
 };
 const levelNodes =[];
 const tenderTree = [];
+let parentId = 0;
 function createTree() {
     const zTree = $.fn.zTree.getZTreeObj('treeLevel');
     if (zTree) {
@@ -167,11 +168,11 @@ function getCategoryHtml() {
     }
     const html = [];
     for (const c of category) {
-        if (c.type === categoryType.key.dropDown) {
+        // if (c.type === categoryType.key.dropDown) {
             html.push(getSelectCategoryHtml(c));
-        } else if (c.type === categoryType.key.radio) {
-            html.push(getRadioCategoryHtml(c));
-        }
+        // } else if (c.type === categoryType.key.radio) {
+        //     html.push(getRadioCategoryHtml(c));
+        // }
     }
     return html.join('');
 }
@@ -187,7 +188,7 @@ function initTenderTree () {
             }
         }
     }
-    function getCategoryNode(category, value, parent) {
+    function getCategoryNode(category, value, parent, i = null) {
         const array = parent ?  parent.children : tenderTree;
         let cate = findCategoryNode(category.id, value, array);
         if (!cate) {
@@ -198,7 +199,8 @@ function initTenderTree () {
                 vid: value,
                 name: cateValue.value,
                 children: [],
-                level: category.level,
+                level: i ? i : category.level,
+                sort_id: ++parentId,
             };
             array.push(cate);
         }
@@ -206,11 +208,17 @@ function initTenderTree () {
     }
     function loadTenderCategory (tender) {
         let tenderCategory = null;
-        for (const lc of levelCategory) {
+        for (const [index, lc] of levelCategory.entries()) {
             const tenderCate = findNode('cid', lc.id, tender.category);
             if (tenderCate) {
                 tenderCategory = getCategoryNode(lc, tenderCate.value, tenderCategory);
             } else {
+                if (index === 0 && tender.category) {
+                    for (const [i,c] of tender.category.entries()) {
+                        const cate = findNode('id', c.cid, category);
+                        tenderCategory = getCategoryNode(cate, c.value, tenderCategory, i+1);
+                    }
+                }
                 return tenderCategory;
             }
         }
@@ -231,6 +239,7 @@ function initTenderTree () {
     for (const t of tenders) {
         calculateTender(t);
         t.valid = true;
+        delete t.level;
         if (t.category && levelCategory.length > 0) {
             const parent = loadTenderCategory(t);
             if (parent) {
@@ -244,13 +253,13 @@ function initTenderTree () {
         }
     }
 }
-function recursiveGetTenderNodeHtml (node, arr) {
+function recursiveGetTenderNodeHtml (node, arr, pid) {
     const html = [];
-    html.push('<tr>');
+    html.push('<tr pid="' + pid + '">');
     // 名称
     html.push('<td class="in-' + node.level + '">');
     if (node.cid) {
-        html.push('<i class="fa fa-folder-o"></i> ', node.name);
+        html.push('<span class="fold-switch mr-1" title="收起" cid="'+ node.sort_id +'"><i class="fa fa-minus-square-o"></i></span> <i class="fa fa-folder-o"></i> ', node.name);
     } else {
         html.push('<span class="text-muted mr-2">');
         html.push(arr.indexOf(node) === arr.length - 1 ? '└' : '├');
@@ -311,7 +320,7 @@ function recursiveGetTenderNodeHtml (node, arr) {
     html.push('</tr>');
     if (node.children) {
         for (const c of node.children) {
-            html.push(recursiveGetTenderNodeHtml(c, node.children));
+            html.push(recursiveGetTenderNodeHtml(c, node.children, node.sort_id));
         }
     }
     return html.join('');
@@ -336,7 +345,7 @@ function getTenderTreeHtml () {
         html.push('<th>', '截止本期应付', '</th>');
         html.push('</tr>', '</thead>');
         for (const t of tenderTree) {
-            html.push(recursiveGetTenderNodeHtml(t, tenderTree));
+            html.push(recursiveGetTenderNodeHtml(t, tenderTree, ''));
         }
         html.push('</table>');
         return html.join('');
@@ -411,13 +420,15 @@ $(document).ready(() => {
             return;
         }
         for (const c of category) {
-            const cate = {cid: c.id};
-            if (c.type === categoryType.key.dropDown) {
+            if (parseInt($('select', '[cate-id=' + c.id + ']').val()) !== 0) {
+                const cate = {cid: c.id};
+                // if (c.type === categoryType.key.dropDown) {
                 cate.value = parseInt($('select', '[cate-id=' + c.id + ']').val());
-            } else if (c.type === categoryType.key.radio) {
-                cate.value = parseInt($('input:checked', '[cate-id=' + c.id + ']').val());
+                // } else if (c.type === categoryType.key.radio) {
+                //     cate.value = parseInt($('input:checked', '[cate-id=' + c.id + ']').val());
+                // }
+                data.category.push(cate);
             }
-            data.category.push(cate);
         }
         $('#hide-all').show();
         postData('/list/add', data, function (result) {
@@ -430,4 +441,51 @@ $(document).ready(() => {
             $('#hide-all').hide();
         });
     });
+
+    // 展开和收起
+    $('body').on('click', '.fold-switch', function () {
+        if ($(this).children('i').hasClass('fa-minus-square-o')) {
+            $(this).children('i').removeClass('fa-minus-square-o').addClass('fa-plus-square-o');
+            $(this).attr('title', '展开');
+            const cid = $(this).attr('cid');
+            const node = findTenderTreeNode(parseInt(cid), tenderTree);
+            doTrStatus(returnItem, 'hide');
+        } else {
+            $(this).children('i').removeClass('fa-plus-square-o').addClass('fa-minus-square-o');
+            $(this).attr('title', '收起');
+            const cid = $(this).attr('cid');
+            const node = findTenderTreeNode(parseInt(cid), tenderTree);
+            doTrStatus(returnItem, 'show');
+        }
+    })
 });
+
+function doTrStatus(node, status) {
+    if (status === 'show') {
+        $('.c-body').find('tr[pid="'+ node.sort_id +'"]').show();
+        $('.c-body').find('tr[pid="'+ node.sort_id +'"] .fold-switch').attr('title', '收起');
+        $('.c-body').find('tr[pid="'+ node.sort_id +'"] .fold-switch i').removeClass('fa-plus-square-o').removeClass('fa-minus-square-o').addClass('fa-minus-square-o');
+    } else {
+        $('.c-body').find('tr[pid="'+ node.sort_id +'"]').hide();
+        $('.c-body').find('tr[pid="'+ node.sort_id +'"] .fold-switch').attr('title', '展开');
+        $('.c-body').find('tr[pid="'+ node.sort_id +'"] .fold-switch i').removeClass('fa-minus-square-o').removeClass('fa-plus-square-o').addClass('fa-plus-square-o');
+
+    }
+    // 判断是否还有一层
+    if (node.children) {
+        for (const c of node.children) {
+            doTrStatus(c, status);
+        }
+    }
+}
+let returnItem;
+const findTenderTreeNode = function(sortId, tree) {
+    tree.forEach((item) => {
+        if (item.sort_id !== undefined && item.sort_id === sortId) {
+            returnItem = item;
+            return item;
+        } else if (item.children && item.children.length > 0) {
+            findTenderTreeNode(sortId, item.children);
+        }
+    });
+}

+ 75 - 17
app/public/js/tender_list_progress.js

@@ -45,6 +45,7 @@ const levelTreeSetting = {
 };
 const levelNodes =[];
 const tenderTree = [];
+let parentId = 0;
 function createTree() {
     const zTree = $.fn.zTree.getZTreeObj('treeLevel');
     if (zTree) {
@@ -167,11 +168,11 @@ function getCategoryHtml() {
     }
     const html = [];
     for (const c of category) {
-        if (c.type === categoryType.key.dropDown) {
+        // if (c.type === categoryType.key.dropDown) {
             html.push(getSelectCategoryHtml(c));
-        } else if (c.type === categoryType.key.radio) {
-            html.push(getRadioCategoryHtml(c));
-        }
+        // } else if (c.type === categoryType.key.radio) {
+        //     html.push(getRadioCategoryHtml(c));
+        // }
     }
     return html.join('');
 }
@@ -187,7 +188,7 @@ function initTenderTree () {
             }
         }
     }
-    function getCategoryNode(category, value, parent) {
+    function getCategoryNode(category, value, parent, i = null) {
         const array = parent ?  parent.children : tenderTree;
         let cate = findCategoryNode(category.id, value, array);
         if (!cate) {
@@ -198,7 +199,8 @@ function initTenderTree () {
                 vid: value,
                 name: cateValue.value,
                 children: [],
-                level: category.level,
+                level: i ? i : category.level,
+                sort_id: ++parentId,
             };
             array.push(cate);
         }
@@ -206,11 +208,17 @@ function initTenderTree () {
     }
     function loadTenderCategory (tender) {
         let tenderCategory = null;
-        for (const lc of levelCategory) {
+        for (const [index, lc] of levelCategory.entries()) {
             const tenderCate = findNode('cid', lc.id, tender.category);
             if (tenderCate) {
                 tenderCategory = getCategoryNode(lc, tenderCate.value, tenderCategory);
             } else {
+                if (index === 0 && tender.category) {
+                    for (const [i,c] of tender.category.entries()) {
+                        const cate = findNode('id', c.cid, category);
+                        tenderCategory = getCategoryNode(cate, c.value, tenderCategory, i+1);
+                    }
+                }
                 return tenderCategory;
             }
         }
@@ -230,6 +238,7 @@ function initTenderTree () {
     for (const t of tenders) {
         calculateTender(t);
         t.valid = true;
+        delete t.level;
         if (t.category && levelCategory.length > 0) {
             const parent = loadTenderCategory(t);
             if (parent) {
@@ -259,13 +268,13 @@ function getProgressHtml(total, pre, cur) {
         return '';
     }
 }
-function recursiveGetTenderNodeHtml (node, arr) {
+function recursiveGetTenderNodeHtml (node, arr, pid) {
     const html = [];
-    html.push('<tr>');
+    html.push('<tr pid="' + pid + '">');
     // 名称
     html.push('<td class="in-' + node.level + '">');
     if (node.cid) {
-        html.push('<i class="fa fa-folder-o"></i> ', node.name);
+        html.push('<span class="fold-switch mr-1" title="收起" cid="'+ node.sort_id +'"><i class="fa fa-minus-square-o"></i></span> <i class="fa fa-folder-o"></i> ', node.name);
     } else {
         html.push('<span class="text-muted mr-2">');
         html.push(arr.indexOf(node) === arr.length - 1 ? '└' : '├');
@@ -296,7 +305,7 @@ function recursiveGetTenderNodeHtml (node, arr) {
     html.push('</tr>');
     if (node.children) {
         for (const c of node.children) {
-            html.push(recursiveGetTenderNodeHtml(c, node.children));
+            html.push(recursiveGetTenderNodeHtml(c, node.children, node.sort_id));
         }
     }
     return html.join('');
@@ -313,7 +322,7 @@ function getTenderTreeHtml () {
         html.push('<th>', '截止上期完成/本期完成/未完成', '</th>');
         html.push('</tr>', '</thead>');
         for (const t of tenderTree) {
-            html.push(recursiveGetTenderNodeHtml(t, tenderTree));
+            html.push(recursiveGetTenderNodeHtml(t, tenderTree, ''));
         }
         html.push('</table>');
         return html.join('');
@@ -388,13 +397,15 @@ $(document).ready(() => {
             return;
         }
         for (const c of category) {
-            const cate = {cid: c.id};
-            if (c.type === categoryType.key.dropDown) {
+            if (parseInt($('select', '[cate-id=' + c.id + ']').val()) !== 0) {
+                const cate = {cid: c.id};
+                // if (c.type === categoryType.key.dropDown) {
                 cate.value = parseInt($('select', '[cate-id=' + c.id + ']').val());
-            } else if (c.type === categoryType.key.radio) {
-                cate.value = parseInt($('input:checked', '[cate-id=' + c.id + ']').val());
+                // } else if (c.type === categoryType.key.radio) {
+                //     cate.value = parseInt($('input:checked', '[cate-id=' + c.id + ']').val());
+                // }
+                data.category.push(cate);
             }
-            data.category.push(cate);
         }
         postData('/list/add', data, function (result) {
             tenders.push(result);
@@ -405,4 +416,51 @@ $(document).ready(() => {
             $('[name=name]', '#add-bd').val('');
         });
     });
+
+    // 展开和收起
+    $('body').on('click', '.fold-switch', function () {
+        if ($(this).children('i').hasClass('fa-minus-square-o')) {
+            $(this).children('i').removeClass('fa-minus-square-o').addClass('fa-plus-square-o');
+            $(this).attr('title', '展开');
+            const cid = $(this).attr('cid');
+            const node = findTenderTreeNode(parseInt(cid), tenderTree);
+            doTrStatus(returnItem, 'hide');
+        } else {
+            $(this).children('i').removeClass('fa-plus-square-o').addClass('fa-minus-square-o');
+            $(this).attr('title', '收起');
+            const cid = $(this).attr('cid');
+            const node = findTenderTreeNode(parseInt(cid), tenderTree);
+            doTrStatus(returnItem, 'show');
+        }
+    })
 });
+
+function doTrStatus(node, status) {
+    if (status === 'show') {
+        $('.c-body').find('tr[pid="'+ node.sort_id +'"]').show();
+        $('.c-body').find('tr[pid="'+ node.sort_id +'"] .fold-switch').attr('title', '收起');
+        $('.c-body').find('tr[pid="'+ node.sort_id +'"] .fold-switch i').removeClass('fa-plus-square-o').removeClass('fa-minus-square-o').addClass('fa-minus-square-o');
+    } else {
+        $('.c-body').find('tr[pid="'+ node.sort_id +'"]').hide();
+        $('.c-body').find('tr[pid="'+ node.sort_id +'"] .fold-switch').attr('title', '展开');
+        $('.c-body').find('tr[pid="'+ node.sort_id +'"] .fold-switch i').removeClass('fa-minus-square-o').removeClass('fa-plus-square-o').addClass('fa-plus-square-o');
+
+    }
+    // 判断是否还有一层
+    if (node.children) {
+        for (const c of node.children) {
+            doTrStatus(c, status);
+        }
+    }
+}
+let returnItem;
+const findTenderTreeNode = function(sortId, tree) {
+    tree.forEach((item) => {
+        if (item.sort_id !== undefined && item.sort_id === sortId) {
+            returnItem = item;
+            return item;
+        } else if (item.children && item.children.length > 0) {
+            findTenderTreeNode(sortId, item.children);
+        }
+    });
+}