/**
 * zzx
 * 2020.03.31
 * 费用规则管理
    */
    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 carousel = layui.carousel;
  carousel.render({
    elem: "#feeRules",
    autoplay: false,
    index: 0,
    arrow: "none",
    indicator: "none",
    anim: "fade",
    width: "100%", //设置容器宽度
    height: "100%"
  });
  // 跳转方法
  function changePanel(name) {
    var slideList = ["#feeRules_main", "#feeRules_edit", "#feeRules_view"];
    for (var i = 0; i < slideList.length; i++) {
      if (slideList[i] == name) {
        $(name).css("display", "block");
      }
      else {
        $(slideList[i]).css("display", "none");
      }
    }
  }
  // 返回
  $(document).on("click", "#feeRules_edit_return", function () {
    changePanel("#feeRules_main");
  });
  $(document).on("click", "#feeRules_view_return", function () {
    changePanel("#feeRules_main");
  });

  // 费用项目table
  var feetypeTable = {
    columns: [
      { id: "feetypeid", name: "id", type: "ro", width: "130", hidden: true },
      { id: "feetypecode", name: "费用项目编号", type: "ro" },
      { id: "feetypename", name: "费用项目名称", type: "ro" }
    ],
    toolbar: [
      { type: "settings", position: "label-left", width: 200 },
      {
        type: "block", id: "bk", blockOffset: 0, list: [
          { type: "input", name: "feetypecode", label: "费用项目编号:", width: 120 },
          { type: "newcolumn" },
          { type: "input", name: "feetypename", label: "费用项目名称:", width: 120 },
          { type: "newcolumn" },
          { type: "button", name: "querycarr", value: "查询" },
          { type: "newcolumn" },
          { type: "button", name: "car_Reset", value: "重置" }
        ]
      }
    ],
    multiselect: false,

    url: UPCLOUD_RDC_TMS_BUSINESS_SERVICE+"/bmsFeeType/queryBmsFeeTypeDailog",//数据接口
    type: "post", //数据提交方式，默认为get
    pagebar: { type: "simple" },
    params: JSON.stringify({ type: "02" }), //查询提交参数，分页参数默认为pageNum,pageSize
    contentType: "application/json",
    page: false, //是否启用分页
    totalCount: "totalCount" //总记录数字段，默认totalCount
  };

  // 获取下拉框
  var dataSelect = {
    CHARGE_TYPE: [],
    PRICE_TYPE: []
  };
  getSelectGJ([
    { "objectcode": "CHARGE_TYPE" },
    { "objectcode": "PRICE_TYPE" }
  ], function (data) {
    dataSelect = data.data;
    dataSelect.CHARGE_TYPE.unshift({ "text": "", "value": "" });
    dataSelect.PRICE_TYPE.unshift({ "text": "", "value": "" });
    dataSelect.YesOrNo = [{ text: "是", value: "1" }, { text: "否", value: "0" }];
  });

  var master_grid, details_grid, edit_form, edit_grid;

  // 主表grid
  var master_grid_opts = {
    skin: "card",
    columns: [
      { id: "feeRuleId", name: "id", type: "ro", width: "100", hidden: true },
      { id: "feeRuleName", name: "规则名称", type: "ro", width: 120 },
      { id: "feetypecode", name: "费用项目编号", type: "ro", width: 120 },
      { id: "feetypename", name: "费用项目名称", type: "ro", width: 120 },
      {
        id: "group1YesNo", name: "启用分组1", type: "ro", width: 100, render: (v) => {
          return getSelectValue(dataSelect.YesOrNo, v);
        }
      },
      {
        id: "group2YesNo", name: "启用分组2", type: "ro", width: 100, render: (v) => {
          return getSelectValue(dataSelect.YesOrNo, v);
        }
      },
      {
        id: "group3YesNo", name: "启用分组3", type: "ro", width: 100, render: (v) => {
          return getSelectValue(dataSelect.YesOrNo, v);
        }
      },
      {
        id: "group4YesNo", name: "启用分组4", type: "ro", width: 100, render: (v) => {
          return getSelectValue(dataSelect.YesOrNo, v);
        }
      },
      {
        id: "group5YesNo", name: "启用分组5", type: "ro", width: 100, render: (v) => {
          return getSelectValue(dataSelect.YesOrNo, v);
        }
      },
      {
        id: "chargeType", name: "计费类型", type: "ro", width: 120, render: (v) => {
          return getSelectValue(dataSelect.CHARGE_TYPE, v);
        }
      },
      { id: "memo", name: "备注", type: "ro", width: 120 },
      {
        id: "op", name: "操作", type: "button", align: "center", fixed: "right", width: 200, render: function () {
          return "删除^feeRules_delete,修改^feeRules_edit,详情^feeRules_view";
        }
      }
    ],
    toolbar: [
      { type: "settings", labelWidth: 90, labelAlign: "right" },
      {
        type: "row",
        list: [
          { type: "input", name: "feeRuleName", label: "规则名称:", className: "layui-col-md3" },
          {
            className: "layui-col-md3",
            type: "selectTable",
            placeholder: "请选择费用项目",
            readonly: false,
            table: feetypeTable,
            tableWidth: 600,
            tableHeight: 400,
            fieldText: "feetypename",
            fieldValue: "feetypeid",
            name: "feetypeidList",
            label: "费用项目:",
            listener: function (Grid) {
              setMethod(Grid, feetypeTable, function () { });
            }
          },
          { type: "combo", name: "chargeType", label: "计费类型:", className: "layui-col-md3", options: dataSelect.CHARGE_TYPE },
          {
            type: "block", className: "layui-col-md2 form_btn_left",
            list: [
              { type: "button", className: "btn-normal", name: "master_search", value: "查询" },
              { type: "newcolumn" },
              { type: "button", name: "master_reset", value: "重置" }
            ]
          },
          {
            type: "block", className: "layui-col-md1 right",
            list: [
              { type: "button", className: "btn-normal", name: "master_add", offsetLeft: 10, value: "<i class='layui-icon layui-icon-add-1'></i>新增" }
            ]
          }
        ]
      }
    ],
    multiselect: true,
    fixedLast: true,

    url: UPCLOUD_RDC_TMS_BUSINESS_SERVICE+"/bmsFeeRule/queryBmsFeeRule",//数据接口
    type: "post",//数据提交方式，默认为get
    pagebar: {
      buttons: [
        { text: "删除", className: "layui-btn-danger", name: "delete" }
      ]
    },
    contentType: "application/json",
    params: "{}",//查询提交参数，分页参数默认为pageNum,pageSize
    page: true, //是否启用分页
    totalCount: "totalCount" //总记录数字段，默认totalCount
  };
  master_grid = new PlgGrid(master_grid_opts);
  master_grid.renderTo("feeRules_master");
  master_grid.loadData();
  // 按钮添加方法
  master_grid.attachToolBarEvent("onButtonClick", function (name) {
    console.log(name);
    if (name === "master_search") {
      var request = master_grid.getToolBarForm().getFormData();
      request.feetypeid = request.feetypeidList ? JSON.parse(request.feetypeidList)[0] : "";
      dealNullQueryCondition(request);
      delete request.feetypeidList;
      master_grid.setParams(JSON.stringify(request));
      master_grid.reload();
    }
    else if (name === "master_reset") {
      console.log(11111111111);
      master_grid.getToolBarForm().clear();
      master_grid.getToolBarForm().setText("feetypeidList", "");
    }
    else if (name === "master_add") {
      changePanel("#feeRules_edit");
      $("#feeRules_edit_title").html("新增");
      editFormInit();
    }
  });
  // 单击事件
  master_grid.on("onRowSelect", function (id) {
    details_grid.setParams(JSON.stringify({ feeRuleId: id }));
    details_grid.reload();
  });
  // 删除
  master_grid.attachPageBarEvent(function (name, ids) {
    if (name === "delete") {
      let dataList = ids.split(",").map(item => master_grid.getRowData(item));
      bmsFeeRuleDelete(dataList);
    }
  });
  window.feeRules_delete = function (rid) {
    let rdata = master_grid.getRowData(rid);
    bmsFeeRuleDelete([rdata]);
  };
  function bmsFeeRuleDelete(params) {
    layer.open({
      title: "删除",
      content: "是否删除?",
      btn: ["确认", "取消"],
      yes: function () {
        let pload = PlgDialog.load(2, { shade: [0.6, "#fff"] });
        Prolog.ajax({
          url: UPCLOUD_RDC_TMS_BUSINESS_SERVICE+"/bmsFeeRule/bmsFeeRuleDelete", type: "post", contentType: "application/json", data: JSON.stringify(params),
          success: function (res) {
            PlgDialog.close(pload);
            if (res.success) {
              layer.closeAll();
              PlgDialog.msg(res.message);
              master_grid.reload();
              details_grid.clearAll();
              return true;
            }
                        return false;
          }, error: function () { PlgDialog.close(pload); return false; }
        });
      }
    });
  }
  // 详情
  window.feeRules_view = function (rid) {
    let rdata = master_grid.getRowData(rid);
    changePanel("#feeRules_view");
    new PlgPanel({
      renderer: "feeRules_view_form",
      skin: 2,
      header: {
        isShow: true,
        title: "基本信息"
      },
      defaultBody: {
        layoutCol: 3,
        valueBj: true,
        cols: [
          [
            { label: "规则名称", value: rdata.feeRuleName },
            { label: "费用项目编号", value: rdata.feetypecode },
            { label: "费用项目名称", value: rdata.feetypename },
            { label: "启用分组1", value: getSelectValue(dataSelect.YesOrNo, rdata.group1YesNo) }
          ],
          [
            { label: "启用分组2", value: getSelectValue(dataSelect.YesOrNo, rdata.group2YesNo) },
            { label: "启用分组3", value: getSelectValue(dataSelect.YesOrNo, rdata.group3YesNo) },
            { label: "启用分组4", value: getSelectValue(dataSelect.YesOrNo, rdata.group4YesNo) },
            { label: "启用分组5", value: getSelectValue(dataSelect.YesOrNo, rdata.group5YesNo) }
          ],
          [
            { label: "计费类型", value: getSelectValue(dataSelect.CHARGE_TYPE, rdata.chargeType) },
            { label: "备注", value: rdata.memo }
          ]
        ]
      }
    });
  };
  // 修改
  window.feeRules_edit = function (rid) {
    let rdata = master_grid.getRowData(rid);
    changePanel("#feeRules_edit");
    $("#feeRules_edit_title").html("修改");
    //字段转换
    rdata.group1 = rdata.group1YesNo;
    rdata.group2 = rdata.group2YesNo;
    rdata.group3 = rdata.group3YesNo;
    rdata.group4 = rdata.group4YesNo;
    rdata.group5 = rdata.group5YesNo;
    editFormInit(rdata);
    editGridInit(rdata, true);
  };

  // 明细表
  var details_grid_opts = {
    skin: "card",
    columns: [
      { id: "id", name: "id", type: "ro", width: "100", hidden: true },
      { id: "feeRuleName", name: "规则名称", type: "ro", width: "120" },
      { id: "feetypecode", name: "费用项目编号", type: "ro", width: "120" },
      { id: "feetypename", name: "费用项目名称", type: "ro", width: "120" },
      { id: "businessgroupid1", name: "分组1", type: "ro", width: "100" },
      { id: "businessgroupid2", name: "分组2", type: "ro", width: "100" },
      { id: "businessgroupid3", name: "分组3", type: "ro", width: "100" },
      { id: "businessgroupid4", name: "分组4", type: "ro", width: "100" },
      { id: "businessgroupid5", name: "分组5", type: "ro", width: "100" },
      { id: "fromqty", name: "数量起", type: "ro", width: "100" },
      { id: "toqty", name: "数量止", type: "ro", width: "100" },
      { id: "price", name: "价格", type: "ro", width: "100" },
      {
        id: "pricetype", name: "价格类型", type: "ro", width: 100, render: (v) => {
          return getSelectValue(dataSelect.PRICE_TYPE, v);
        }
      },
      { id: "minusqty", name: "可免数量", type: "ro", width: "100" },
      { id: "memo", name: "备注", type: "ro", width: "120" }
    ],

    url: UPCLOUD_RDC_TMS_BUSINESS_SERVICE+"/bmsFeeRule/queryBmsFeeRuleItem",//数据接口
    type: "post",//数据提交方式，默认为get
    contentType: "application/json",
    params: "{}",//查询提交参数，分页参数默认为pageNum,pageSize
    page: false, //是否启用分页
    totalCount: "totalCount" //总记录数字段，默认totalCount
  };
  details_grid = new PlgGrid(details_grid_opts);
  details_grid.renderTo("feeRules_details");

  // 注册表单
  function editFormInit(params) {
    $("#feeRules_edit_form").html("");
    // 编辑表单
    var edit_form_opts = {
      renderer: "feeRules_edit_form",
      items: [
        { type: "settings", labelWidth: 90, labelAlign: "right" },
        {
          type: "row",
          list: [
            { type: "hidden", name: "feeRuleId", label: "规则id:", className: "layui-col-md3" },
            { type: "input", name: "feeRuleName", label: "规则名称:", className: "layui-col-md3", required: true },
            {
              className: "layui-col-md3",
              type: "selectTable",
              placeholder: "请选择费用项目",
              readonly: false,
              table: feetypeTable,
              tableWidth: 600,
              tableHeight: 400,
              fieldText: "feetypename",
              fieldValue: "feetypeid",
              name: "feetypeidList",
              label: "费用项目:<span class='dhxform_item_required'>*<span>",
              listener: {
                "init": function (Grid) {
                  // 注册按钮事件
                  Grid.attachToolBarEvent("onButtonClick", function (name) {
                    switch (name) {
                      case "querycarr":
                        var request = Grid.getToolBarForm().getFormData();
                        request.type = "02";
                        Grid.setParams(JSON.stringify(request));
                        Grid.reload();
                        break;
                      case "car_Reset":
                        Grid.getToolBarForm().clear();
                        break;
                    }
                  });
                },
                "afterSelect": function (state, selectId, grid) {
                  var rdata = grid.getRowData(selectId);
                  if (state) {
                    edit_form.setFormData({
                      feetypeid: rdata.feetypeid,
                      feetypecode: rdata.feetypecode,
                      feetypename: rdata.feetypename,
                      group1YesNo: rdata.group1,
                      group2YesNo: rdata.group2,
                      group3YesNo: rdata.group3,
                      group4YesNo: rdata.group4,
                      group5YesNo: rdata.group5
                    });
                    editGridInit(rdata);
                  }
                  else {
                    edit_form.setFormData({
                      feetypeid: "",
                      feetypecode: "",
                      feetypename: "",
                      group1YesNo: "",
                      group2YesNo: "",
                      group3YesNo: "",
                      group4YesNo: "",
                      group5YesNo: ""
                    });
                    $("#feeRules_edit_grid").html("");
                  }
                }
              }
            },
            { type: "hidden", name: "feetypeid", label: "费用项目id:" },
            { type: "hidden", name: "feetypecode", label: "费用项目编号:" },
            { type: "hidden", name: "feetypename", label: "费用项目名称:" },
            { type: "combo", name: "chargeType", label: "计费类型:", className: "layui-col-md3", readonly: true, options: dataSelect.CHARGE_TYPE },
            { type: "input", name: "memo", label: "备注:", className: "layui-col-md3" }
          ]
        },
        {
          type: "row",
          list: [
            { type: "checkbox", name: "group1YesNo", label: "启用分组1:", className: "layui-col-md3", disabled: true },
            { type: "checkbox", name: "group2YesNo", label: "启用分组2:", className: "layui-col-md3", disabled: true },
            { type: "checkbox", name: "group3YesNo", label: "启用分组3:", className: "layui-col-md3", disabled: true },
            { type: "checkbox", name: "group4YesNo", label: "启用分组4:", className: "layui-col-md3", disabled: true },
            { type: "checkbox", name: "group5YesNo", label: "启用分组5:", className: "layui-col-md3", disabled: true },
            {
              type: "block", className: "layui-col-md9 right",
              list: [
                { type: "button", className: "btn-normal", name: "editGrid_add", value: "<i class='layui-icon layui-icon-add-1'></i>新增" }
              ]
            }
          ]
        }
      ]
    };
    edit_form = new PlgForm(edit_form_opts);

    // 刷新数据
    if (params) {
      params.feetypeidList = JSON.stringify([params.feetypeid]);
      edit_form.setFormData(params);
      edit_form.setText("feetypeidList", params.feetypename);
    }
    else if (edit_grid) {
      edit_grid.clearAll(false)
      edit_grid.loadData({ data: { lst: [] } })
    }

    // 新增明细
    edit_form.attachEvent("onButtonClick", function (name) {
      if (name === "editGrid_add") {
        let id = new Date().getTime();
        let formData = edit_form.getFormData();
        if (!formData.feeRuleName) {
          layer.msg("请输入规则名称");
          return false;
        }
        if (!formData.feetypeid) {
          layer.msg("请选择费用项目");
          return false;
        }
        let rowData = {
          id: "",
          feeRuleName: formData.feeRuleName,
          feetypeid: formData.feetypeid,
          feetypecode: formData.feetypecode,
          feetypename: formData.feetypename,
          op: "删除^feeRules_editGrid_delete"
        };
        edit_grid.addRow(id, rowData);
      }
    });
  }

  // 注册表格 isEdit-是否编辑
  function editGridInit(params, isEdit) {
    $("#feeRules_edit_grid").html("");
    // 编辑表格
    var edit_grid_opts = {
      skin: "card",
      columns: [
        { id: "id", name: "id", type: "ro", width: "100", hidden: true },
        { id: "feetypecode", name: "费用项目编号", type: "ro", width: "100" },
        { id: "feetypename", name: "费用项目名称", type: "ro", width: "100" },
        { id: "businessgroupid1", name: params.group1 == "1" ? "<span style='color:#096dd9;'>分组1</span>" : "分组1", type: params.group1 == "1" ? "coro" : "ro", width: "100" }, // 4
        { id: "businessgroupid2", name: params.group2 == "1" ? "<span style='color:#096dd9;'>分组2</span>" : "分组2", type: params.group2 == "1" ? "coro" : "ro", width: "100" }, // 5
        { id: "businessgroupid3", name: params.group3 == "1" ? "<span style='color:#096dd9;'>分组3</span>" : "分组3", type: params.group3 == "1" ? "coro" : "ro", width: "100" }, // 5
        { id: "businessgroupid4", name: params.group4 == "1" ? "<span style='color:#096dd9;'>分组4</span>" : "分组4", type: params.group4 == "1" ? "coro" : "ro", width: "100" }, // 7
        { id: "businessgroupid5", name: params.group5 == "1" ? "<span style='color:#096dd9;'>分组5</span>" : "分组5", type: params.group5 == "1" ? "coro" : "ro", width: "100" }, // 8
        { id: "fromqty", name: "<span style='color:#096dd9;'>数量起</span>", type: "ed", width: "100" }, // 9
        { id: "toqty", name: "<span style='color:#096dd9;'>数量止</span>", type: "ed", width: "100" }, // 10
        { id: "price", name: "<span style='color:#096dd9;'>价格</span>", type: "ed", width: "100" }, // 11
        { id: "pricetype", name: "<span style='color:#096dd9;'>价格类型</span>", type: "coro", width: "100" }, // 12
        { id: "minusqty", name: "<span style='color:#096dd9;'>可免数量</span>", type: "ed", width: "100" }, // 13
        { id: "memo", name: "<span style='color:#096dd9;'>备注</span>", type: "ed", width: "150" }, // 14
        { id: "feetypeid", name: "费用id", type: "ro", width: "100", hidden: true },
        {
          id: "op", name: "操作", type: "button", align: "center", fixed: "right", width: 200, render: function () {
            return "删除^feeRules_editGrid_delete";
          }
        }
      ],
      fixedLast: true,

      url: UPCLOUD_RDC_TMS_BUSINESS_SERVICE+"/bmsFeeRule/queryBmsFeeRuleItem",//数据接口
      type: "post",//数据提交方式，默认为get
      contentType: "application/json",
      params: "{}",//查询提交参数，分页参数默认为pageNum,pageSize
      page: false, //是否启用分页
      totalCount: "totalCount", //总记录数字段，默认totalCount
      beforeLoadData: function (res) {
        //初始修改值，coro值不能为null
        res.data.forEach((item) => {
          item.businessgroupid1 = item.businessgroupid1 || "";
          item.businessgroupid2 = item.businessgroupid2 || "";
          item.businessgroupid3 = item.businessgroupid3 || "";
          item.businessgroupid4 = item.businessgroupid4 || "";
          item.businessgroupid5 = item.businessgroupid5 || "";
        });
        return res;
      }
    };
    edit_grid = new PlgGrid(edit_grid_opts);
    edit_grid.renderTo("feeRules_edit_grid");
    edit_grid.getGrid().enableEditEvents(true, false, true);

    // 下拉赋值
    let combo_4 = edit_grid.getGrid().getCombo(4);
    let combo_5 = edit_grid.getGrid().getCombo(5);
    let combo_6 = edit_grid.getGrid().getCombo(6);
    let combo_7 = edit_grid.getGrid().getCombo(7);
    let combo_8 = edit_grid.getGrid().getCombo(8);
    let combo_12 = edit_grid.getGrid().getCombo(12);
    dataSelect.PRICE_TYPE.forEach(v => {
      combo_12.put(v.value, v.text);
    });
    bmsFeeRuleGroupQuery({ feetypeid: params.feetypeid }).then(res => {
      console.log(res)
      if (params.group1) {
        res.group01.push({ value: "", text: "" });
        res.group01.forEach(v => {
          combo_4.put(v.value, v.text);
        });
      }
      if (params.group2) {
        res.group02.push({ value: "", text: "" });
        res.group02.forEach(v => {
          combo_5.put(v.value, v.text);
        });
      }
      if (params.group3) {
        res.group03.push({ value: "", text: "" });
        res.group03.forEach(v => {
          combo_6.put(v.value, v.text);
        });
      }
      if (params.group4) {
        res.group04.push({ value: "", text: "" });
        res.group04.forEach(v => {
          combo_7.put(v.value, v.text);
        });
      }
      if (params.group5) {
        res.group05.push({ value: "", text: "" });
        res.group05.forEach(v => {
          combo_8.put(v.value, v.text);
        });
      }
    });

    // 离开事件
    edit_grid.attachEvent("onEditCell", function (stage, rId, cInd, nValue) {
      if (stage == 2) {
        edit_grid.setCellValue(rId, cInd, nValue);
      }
      return true;
    });

    // 刷新
    if (isEdit) {
      edit_grid.setParams(JSON.stringify({ feeRuleId: params.feeRuleId }));
      edit_grid.reload();
    }
  }

  window.feeRules_editGrid_delete = function (rid) {
    let rdata = edit_grid.getRowData(rid);
    if (rdata.id) {
      bmsFeeRuleItemDelete([rdata]);
    }
    else {
      edit_grid.deleteRow(rid);
    }
  };

  // 删除
  function bmsFeeRuleItemDelete(params) {
    let pload = PlgDialog.load(2, { shade: [0.6, "#fff"] });
    Prolog.ajax({
      url: UPCLOUD_RDC_TMS_BUSINESS_SERVICE+"/bmsFeeRule/bmsFeeRuleItemDelete", type: "post", contentType: "application/json", data: JSON.stringify(params),
      success: function (res) {
        PlgDialog.close(pload);
        if (res.success) {
          PlgDialog.msg(res.message);
          edit_grid.reload();
          return true;
        }
                return false;

      }, error: function () { PlgDialog.close(pload); }
    });
  }

  // 获取分组字典
  function bmsFeeRuleGroupQuery(params) {
    return new Promise((resolve, reject) => {
      let pload = PlgDialog.load(2, { shade: [0.6, "#fff"] });
      Prolog.ajax({
        url: UPCLOUD_RDC_TMS_BUSINESS_SERVICE+"/bmsFeeRule/bmsFeeRuleGroupQuery", type: "post", contentType: "application/json", data: JSON.stringify(params),
        success: function (res) {
          PlgDialog.close(pload);
          if (res.success) {
            resolve(res.data);
            return true;
          }
                    reject();
          return false;

        }, error: function () { PlgDialog.close(pload); reject(); }
      });
    });
  }

  // 保存
  $("#feeRules_edit_saveBtn").on("click", function () {
    var feik = edit_form.validate();
    if (!feik) return false;

    let formData = edit_form.getFormData();
    delete formData.feetypeidList;

    let dataList = [];
    let indexNum = edit_grid.getGrid().getRowsNum();
    for (let i = 0; i < indexNum; i++) {
      const element = edit_grid.getRowData(edit_grid.getRowId(i));
      element.feeRuleName = formData.feeRuleName;
      delete element.op;
      dataList.push(element);
    }

    if (!dataList.length) {
      layer.msg("请添加明细");
      return false;
    }

    let url = formData.feeRuleId ? UPCLOUD_RDC_TMS_BUSINESS_SERVICE+"/bmsFeeRule/bmsFeeRuleUpdate" : UPCLOUD_RDC_TMS_BUSINESS_SERVICE+"/bmsFeeRule/bmsFeeRuleSave";
    let pload = PlgDialog.load(2, { shade: [0.6, "#fff"] });
    Prolog.ajax({
      url, type: "post", contentType: "application/json", data: JSON.stringify({ bmsFeeRuleVo: formData, list: dataList }),
      success: function (res) {
        PlgDialog.close(pload);
        if (res.success) {
          PlgDialog.msg(res.message);
          changePanel("#feeRules_main");
          master_grid.reload();
          details_grid.clearAll();
          return true;
        }
                return false;
      }, error: function () { PlgDialog.close(pload); return false; }
    });
  });
};