function PowerPackageComponent(option) {
var _el = option.el;
var _packages = option.packages;
var _price = option.price;
var app = this.app = new Vue({
el: _el,
template: `
`
,
data: {
info: {
dialogIndex: 0,
dialogOpen: false,
dialogData: {},
price: 1,
packages: []
},
},
mounted: function () {
var that = this
that.initPackages();
},
computed: {},
filters: {},
methods: {
initPackages: function () {
this.info.packages = _packages;
this.info.price = _price;
},
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 tnArray = ['取消', '确认'];
mui.confirm('确定要删除该套餐?', '温馨提示', tnArray, function (e) {
if (e.index == 0) {
} else {
//点击确认业务
that.info.packages.splice(index, 1);
}
});
},
closeRulePanel: function () {
this.info.dialogOpen = false;
$("body").removeClass("over-hide");//恢复body滚动
},
savePackageRule: function () {
var dialogData = this.info.dialogData;
var packages = this.info.packages
if ($.trim(dialogData.min) == '') {
mui.toast("最小功率不能为空");
return;
}
if ($.trim(dialogData.max) == '') {
mui.toast("最大功率不能为空");
return;
}
var dialogIndex = this.info.dialogIndex;
if (dialogIndex >= 1) {
var prvItem = packages[dialogIndex-1];
if (dialogData.min < prvItem.max) {
mui.toast("最小功率必须大于上一个配置的最大功率");
return;
}
}
if (dialogIndex < (packages.length - 1)) {
var lastItem = packages[dialogIndex + 1];
if (dialogData.max > lastItem.min) {
mui.toast("最大功率必须大于上一个配置的最小功率");
return;
}
}
if (dialogData.min >= dialogData.max) {
mui.toast("最大功率必须大于最小功率");
return;
}
if ($.trim(dialogData.price) == '') {
mui.toast("价格不能为空");
return;
}
this.info.packages[this.info.dialogIndex] = $.extend(true, {}, this.info.dialogData);
this.info.dialogOpen = false;
$("body").removeClass("over-hide");//恢复body滚动
},
addPackageRule: function () {
this.info.dialogIndex = this.info.packages.length;
this.info.dialogOpen = true;
$("body").addClass("over-hide");//避免滚动穿透,直接禁止body滚动
this.info.dialogData = {
};
},
}
});
}
PowerPackageComponent.prototype.getPackages = function () {
return this.app.info.packages;
};
PowerPackageComponent.prototype.getPrice = function () {
return this.app.info.price;
};
function PowerPackageComponent2(option) {
var _el = option.el;
var _packages = option.packages;
var _price = option.price;
var app = this.app = new Vue({
el: _el,
template: `
`
,
data: {
info: {
dialogIndex: 0,
dialogOpen: false,
dialogData: {},
price: 1,
packages: []
},
},
mounted: function () {
var that = this
that.initPackages();
},
computed: {},
filters: {},
methods: {
initPackages: function () {
this.info.packages = _packages;
this.info.price = _price;
},
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 tnArray = ['取消', '确认'];
mui.confirm('确定要删除该套餐?', '温馨提示', tnArray, function (e) {
if (e.index == 0) {
} else {
//点击确认业务
that.info.packages.splice(index, 1);
}
});
},
closeRulePanel: function () {
this.info.dialogOpen = false;
$("body").removeClass("over-hide");//恢复body滚动
},
savePackageRule: function () {
var dialogData = this.info.dialogData;
if ($.trim(dialogData.max) == '') {
mui.toast("起始时间不能为空");
return;
}
if ($.trim(dialogData.min) == '') {
mui.toast("结束不能为空");
return;
}
if ($.trim(dialogData.price) == '') {
mui.toast("价格不能为空");
return;
}
this.info.packages[this.info.dialogIndex] = $.extend(true, {}, this.info.dialogData);
this.info.dialogOpen = false;
$("body").removeClass("over-hide");//恢复body滚动
},
addPackageRule: function () {
this.info.dialogIndex = this.info.packages.length;
this.info.dialogOpen = true;
$("body").addClass("over-hide");//避免滚动穿透,直接禁止body滚动
this.info.dialogData = {
};
},
}
});
}
PowerPackageComponent2.prototype.getPackages = function () {
return this.app.info.packages;
};
PowerPackageComponent2.prototype.getPrice = function () {
return this.app.info.price;
};