MaiXinRong 4 месяцев назад
Родитель
Сommit
c100e72b81
2 измененных файлов с 39 добавлено и 8 удалено
  1. 32 3
      app/public/js/shares/ledger_template.js
  2. 7 5
      app/service/ledger_template.js

+ 32 - 3
app/public/js/shares/ledger_template.js

@@ -26,7 +26,7 @@
             cols: [
                 {title: '名称', colSpan: '1', rowSpan: '1', field: 'name', hAlign: 0, width: 145, formatter: '@'},
                 {title: '创建人', colSpan: '1', rowSpan: '1', field: 'user_name', hAlign: 1, width: 70, formatter: '@', readOnly: true},
-                {title: '创建时间', colSpan: '1', rowSpan: '1', field: 'create_time', hAlign: 1, width: 80, formatter: '@', getValue: function(data) { return moment(data.create_time).format('YYYY-HH-DD')}, readOnly: true},
+                {title: '创建时间', colSpan: '1', rowSpan: '1', field: 'create_time', hAlign: 1, width: 80, formatter: '@', getValue: function(data) { return moment(data.create_time).format('YYYY-MM-DD')}, readOnly: true},
                 {title: '来源', colSpan: '1', rowSpan: '1', field: 'source', hAlign: 0, width: 200, formatter: '@', readOnly: true},
             ],
             emptyRows: 0,
@@ -53,7 +53,7 @@
                     },
                     disabled: function() {
                         const node = SpreadJsObj.getSelectObject(tempSheet);
-                        return node.create_user_id === userID;
+                        return node.create_user_id !== userID;
                     },
                 },
                 apply: {
@@ -66,7 +66,31 @@
                     visible: function() {
                         return !!setting.applyTemplate;
                     }
-                }
+                },
+                share: {
+                    name: '共享',
+                    icon: 'fa-link',
+                    callback: function() {
+                        const node = SpreadJsObj.getSelectObject(tempSheet);
+                        shareTemplate(node, true);
+                    },
+                    visible: function() {
+                        const node = SpreadJsObj.getSelectObject(tempSheet);
+                        return node.create_user_id === userID && !node.is_share;
+                    }
+                },
+                keep: {
+                    name: '取消共享',
+                    icon: 'fa-unlink',
+                    callback: function() {
+                        const node = SpreadJsObj.getSelectObject(tempSheet);
+                        shareTemplate(node, false);
+                    },
+                    visible: function() {
+                        const node = SpreadJsObj.getSelectObject(tempSheet);
+                        return node.create_user_id === userID && !!node.is_share;
+                    }
+                },
             }
         });
         $('#temp-search').click(function() {
@@ -108,6 +132,11 @@
             }
             SpreadJsObj.refreshTreeRowVisible(tempSheet);
         };
+        const shareTemplate = function(template, share) {
+            postData('/template/ledger/save', { update: { id: template.id, is_share: share ? 1 : 0 } }, function(result) {
+                template.is_share = result.update.is_share;
+            });
+        };
         const loadDatas = function (datas) {
             templateList = datas;
             SpreadJsObj.loadSheetData(tempSheet, SpreadJsObj.DataType.Data, templateList);

+ 7 - 5
app/service/ledger_template.js

@@ -23,11 +23,13 @@ module.exports = app => {
         }
 
         async getAllTemplate(pid) {
-            const result = await this.getAllDataByCondition({
-                columns: ['id', 'create_user_id', 'user_name', 'create_time', 'name', 'source', 'is_share'],
-                where: { pid },
-                orders: [['create_time', 'asc']],
-            });
+            // const result = await this.getAllDataByCondition({
+            //     columns: ['id', 'create_user_id', 'user_name', 'create_time', 'name', 'source', 'is_share'],
+            //     where: { pid },
+            //     orders: [['create_time', 'ASC']],
+            // });
+            const sql = `SELECT id, create_user_id, user_name, create_time, name, source, is_share FROM ${this.tableName} WHERE pid = ? AND (create_user_id = ? OR is_share) ORDER BY create_time ASC`;
+            const result = await this.db.query(sql, [pid, this.ctx.session.sessionUser.accountId]);
             return result;
         }
         async getTemplateData(id) {