/**
* guoj
* 2019.04.17
* 站台维护
*/
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;
    var laydate = layui.laydate;
    //获取下拉框
    getSelectGJ([{ "objectcode": "pfrom_status" }, { "objectcode": "Plattype" }, { "objectcode": "stationattr2" },
         { "objectcode": "stationtype" }], function (data) {
            $("#platform_select").attr("consignor", JSON.stringify(data.data));
        });
    var opts = {
        //terrace显示全部，card分页显示
        skin: "card",
        //renderer:"grid",
        columns: [
            { id: "platid", name: "id", type: "ro", width: 100, hidden: true },
            { id: "platcode", name: "站台编码", type: "ro", width: 100 },
            { id: "platname", name: "站台名称", type: "ro", width: 100 },
            {
                id: "platattr1", name: "顺序", type: "ro", align: "right", width: 100
            },
            { id: "plattypename", name: "类型", type: "ro", width: 100, align: "center" },
            { id: "plafromtime1", name: "开始时间1", type: "ro", width: 100 },
            {
                id: "platotime1", name: "结束时间1", type: "ro", width: 100
            },
            {
                id: "plafromtime2", name: "开始时间2", type: "ro", width: 100
            },
            {
                id: "platotime2", name: "结束时间2", type: "ro", width: 100
            },
            {
                id: "statusname", name: "状态", type: "ro", width: 100, render: function (v, record) {
                    if (record["status"] == 20) {
                        return Prolog.getCircle("red") + "锁定";
                    }
                    if (record["status"] == 30) {
                        return Prolog.getCircle("green") + "空闲";
                    }
                    if (record["status"] == 10) {
                        return Prolog.getCircle("yellow") + "使用";
                    }
                }
            },
            { id: "remark", name: "备注", type: "ro", width: 100 },
            {
                id: "op", name: "操作", type: "button", align: "center", fixed: "right", width: 230, render: function () {
                    return "删除^platform_deleteClick,修改^platform_updataClick,复制^platform_copy,详情^platform_details";
                }
            }
        ],
        multiselect: true,
        fixedLast: true, //开启固定列，固定最后一行，倒数第二列不能隐藏
        toolbar: [
            { type: "newcolumn", offset: 10 },
            { type: "input", name: "platcode", label: "站台编码:", width: 300 },
            { type: "newcolumn", offset: 10 },
            { type: "button", name: "querywork", value: "查询" }, { type: "newcolumn" },
            { type: "button", name: "work_Reset", className: "normal", value: "重置" }, { type: "newcolumn" },
            { type: "button", name: "addBtn", offsetLeft: 10, className: "plg-toolbar-right", value: "<i class='layui-icon layui-icon-add-1'></i>新增" }, { type: "newcolumn" }],
        imagePath: "/prologui/dist/images/PlgGrid",
        url: "/booking/platformMaintenance/getplatformMaintenance/v1.0",//数据接口
        type: "get",//数据提交方式，默认为get
        pagebar: {
            buttons: [
                { text: "删除", className: "layui-btn-danger", name: "delete" },
                { text: "锁定", className: "layui-btn-normal", name: "lock" },
                { text: "启用", className: "layui-btn-normal", name: "unlock" }
            ]
            // type: 'simple' //full simple
        },
        params: {},//查询提交参数，分页参数默认为pageNum,pageSize
        page: true, //是否启用分页
        totalCount: "totalCount" //总记录数字段，默认totalCount
    };
    //分页参数 pageSize pageNum
    var grid = new PlgGrid(opts);
    grid.renderTo("platform_table");
    $("#platform_table").addClass("layui-form");
    grid.attachEvent("onDataReady", function () {
        setTimeout(function () {
            layui.form.render();
        }, 200);
    });
    grid.loadData();

    //按钮添加方法
    grid.attachToolBarEvent("onButtonClick", function (name) {
        if (name == "querywork") {
            var fdata = grid.getToolBarForm().getFormData();
            grid.setParams(fdata);
            grid.reload();
        }
        if (name == "addBtn") {
            $("#platform_div1").css("display", "block");
            $("#platform_div3").css("display", "none");
            $("#platform_div9").css("display", "none");
            $("#platform_Template").css("display", "none");
            ddfrom.enableAllItem();
            ddfrom.clear();
            ddfrom.disableItem("status");
            ddfrom.setFormData({ "status": "30" });
            $("#platform_title").html("新增");
            iptTimeInit();
        }
        if (name == "work_Reset") {
            grid.getToolBarForm().clear();
        }
    });


    utilImportGJ2("platform_Template1", "platformImportId", "platformExportId", "url", function () {
        $("#platform_div1").css("display", "none");
        $("#platform_div3").css("display", "block");
        $("#platform_div9").css("display", "none");
        $("#platform_Template").css("display", "none");
    });
    //按钮添加方法
    grid.attachPageBarEvent(function (name) {
        //删除
        if (name == "delete") {
            let datas = getDeleteAll(grid);
            utilDelete("/booking/platformMaintenance/deletePlatformMaintenance/v1.0 ", "post", JSON.stringify(datas), function (data) {
                setTimeout(() => { PlgDialog.msg(data.message == null ? "接口调用失败" : data.message); }, 300);
                grid.reload();
            }, "application/json");
        } //锁定
        if (name == "lock") {
            let datas = getDeleteAll(grid);
            let data = { "platids": datas, "status": "20" };
            utilAjaxGJ("/booking/platformMaintenance/batchModifyStatus/v1.0", "post", JSON.stringify(data), function (data) {
                setTimeout(() => { PlgDialog.msg(data.message == null ? "接口调用失败" : data.message); }, 300);
                grid.reload();
            }, "application/json");
        }
        //启用
        if (name == "unlock") {
            let datas = getDeleteAll(grid);
            let data = { "platids": datas, "status": "10" };
            utilAjaxGJ("/booking/platformMaintenance/batchModifyStatus/v1.0", "post", JSON.stringify(data), function (data) {
                setTimeout(() => { PlgDialog.msg(data.message == null ? "接口调用失败" : data.message); }, 300);
                grid.reload();
            }, "application/json");
        }
    });
    //删除
    window.platform_deleteClick = function (rid) {
        grid.selectRowById(rid);
        let datas = getDeleteAll(grid);
        utilDelete("/booking/platformMaintenance/deletePlatformMaintenance/v1.0 ", "post", JSON.stringify(datas), function (data) {
            setTimeout(() => { PlgDialog.msg(data.message == null ? "接口调用失败" : data.message); }, 300);
            grid.reload();
        }, "application/json");
    };
    //修改
    window.platform_updataClick = function (rid, data) {
        ddfrom.enableAllItem();
        grid.selectRowById(rid);
        ddfrom.clear();
        ddfrom.setFormData(data);
        ddfrom.disableItem("platcode");
        $("#platform_div1").css("display", "block");
        $("#platform_div3").css("display", "none");
        $("#platform_div9").css("display", "none");
        $("#platform_Template").css("display", "none");
        $("#platform_title").html("编辑");

        iptTimeInit();
    };
    //复制
    window.platform_copy = function (rid, data) {
        ddfrom.enableAllItem();
        grid.selectRowById(rid);
        ddfrom.clear();
        data.platcode = "";
        data.platname = "";
        data.platid = "";
        ddfrom.setFormData(data);
        ddfrom.disableItem("status");
        ddfrom.setFormData({ "status": "30" });
        $("#platform_div1").css("display", "block");
        $("#platform_div3").css("display", "none");
        $("#platform_div9").css("display", "none");
        $("#platform_Template").css("display", "none");
        $("#platform_title").html("新增");
    };
    //详情
    window.platform_details = function (rid, rdata) {
        grid.selectRowById(rid);
        $("#platform_div1").css("display", "none");
        $("#platform_div3").css("display", "none");
        $("#platform_div9").css("display", "block");
        $("#platform_Template").css("display", "none");
        new PlgPanel({
            renderer: "platform_div422",
            skin: 2,
            header: {
                isShow: true,
                title: "基本信息"
            },
            defaultBody: {
                layoutCol: 3,
                valueBj: true,
                cols: [
                    [{
                        label: "站台编码",
                        value: rdata.platcode
                    },
                    {
                        label: "站台名称",
                        value: rdata.platname
                    },
                    {
                        label: "顺序",
                        value: rdata.platattr1
                    },
                    {
                        label: "类型",
                        value: rdata.plattypename
                    }],
                    [
                        {
                            label: "开始时间1",
                            value: rdata.plafromtime1
                        },
                        {
                            label: "结束时间1",
                            value: rdata.platotime1
                        },
                        {
                            label: "开始时间2",
                            value: rdata.plafromtime2
                        },
                        {
                            label: "结束时间2",
                            value: rdata.platotime2
                        }
                    ],
                    [
                        {
                            label: "状态",
                            value: rdata.statusname
                        },
                        {
                            label: "备注",
                            value: rdata.remark
                        }
                    ]
                ]
            }
        });
    };
    function iptTimeInit() {
        let ipt1 = $("#platform_div4 input[name=\"plafromtime1\"]");
        laydate.render({
            elem: "#" + ipt1[0].id,
            type: "time",
            format: "HH:mm"
        });
        let ipt2 = $("#platform_div4 input[name=\"plafromtime2\"]");
        laydate.render({
            elem: "#" + ipt2[0].id,
            type: "time",
            format: "HH:mm"
        });
        let ipt3 = $("#platform_div4 input[name=\"platotime1\"]");
        laydate.render({
            elem: "#" + ipt3[0].id,
            type: "time",
            format: "HH:mm"
        });
        let ipt4 = $("#platform_div4 input[name=\"platotime2\"]");
        laydate.render({
            elem: "#" + ipt4[0].id,
            type: "time",
            format: "HH:mm"
        });
    }
    //跳转页面
    var carousel = layui.carousel;
    carousel.render({
        elem: "#platform_div2",
        autoplay: false,
        index: 0,
        arrow: "none",
        indicator: "none",
        anim: "fade",
        width: "100%", //设置容器宽度
        height: "100%"
    });

    ddfrom = $("#platform_div4").initPlgForm({
        items: [
            { type: "settings", position: "label-left", width: 300, labelWidth: 80 },
            { type: "hidden", name: "platid", label: "id:", width: 230 },
            { type: "input", name: "platcode", label: "站台编码:", width: 230, editable: false, validate: "NotEmpty", required: true },
            { type: "input", name: "platname", label: "站台名称:", width: 230, validate: "NotEmpty", required: true },

            { type: "input", name: "platattr1", label: "顺序:", width: 230 },
            { type: "input", name: "remark", label: "备注:", width: 230 },
            { type: "newcolumn", offset: 10 },
            {
                type: "select", name: "plattype", label: "类型:", width: 230, options: JSON.parse($("#platform_select").attr("consignor")).Plattype
            },
            { type: "input", name: "plafromtime1", label: "开始时间1:", width: 230, readonly: true },
            { type: "input", name: "plafromtime2", label: "开始时间2:", width: 230, dateFormat: "%H:%i", enableTime: true, readonly: true },
            { type: "newcolumn", offset: 10 },
            {
                type: "select", name: "status", label: "状态:", width: 230, options: JSON.parse($("#platform_select").attr("consignor")).pfrom_status
            },
            { type: "input", name: "platotime1", label: "结束时间1:", width: 230, dateFormat: "%H:%i", enableTime: true, readonly: true },
            { type: "input", name: "platotime2", label: "结束时间2:", width: 230, dateFormat: "%H:%i", enableTime: true, readonly: true },
            { type: "newcolumn", offset: 10 }]
    });
    //返回
    $(document).on("click", "#platform_return", function () {
        $("#platform_div1").css("display", "none");
        $("#platform_div3").css("display", "block");
        $("#platform_div9").css("display", "none");
        $("#platform_Template").css("display", "none");
    });
    //保存
    document.querySelector("#platform_save").onclick = function () {
        //数据data
        var data = ddfrom.getFormData();
        if (data.remark.length > 30) {
            layer.msg("备注长度不能超过30");
            return;
        }
        var feik = ddfrom.validate();
        if (!feik) {
            return;
        }
        data.plafromtime1 = $("#platform_div4 input[name=\"plafromtime1\"]").val();
        data.plafromtime2 = $("#platform_div4 input[name=\"plafromtime2\"]").val();
        data.platotime1 = $("#platform_div4 input[name=\"platotime1\"]").val();
        data.platotime2 = $("#platform_div4 input[name=\"platotime2\"]").val();
        //请求地址和类型
        var url = "/booking/platformMaintenance/modifyPlatformMaintenance/v1.0";
        var type = "post";
        //message新增为0，修改为1
        if (data.platid == null || data.platid == "") {
            url = "/booking/platformMaintenance/newplatformMaintenance/v1.0";
        }
        //调用ajax方法
        utilAjaxGJ(url, type, data, function (data) {
            setTimeout(() => { PlgDialog.msg(data.message == null ? "接口调用失败" : data.message); }, 300);
            $("#platform_div1").css("display", "none");
            $("#platform_div3").css("display", "block");
            $("#platform_div9").css("display", "none");
            $("#platform_Template").css("display", "none");
            grid.reload();
        });
    };
};
