585 lines
15 KiB
JavaScript
585 lines
15 KiB
JavaScript
import _ from '../../../commons/js/commons'
|
|
const app = getApp()
|
|
Page({
|
|
data: {
|
|
name:'',//名字
|
|
mobile:'',//手机号
|
|
// brand_id:'',//品牌
|
|
// car_id:'',//车系id
|
|
// v_id:'',//车辆版本id
|
|
// color_id:'',//颜色id
|
|
// b_s_id:'',//备选车型id
|
|
buy_time:'',//预计购车时间
|
|
// brandIndex:-1,//车辆品牌索引
|
|
// modelIndex:-1,//车系车型索引
|
|
// spareIndex:-1,//备选车型索引
|
|
// colorArray:[],//车身颜色列表
|
|
// levelArray:[],//车辆版本列表
|
|
// colorIndex:-1,//车身颜色索引
|
|
// levelIndex:-1,//车辆版本索引
|
|
timeArray:[],//预计购车时间列表
|
|
timeIndex:-1,//预计购车时间索引
|
|
submitFlag:false,
|
|
|
|
status:0,//状态
|
|
statuslist:[
|
|
'未见客户',
|
|
'到店客户',
|
|
],
|
|
of_id:'',
|
|
of2_id:'',
|
|
of1Index:-1,
|
|
of2Index:-1,
|
|
|
|
cityIndex:-1,
|
|
city_id:'',
|
|
countyIndex:-1,
|
|
county_id:'',
|
|
|
|
isShowExist:false, //客户是否已存在
|
|
wxgr:0,//是否添加个微
|
|
},
|
|
//生命周期函数--监听页面加载
|
|
onLoad: function (options) {
|
|
for (let key in options) {
|
|
this.setData({
|
|
[key]: options[key]
|
|
})
|
|
}
|
|
//获取车型品牌
|
|
// this.getAppSeriesBrands()
|
|
//获取列表筛选条件-时间
|
|
this.getAppCustomersFilter()
|
|
//客户来源
|
|
this.getAppCustomersOffline_sources()
|
|
//客户标签
|
|
this.getAppCustomersTag()
|
|
|
|
if(this.data.status == 1){
|
|
this.setData({
|
|
buy_time:3,
|
|
})
|
|
}
|
|
|
|
},
|
|
|
|
//获取车型品牌
|
|
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,
|
|
})
|
|
}
|
|
});
|
|
},
|
|
|
|
//获取车辆版本
|
|
getAppSeriesAttrslevel(){
|
|
let params = {};
|
|
params['id'] = this.data.car_id;
|
|
params['type'] = 0;
|
|
_.apiQuery.getAppSeriesAttrs(params).then(res => {
|
|
if(res.data.total>0){
|
|
let levelArray = []
|
|
res.data.list.forEach(item => {
|
|
levelArray.push(item.title)
|
|
})
|
|
this.setData({
|
|
levelArray:levelArray,
|
|
levelList:res.data.list,
|
|
levelIndex:-1,
|
|
})
|
|
}
|
|
});
|
|
},
|
|
|
|
//获取车身颜色
|
|
getAppSeriesAttrscolor(){
|
|
let params = {};
|
|
params['id'] = this.data.car_id;
|
|
params['type'] = 1;
|
|
params['v_id'] = this.data.v_id;
|
|
_.apiQuery.getAppSeriesAttrs(params).then(res => {
|
|
if(res.data.total>0){
|
|
let colorArray = []
|
|
res.data.list.forEach(item => {
|
|
colorArray.push(item.title)
|
|
})
|
|
this.setData({
|
|
colorArray:colorArray,
|
|
colorList:res.data.list,
|
|
colorIndex:-1,
|
|
})
|
|
}
|
|
});
|
|
},
|
|
|
|
//获取列表筛选条件-时间
|
|
getAppCustomersFilter(){
|
|
_.apiQuery.getAppCustomersFilter().then(res => {
|
|
let timeArray = []
|
|
res.data.buy_time.forEach(item => {
|
|
timeArray.push(item.name)
|
|
})
|
|
this.setData({
|
|
timeArray:timeArray,
|
|
timeList:res.data.buy_time,
|
|
timeIndex:-1,
|
|
})
|
|
});
|
|
},
|
|
|
|
//输入
|
|
inputTx(e) {
|
|
this.setData({
|
|
submitFlag:false,
|
|
[e.currentTarget.dataset.key]: e.detail.value
|
|
})
|
|
},
|
|
|
|
//选择状态
|
|
changeStatus(e) {
|
|
if(this.data.status != e.detail.value){
|
|
this.setData({
|
|
of_id:'',
|
|
of2_id:'',
|
|
of1Index:-1,
|
|
of2Index:-1,
|
|
of2Arr:[],
|
|
status:e.detail.value,
|
|
buy_time:e.detail.value==1?'3':'',
|
|
})
|
|
this.getAppCustomersOffline_sources()
|
|
}
|
|
},
|
|
|
|
//选择品牌
|
|
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,
|
|
car_id:'',//车系id
|
|
v_id:'',//车辆版本id
|
|
color_id:'',//车身颜色id
|
|
incolor_id:'',//内饰颜色id
|
|
b_s_id:'',//备选车型id
|
|
modelIndex:-1,//车系车型索引
|
|
spareIndex:-1,//备选车型索引
|
|
colorArray:[],//车身颜色列表
|
|
levelArray:[],//车辆版本列表
|
|
interiorArray:[],//内饰颜色
|
|
colorIndex:-1,//车身颜色索引
|
|
levelIndex:-1,//车辆版本索引
|
|
interiorIndex:-1,//内饰颜色索引
|
|
})
|
|
this.getAppSeries()
|
|
}
|
|
},
|
|
|
|
//选择车系
|
|
changeModel(e) {
|
|
if(this.data.modelIndex != e.detail.value && e.detail.value >= 0){
|
|
this.setData({
|
|
car_id:this.data.modelList[e.detail.value].id,
|
|
modelIndex:e.detail.value,
|
|
v_id:'',//车辆版本id
|
|
color_id:'',//车身颜色id
|
|
incolor_id:'',//内饰颜色id
|
|
b_s_id:'',//备选车型id
|
|
spareIndex:-1,//备选车型索引
|
|
colorArray:[],//车身颜色列表
|
|
levelArray:[],//车辆版本列表
|
|
interiorArray:[],//内饰颜色
|
|
colorIndex:-1,//车身颜色索引
|
|
levelIndex:-1,//车辆版本索引
|
|
interiorIndex:-1,//内饰颜色索引
|
|
})
|
|
this.getAppSeriesAttrslevel()
|
|
}
|
|
},
|
|
|
|
//车辆版本
|
|
changeLevel(e) {
|
|
if(this.data.levelIndex != e.detail.value && e.detail.value >= 0){
|
|
this.setData({
|
|
v_id:this.data.levelList[e.detail.value].id,
|
|
levelIndex:e.detail.value,
|
|
color_id:'',//车身颜色id
|
|
colorArray:[],//车身颜色列表
|
|
colorIndex:-1,//车身颜色索引
|
|
})
|
|
this.getAppSeriesAttrscolor()
|
|
}
|
|
},
|
|
|
|
//车身颜色
|
|
changeColor(e) {
|
|
if(this.data.colorIndex != e.detail.value && e.detail.value >= 0){
|
|
this.setData({
|
|
color_id:this.data.colorList[e.detail.value].id,
|
|
colorIndex:e.detail.value,
|
|
})
|
|
}
|
|
},
|
|
|
|
//备选车型
|
|
changeSpare(e) {
|
|
if(this.data.spareIndex != e.detail.value && e.detail.value >= 0){
|
|
this.setData({
|
|
b_s_id:this.data.modelList[e.detail.value].id,
|
|
spareIndex:e.detail.value,
|
|
})
|
|
}
|
|
},
|
|
|
|
//预计购车时间
|
|
changeTime(e) {
|
|
this.setData({
|
|
buy_time:this.data.timeList[e.detail.value].id,
|
|
timeIndex:e.detail.value,
|
|
})
|
|
},
|
|
|
|
//新建客户
|
|
postAppCustomers() {
|
|
let that = this
|
|
if (that.data.name == '' ) {
|
|
wx.showToast({
|
|
title: '请输入客户姓名',
|
|
icon: 'none'
|
|
})
|
|
} else if (!/^1[3456789]\d{9}$/.test(that.data.mobile)){
|
|
wx.showToast({
|
|
title: '请输入正确的手机号码',
|
|
icon: 'none'
|
|
})
|
|
}
|
|
else if (that.data.sources.length>0&&that.data.of_id == '' ) {
|
|
wx.showToast({
|
|
title: '请选择客户来源',
|
|
icon: 'none'
|
|
})
|
|
}
|
|
else if (that.data.sources.length>0&&that.data.sources[that.data.of1Index].list.length>0&&that.data.of2_id == '' ) {
|
|
wx.showToast({
|
|
title: '请选择'+that.data.sources[that.data.of1Index].name+'类型',
|
|
icon: 'none'
|
|
})
|
|
}
|
|
else if (that.data.city_id == '' ) {
|
|
wx.showToast({
|
|
title: '请选择所在城市',
|
|
icon: 'none'
|
|
})
|
|
}
|
|
else if (that.data.county_id == '' ) {
|
|
wx.showToast({
|
|
title: '请选择所在地区',
|
|
icon: 'none'
|
|
})
|
|
}
|
|
else if (that.data.buy_time == '' ) {
|
|
wx.showToast({
|
|
title: '请选择预计购车时间',
|
|
icon: 'none'
|
|
})
|
|
}
|
|
// else if(that.data.car_id == '' ){
|
|
// wx.showToast({
|
|
// title: '请选择车系车型',
|
|
// icon: 'none'
|
|
// })
|
|
// }else if(that.data.v_id == '' ){
|
|
// wx.showToast({
|
|
// title: '请选择车辆版本',
|
|
// icon: 'none'
|
|
// })
|
|
// }else if(that.data.color_id == '' ){
|
|
// wx.showToast({
|
|
// title: '请选择车身颜色',
|
|
// icon: 'none'
|
|
// })
|
|
// }
|
|
else{
|
|
that.setData({
|
|
submitFlag: true,
|
|
})
|
|
let params = {};
|
|
params['status'] = that.data.status;
|
|
params['name'] = that.data.name;
|
|
params['mobile'] = that.data.mobile;
|
|
// params['car_id'] = that.data.car_id;
|
|
// params['v_id'] = that.data.v_id;
|
|
// params['color_id'] = that.data.color_id;
|
|
params['tag'] = that.data.taglList;
|
|
// if(this.data.b_s_id != ''){
|
|
// params['b_s_id'] = this.data.b_s_id;
|
|
// }
|
|
if(this.data.of_id != ''){
|
|
params['of_id'] = this.data.of_id;
|
|
}
|
|
if(this.data.of2_id != ''){
|
|
params['of2_id'] = this.data.of2_id;
|
|
}
|
|
params['wxgr'] = this.data.wxgr;
|
|
params['city_id'] = this.data.city_id;
|
|
params['county_id'] = this.data.county_id;
|
|
params['buy_time'] = this.data.buy_time;
|
|
_.apiQuery.postAppCustomers(params).then(res => {
|
|
|
|
//刷新列表页
|
|
let pages = getCurrentPages();
|
|
let prevPage = null; //上一个页面
|
|
if (pages.length >= 2) {
|
|
prevPage = pages[pages.length - 2]; //上一个页面
|
|
if(prevPage.route == 'pages/customer/index'){
|
|
prevPage.onPullDownRefresh()
|
|
}
|
|
}
|
|
|
|
wx.showModal({
|
|
title: '创建成功',
|
|
content: '',
|
|
confirmText: "继续创建",
|
|
confirmColor: "#36afa2",
|
|
cancelText: "返回",
|
|
cancelColor: "#666",
|
|
success(res) {
|
|
if (res.confirm) {
|
|
that.setData({
|
|
name:'',//名字
|
|
mobile:'',//手机号
|
|
// brand_id:'',//品牌
|
|
// car_id:'',//车系id
|
|
// v_id:'',//车辆版本id
|
|
// color_id:'',//颜色id
|
|
// b_s_id:'',//备选车型id
|
|
buy_time:'',//预计购车时间
|
|
// brandIndex:-1,//车辆品牌索引
|
|
// modelIndex:-1,//车系车型索引
|
|
// spareIndex:-1,//备选车型索引
|
|
// colorArray:[],//车身颜色列表
|
|
// levelArray:[],//车辆版本列表
|
|
// colorIndex:-1,//车身颜色索引
|
|
// levelIndex:-1,//车辆版本索引
|
|
timeIndex:-1,//预计购车时间索引
|
|
submitFlag:false,
|
|
|
|
|
|
of_id:'',
|
|
of2_id:'',
|
|
of2Arr:[],
|
|
of1Index:-1,
|
|
of2Index:-1,
|
|
})
|
|
that.getAppCustomersTag()
|
|
} else if (res.cancel) {
|
|
wx.navigateBack({
|
|
delta: 1
|
|
})
|
|
}
|
|
|
|
}
|
|
})
|
|
}).catch(res=>{
|
|
this.setData({
|
|
submitFlag: false,
|
|
})
|
|
if(res.data.id){
|
|
wx.hideToast();
|
|
this.setData({
|
|
isShowExist: true,
|
|
exist: res,
|
|
})
|
|
}
|
|
});
|
|
}
|
|
},
|
|
|
|
//客户来源
|
|
getAppCustomersOffline_sources(){
|
|
let params = {};
|
|
params['status'] = this.data.status;
|
|
_.apiQuery.getAppCustomersOffline_sources(params).then(res => {
|
|
let of1Arr = []
|
|
res.data.sources.forEach(item => {
|
|
of1Arr.push(item.name)
|
|
})
|
|
this.setData({
|
|
of1Arr,
|
|
sources:res.data.sources
|
|
})
|
|
});
|
|
},
|
|
|
|
//客户来源
|
|
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,
|
|
})
|
|
}
|
|
},
|
|
|
|
//客户标签
|
|
getAppCustomersTag(){
|
|
_.apiQuery.getAppCustomersTag().then(res => {
|
|
this.setData({
|
|
city_id:res.data.city_id,
|
|
county_id:res.data.county_id,
|
|
taglList:res.data.tags&&res.data.tags.length>0?res.data.tags:[],
|
|
})
|
|
//获取城市
|
|
this.getAppCityArea_city()
|
|
//获取地区
|
|
this.getAppCityArea_county()
|
|
});
|
|
},
|
|
|
|
//单选
|
|
radioPicker(e){
|
|
let taglList = this.data.taglList
|
|
taglList[e.currentTarget.dataset.i].list.forEach(item => {
|
|
item.checked=false
|
|
})
|
|
taglList[e.currentTarget.dataset.i].list[e.currentTarget.dataset.j].checked=true
|
|
this.setData({
|
|
taglList,
|
|
})
|
|
},
|
|
|
|
//多选
|
|
checkPicker(e){
|
|
this.setData({
|
|
['taglList['+e.currentTarget.dataset.i+'].list['+e.currentTarget.dataset.j+'].checked']:!this.data.taglList[e.currentTarget.dataset.i].list[e.currentTarget.dataset.j].checked,
|
|
})
|
|
},
|
|
|
|
|
|
//获取城市
|
|
getAppCityArea_city(){
|
|
let params = {};
|
|
params['type'] = 'city';
|
|
_.apiQuery.getAppCityArea(params).then(res => {
|
|
let cityArr = []
|
|
let cityIndex = -1
|
|
res.data.list.forEach((item,index) => {
|
|
cityArr.push(item.name)
|
|
if(this.data.city_id == item.id){
|
|
cityIndex = index
|
|
}
|
|
})
|
|
this.setData({
|
|
cityIndex,
|
|
cityArr,
|
|
city:res.data.list
|
|
})
|
|
});
|
|
},
|
|
|
|
//获取行政区
|
|
getAppCityArea_county(){
|
|
let params = {};
|
|
params['pid'] = this.data.city_id;
|
|
params['type'] = 'county';
|
|
_.apiQuery.getAppCityArea(params).then(res => {
|
|
let countyArr = []
|
|
let countyIndex = -1
|
|
res.data.list.forEach((item,index) => {
|
|
countyArr.push(item.name)
|
|
if(this.data.county_id == item.id){
|
|
countyIndex = index
|
|
}
|
|
})
|
|
this.setData({
|
|
countyIndex,
|
|
countyArr,
|
|
county:res.data.list
|
|
})
|
|
});
|
|
},
|
|
|
|
//选择城市
|
|
changeCity(e) {
|
|
if(this.data.cityIndex!=e.detail.value){
|
|
this.setData({
|
|
cityIndex:e.detail.value,
|
|
city_id:this.data.city[e.detail.value].id,
|
|
})
|
|
this.getAppCityArea_county()
|
|
}
|
|
},
|
|
|
|
//选择地区
|
|
changeCounty(e) {
|
|
if(this.data.countyIndex!=e.detail.value){
|
|
this.setData({
|
|
countyIndex:e.detail.value,
|
|
county_id:this.data.county[e.detail.value].id,
|
|
})
|
|
}
|
|
},
|
|
|
|
//查看存在客户信息
|
|
viewDetails(e){
|
|
wx.redirectTo({
|
|
url: '/pages/customer/detail/index?id=' + this.data.exist.data.id
|
|
})
|
|
},
|
|
|
|
//关闭客户已存在提示
|
|
colseExist(){
|
|
this.setData({
|
|
isShowExist: false,
|
|
})
|
|
},
|
|
|
|
//是否添加个微
|
|
switchWxgr:function(e){
|
|
this.setData({
|
|
wxgr:e.detail.value ? 1 :0
|
|
})
|
|
},
|
|
|
|
}) |