Browse Source

列表排序

laiguoran 4 years ago
parent
commit
9910eff738

+ 23 - 0
app/public/js/category.js

@@ -58,6 +58,7 @@ function getValueHtml(value) {
     const html = [];
     for (const v of value) {
         html.push('<tr name="value" vid="' + v.id + '">');
+        html.push('<td><a href="javascript:void(0);" class="up-btn mr-2" title="上移"><i class="fa fa-caret-up"></i></a><a href="javascript:void(0);" class="down-btn" title="下移"><i class="fa fa-caret-down "></i></a></td>');
         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="javascript: void(0);" class="text-danger" name="del-value" vid="' + v.id + '">删除</a></td>');
@@ -113,11 +114,14 @@ function bindCategoryValueControl() {
         const value = _.find(editCate.value, function (v) {
             return v.id == vid;
         });
+        const delHtml = $(this).parents('td').html();
+        const _self = $(this).parents('td');
         $(this).remove();
         if (value.delete) { return; }
 
         if (value.relaTenders.length > 0) {
             // 提示用户转移标段
+            _self.html(delHtml);
             $('#tender-count').text(value.relaTenders.length).attr('vid', vid);
             $('#tender-target').html(getValidValueHtml(vid));
             $('input[type=radio]', '#tender-target')[0].checked = true;
@@ -293,4 +297,23 @@ $(document).ready(() => {
             $('#del-cate').modal('hide');
         });
     });
+
+    // 上移值
+    $('body').on('click', '.up-btn', function () {
+        const prev = $(this).parents("tr").prev();
+        const prevIndex = parseInt($(prev).index('#value-list tr'));
+        $(this).parents("tr").insertBefore(prev);
+        // if(prevIndex === 1){
+        //     console.log('hello');
+        // }
+    });
+    // 下一值
+    $('body').on('click', '.down-btn', function () {
+        const next = $(this).parents("tr").next();
+        const nextIndex = parseInt($(next).index('#value-list tr'));
+        const nowlength = $('#value-list tr').length - 1;
+        if (nextIndex < nowlength) {
+            $(this).parents("tr").insertAfter(next);
+        }
+    });
 });

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

@@ -93,6 +93,7 @@ function initTenderTree () {
             tenderTree.push(t);
         }
     }
+    sortTenderTree();
 }
 function recursiveGetTenderNodeHtml (node, arr, pid, this_code, this_status, aidList = []) {
     const html = [];

+ 6 - 3
app/public/js/tender_list.js

@@ -217,6 +217,7 @@ function initTenderTree () {
                 children: [],
                 level: i ? i : category.level,
                 sort_id: ++parentId,
+                sort: cateValue.sort,
             };
             array.push(cate);
         }
@@ -268,7 +269,9 @@ function initTenderTree () {
             tenderTree.push(t);
         }
     }
+    sortTenderTree();
 }
