function PackageComponent(option) {
var _el = option.el;
var _rule = option.policy.rule;
var _money = option.policy.money;
var _auto_stop = option.policy.auto_stop;
var _type = option.policy.type;
var app = this.app = new Vue({
el: _el,
template: `
`
,
data: {
info: {
type: 'time',
dialogIndex: 0,
dialogOpen: false,
dialogData: {},
rule: {
prices:[],
},
money: 0,
auto_stop: false,
},
},
mounted: function () {
var that = this
that.initPackages();
},
computed: {},
filters: {},
methods: {
save_obj() {
if (this.info.type === 'time') {
delete this.info.rule.price
} else if (this.info.type === 'elec') {
delete this.info.rule.prices
delete this.info.rule.time
} else if (this.info.type === 'count') {
this.info.type = 'elec'
delete this.info.rule.prices
}
console.log('this.info.type111', this.info.type)
console.log('this.info', this.info)
},
initPackages: function () {
this.info.type = _type;
this.info.auto_stop = _auto_stop;
this.info.money = _money;
this.info.rule = _rule;
},
getDefaultPolicyDialog() {
return {
"power": '',
"price": ''
}
},
addPolicyRule() {
this.info.dialogIndex = (this.info.rule.prices || []).length;
this.info.dialogOpen = true;
$("body").addClass("over-hide");
this.info.dialogData = this.getDefaultPolicyDialog();
},
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 packages = info.rule.prices
if (info.type === 'elec') {
if (packages.length <= 1) {
mui.toast("必须有一条配置");
return
}
}
info.rule.prices.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
if (info.type == 'time') {
packages = this.info.rule.prices || []
}
if (info.type === 'time') {
if ($.trim(dialogData.power) === '') {
mui.toast("功率不能为空");
return;
}
if (!dialogData.price) {
mui.toast("价格不能为空");
return;
}
}
if (info.type === 'elec') {
if ($.trim(dialogData.power) === '') {
mui.toast("功率不能为空");
return;
}
if (!dialogData.price) {
mui.toast("价格不能为空");
return;
}
}
if (info.chrmt === 'ELEC') {
if (!dialogData.elec) {
mui.toast("电量不能为空");
return;
}
}
console.log('info.dialogIndex', info.dialogIndex)
console.log('packages', packages)
packages[info.dialogIndex] = $.extend(true, {}, info.dialogData);
this.info.rule.prices = packages
info.dialogOpen = false;
$("body").removeClass("over-hide");//恢复body滚动
},
addPackageRule: function () {
var that = this;
var info = that.info
var key = 'package_' + info.chrmt.toLowerCase()
var packages = info[key]
if (key === 'package_elec') {
if (packages.length >= 1) {
mui.toast("只能有一条配置");
return
}
}
info.dialogIndex = packages.length;
info.dialogOpen = true;
$("body").addClass("over-hide");//避免滚动穿透,直接禁止body滚动
if (info.chrmt === 'TIME') {
info.dialogData = {
power: "",
time: "",
};
}
if (info.chrmt === 'ELEC') {
info.dialogData = {
price: "1",
elec: "",
};
}
if (info.chrmt === 'POWER') {
info.dialogData = {
power: "",
time: "",
};
}
},
powerRadio(item, index, obj) {
return ((obj[index - 1] && obj[index - 1].power) || 0) + "W-" + item.power + "W"
},
}
});
}
PackageComponent.prototype.getPolicyTemp = function () {
return {
"money": this.app.info.money,
"type": this.app.info.type,
"rule": this.app.info.rule,
"auto_stop": this.app.info.auto_stop
}
};
function VolumeComponent(option) {
var _el = option.el;
var _packages = option.packages;
var _volume = option.volume;
var app = this.app = new Vue({
el: _el,
template: `
`
,
data: {
info: {
dialogIndex: 0,
dialogOpen: false,
dialogData: {},
volume: 1,
packages: []
},
},
mounted: function () {
var that = this
that.initPackages();
},
computed: {},
filters: {},
methods: {
initPackages: function () {
this.info.packages = _packages;
this.info.volume = _volume;
},
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;
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.start) === '') {
mui.toast("开始时间不能为空");
return;
}
if ($.trim(dialogData.end) === '') {
mui.toast("结束时间不能为空");
return;
}
if (dialogData.volume === '') {
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 = {
start: "",
end: "",
volume: "",
};
},
}
});
}
VolumeComponent.prototype.getVolumeList = function () {
return this.app.info.packages;
};
VolumeComponent.prototype.getDefaultVolume = function () {
return this.app.info.volume;
};