 /**
 * guoj
 * 2020.09.21
 * 费用项管理
    */
    import { UPCLOUD_RDC_TMS_MAINDATA_SERVICE,UPCLOUD_RDC_TMS_BUSINESS_SERVICE,UPCLOUD_RDC_TMS_INTERFACE_SERVICE} from '@/config/serviceSettings.js';
    import { getSelectGJ, querySysPicture } from '@/utils/prolog.ajax.js';
export default () => {
    var ddfrom = null;
    let dataSelect;
    //获取下拉框
    getSelectGJ([{ "objectcode": "FEE_TYPE" }], function (data) {
        dataSelect = data.data;
        dataSelect.FEE_TYPE.unshift({ "text": "", "value": "" });
    });
    var opts = {
        //terrace显示全部，card分页显示
        skin: "card",
        //renderer:"grid",
        columns: [
            { id: "feetypeid", name: "id", type: "ro", width: "100", hidden: true },
            { id: "feetypecode", name: "费用项目编号", type: "ro", width: 150 },
            { id: "feetypename", name: "费用项目名称", type: "ro", width: 150 },
            {
                id: "type", name: "费用类型", type: "ro", width: 100,render: (v)=>{
                    return getSelectValue( dataSelect.FEE_TYPE,v);
                }
            },
            { id: "description", name: "费用描述", type: "ro", width: 100 },
            { id: "memo", name: "备注", type: "ro", width: 100 },
            { id: "createtime", name: "创建时间", type: "ro", width: 130 },
            { id: "createperson", name: "创建人", type: "ro", width: 100 },
            {
                id: "op", name: "操作", type: "button", align: "center", fixed: "right", width: 200, render: function () {
                    return "删除^expenseItem_deleteClick,修改^expenseItem_updataClick,复制^expenseItem_copy,详情^expenseItem_details";
                }
            }
        ],
        multiselect: true,
        fixedLast: true, //开启固定列，固定最后一行，倒数第二列不能隐藏
        toolbar: [
            { type: "settings", labelWidth: 90, labelAlign: "right" },
            {
                type: "row",
                list: [
                    { type: "input", name: "feetypecode", label: "项目编号:", className: "layui-col-md3"},
                    { type: "input", name: "feetypename", label: "项目名称:", className: "layui-col-md3"},
                    { type: "combo", name: "type", label: "项目类型:", className: "layui-col-md3",options: dataSelect.FEE_TYPE},
                    {
                        type: "block", className: "layui-col-md2 form_btn_left",
                        list: [
                            { type: "button", className: "btn-normal", name: "querywork", value: "查询" },
                            { type: "newcolumn" },
                            { type: "button", name: "work_Reset", className: "normal", value: "重置" }
                        ]
                    },
                    {
                        type: "block", className: "layui-col-md1 right",
                        list: [
                            { type: "button", className: "btn-normal", name: "addBtn", offsetLeft: 10, value: "<i class='layui-icon layui-icon-add-1'></i>新增" }
                        ]
                    }
                ]
            }],

        url: UPCLOUD_RDC_TMS_BUSINESS_SERVICE+"/bmsFeeType/queryBmsFeeType",//数据接口
        type: "post",//数据提交方式，默认为get
        pagebar: {
            buttons: [
                { text: "删除", className: "layui-btn-danger", name: "delete" }
            ]
        },
        contentType: "application/json",
        params: "{}",//查询提交参数，分页参数默认为pageNum,pageSize
        page: true, //是否启用分页
        totalCount: "totalCount" //总记录数字段，默认totalCount
    };
    //分页参数 pageSize pageNum
    var grid = new PlgGrid(opts);
    grid.renderTo("expenseItem_guojzhuans2");
    grid.loadData();
    //按钮添加方法
    grid.attachToolBarEvent("onButtonClick", function (name) {
        if (name == "querywork") {
            var fdata = grid.getToolBarForm().getFormData();
            grid.setParams(JSON.stringify(fdata));
            grid.reload();
        }
        if (name == "addBtn") {
            setViewName("#expenseItem_div1");
            ddfrom.clear();
            $("#expenseItem_title").html("新增");
        }
        if (name == "work_Reset") {
            grid.getToolBarForm().clear();
        }
    });
    //按钮添加方法
    grid.attachPageBarEvent(function (name) {
        //删除
        if (name == "delete") {
            let data = [];
            let datas = getDeleteAll(grid);
            datas.forEach(v => {
                data.push(grid.getRowData( v ));
            });
            data = JSON.stringify(data);
            utilDelete(UPCLOUD_RDC_TMS_BUSINESS_SERVICE+"/bmsFeeType/deleteBmsFeeType", "post", data, function (data) {
                        grid.reload();
            }, "application/json");
        }
    });
    //删除
    window.expenseItem_deleteClick = function (rid,rdata) {
        grid.selectRowById(rid);
        rdata = JSON.stringify([rdata]);
        utilDelete(UPCLOUD_RDC_TMS_BUSINESS_SERVICE+"/bmsFeeType/deleteBmsFeeType", "post", rdata, function (data) {
                grid.reload();
        }, "application/json");
    };
    //修改
    window.expenseItem_updataClick = function (rid, data) {
        grid.selectRowById(rid);
        ddfrom.clear();
        ddfrom.setFormData(data);
        setViewName("#expenseItem_div1");
        $("#expenseItem_title").html("编辑");
    };
    //复制
    window.expenseItem_copy = function (rid, data) {
        grid.selectRowById(rid);
        ddfrom.clear();
        data.feetypeid = "";
        ddfrom.setFormData(data);
        setViewName("#expenseItem_div1");
        $("#expenseItem_title").html("新增");
    };
    //详情
    window.expenseItem_details = function (rid, rdata) {
        grid.selectRowById(rid);
        setViewName("#expenseItem_div9");
        new PlgPanel({
            renderer: "expenseItem_div422",
            skin: 2,
            header: {
                isShow: true,
                title: "基本信息"
            },
            defaultBody: {
                layoutCol: 3,
                valueBj: true,
                cols: [
                    [{
                        label: "费用项目编号",
                        value: rdata.feetypecode
                    },
                    {
                        label: "费用项目名称",
                        value: rdata.feetypename
                    },
                    {
                        label: "费用类型",
                        value: getSelectValue(dataSelect.FEE_TYPE, rdata.type )
                    },
                    {
                        label: "费用描述",
                        value: rdata.description
                    }],
                    [
                        {
                            label: "备注",
                            value: rdata.memo
                        },
                        {
                            label: "创建时间",
                            value: rdata.createtime
                        },
                        {
                            label: "创建人",
                            value: rdata.createperson
                        }
                    ]
                ]
            }
        });
    };
    //跳转页面
    var carousel = layui.carousel;
    carousel.render({
        elem: "#expenseItem_div2",
        autoplay: false,
        index: 0,
        arrow: "none",
        indicator: "none",
        anim: "fade",
        width: "100%", //设置容器宽度
        height: "100%"
    });
    let dataView = ["#expenseItem_div1","#expenseItem_div3","#expenseItem_div9"];
    function setViewName(name){
        for(var i = 0;i < dataView.length;i++){
            if(name == dataView[i]){
                $(name).css("display", "block");
            }
            else{
                $(dataView[i]).css("display", "none");
            }
        }
    }
    ddfrom = new PlgForm({
        renderer: "expenseItem_div4",
        items: [
            { type: "settings", position: "label-left", width: 300, labelWidth: 90 },
            { type: "hidden", name: "feetypeid", label: "id:", width: 230 },
            { type: "input", name: "feetypecode", label: "费用项目编号:", width: 230, editable: false, validate: "NotEmpty", required: true },
            { type: "input", name: "feetypename", label: "费用项目名称:", width: 230, validate: "NotEmpty", required: true },
            { type: "newcolumn", offset: 10 },
            { type: "combo", name: "type", label: "费用类型:", width: 230 ,options: dataSelect.FEE_TYPE},
            { type: "input", name: "description", label: "费用描述:", width: 230 },
            { type: "newcolumn", offset: 10 },
            {
                type: "input", name: "memo", label: "备注:", width: 230
            }]
    });
    //返回
    $(document).on("click", "#expenseItem_return", function () {
        setViewName("#expenseItem_div3");
    });
    //保存
    document.querySelector("#expenseItem_save").onclick = function () {
        //数据data
        var data = ddfrom.getFormData();
        var feik = ddfrom.validate();
        if (!feik) {
            return;
        }
        //请求地址和类型
        var url = UPCLOUD_RDC_TMS_BUSINESS_SERVICE+"/bmsFeeType/updateBmsFeeType";
        var type = "post";
        var contentType = "application/json";
        //message新增为0，修改为1
        if (data.feetypeid == null || data.feetypeid == "") {
            url = UPCLOUD_RDC_TMS_BUSINESS_SERVICE+"/bmsFeeType/addBmsFeeType";
        }
        //调用ajax方法
        utilAjaxGJ(url, type, JSON.stringify(data), function (data) {
                setViewName("#expenseItem_div3");
            grid.reload();
        }, contentType);
    };
};