+
 function recursiveGetTenderNodeHtml (node, arr, pid) {
     const html = [];
     html.push('<tr pid="' + pid + '">');
@@ -363,10 +366,10 @@ $(document).ready(() => {
     $('.modal-body', '#add-bd').append(getCategoryHtml());
     // 初始化标段树结构
     tenderListOrder.reOrderTenders();
-    initTenderTree();
-    $('.c-body').html(getTenderTreeHtml());
+    // initTenderTree();
+    // $('.c-body').html(getTenderTreeHtml());
     bindTenderUrl();
-    localHideList();
+    // localHideList();
 
     // 分类
     $('#cate-set').on('show.bs.modal', function () {

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

@@ -288,6 +288,7 @@ function initTenderTree () {
             tenderTree.push(t);
         }
     }
+    sortTenderTree();
     for (const t of tenderTree) {
         calculateParent(t);
     }

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

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

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

@@ -284,6 +284,7 @@ function initTenderTree () {
             tenderTree.push(t);
         }
     }
+    sortTenderTree();
     for (const t of tenderTree) {
         calculateParent(t);
     }

+ 20 - 1
app/public/js/tender_showhide.js

@@ -29,7 +29,26 @@ function removeValueToCate(cate) {
     }
     return newCate;
 }
-
+// 根据标段类别设置排序
+function sortTenderTree(teTree = tenderTree) {
+    for (const tender of teTree) {
+        if (tender.sort) {
+            // 当前层排序
+            teTree.sort(function (a, b) {
+                if (a.sort && b.sort) {
+                    return a.sort - b.sort;
+                } else if (a.sort && !b.sort) {
+                    return -1;
+                } else if (b.sort && !a.sort) {
+                    return 1;
+                } else {
+                    return 0;
+                }
+            });
+            sortTenderTree(tender.children);
+        }
+    }
+}
 function localHideList(wap = false) {
     const pro_cate = getLocalCache('pro_'+ pid + '_category_list');
     const cate = JSON.stringify(removeValueToCate(category));

+ 1 - 0
app/public/js/wap/list.js

@@ -134,6 +134,7 @@ function initTenderTree () {
             tenderTree.push(t);
         }
     }
+    sortTenderTree();
     for (const t of tenderTree) {
         calculateParent(t);
     }

+ 8 - 3
app/service/category.js

@@ -129,7 +129,7 @@ module.exports = app => {
          */
         async getCategory(id) {
             const data = await this.getDataByCondition({id: id});
-            data.value = await this.ctx.service.categoryValue.getAllDataByCondition({ where: {cid: id} });
+            data.value = await this.ctx.service.categoryValue.getAllDataByCondition({ where: { cid: id }, orders: [['sort', 'asc'], ['id', 'asc']] });
             return data;
         }
         /**
@@ -139,8 +139,13 @@ module.exports = app => {
          * @returns {Promise<*>}
          */
         async getAllCategory(pid) {
-            const data = await this.getAllDataByCondition({where: {pid: pid}});
-            const values = await this.ctx.service.categoryValue.getAllDataByCondition({ where: {pid: pid} });
+            const data = await this.getAllDataByCondition({ where: { pid } });
+            const values = await this.ctx.service.categoryValue.getAllDataByCondition({
+                where: { pid },
+                orders: [['sort', 'asc'], ['id', 'asc']],
+            });
+            // values 按名称排序
+            // values.sort((a, b) => a.value.localeCompare(b.value, 'zh-Hans-CN', { sensitivity: 'accent' }));
             for (const d of data) {
                 d.value = values.filter(function (v) {
                     return v.cid === d.id;

+ 6 - 2
app/service/category_value.js

@@ -69,18 +69,22 @@ module.exports = app => {
 
             this.transaction = await this.db.beginTransaction();
             try {
+                let sort = 1;
                 for (const v of value) {
                     if (v.delete) {
                         await this.transaction.delete(this.tableName, {id: v.id});
                     } else if (v.new) {
                         const result = await this.transaction.insert(this.tableName, {
-                            cid: cid,
+                            cid,
                             pid: this.ctx.session.sessionProject.id,
                             value: v.value,
+                            sort,
                         });
                         v.id = result.insertId;
+                        sort++;
                     } else {
-                        await this.transaction.update(this.tableName, {id: v.id, value: v.value});
+                        await this.transaction.update(this.tableName, { id: v.id, value: v.value, sort });
+                        sort++;
                     }
                     if (!v.newTenders) { continue }
                     for (const nt of v.newTenders) {

+ 1 - 1
app/view/setting/category_modal.ejs

@@ -58,7 +58,7 @@
             <div class="modal-body">
                 <table class="table table-bordered">
                     <thead>
-                    <tr><th>值</th><th>包含标段</th><th>删除</th></tr>
+                    <tr><th width="40">排序</th><th>值</th><th>包含标段</th><th>删除</th></tr>
                     </thead>
                     <tbody id="value-list">
                     </tbody>