//page/index/index.js
var qcloud = require('../../vendor/wafer2-client-sdk/index')
var util = require('../../utils/util.js')
var config = require('../../config')
var WXB_SESSION_LOGIN_DATA = 'weapp_session_login_data';
var app = getApp();
Page({
/**
* 页面的初始数据
*/
data: {
pageNum: 1,
pageSize: 5,
totalPages: 0,
totalSize: 0,
mobileList:[],//通话记录
followRecord: [],
customerSourceList: [],//客户轨迹
"customerId": "",
"agentId": "",
barList: ['跟进记录', '资料信息', '用户轨迹', '通话记录'],
barIndex: 0,
data:{},
iszhezhao: false,
iscall: false,
stars: [{
lightImg: '/images/index/index12.png',
blackImg: '/images/index/index13.png',
flag: 1,
message: 'A',
level: 1
}, {
lightImg: '/images/index/index12.png',
blackImg: '/images/index/index13.png',
flag: 1,
message: 'B',
level: 2
}, {
lightImg: '/images/index/index12.png',
blackImg: '/images/index/index13.png',
flag: 1,
message: 'C',
level: 3
}, {
lightImg: '/images/index/index12.png',
blackImg: '/images/index/index13.png',
flag: 1,
message: 'D',
level: 4
}],
type: 1,
isPlayAudio: false,
innerAudioContext: undefined,
pone1: "",
},
// 意向级别
starClick: function () {
var that = this;
for (var i = 0; i < that.data.stars.length; i++) {
var allItem = 'stars[' + i + '].flag';
that.setData({
[allItem]: 1
})
}
var level = this.data.data.level;
level = level -1;
for (var i = 0; i <= level; i++) {
var item = 'stars[' + i + '].flag';
that.setData({
[item]: 2
})
}
},
clickBar: function(e) {
var index = e.currentTarget.dataset.index;
this.setData({
barIndex: index,
pageNum: 1,
pageSize: 9,
totalPages: 0,
totalSize:0,
})
if (index==0){
this.followRecord(1);
this.clear();
}
if (index==1){
this.clear();
}
if (index==2){
this.clear();
this.findCustomerSourcePage(1);
}
if (index==3){
this.findMobileList(1);
}
},
onLoad(e){
this.setData({
customerId: e.customerid,
agentId: e.agentid,
type: e.type,
});
},
onShow(){
if (this.data.type == 1) {
wx.setNavigationBarTitle({
title: '线索详情'
})
}
if(this.data.type==2){
wx.setNavigationBarTitle({
title: '客户详情'
})
}
this.findCustomerDetail({ "customerId": this.data.customerId, "agentId": this.data.agentId });
this.followRecord(1);
},
//客户详情
findCustomerDetail: function (param) {
var that = this;
util.getRequestPromise(config.service.findCustomerDetail,param).then(data => {
let result = data ? data : [];
var pone1 = util.hiddenString(result.phone, 3, 4);
that.setData({
data: result,
pone1: pone1,
});
that.starClick();
});
},
// 打开呼叫
opencall: function(e) {
var that = this;
this.setData({
iscall: true,
})
},
// 关闭呼叫
closecall: function(e) {
this.setData({
iscall: false,
})
},
//直接呼叫
callPhone1:function(e){
var that = this;
wx.makePhoneCall({
phoneNumber: that.data.data.phone,
success:function(){
that.closecall();
}
})
},
//虚拟号拨号
callPhone2:function(e){
var that =this;
var opencall_customerId = that.data.data.customerId;
//获取虚拟接口
var param = {
"customerId":opencall_customerId
};
util.getRequestPromise(config.service.getVirtualMobile, param)
.then(data => {
let result = data ? data : [];
wx.makePhoneCall({
phoneNumber: result,
success:function(){
that.closecall();
}
})
});
},
//跟进记录
// followRecord: function (param) {
// var that = this;
// util.getRequestPromise(config.service.followUp,param).then(data => {
// let result = data ? data : [];
// that.setData({
// followRecord: data.content,
// pageNum: data.pageNum,
// pageSize: data.pageSize,
// totalPages: data.totalPages,
// totalSize: data.totalSize,
// });
// });
// },
//跟进记录
followRecord: function (pageNum) {
var that = this;
var followUp = [];
var param = {};
param.pageNum = pageNum;
param.pageSize = that.data.pageSize;
param.query = { "customerId": this.data.customerid, "createBy": this.data.agentid };
console.log(param);
util.getRequestPromise(config.service.followUp, param).then(data => {
let result = data ? data : [];
var followRecord = result.content;
var totalPages = result.totalPages;
var pageNum = result.pageNum;
var totalSize = result.totalSize;
if (pageNum == 1) {//查询第一页的不进行数据累加
that.setData({
totalPages: totalPages,
followRecord: followRecord,
pageNum: pageNum,
totalSize: totalSize,
});
} else {
var resList = that.data.followRecord.concat(followRecord);
that.setData({
totalPages: totalPages,
followRecord: resList,
pageNum: pageNum,
});
}
});
},
//新增记录
// goNewPerfectInformation: function (param) {
// var customerId = this.data.customerId;
// wx.navigateTo({
// url: '/pages/newPerfectInformation/newPerfectInformation',
// })
// },
//新增记录
followRecordAdd: function (param) {
var customerId = this.data.customerId;
wx.navigateTo({
url: '/pages/newFollowup/newFollowup?customerId=' + customerId,
})
},
//通话记录
findMobileList: function (pageNum) {
var that = this;
var followUp = [];
var param = {};
param.pageNum = pageNum;
param.pageSize = that.data.pageSize;
param.query = { "seqId": this.data.data.id};
console.log(param);
util.getRequestPromise(config.service.getMobileList, param).then(data => {
let result = data ? data : [];
var mobileList = result.content;
if (mobileList != null) {
for (var i = 0; i < mobileList.length; i++) {
var item = mobileList[i];
item.longTime = util.formatLongTime(item.callEnd - item.callAnswer );
}
}
var totalPages = result.totalPages;
var pageNum = result.pageNum;
var totalSize = result.totalSize;
if (pageNum == 1) {//查询第一页的不进行数据累加
that.setData({
totalPages: totalPages,
mobileList: mobileList,
pageNum: pageNum,
totalSize: totalSize,
});
} else {
var resList = that.data.mobileList.concat(mobileList);
that.setData({
totalPages: totalPages,
mobileList: resList,
pageNum: pageNum,
});
}
});
},
//轨迹
findCustomerSourcePage: function (pageNum) {
var that = this;
var followUp = [];
var param = {};
param.pageNum = pageNum;
param.pageSize = that.data.pageSize;
param.query = { "seqId": this.data.data.id};
console.log(param);
util.getRequestPromise(config.service.findCustomerSourcePage, param).then(data => {
let result = data ? data : [];
var customerSourceList = result.content;
// if (customerSourceList != null) {
// // for (var i = 0; i < mobileList.length; i++) {
// // var item = mobileList[i];
// // item.longTime = util.formatLongTime(item.callEnd - item.callAnswer );
// // }
// }
var totalPages = result.totalPages;
var pageNum = result.pageNum;
var totalSize = result.totalSize;
if (pageNum == 1) {//查询第一页的不进行数据累加
that.setData({
totalPages: totalPages,
customerSourceList: customerSourceList,
pageNum: pageNum,
totalSize: totalSize,
});
} else {
var resList = that.data.customerSourceList.concat(customerSourceList);
that.setData({
totalPages: totalPages,
customerSourceList: resList,
pageNum: pageNum,
});
}
});
},
//上拉加载
onReachBottom: function () {
var that = this;
var pageNum = that.data.pageNum;
var pageNum2 = pageNum + 1;
var totalPages = that.data.totalPages;
if (this.data.barIndex == 0 && pageNum2 <= totalPages) {
that.followRecord(pageNum2);
}
if (this.data.barIndex == 2 && pageNum2 <= totalPages) {
that.findCustomerSourcePage(pageNum2);
}
if (this.data.barIndex == 3 && pageNum2 <= totalPages) {
that.findMobileList(pageNum2);
}
},
//下拉刷新
onPullDownRefresh: function () {
var that = this;
if(this.data.barIndex == 0){
this.followRecord(1);
}
if (this.data.barIndex == 2) {
this.findCustomerSourcePage(1);
}
if (this.data.barIndex == 3) {
this.findMobileList(1);
}
wx.stopPullDownRefresh();
},
//完善资料
goNewPerfectInformation:function(){
wx.navigateTo({
url: '/pages/customer/input/index/index',
})
},
playAudio: function(e){
var idx = e.currentTarget.dataset.idx;
var voiceurl = e.currentTarget.dataset.voiceurl;
if (voiceurl == "" || voiceurl == undefined){
util.showNone('录音正在生成中,建议三分钟后重试~');
return;
}
if (this.data.innerAudioContext != undefined ){
this.data.innerAudioContext.destroy();
}
var innerAudioContext = wx.createInnerAudioContext();
innerAudioContext.src = voiceurl;
this.setData({
isPlayAudio: !this.data.isPlayAudio,
idx: idx,
innerAudioContext: innerAudioContext,
});
innerAudioContext.play();
innerAudioContext.onPlay(() => {
console.log('开始播放')
})
innerAudioContext.onError((res) => {
console.log(res.errMsg)
console.log(res.errCode)
})
},
stop(e){
this.data.innerAudioContext.stop();
this.setData({
isPlayAudio: !this.data.isPlayAudio,
});
},
clear(){
if (this.data.innerAudioContext != undefined) {
this.data.innerAudioContext.destroy();
}
this.setData({
isPlayAudio: !this.data.isPlayAudio,
});
},
onUnload(){
this.clear();
}
})