Files
lichebao/pages/order/register/index.js
T
2021-08-09 16:26:51 +08:00

421 lines
10 KiB
JavaScript

import _ from '../../../commons/js/commons'
const app = getApp()
Page({
data: {
car_id:'',//车型id
v_id:'',//车型级别id
color_id:'',//车型颜色id
incolor_id:'',//内饰颜色id
b_s_id:'',//备选车型id
buy_time:'',//预计购车时间
modelIndex:-1,//品牌车型索引
spareIndex:-1,//备选车型索引
colorArray:[],//车型颜色列表
levelArray:[],//车型级别列表
interiorArray:[],//内饰颜色
packArray:[],//代办包
packIndex:-1,//代办包索引
colorIndex:-1,//车型颜色索引
levelIndex:-1,//车型级别索引
interiorIndex:-1,//内饰颜色索引
submitFlag:false,
customerIndex:-1,
customer: [],//客户列表
pageNo: 1,
noData: false,
end: false,
load: true,
loading: false,
isShowSelectCustomer:false,
paymentIndex:-1,//付款方式
payment:['全款', '分期',],
mainIndex:-1,//购车主体
main:['个人', '公司',],
entrustIndex:-1,//是否委托
entrust:['是','否',],
entrust_name:'',//委托人姓名
entrust_idcard:'',//委托人身份证
},
//生命周期函数--监听页面加载
onLoad: function (options) {
for (let key in options) {
this.setData({
[key]: options[key]
})
}
this.getAppCustomersList()
this.getAppSeriesCars()
this.getAppServicesPackage()
this.getUserInfo()
},
//获取用户信息
getUserInfo(){
_.apiQuery.getUserInfo().then(res => {
this.setData({
userInfo: res
})
});
},
//获取客户列表
getAppCustomersList(){
this.setData({
load: false,
loading: true,
})
let params = {};
params['page'] = this.data.pageNo;
params['size'] = 20;
params['status'] = 2;
params['ismy'] = 1;
_.apiQuery.getAppCustomersList(params).then(res => {
this.setData({
pageNo: this.data.pageNo + 1,
customer: this.data.customer.concat(res.data.list),
load: true,
loading: false,
})
if (res.data.total == 0) {
this.setData({
noData: true
})
} else if (this.data.customer.length == res.data.total) {
this.setData({
end: true
})
}
wx.stopPullDownRefresh()
});
},
//获取车型库
getAppSeriesCars(){
_.apiQuery.getAppSeriesCars().then(res => {
if(res.data.length>0){
let modelArray = []
res.data.forEach(item => {
modelArray.push(item.title)
})
this.setData({
modelArray:modelArray,
modelList:res.data,
})
}
});
},
//获取车型属性 /颜色 /车型级别
getAppSeriesAttrs(){
let params1 = {};
params1['id'] = this.data.car_id;
params1['type'] = 0;
_.apiQuery.getAppSeriesAttrs(params1).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,
})
}
});
let params2 = {};
params2['id'] = this.data.car_id;
params2['type'] = 1;
_.apiQuery.getAppSeriesAttrs(params2).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,
})
}
});
let params3 = {};
params3['id'] = this.data.car_id;
params3['type'] = 2;
_.apiQuery.getAppSeriesAttrs(params3).then(res => {
if(res.data.total>0){
let interiorArray = []
res.data.list.forEach(item => {
interiorArray.push(item.title)
})
this.setData({
interiorArray:interiorArray,
interiorList:res.data.list,
interiorIndex:-1,
})
}
});
},
//获取代办包
getAppServicesPackage(){
let params = {};
params['page'] = 1;
params['size'] = 100;
_.apiQuery.getAppServicesPackage(params).then(res => {
if(res.data.list.length>0){
let packArray = []
res.data.list.forEach(item => {
packArray.push(item.title)
})
this.setData({
packArray:packArray,
packList:res.data.list,
})
}
});
},
//选择车型
changeModel(e) {
let car_id = ''
if(e.detail.value >= 0){
car_id = this.data.modelList[e.detail.value].id
}
this.setData({
car_id:car_id,
modelIndex:e.detail.value,
})
if(car_id != ''){
this.getAppSeriesAttrs()
}
},
//车型级别
changeLevel(e) {
let v_id = ''
if(e.detail.value >= 0){
v_id = this.data.levelList[e.detail.value].id
}
this.setData({
v_id:v_id,
levelIndex:e.detail.value,
})
},
//车型颜色
changeColor(e) {
let color_id = ''
if(e.detail.value >= 0){
color_id = this.data.colorList[e.detail.value].id
}
this.setData({
color_id:color_id,
colorIndex:e.detail.value,
})
},
//内饰颜色
changeInterior(e) {
let incolor_id = ''
if(e.detail.value >= 0){
incolor_id = this.data.interiorList[e.detail.value].id
}
this.setData({
incolor_id:incolor_id,
interiorIndex:e.detail.value,
})
},
//代办包
changePack(e) {
let pack_id = ''
if(e.detail.value >= 0){
pack_id = this.data.packList[e.detail.value].id
}
this.setData({
pack_id:pack_id,
packIndex:e.detail.value,
})
},
//付款方式
changePayment(e) {
this.setData({
paymentIndex:e.detail.value,
})
},
//购车主体
changeMain(e) {
this.setData({
mainIndex:e.detail.value,
})
},
//是否委托
changeEntrust(e) {
this.setData({
entrustIndex:e.detail.value,
entrust_name:'',
entrust_idcard:'',
})
},
//新建订单
postAppCusorder() {
let that = this
if (that.data.customerIndex == -1 ) {
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 if(that.data.incolor_id == '' ){
wx.showToast({
title: '请选择内饰颜色',
icon: 'none'
})
}else if(that.data.paymentIndex == -1 ){
wx.showToast({
title: '请选择付款方式',
icon: 'none'
})
}else if(that.data.packIndex == -1 ){
wx.showToast({
title: '请选择代办包',
icon: 'none'
})
}else if(that.data.mainIndex == -1 ){
wx.showToast({
title: '请选择购车主体',
icon: 'none'
})
}else if(that.data.entrustIndex == -1 ){
wx.showToast({
title: '请选择是否委托',
icon: 'none'
})
}else if(that.data.entrustIndex == 0 && that.data.entrust_name == ''){
wx.showToast({
title: '请填写委托人姓名',
icon: 'none'
})
}else if(that.data.entrustIndex == 0 && (that.data.entrust_idcard == ''|| !/^\d{6}(18|19|20)?\d{2}(0[1-9]|1[012])(0[1-9]|[12]\d|3[01])\d{3}(\d|[xX])$/.test(that.data.entrust_idcard))){
wx.showToast({
title: '请填写正确委托人身份证',
icon: 'none'
})
}else{
that.setData({
submitFlag: true,
})
let params = {};
params['cus_id'] = that.data.customer[that.data.customerIndex].id;
params['car_id'] = that.data.car_id;
params['v_id'] = that.data.v_id;
params['color_id'] = that.data.color_id;
params['incolor_id'] = that.data.incolor_id;
params['price'] = that.data.levelList[that.data.levelIndex].price;
params['deposit'] = that.data.levelList[that.data.levelIndex].deposit;
params['payway'] = that.data.paymentIndex==0?'1':'0';
params['pack_id'] = that.data.pack_id;
params['main_type'] = that.data.mainIndex==0?'0':'1';
params['ifentrust'] = that.data.entrustIndex==0?'1':'0';
if(this.data.entrust_name != ''){
params['entrust_name'] = this.data.entrust_name;
}
if(this.data.entrust_idcard != ''){
params['entrust_idcard'] = this.data.entrust_idcard;
}
_.apiQuery.postAppCusorder(params).then(res => {
//刷新列表页
let pages = getCurrentPages();
let prevPage = null; //上一个页面
if (pages.length >= 2) {
prevPage = pages[pages.length - 2]; //上一个页面
if(prevPage.route == 'pages/order/index'){
prevPage.onPullDownRefresh()
}
}
wx.showModal({
title: '登记成功',
content: '',
confirmText: "查看详情",
confirmColor: "#36afa2",
showCancel:false,
success() {
wx.redirectTo({
url: '/pages/order/detail/index?id=' + res.data.id
})
}
})
}).catch(res=>{
that.setData({
submitFlag: false,
})
});
}
},
//输入
inputTx(e) {
this.setData({
[e.currentTarget.dataset.key]: e.detail.value
})
},
//选择客户
radioPicker(e){
if(e.currentTarget.dataset.index != this.data.customerIndex){
this.setData({
isSubmiting: false,
customerIndex:e.currentTarget.dataset.index,
})
}
},
//显示选择客户
showSelectCustomer(){
this.setData({
isShowSelectCustomer:true,
})
},
//确认选择客户
hideSelectCustomer(){
this.setData({
isShowSelectCustomer:false,
})
},
//客户列表上拉触底事件的处理函数
scrolltolower(e) {
if (this.data.noData || this.data.end||!this.data.load) return;
this.getAppCustomersList()
},
})