function ChargeTypeComponent(option) { var _el = option.el; var _chargeType = option.chargeType; var _powerPackage = option.powerPackage; var _elecPackage = option.elecPackage; var _billAsServicePackage = option.billAsServicePackage; var app = this.app = new Vue({ el: _el, template: `
计费模式设置 ?
编辑 删除
添加
取消 确认
` , data: { info: { chargeType: 'time', dialogIndex: 0, dialogOpen: false, dialogData: {}, powerPackage: [], elecPackage: [], billAsServicePackage: [], }, }, mounted: function () { var that = this; that.initPackages(); }, computed: {}, filters: {}, methods: { initPackages: function () { this.info.chargeType = _chargeType; this.info.powerPackage = _powerPackage; this.info.elecPackage = _elecPackage; this.info.billAsServicePackage = _billAsServicePackage; }, editPackageRule: function (obj, index) { this.info.dialogIndex = index; this.info.dialogOpen = true; this.info.dialogData = $.extend(true, {}, obj); $("body").addClass("over-hide");//避免滚动穿透,直接禁止body滚动 }, deletePackageRule: function (obj, index) { var that = this; var info = that.info; var key = info.chargeType + 'Package'; var packages = info[key]; if (key === 'elecPackage' || key === 'powerPackage') { if (packages.length <= 1) { mui.toast("无法删除"); return } } info[key].splice(index, 1); }, closeRulePanel: function () { this.info.dialogOpen = false; $("body").removeClass("over-hide");//恢复body滚动 }, savePackageRule: function () { var that = this; var info = that.info; var dialogData = info.dialogData; var packages = info[info.chargeType + 'Package']; if (info.chargeType === 'elec') { if (!dialogData.price) { mui.toast("电量计费价格不能为空"); return; } } if (info.chargeType === 'power') { if (dialogData.lowLimit === "") { mui.toast("功率范围下限不能为空"); return; } if (dialogData.upLimit === "") { mui.toast("功率范围上限不能为空"); return; } if (!dialogData.price) { mui.toast("价格不能为空"); return; } if (dialogData.lowLimit * 1 > dialogData.upLimit * 1) { mui.toast("功率范围上限不得小于功率范围下限"); return; } } packages[info.dialogIndex] = $.extend(true, {}, info.dialogData); info.dialogOpen = false; $("body").removeClass("over-hide");//恢复body滚动 }, addPackageRule: function () { var that = this; var info = that.info; var key = info.chargeType + 'Package'; var packages = info[key]; info.dialogIndex = packages.length; info.dialogOpen = true; $("body").addClass("over-hide");//避免滚动穿透,直接禁止body滚动 // 只有功率的会存在多档的情况 其余的暂时不考虑 if (info.chargeType === "power") { info.dialogData = {lowLimit: "", upLimit: "", price: ""} } }, } }); } // 获取获取功率计费 ChargeTypeComponent.prototype.getPowerPackage = function () { return this.app.info.powerPackage; }; // 获取电量单价 ChargeTypeComponent.prototype.getElecPrice = function () { return this.app.info.elecPackage[0].price; }; // 获取计费方式 ChargeTypeComponent.prototype.getChargeType = function () { return this.app.info.chargeType; }; // 获取服务费(电量)模式 ChargeTypeComponent.prototype.getBillAsServicePackage = function () { return this.app.info.billAsServicePackage[0]; };