2021-10-10 15:10:11 +08:00

141 lines
5.4 KiB
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

import BaseRoute from '../base';
export default BaseRoute.extend({
queryParams: {
campaignId: {
refreshModel: true
}
},
model(params) {
return this.get('service').ajaxGet('summary', params);
},
afterModel(model) {
this.set('breadcrumbs',
[{route: 'campaign.list', text: '呼叫活动列表'},
{text: '呼叫活动[' + model.campaign.name + ']拨打名单管理'}]);
},
actions: {
closeDialog() {
this.get('controller').setProperties({
showDialog: false
});
},
importPrepared(it) {
const me = this;
me.get('controller').setProperties({
preparedItem: it,
'model.limit': it.ready > 1000 ? 1000 : it.ready,
'model.dailyFrom': '09:30',
'model.dailyTo': '12:00',
showDialog: true,
dialogTitle: '导入行方投放数据',
dialogSubmitAction: 'doImportPrepared'
});
},
doImportPrepared() {
const me = this;
const controller = me.get('controller');
const preparedItem = controller.get('preparedItem');
const params = me.getDialogParams(preparedItem)
params.insertBatchKey = preparedItem.insertBatchKey;
me.get('dialog').confirm('确认要导入' + params.limit + '条新数据到呼叫拨打列表吗?', () => {
me.get('service').ajaxPost('import-prepared', params).then((rows) => {
me.get('message').alert('导入成功,数量:' + rows);
controller.set('showDialog', false);
me.refresh();
});
});
},
importHistorical(historical) {
const me = this;
me.get('controller').setProperties({
'model.limit': historical.ready > 1000 ? 1000 : historical.ready,
'model.dailyFrom': '13:30',
'model.dailyTo': '15:00',
'model.lastDialDate': historical.lastDialDate,
'model.putInDate': historical.putInDate,
showDialog: true,
dialogTitle: '导入历史数据',
dialogSubmitAction: 'doImportHistorical'
});
},
doImportHistorical() {
const me = this;
const controller = me.get('controller');
const params = me.getDialogParams(controller.get('model'))
me.get('dialog').confirm('确认要导入' + params.limit + '条历史数据到呼叫拨打列表吗?', () => {
me.get('service').ajaxPost('import-historical', params).then((rows) => {
me.get('message').alert('导入成功,数量:' + rows);
controller.set('showDialog', false);
me.refresh();
});
});
},
redial(arg) {
const me = this;
console.log('Redial campaign:', arg);
me.get('dialog').confirm('确认要重呼4小时前未接通拨打名单吗', () => {
me.get('service').ajaxPost('redial', arg).then(count => {
me.get('message').alert('重呼成功,重呼数据量: ' + count);
me.refresh();
});
});
},
revert(arg) {
const me = this;
console.log('Revert campaign:', arg);
me.get('dialog').confirm('确认要撤回未拨打名单吗?', () => {
me.get('service').ajaxPost('revert', arg).then(count => {
me.get('message').alert('撤回成功,撤回数据量: ' + count);
me.refresh();
});
});
},
fetchRemote(campaignId) {
const me = this;
console.log('Fetch campaign:', campaignId);
me.get('dialog').confirm('确认要拉取拨打名单吗?', () => {
me.get('service').ajaxPost('fetch-remote', {campaignId}).then(count => {
me.get('message').alert('拉取成功,拉取数据量: ' + count);
me.refresh();
});
});
}
},
getDialogParams(data) {
const me = this;
const controller = me.get('controller');
const model = controller.get('model');
const params = {
limit: model.limit,
dailyFrom: model.dailyFrom,
dailyTo: model.dailyTo,
putInDate: model.putInDate,
lastDialDate: model.lastDialDate
};
if (params.limit < 1) {
me.get('message').warn('数量不能小于1');
return;
}
if (params.limit > data.ready) {
me.get('message').warn('数量不能大于数据源就绪量' + data.ready);
return;
}
const timePattern = /^([01]?[0-9]|2[0-3]):([0-5]?[0-9])(:[0-5]?[0-9])?$/;
if (!timePattern.test(params.dailyFrom)) {
me.get('message').warn('开始时间不是有效时间格式');
return;
}
if (!timePattern.test(params.dailyTo)) {
me.get('message').warn('结束时间不是有效时间格式');
return;
}
params.campaignId = controller.get('campaignId');
return params;
}
});