project-api.js 4.9 KB
define([], function() {
    'use strict';
    /**
     * 项目管理相关api
     */
    var projectApi = {
        /**
         * 刷新table
         */
        refreshTable: function (table) {
            table.trigger("uncheckbox");
            table.bootstrapTable("refresh");
        },
        /**
         * 修改项目状态
         * @param {object} data 
         * @param {function} success 
         */
        editProject: function (data, table, success) {
            var _me = this
            $.ajax({
                url: '/teacher/Container/container_detail/passProject',
                method: 'POST',
                data: data,
                success: function (res) {
                    if (1 === res.code) {
                        success && success()
                        _me.refreshTable(table)
                    } else {
                        Toastr.error(res.msg)
                    }
                }
            })
        },
        /**
         * 驳回项目
         * @param {array|string} ids 驳回项目的id
         * @param {object} table 当前的表格对象
         */
        backProject: function (ids, table) {
            ids = this.checkIds(ids)
            this.editProject({
                list: JSON.stringify(
                    ids.map(function (id) {
                        return { id: id, project_status: 2, check_stage: 0, review_stage: 0 }
                    })
                )
            }, table)
        },
        /**
         * 通过项目
         * @param {array|string} ids 通过项目的id
         * @param {object} table 当前的表格对象
         * @param {number|string} status 审核进度(0:教师审核;1:学院审核;2:学校审核;3:全部审核完)
         */
        passProject: function (ids, table, status) {
            if (('undefined' === typeof status) || ('' === status)) { throw new Error('审核进度参数不能为空') }
            ids = this.checkIds(ids)
            this.editProject({
                list: JSON.stringify(
                    ids.map(function (id) {
                        var editItem = {id: id, check_stage: status};
                        // 学校审核完,进入下一个评审阶段(项目结题除外)
                        if (3 === Number(status) && (2 != Config.review_stage)) {
                            editItem.review_stage = Number(Config.review_stage) + 1;
                            editItem.check_stage = 0;
                        }
                        return editItem;
                    })
                )
            }, table)
        },
        /**
         * 淘汰项目
         */
        outProject: function (ids, table) {
            ids = this.checkIds(ids)
            this.editProject({
                list: JSON.stringify(
                    ids.map(function (id) {
                        return { id: id, project_status: 1 }
                    })
                )
            }, table)
        },
        /**
         * 延期项目
         */
        delayProject: function (ids, table) {
            ids = this.checkIds(ids)
            this.editProject({
                list: JSON.stringify(
                    ids.map(function (id) {
                        return { id: id, project_status: 3 }
                    })
                )
            }, table)
        },
        /**
         * 把传入的ids转为符合规则格式
         * @return {array|string}
         */
        checkIds: function (ids) {
            if ('array' !== typeof ids) {
                ids = (''+ids).split(',')
            }
            if (!ids.length) {
                throw new Error('id不能为空')
            }
            return ids
        },
        /**
         * 构建表格评审列数据
         * @return {Array}
         */
        getReviewColumns: function () {
            var reviewStageIds = Config.review_stage_ids || []
            return reviewStageIds.map(function (v, i) {
                return {
                    field: ('review' + v), title: ('评审' + (i + 1)), operate: false, formatter: function (val, row) {
                        var reviewScores = row.review_scores || []
                        // 评审结果为空或者为'-'时,显示'-'
                        return (('-' !== reviewScores[v]) && ('undefined' !== typeof reviewScores[v])) ? Number(reviewScores[v]) : '-'
                    }
                }
            })
        },
        /**
         * 更新单行数据
         * @param table_index
         * @param row_index
         * @param field
         * @param field_val
         */
        containerUpdateRow:function(table_index,row_index,field,field_val){
            $('#table'+table_index).bootstrapTable('updateRow', {
                index: row_index,
                row: {
                    field: field_val,
                }
            });
        }
    }

    return projectApi
});