Jelajahi Sumber

课程表批量发布

zhuth 7 tahun lalu
induk
melakukan
2326e938fe

+ 11 - 1
frontend/pc-web/app/view/Interaction/timetable/List.js

@@ -168,6 +168,13 @@ Ext.define('school.view.interaction.timetable.List', {
                         var g = me.down('grid');
                         g.store.loadPage(g.store.currentPage);
                     }
+                }, {
+                    xtype: 'button',
+                    text: '发布',
+                    type: 'publish',
+                    path: 'batchPublish',
+                    reference: 'publish',
+                    handler: 'onPublishClick'
                 }, {
                     xtype: 'button',
                     text: '删除',
@@ -246,7 +253,10 @@ Ext.define('school.view.interaction.timetable.List', {
                     renderer: function(v) {
                         return v == '1' ? '已生效' : '未生效'
                     }
-                }]
+                }],
+                listeners: {
+                    selectionchange: 'selectionchange'
+                }
             },
         });
         this.callParent(arguments);

+ 68 - 0
frontend/pc-web/app/view/Interaction/timetable/ListController.js

@@ -4,5 +4,73 @@ Ext.define('school.view.interaction.timetable.ListController', {
 
     onAddClick: function() {
         school.util.BaseUtil.openTab('interaction-timetable-detail', '新增课程表', 'interaction-timetable-detail-add'); 
+    },
+
+    selectionchange: function(table, selected, eOpts) {
+        let me = this,
+        refs = me.getReferences(),
+        btn = refs.publish,
+        type = btn.type;
+
+        btn.setDisabled(false);
+        if(selected.length == 1) {
+            btn.setText(selected[0].get('status') == '1' ? '取消发布' : '发布');
+            btn.type = (selected[0].get('status') == '1' ? 'republish' : 'publish');
+            btn.path = (selected[0].get('status') == '1' ? 'batchRepublish' : 'batchPublish');
+            return;
+        }else if(selected.length == 0) {
+            btn.setText('发布');
+            btn.type = 'publish';
+            btn.path = 'batchPublish';
+            return;
+        }else {
+            for(let i = 0; i < selected.length; i++) {
+                let s = selected[i];
+                if((s.get('status') == '1' && type == 'publish') || (s.get('status') == '0' && type == 'republish')) {
+                    btn.setDisabled(true);
+                    return;
+                }
+            }
+        }
+    },
+
+    onPublishClick: function() {
+        let me = this,
+        view = me.getView(),
+        grid = view.down('grid'),
+        selectedRecords = grid.getSelection(),
+        refs = me.getReferences(),
+        btn = refs.publish,
+        path = btn.path,
+        data;
+
+        data = selectedRecords.map(function (r) {
+            return {
+                id: r.get('id')
+            };
+        });
+
+        if (data.length == 0) {
+            school.util.BaseUtil.showErrorToast('请先勾选需要发布的记录');
+            return;
+        }
+
+        grid.setLoading(true);
+        school.util.BaseUtil.request({
+            // url: 'http://10.1.80.36:9520/api/school/curriculum/batchDelete',
+            url: '/api/school/curriculum/' + path,
+            method: 'POST',
+            params: JSON.stringify({
+                baseDTOs: data
+            })
+        }).then(function (res) {
+            grid.setLoading(false);
+            school.util.BaseUtil.showSuccessToast('操作成功');
+            grid.store.loadPage(grid.store.currentPage);
+            grid.getSelectionModel().deselectAll();
+        }).catch(function (e) {
+            grid.setLoading(false);
+            school.util.BaseUtil.showErrorToast('操作失败: ' + e.message);
+        });
     }
 });