/* * 版 本 PIT-ADMS V7.0.3 敏捷开发框架
 * Copyright (c) 2013-2018 Hexagon PPM
 * 创建人：超级管理员
 * 日  期：2020-12-04 11:05
 * 描  述：流程分类
 */
var refreshGirdData;
var ProjectId = request('ProjectId');
var parentPage = $(parent.document).find("li .lr-frame-iframe,.active")[3].contentWindow;
var plantType = request("plantType");

var bootstrap = function ($, learun) {
    "use strict";
    var page = {
        init: function () {
            page.bind();
            page.initGird();
        },
        bind: function () {
            // 刷新
            $('#lr_refresh').on('click', function () {
                refreshGirdData();
            });
            //平台分类
            $('#PlantType').lrDataItemSelect({
                code: 'Biz_PlantType'
            });
            $('#PlantType').lrselectSet(plantType); 
            //查询
            $('#btn_Search').on('click', function () {
                page.search();
            });
            // 新增
            $('#lr_add').on('click', function () {
                learun.layerForm({
                    id: 'CategoryAdd',
                    title: '新增',
                    url: top.$.rootUrl + '/LR_NewWorkFlow/NWFScheme/CategoryForm?ProjectId=' + ProjectId,
                    width: 600,
                    height: 230,
                    callBack: function (id) {
                        parentPage.isCaoz = true;
                        return top[id].acceptClick(refreshGirdData);
                    }
                });
            });
            // 编辑
            $('#lr_edit').on('click', function () {
                var keyValue = $('#gridtable').jfGridValue('FlowClassifyID');
                if (learun.checkrow(keyValue)) {
                    learun.layerForm({
                        id: 'CategoryEdit',
                        title: '编辑',
                        url: top.$.rootUrl + '/LR_NewWorkFlow/NWFScheme/CategoryForm?keyValue=' + keyValue ,
                        width: 600,
                        height: 230,
                        callBack: function (id) {
                            parentPage.isCaoz = true;
                            return top[id].acceptClick(refreshGirdData);
                        }
                    });
                }
            });
            // 删除
            $('#lr_delete').on('click', function () {
                var keyValue = $('#gridtable').jfGridValue('FlowClassifyID');
                if (learun.checkrow(keyValue)) {
                    learun.layerConfirm('是否确认删除该项！', function (res) {
                        if (res) {
                            learun.deleteForm(top.$.rootUrl + '/LR_NewWorkFlow/NWFScheme/CategoryDeleteEntity', { keyValue: keyValue }, function () {
                                refreshGirdData();
                                parentPage.isCaoz = true;
                            });
                        }
                    });
                }
            });
        },
        // 初始化列表
        initGird: function () {
            //var tbalewidth = $('#gridtable').width() / 2;
            $('#gridtable').jfGrid({
                url: top.$.rootUrl + '/LR_NewWorkFlow/NWFScheme/GetCategoryList',
                headData: [
                    {
                        label: '平台分类', name: 'PlantType', width: 150, align: 'center' ,
                        formatterAsync: function (callback, value, row, op, $cell) {
                            learun.clientdata.getAsync('dataItem', {
                                key: value,
                                code: 'Biz_PlantType',
                                callback: function (_data) {
                                    callback(_data.text);
                                }
                            });
                        }
                    },
                    { label: '分类名称', name: 'ClassifyName', width: 300, align: 'left' },
                    { name: '' }
                ],
                mainId: 'FlowClassifyID',
                reloadSelected: true
            });
            page.search();
        },
        search: function (param) {
            param = param || {};
            param.ProjectId = ProjectId;
            param.PlantType = $("#PlantType").lrselectGet();
            param.keyword = $('#txt_Keyword').val();
            $('#gridtable').jfGridSet('reload', { queryJson: JSON.stringify(param) });
        }
    };
    refreshGirdData = function () {
        $('#gridtable').jfGridSet('reload');
    };
    page.init();
}
