Files
lichebao/pages/customer/index.js
T
2022-03-09 17:21:34 +08:00

652 lines
14 KiB
JavaScript

import _ from '../../commons/js/commons'
import popularData from '../../commons/js/lib/popularData';
const app = getApp()
Page({
data: {
key:'',//tab状态值
list: [],//客户列表
pageNo: 1,
noData: false,
end: false,
load: true,
loading: false,
flag:1,
cus_id:'',//客户编号
name:'',//名字
mobile:'',//手机号
s_time:'',//开始时间
e_time:'',//结束时间
if_driver:'',//是否试驾
level:'',//客户顶级
brand_id:'',//品牌
s_id:'',//车型id
v_id:'',//车型级别id
cfrom:'',//客户来源
o_type:'',//排序类型
isShowfilter:false,//是否显示筛查
timeSlotIndex:-1,//常用时间索引
timeSlot:[//常用时间数组
{
title:'今天',
},
{
title:'昨天',
},
{
title:'近七天',
},
{
title:'近三十天',
},
],
testDriveIndex:-1,//是否试驾索引
testDrive:[//是否试驾数组
{
title:'全部',
},
{
title:'是',
},
{
title:'否',
},
],
sortList:['建卡日期','最近联系','特别关注',],//排序数组
sortListIndex:0,//排序索引
levelIndex:-1,//意向等级索引
brandIndex:-1,//车辆品牌索引
modelIndex:-1,//车型车系索引
cfromIndex:-1,//客户来源索引
isShowMessage:false,//是否显示短信弹窗
content:'',//短信内容
isRefresh:false,//判断返回是否需要刷新
isShowMobile: false,
staffArray: [],
staffobj: [],
staffIndex:-1,
userInfo:app.getStorageByKey("userInfo"),
of_id:'',
of2_id:'',
of1Index:-1,
of2Index:-1,
},
onLoad(options) {
for (let key in options) {
this.setData({
[key]: options[key]
})
}
this.getAppCustomersTabs()
this.getAppCustomersFilter()
this.getAppSeriesBrands()
this.getAppUserAdmins()
this.getAppCustomersOffline_sources()
},
onShow(){
this.getDateLater()
},
//客户-tab
getAppCustomersTabs() {
_.apiQuery.getAppCustomersTabs().then(res => {
this.setData({
tab:res.data,
key:this.data.key==''?res.data[0].key:this.data.key,
})
this.getAppCustomersList()
wx.stopPullDownRefresh()
});
},
//获取销售顾问
getAppUserAdmins(){
let params = {};
params['page'] = 1;
params['size'] = 1000;
_.apiQuery.getAppUserAdmins(params).then(res => {
let staffArray = []
res.data.list.forEach(item => {
staffArray.push(item.uname)
})
this.setData({
staffArray:staffArray,
staffobj: res.data.list,
})
});
},
//切换tab
changeTab(e){
this.setData({
key: this.data.tab[e.currentTarget.dataset.index].key,
})
this.searchSubmit()
},
// 显示弹框
showMobileMsg(){
this.setData({
isShowMobile: true
})
},
//获取列表筛选条件
getAppCustomersFilter(){
_.apiQuery.getAppCustomersFilter().then(res => {
this.setData({
filter:res.data,
})
});
},
//获取车型品牌
getAppSeriesBrands(){
_.apiQuery.getAppSeriesBrands().then(res => {
if(res.data.list.length>0){
let brandArray = []
res.data.list.forEach(item => {
brandArray.push(item.name)
})
this.setData({
brandArray:brandArray,
brandList:res.data.list,
})
}
});
},
//获取车型车系
getAppSeries(){
let params = {};
params['brand_id'] = this.data.brand_id;
_.apiQuery.getAppSeries(params).then(res => {
if(res.data.list.length>0){
let modelArray = []
res.data.list.forEach(item => {
modelArray.push(item.name)
})
this.setData({
modelArray:modelArray,
modelList:res.data.list,
})
}
});
},
//选择人员
changeStaff(e) {
this.setData({
staffIndex: e.detail.value
})
},
//获取客户列表
getAppCustomersList() {
this.setData({
load: false,
loading: true,
})
let params = {};
params['page'] = this.data.pageNo;
params['size'] = 10;
params['status'] = this.data.key;
if(this.data.cus_id != ''){
params['cus_id'] = this.data.cus_id;
}
if(this.data.name != ''){
params['name'] = this.data.name;
}
if(this.data.mobile != ''){
params['mobile'] = this.data.mobile;
}
if(this.data.s_time != ''){
params['s_time'] = this.data.s_time;
}
if(this.data.e_time != ''){
params['e_time'] = this.data.e_time;
}
if(this.data.if_driver != ''){
params['if_driver'] = this.data.if_driver;
}
if(this.data.level != ''){
params['level'] = this.data.level;
}
if(this.data.brand_id != ''){
params['brand_id'] = this.data.brand_id;
}
if(this.data.s_id != ''){
params['s_id'] = this.data.s_id;
}
if(this.data.v_id != ''){
params['v_id'] = this.data.v_id;
}
if(this.data.cfrom != ''){
params['cfrom'] = this.data.cfrom;
}
if(this.data.o_type != ''){
params['o_type'] = this.data.o_type;
}
if(this.data.of_id != ''){
params['of_id'] = this.data.of_id;
}
if(this.data.of2_id != ''){
params['of2_id'] = this.data.of2_id;
}
if(this.data.staffIndex>-1){
params['admin_id'] = this.data.staffobj[this.data.staffIndex].id;
}
_.apiQuery.getAppCustomersList(params).then(res => {
this.setData({
flag: this.data.flag - 1
})
if (!this.data.flag) {
this.setData({
total: res.data.total,
pageNo: this.data.pageNo + 1,
list: this.data.list.concat(res.data.list),
load: true,
loading: false,
})
if (res.data.total == 0) {
this.setData({
noData: true
})
} else if (this.data.list.length == res.data.total) {
this.setData({
end: true
})
}
}
wx.stopPullDownRefresh()
});
},
//置顶操作
optTop(e){
let params = {};
params['id'] = this.data.list[e.currentTarget.dataset.index].id;
params['is_top'] = this.data.list[e.currentTarget.dataset.index].is_top==1?0:1;
_.apiQuery.putAppCustomers(params).then(res=>{
this.setData({
['list['+e.currentTarget.dataset.index+'].is_top']:this.data.list[e.currentTarget.dataset.index].is_top==1?0:1,
})
})
},
//候取常用时间段
getDateLater(){
popularData.getDateLater(0,0).then(res => {
this.setData({
today:res,
})
})
popularData.getDateLater(1,0).then(res => {
this.setData({
tomorrow:res,
})
})
popularData.getDateLater(0,6).then(res => {
this.setData({
last7:res,
})
})
popularData.getDateLater(0,29).then(res => {
this.setData({
last30:res,
})
})
},
//拨打客户电话xz
call(e) {
let params = {};
params['id'] = e.currentTarget.dataset.id;
params['type'] = 0;
_.apiQuery.getAppXz(params).then(res=>{
wx.makePhoneCall({
phoneNumber: res.data.mobile,
})
})
},
//提交搜索
searchSubmit(){
this.setData({
list: [],
pageNo: 1,
noData: false,
end: false,
load: true,
loading: false,
flag: this.data.flag + 1
})
this.getAppCustomersList()
},
//排序方式
changeSortList(e){
let o_type = ''
if(e.detail.value == 0){
o_type = 1
}else if(e.detail.value == 1){
o_type = 2
}
this.setData({
o_type: o_type,
sortListIndex: e.detail.value,
})
this.searchSubmit()
},
//建卡时间
startDate(e){
this.setData({
s_time: e.detail.value,
})
this.matchDate()
},
//建卡时间
endDate(e){
this.setData({
e_time: e.detail.value,
})
this.matchDate()
},
//匹配选择时间是否等于常用时间
matchDate(){
this.setData({
timeSlotIndex:-1,
})
if(this.data.s_time == this.data.today[0] && this.data.e_time == this.data.today[1] ){
this.setData({
timeSlotIndex:0,
})
}
if(this.data.s_time == this.data.tomorrow[0] && this.data.e_time == this.data.tomorrow[1] ){
this.setData({
timeSlotIndex:1,
})
}
if(this.data.s_time == this.data.last7[0] && this.data.e_time == this.data.last7[1] ){
this.setData({
timeSlotIndex:2,
})
}
if(this.data.s_time == this.data.last30[0] && this.data.e_time == this.data.last30[1] ){
this.setData({
timeSlotIndex:3,
})
}
},
//单选
radioPicker(e){
if(e.currentTarget.dataset.type == 'timeSlot'){
this.setData({
timeSlotIndex:e.currentTarget.dataset.index,
})
switch (e.currentTarget.dataset.index) {
case 0:
this.setData({
s_time:this.data.today[0],
e_time:this.data.today[1],
})
break;
case 1:
this.setData({
s_time:this.data.tomorrow[0],
e_time:this.data.tomorrow[1],
})
break;
case 2:
this.setData({
s_time:this.data.last7[0],
e_time:this.data.last7[1],
})
break;
case 3:
this.setData({
s_time:this.data.last30[0],
e_time:this.data.last30[1],
})
break;
}
} else if(e.currentTarget.dataset.type == 'testDrive'){
let if_driver = ''
if(e.currentTarget.dataset.index == 1){
if_driver = 1
}else if(e.currentTarget.dataset.index == 2){
if_driver = 0
}
this.setData({
if_driver:if_driver,
testDriveIndex:e.currentTarget.dataset.index,
})
}
},
//客户等级
changeLevel(e){
let level = ''
if(e.detail.value >= 0){
level = this.data.filter.level[e.detail.value]
}
this.setData({
level:level,
levelIndex: e.detail.value,
})
},
//选择品牌
changeBrand(e) {
if(this.data.brandIndex != e.detail.value && e.detail.value >= 0){
this.setData({
brand_id:this.data.brandList[e.detail.value].id,
brandIndex:e.detail.value,
s_id:'',//车系id
modelIndex:-1,//车型车系索引
})
this.getAppSeries()
}
},
//选择车型
changeModel(e) {
if(this.data.modelIndex != e.detail.value && e.detail.value >= 0){
this.setData({
s_id:this.data.modelList[e.detail.value].id,
modelIndex:e.detail.value,
})
}
},
//客户来源
changeCfrom(e){
let cfrom = ''
if(e.detail.value >= 0){
cfrom = this.data.filter.cfrom[e.detail.value]
}
this.setData({
cfrom:cfrom,
cfromIndex: e.detail.value,
})
},
//显示高级搜索
optfilter(){
this.setData({
isShowfilter: !this.data.isShowfilter
})
this.resetFilter()
},
//确定高级搜索
submitFilter() {
this.setData({
isShowfilter:false,
})
this.searchSubmit()
},
//重置高级搜索
resetFilter() {
this.setData({
cus_id:'',//编号
name:'',//名字
mobile:'',//手机号
s_time:'',
e_time:'',
if_driver:'',
level:'',
brand_id:'',
s_id:'',
cfrom:'',
of_id:'',
of2_id:'',
of1Index:-1,
of2Index:-1,
timeSlotIndex:-1,
testDriveIndex:-1,
levelIndex:-1,
brandIndex:-1,
modelIndex:-1,
cfromIndex:-1,
staffIndex:-1,
})
},
//显示短信弹框
showMessage(e){
this.setData({
messageId:e.currentTarget.dataset.id,
isShowMessage:true,
content:'',
})
},
//关闭短信弹框
hideMessage(e){
this.setData({
isShowMessage:false,
})
},
//输入
inputTx(e) {
this.setData({
submitFlag: false,
[e.currentTarget.dataset.key]: e.detail.value
})
},
//发短信
postAppSmsCustomer(){
if (this.data.submitFlag) return;
if (this.data.content == '') {
wx.showToast({
title: '请填写短信内容',
icon: 'none'
})
} else {
this.setData({
submitFlag: true,
})
let params = {};
params['id'] = this.data.messageId;
params['content'] = this.data.content;
_.apiQuery.postAppSmsCustomer(params).then(res=>{
this.setData({
isShowMessage:false,
submitFlag:false,
content:'',
})
wx.showToast({
title: res.msg,
icon: 'none'
})
})
}
},
//推送链接
pushLink(e){
if(e.currentTarget.dataset.url){
_.$router.openUrlScheme(e.currentTarget.dataset.url)
}
},
//线索来源
getAppCustomersOffline_sources(){
_.apiQuery.getAppCustomersOffline_sources().then(res => {
let of1Arr = []
res.data.forEach(item => {
of1Arr.push(item.name)
})
this.setData({
of1Arr,
sources:res.data
})
});
},
//线索来源
changeOf1(e) {
if(this.data.of1Index!=e.detail.value){
let of2Arr = []
this.data.sources[e.detail.value].list.forEach(item => {
of2Arr.push(item.name)
})
this.setData({
of2Arr,
of2Index:-1,
of_id:this.data.sources[e.detail.value].id,
of1Index:e.detail.value,
})
}
},
changeOf2(e) {
if(this.data.of2Index!=e.detail.value){
this.setData({
of2_id:this.data.sources[this.data.of1Index].list[e.detail.value].id,
of2Index:e.detail.value,
})
}
},
//页面相关事件处理函数--监听用户下拉动作
onPullDownRefresh(){
this.setData({
list: [],
pageNo: 1,
noData: false,
end: false,
load: true,
loading: false,
flag: this.data.flag + 1
})
this.getAppCustomersList()
},
//页面上拉触底事件的处理函数
onReachBottom(){
if (this.data.noData || this.data.end||!this.data.load) return;
this.setData({
flag: this.data.flag + 1
})
this.getAppCustomersList()
},
})