611 lines
16 KiB
JavaScript
611 lines
16 KiB
JavaScript
import _ from '../../../commons/js/commons'
|
|
const app = getApp()
|
|
Page({
|
|
data: {
|
|
tab: [{
|
|
title: '车辆信息',
|
|
step: 2,
|
|
},
|
|
{
|
|
title: '其他信息',
|
|
step: 3,
|
|
},
|
|
],
|
|
step: 2,
|
|
name: '', //姓名
|
|
mobile: '', //手机号
|
|
address: '', //地址
|
|
cardid: '', //身份证
|
|
customerIndex: -1,
|
|
customer: [], //客户列表
|
|
pageNo: 1,
|
|
noData: false,
|
|
end: false,
|
|
load: true,
|
|
loading: false,
|
|
isShowSelectCustomer: false,
|
|
|
|
brand_id: '', //品牌
|
|
brand_name: '', //品牌名称
|
|
brandIndex: -1, //车辆品牌索引
|
|
series_id: '', //车系id
|
|
modelIndex: -1, //车系车型索引
|
|
|
|
car_id: '', //车辆版本id
|
|
carIndex: -1,
|
|
|
|
delry_time: '', //期望交付时间
|
|
submitFlag: false,
|
|
|
|
paymentIndex: -1, //付款方式
|
|
payment: ['全款', '按揭', ],
|
|
mainIndex: -1, //购车主体
|
|
main: ['个人', '公司', ],
|
|
|
|
isPreview: false, //是否预览
|
|
isShowcheck: false, //是否显示预览核对弹框
|
|
checkCount: 2,
|
|
checktext: '3s',
|
|
|
|
firstPayArr: ['现金', '0首付', '按揭', ], //首付类型
|
|
firstPayIndex: 0, //首付类型
|
|
is_get_brand: 0, //是否店内上牌
|
|
is_get_insure: 0, //是否店内投保
|
|
color: '', //车身体颜色
|
|
in_color: '', //内饰颜色
|
|
loan_amount: '', //贷款额度
|
|
loan_periods: '', //贷款期数
|
|
monthly_payment: '', //月供
|
|
register_amount: '', //上牌费
|
|
confirm_amount: '', //定⾦
|
|
discount_amount: '', //⻋身优惠
|
|
business_type: 0,
|
|
brand_page_show: false
|
|
},
|
|
//生命周期函数--监听页面加载
|
|
onLoad: function (options) {
|
|
for (let key in options) {
|
|
this.setData({
|
|
[key]: options[key]
|
|
})
|
|
}
|
|
|
|
this.getAppCusorder()
|
|
this.getAppSeriesBrands()
|
|
this.getUserInfo()
|
|
},
|
|
|
|
//获取订单详情
|
|
getAppCusorder() {
|
|
let params = {};
|
|
params['id'] = this.data.id;
|
|
_.apiQuery.getAppCusorderDetails(params).then(res => {
|
|
|
|
this.setData({
|
|
info: res.data,
|
|
color: res.data.color,
|
|
in_color: res.data.in_color,
|
|
brand_id: res.data.brand_id,
|
|
brand_name: res.data.brand_name,
|
|
series_id: res.data.series_id,
|
|
car_id: res.data.car_id,
|
|
firstPayIndex: res.data.downpayment_type - 1,
|
|
delry_time: res.data.delry_time,
|
|
loan_amount: res.data.money_json.loan_amount ?? '', //贷款额度
|
|
loan_periods: res.data.money_json.loan_periods ?? '', //贷款期数
|
|
monthly_payment: res.data.money_json.monthly_payment ?? '', //月供
|
|
register_amount: res.data.money_json.register_amount ?? '', //上牌费
|
|
confirm_amount: res.data.money_json.confirm_amount ?? '', //定⾦
|
|
discount_amount: res.data.money_json.discount_amount ?? '', //⻋身优惠
|
|
is_get_brand: parseInt(res.data.if_num),
|
|
is_get_insure: parseInt(res.data.if_insure),
|
|
})
|
|
/*匹配车辆信息*/
|
|
//匹配品牌
|
|
if (!!res.data.brand_id) {
|
|
_.apiQuery.getAppSeriesBrands().then(res1 => {
|
|
if (res1.data.list.length > 0) {
|
|
let brandArray = []
|
|
res1.data.list.forEach((item, index) => {
|
|
if (item.id == res.data.brand_id) {
|
|
this.setData({
|
|
brandIndex: index,
|
|
})
|
|
}
|
|
brandArray.push(item.name)
|
|
})
|
|
this.setData({
|
|
brand_id: res.data.brand_id,
|
|
brandArray: brandArray,
|
|
brandList: res1.data.list,
|
|
})
|
|
|
|
//匹配车系
|
|
if (!!res.data.series_id) {
|
|
let modeparams = {};
|
|
modeparams['brand_id'] = res.data.brand_id;
|
|
_.apiQuery.getAppSeries(modeparams).then(res2 => {
|
|
if (res2.data.list.length > 0) {
|
|
let modelArray = []
|
|
res2.data.list.forEach((item, index) => {
|
|
if (item.id == res.data.series_id) {
|
|
this.setData({
|
|
modelIndex: index,
|
|
})
|
|
}
|
|
modelArray.push(item.name)
|
|
})
|
|
this.setData({
|
|
series_id: res.data.series_id,
|
|
modelArray: modelArray,
|
|
modelList: res2.data.list,
|
|
})
|
|
}
|
|
});
|
|
}
|
|
//匹配车型
|
|
if (!!res.data.car_id) {
|
|
let modeparams = {};
|
|
modeparams['series_id'] = res.data.series_id;
|
|
_.apiQuery.getAppSeriesCars(modeparams).then(res2 => {
|
|
if (res2.data.list.length > 0) {
|
|
let carArray = []
|
|
res2.data.list.forEach((item, index) => {
|
|
if (item.id == res.data.car_id) {
|
|
this.setData({
|
|
carIndex: index,
|
|
})
|
|
}
|
|
carArray.push(item.name)
|
|
})
|
|
this.setData({
|
|
car_id: res.data.car_id,
|
|
carArray: carArray,
|
|
carList: res2.data.list,
|
|
})
|
|
}
|
|
});
|
|
}
|
|
}
|
|
});
|
|
}
|
|
/*end匹配车辆信息*/
|
|
|
|
/*匹配其他信息*/
|
|
//匹配付款方式
|
|
if (res.data.payway == 0 || res.data.payway == 1) {
|
|
let paymentIndex = -1
|
|
if (res.data.payway == 0) {
|
|
paymentIndex = 1
|
|
} else if (res.data.payway == 1) {
|
|
paymentIndex = 0
|
|
}
|
|
this.setData({
|
|
paymentIndex: paymentIndex,
|
|
})
|
|
|
|
if (res.data.payway == 0) {
|
|
this.setData({
|
|
firstPayIndex: res.data.downpayment_type - 1,
|
|
})
|
|
}
|
|
}
|
|
|
|
})
|
|
},
|
|
|
|
//修改步骤
|
|
optstep(e) {
|
|
this.setData({
|
|
step: e.currentTarget.dataset.step,
|
|
})
|
|
},
|
|
|
|
//下一步
|
|
nextstep() {
|
|
switch (this.data.step) {
|
|
case 1:
|
|
this.setData({
|
|
mobile: this.trimAll(this.data.mobile),
|
|
cardid: this.trimAll(this.data.cardid)
|
|
})
|
|
if (this.data.main_type == 0 && this.data.name == '') {
|
|
wx.showToast({
|
|
title: '请输入客户姓名',
|
|
icon: 'none'
|
|
})
|
|
} else if (this.data.mobile != this.data.org_mobile && !/^1[3456789]\d{9}$/.test(this.data.mobile)) {
|
|
wx.showToast({
|
|
title: '请输入客户手机号',
|
|
icon: 'none'
|
|
})
|
|
} else if (this.data.main_type == 0 && (this.data.cardid == '' || !/^\d{6}(18|19|20)?\d{2}(0[1-9]|1[012])(0[1-9]|[12]\d|3[01])\d{3}(\d|[xX])$/.test(this.data.cardid))) {
|
|
wx.showToast({
|
|
title: '请填写正确客户身份证',
|
|
icon: 'none'
|
|
})
|
|
} else if (this.data.main_type == 1 && this.data.name == '') {
|
|
wx.showToast({
|
|
title: '请填写企业名称',
|
|
icon: 'none'
|
|
})
|
|
} else if (this.data.main_type == 1 && this.data.cardid == '') {
|
|
wx.showToast({
|
|
title: '请填写企业信用代码',
|
|
icon: 'none'
|
|
})
|
|
} else {
|
|
this.setData({
|
|
step: 2,
|
|
})
|
|
}
|
|
break;
|
|
case 2:
|
|
if (this.data.series_id == '') {
|
|
wx.showToast({
|
|
title: '请选择车系车型',
|
|
icon: 'none'
|
|
})
|
|
} else if (this.data.car_id == '') {
|
|
wx.showToast({
|
|
title: '请选择车辆版本',
|
|
icon: 'none'
|
|
})
|
|
} else {
|
|
this.setData({
|
|
step: 3,
|
|
})
|
|
}
|
|
break;
|
|
case 3:
|
|
if (this.data.paymentIndex == -1) {
|
|
wx.showToast({
|
|
title: '请选择付款方式',
|
|
icon: 'none'
|
|
})
|
|
} else {
|
|
let that = this
|
|
that.setData({
|
|
isPreview: true,
|
|
isFill: true,
|
|
})
|
|
wx.pageScrollTo({
|
|
scrollTop: 0
|
|
})
|
|
|
|
that.setData({
|
|
isShowcheck: true,
|
|
checkCount: 2,
|
|
checktext: 3 + 's'
|
|
})
|
|
let interval = setInterval(res => {
|
|
if (that.data.checkCount > 0) {
|
|
that.setData({
|
|
checkCount: that.data.checkCount - 1,
|
|
checktext: that.data.checkCount + 's'
|
|
})
|
|
} else {
|
|
clearInterval(interval)
|
|
that.setData({
|
|
checkCount: 5,
|
|
checktext: '我知道了'
|
|
})
|
|
}
|
|
}, 1000)
|
|
|
|
}
|
|
break;
|
|
|
|
}
|
|
},
|
|
|
|
//获取用户信息
|
|
getUserInfo() {
|
|
_.apiQuery.getUserInfo().then(res => {
|
|
this.setData({
|
|
userInfo: res,
|
|
})
|
|
});
|
|
},
|
|
|
|
|
|
|
|
//获取车型品牌
|
|
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,
|
|
})
|
|
}
|
|
});
|
|
this.getAppCusorder
|
|
},
|
|
|
|
//获取车辆版本
|
|
getAppSeriesCarlevel() {
|
|
let params = {};
|
|
params['series_id'] = this.data.series_id;
|
|
_.apiQuery.getAppSeriesCars(params).then(res => {
|
|
if (res.data.total > 0) {
|
|
let carArray = []
|
|
res.data.list.forEach(item => {
|
|
carArray.push(item.name)
|
|
})
|
|
this.setData({
|
|
carArray: carArray,
|
|
carList: res.data.list,
|
|
carIndex: -1,
|
|
})
|
|
}
|
|
});
|
|
},
|
|
|
|
|
|
//选择品牌
|
|
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,
|
|
series_id: '', //车系id
|
|
car_id: '', //车系id
|
|
modelIndex: -1, //车系车型索引
|
|
levelArray: [], //车辆版本列表
|
|
levelIndex: -1, //车辆版本索引
|
|
business_type: 0,
|
|
})
|
|
this.getAppSeries()
|
|
}
|
|
},
|
|
|
|
//选择车系
|
|
changeModel(e) {
|
|
if (this.data.modelIndex != e.detail.value && e.detail.value >= 0) {
|
|
this.setData({
|
|
series_id: this.data.modelList[e.detail.value].id,
|
|
modelIndex: e.detail.value,
|
|
car_id: '', //车辆版本id
|
|
carArray: [], //车辆版本列表
|
|
business_type: 0,
|
|
})
|
|
this.getAppSeriesCarlevel()
|
|
}
|
|
},
|
|
|
|
//车辆版本
|
|
changeCar(e) {
|
|
if (this.data.levelIndex != e.detail.value && e.detail.value >= 0) {
|
|
this.setData({
|
|
car_id: this.data.carList[e.detail.value].id,
|
|
carIndex: e.detail.value,
|
|
business_type: 0,
|
|
})
|
|
}
|
|
},
|
|
|
|
//付款方式
|
|
changePayment(e) {
|
|
if (this.data.paymentIndex != e.detail.value && e.detail.value >= 0) {
|
|
this.setData({
|
|
paymentIndex: e.detail.value,
|
|
firstPayIndex: 0,
|
|
})
|
|
}
|
|
},
|
|
|
|
//购车主体
|
|
changeMain(e) {
|
|
this.setData({
|
|
mainIndex: e.detail.value,
|
|
})
|
|
},
|
|
|
|
//建卡时间
|
|
delryTime(e) {
|
|
this.setData({
|
|
delry_time: e.detail.value,
|
|
})
|
|
},
|
|
|
|
//修改订单信息
|
|
putAppCusorderV2() {
|
|
let that = this
|
|
that.setData({
|
|
submitFlag: true,
|
|
})
|
|
|
|
let params = {};
|
|
params['id'] = that.data.id;
|
|
params['brand_id'] = that.data.brand_id;
|
|
params['series_id'] = that.data.series_id;
|
|
params['car_id'] = that.data.car_id;
|
|
if (this.data.color) {
|
|
params['color'] = this.data.color;
|
|
}
|
|
if (this.data.in_color) {
|
|
params['in_color'] = this.data.in_color;
|
|
}
|
|
params['payway'] = that.data.paymentIndex == 0 ? '1' : '0';
|
|
params['delry_time'] = that.data.delry_time;
|
|
if (that.data.paymentIndex == 1) {
|
|
params['downpayment_type'] = parseInt(that.data.firstPayIndex) + 1;
|
|
}
|
|
params['loan_amount'] = that.data.loan_amount;
|
|
params['loan_periods'] = that.data.loan_periods;
|
|
params['monthly_payment'] = that.data.monthly_payment;
|
|
params['if_num'] = that.data.is_get_brand;
|
|
params['if_insure'] = that.data.is_get_insure;
|
|
if (that.data.is_get_brand) {
|
|
params['register_amount'] = that.data.register_amount;
|
|
}
|
|
params['confirm_amount'] = that.data.confirm_amount;
|
|
params['discount_amount'] = that.data.discount_amount;
|
|
_.apiQuery.putAppCusorder(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/index2?id=' + that.data.id
|
|
})
|
|
}
|
|
})
|
|
}).catch(res => {
|
|
that.setData({
|
|
submitFlag: false,
|
|
})
|
|
});
|
|
},
|
|
|
|
//显示隐藏预览
|
|
optPreview(e) {
|
|
this.setData({
|
|
isPreview: !this.data.isPreview,
|
|
})
|
|
wx.pageScrollTo({
|
|
scrollTop: 0
|
|
})
|
|
},
|
|
|
|
//显示隐藏预览提示
|
|
optShowcheck() {
|
|
this.setData({
|
|
isShowcheck: !this.data.isShowcheck,
|
|
})
|
|
},
|
|
|
|
//输入
|
|
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,
|
|
name: this.data.customer[e.currentTarget.dataset.index].name,
|
|
mobile: this.data.customer[e.currentTarget.dataset.index].complete_mobile,
|
|
})
|
|
}
|
|
},
|
|
|
|
//显示选择客户
|
|
showSelectCustomer() {
|
|
this.setData({
|
|
isShowSelectCustomer: true,
|
|
})
|
|
},
|
|
|
|
//确认选择客户
|
|
hideSelectCustomer() {
|
|
this.setData({
|
|
isShowSelectCustomer: false,
|
|
})
|
|
},
|
|
|
|
|
|
changeIsGetBrand(e) {
|
|
this.setData({
|
|
is_get_brand: e.detail.value ? 1 : 0
|
|
})
|
|
},
|
|
|
|
changeIsGetInsure(e) {
|
|
this.setData({
|
|
is_get_insure: e.detail.value ? 1 : 0
|
|
})
|
|
},
|
|
|
|
//页面相关事件处理函数--监听用户下拉动作
|
|
onPullDownRefresh() {
|
|
this.getAppCusorderV2()
|
|
},
|
|
|
|
//去除空格
|
|
trimAll(ele) {
|
|
if (typeof ele === 'string') {
|
|
return ele.split(' ').join('');
|
|
} else {
|
|
console.error(`${typeof ele} is not the expected type, but the string type is expected`)
|
|
}
|
|
},
|
|
|
|
|
|
//选择首付类型
|
|
changeFirstPay(e) {
|
|
if (this.data.firstPayIndex != e.detail.value && e.detail.value >= 0) {
|
|
this.setData({
|
|
firstPayIndex: e.detail.value,
|
|
})
|
|
}
|
|
},
|
|
|
|
//显示选择品牌
|
|
bindShowBrand(){
|
|
this.setData({
|
|
brand_page_show: true
|
|
})
|
|
},
|
|
|
|
//获取品牌信息
|
|
getBrandData(e){
|
|
// console.log(e.detail)
|
|
if(e.detail.index>-1&&e.detail.item){
|
|
this.setData({
|
|
brand_id: e.detail.item.id,
|
|
brand_name: e.detail.item.name,
|
|
brandIndex: e.detail.index,
|
|
series_id: '', //车系id
|
|
car_id: '', //车系id
|
|
modelIndex: -1, //车系车型索引
|
|
levelArray: [], //车辆版本列表
|
|
levelIndex: -1, //车辆版本索引
|
|
business_type: 0,
|
|
})
|
|
this.getAppSeries()
|
|
}
|
|
}
|
|
|
|
}) |