你可以在现有的代码中,调整 self.getContactInfoGridsettings
方法,使其在点击“上一步”和“下一步”按钮时都会重新调用接口并更新参数。以下是修改后的代码示例:
self.getContactInfoGridSettings = ggNamespace.functions.WorkPage_getContactInfoGridSettings;
// 统一的方法来获取联系人信息
function updateContactInfo() {
self.contactPhones = new ContactPhonePanel({
custId: allData[currentIndexs].customerId,
queue: self.queue,
complaintPhone: self.complaintPhone,
complaintPhoneNew: self.complaintPhoneNew,
complaintUsername: self.complaintUsername,
complaintRelation: self.complaintRelation,
auto: self.auto,
callPhone: (phoneNum, customerId) => self.header.callPhone(phoneNum, customerId)
});
// 调用获取设置的方法
self.getContactInfoGridsettings();
}
self.lastButton.addClickHandler(function() {
if (currentIndexs > 0) {
currentIndexs--;
} else {
currentIndexs = allData.length - 1;
}
updateContactInfo(); // 更新联系人信息
});
self.nextButton.addClickHandler(function() {
if (currentIndexs < allData.length - 1) {
currentIndexs++;
} else {
currentIndexs = 0;
}
updateContactInfo(); // 更新联系人信息
});
ggNamespace.functions.WorkPage.getContactInfoGridsettings = function() {
const me = this;
let settings;
const columns = [];
settings = {
columns: columns,
processing: true,
serverSide: true,
ajax: {
url: '../d/detail/contacts',
contentType: 'application/json',
type: 'POST',
lang: defLanguage,
complete: function() {
me.contacts = {
contactPersons: {},
contactNumbers: {},
contactIndexs: {},
ptpCode: 'promiseToPay',
callbackCode: 'callbackRequest',
contactPersonIds: {}
};
me.mobileContacts = {
contactPersons: {},
contactNumbers: {},
contactPersonIds: {}
};
me.phoneNumbers = {};
me.detailAddresses = {};
me.phoneNumberIndexes = {};
me.phoneNumberIndexesForSms = {};
me.contactPersonAddresses = {};
const selfPhoneNumberArr = [];
var result = me.contactPhones.contactInfo.getRecords();
}
}
};
return settings;
};
修改说明:
- 抽取方法:创建了一个名为
updateContactInfo
的方法,用于处理更新联系人的逻辑,避免代码重复。 - 按钮事件:在上一步和下一步按钮的点击事件中,调用
updateContactInfo()
来重新赋值参数并触发数据更新。
这样做后,当用户点击“上一步”或“下一步”按钮时,相关的联系人信息将会被重新加载并更新。
内容由零声教学AI助手提供,问题来源于学员提问