Commit b1c88250 by zhangshengren

增加验证码

parent c8c8bb17
......@@ -3,6 +3,7 @@ App({
globalData: {
app_id: 'wx3722cae0d0b62fff',
url: 'https://test-es.checheng.com/api/',
urlSpecial: 'https://test-es.checheng.com/api-weapp/',
name: '爱车估价助手',
width: 0,
height: 0,
......
const app = getApp();
const utils = require('../../utils/util.js');
const { md5 } = require('../../utils/md5.js');
const {
md5
} = require('../../utils/md5.js');
Page({
data: {
userForms: {
link: app.globalData.link,
specification_id: '',
specification_name: '',
buy_time: '',
mileage: '',
city_id: '',
city_name: '',
phone: ''
},
startTime: '',
endTime: '',
provinceList: [],
province: '',
province_index: '',
cityList: [],
city_index: '',
showPhoneInput: false,
valuation: {},
carInfo: {},
terminal_names: []
data: {
userForms: {
link: app.globalData.link,
specification_id: '',
specification_name: '',
buy_time: '',
mileage: '',
city_id: '',
city_name: '',
phone: '',
pre_phone: ''
},
onShow: function() {
let _this = this
this.setData({
provinceList: app.globalData.provinceList,
province_index: wx.getStorageSync('province_index'),
city_index: wx.getStorageSync('city_index')
}, () => {
if (_this.data.provinceList.length === 0) {
_this.getProvinceList()
} else {
let index = wx.getStorageSync('province_index')
let id = wx.getStorageSync('province_id')
if (index) {
_this.setData({
province: _this.data.provinceList[index].name
})
_this.getCityList(id, _this)
}
}
})
let years = wx.getStorageSync('years')
let startTime, endTime
if (years.length > 4) {
startTime = years.substr(0, 4)
endTime = years.substr(-4, 4)
let today = utils.formatDate(new Date())
if (today.indexOf(endTime) > -1) {
endTime = today
} else {
endTime = endTime + '-12-31'
}
this.setData({
startTime: startTime + '-01-01',
endTime: endTime
})
inputSmsCode: '',
smsCode: '',
disabled: false,
totalTime: 120,
timer: null,
btnText: '获取验证码',
startTime: '',
endTime: '',
provinceList: [],
province: '',
province_index: '',
cityList: [],
city_index: '',
showPhoneInput: false,
valuation: {},
carInfo: {},
terminal_names: []
},
onShow: function() {
let _this = this
if (this.timer) {
clearInterval(this.timer)
}
this.setData({
provinceList: app.globalData.provinceList,
province_index: wx.getStorageSync('province_index'),
city_index: wx.getStorageSync('city_index'),
inputSmsCode: '',
smsCode: '',
disabled: false,
totalTime: 120,
timer: null,
btnText: '获取验证码'
}, () => {
if (_this.data.provinceList.length === 0) {
_this.getProvinceList()
} else {
let index = wx.getStorageSync('province_index')
let id = wx.getStorageSync('province_id')
if (index) {
_this.setData({
province: _this.data.provinceList[index].name
})
_this.getCityList(id, _this)
}
}
})
let years = wx.getStorageSync('years')
let startTime, endTime
if (years.length > 4) {
startTime = years.substr(0, 4)
endTime = years.substr(-4, 4)
let today = utils.formatDate(new Date())
if (today.indexOf(endTime) > -1) {
endTime = today
} else {
endTime = endTime + '-12-31'
}
this.setData({
startTime: startTime + '-01-01',
endTime: endTime
})
}
this.getItem('specification_id')
this.getItem('specification_name')
this.getItem('city_id')
this.getItem('city_name')
this.getItem('buy_time')
this.getItem('mileage')
this.getItem('phone')
let province = wx.getStorageSync('province')
this.setData({
province: province ? province : ''
})
this.data.terminal_names = []
},
// 获取省份
getProvinceList: function () {
let _this = this;
wx.request({
url: app.globalData.url + 'assess/provinces',
success: function (res) {
if (res.data && res.data.length > 0) {
let data = res.data
let arr = []
for (let key in data) {
if (data[key].id === 32) {
continue
}
arr.push(data[key])
}
_this.setData({
provinceList: arr
})
}
}
})
},
// 城市列表
getCityList: function(parent_id, _this) {
wx.request({
url: app.globalData.url + 'assess/cities',
data: {
parent_id
},
success: function(res) {
if (res.data && res.data.length > 0) {
let data = res.data
_this.setData({
cityList: data,
}, () => {
let index = wx.getStorageSync('city_index') || '0'
_this.setData({
['userForms.city_name']: _this.data.cityList[index].name
})
let city_id = _this.data.cityList[index].id;
let city_name = _this.data.cityList[index].name;
_this.setData({
['userForms.city_id']: city_id,
['userForms.city_name']: city_name,
})
wx.setStorageSync('city_id', city_id)
wx.setStorageSync('city_name', city_name)
})
}
}
})
},
// 选择省份
changeProvince: function(e) {
let _this = this
let index = e.detail.value
let parent_id = this.data.provinceList[index].id
this.getCityList(parent_id, _this)
let province = this.data.provinceList[index].name;
let province_id = this.data.provinceList[index].id;
wx.setStorageSync('province', province)
wx.setStorageSync('province_id', province_id)
wx.setStorageSync('province_index', index)
this.setData({
province: province,
city_index: '0'
}, () => {
wx.setStorageSync('city_index', '0')
})
},
// 选择城市
changeCity: function(e) {
let index = e.detail.value
let city_id = this.data.cityList[index].id;
let city_name = this.data.cityList[index].name;
this.setData({
['userForms.city_id']: city_id,
['userForms.city_name']: city_name,
})
wx.setStorageSync('city_id', city_id)
wx.setStorageSync('city_name', city_name)
wx.setStorageSync('city_index', index)
},
// 选择品牌
selectBrand: function() {
app.globalData.enter = 'index'
wx.navigateTo({
url: '/pages/car-select/brand',
})
},
// 更新值
getItem(item) {
let _this = this;
let data = wx.getStorageSync(item)
this.setData({
['userForms.' + item]: data ? data : ''
}, () => {
if (item === 'phone' && data) {
_this.setData({
showPhoneInput: true
})
this.getItem('specification_id')
this.getItem('specification_name')
this.getItem('city_id')
this.getItem('city_name')
this.getItem('buy_time')
this.getItem('mileage')
this.getItem('phone')
let province = wx.getStorageSync('province')
this.setData({
province: province ? province : ''
})
this.data.terminal_names = []
},
// 获取省份
getProvinceList: function() {
let _this = this;
wx.request({
url: app.globalData.url + 'assess/provinces',
success: function(res) {
if (res.data && res.data.length > 0) {
let data = res.data
let arr = []
for (let key in data) {
if (data[key].id === 32) {
continue
}
arr.push(data[key])
}
_this.setData({
provinceList: arr
})
}
}
})
},
// 城市列表
getCityList: function(parent_id, _this) {
wx.request({
url: app.globalData.url + 'assess/cities',
data: {
parent_id
},
success: function(res) {
if (res.data && res.data.length > 0) {
let data = res.data
_this.setData({
cityList: data,
}, () => {
let index = wx.getStorageSync('city_index') || '0'
_this.setData({
['userForms.city_name']: _this.data.cityList[index].name
})
let city_id = _this.data.cityList[index].id;
let city_name = _this.data.cityList[index].name;
_this.setData({
['userForms.city_id']: city_id,
['userForms.city_name']: city_name,
})
wx.setStorageSync('city_id', city_id)
wx.setStorageSync('city_name', city_name)
})
}
}
})
},
// 选择省份
changeProvince: function(e) {
let _this = this
let index = e.detail.value
let parent_id = this.data.provinceList[index].id
this.getCityList(parent_id, _this)
let province = this.data.provinceList[index].name;
let province_id = this.data.provinceList[index].id;
wx.setStorageSync('province', province)
wx.setStorageSync('province_id', province_id)
wx.setStorageSync('province_index', index)
this.setData({
province: province,
city_index: '0'
}, () => {
wx.setStorageSync('city_index', '0')
})
},
// 选择城市
changeCity: function(e) {
let index = e.detail.value
let city_id = this.data.cityList[index].id;
let city_name = this.data.cityList[index].name;
this.setData({
['userForms.city_id']: city_id,
['userForms.city_name']: city_name,
})
wx.setStorageSync('city_id', city_id)
wx.setStorageSync('city_name', city_name)
wx.setStorageSync('city_index', index)
},
// 选择品牌
selectBrand: function() {
app.globalData.enter = 'index'
wx.navigateTo({
url: '/pages/car-select/brand',
})
},
// 更新值
getItem(item) {
let _this = this;
let data = wx.getStorageSync(item)
this.setData({
['userForms.' + item]: data ? data : ''
}, () => {
if (item === 'phone' && data) {
_this.setData({
showPhoneInput: true
})
},
}
})
},
// 选择日期
changeDate: function(e) {
let time = e.detail.value;
this.setData({
['userForms.buy_time']: time
})
wx.setStorageSync('buy_time', time)
},
// 输入行驶里程
mileageInput: function(e) {
let mileage = e.detail.value
this.setData({
['userForms.mileage']: mileage
})
wx.setStorageSync('mileage', mileage)
},
// 输入手机号 
phoneInput: function(e) {
let pre_phone = this.data.userForms.pre_phone
let phone = e.detail.value
if (pre_phone != phone) {
this.setData({
showSmsCode: true
})
} else if (pre_phone == phone) {
this.setData({
showSmsCode: false
})
wx.setStorageSync('phone', phone)
}
// 选择日期
changeDate: function(e) {
let time = e.detail.value;
this.setData({
['userForms.buy_time']: time
this.setData({
['userForms.phone']: phone
})
// if (phone.length === 11) {
// wx.setStorageSync('phone', phone)
// }
},
// 输入验证码
smsCodeInput: function(e) {
let code = e.detail.value
this.setData({
inputSmsCode: code
})
},
// 倒计时
countDown: function() {
let _this = this;
_this.timer = setInterval(function() {
_this.data.totalTime--;
_this.data.btnText = _this.data.totalTime + '秒';
if (_this.data.totalTime < 0) {
clearInterval(_this.timer)
_this.setData({
totalTime: 120,
btnText: '重新获取'
})
wx.setStorageSync('buy_time', time)
},
// 输入行驶里程
mileageInput: function(e) {
let mileage = e.detail.value
this.setData({
['userForms.mileage']: mileage
} else {
_this.setData({
totalTime: _this.data.totalTime,
btnText: _this.data.btnText
})
wx.setStorageSync('mileage', mileage)
},
}
}, 1000)
},
// 发送短信验证码
sendSmsCode: function(e) {
let _this = this
if (!this.data.userForms.specification_name) {
wx.showToast({
icon: 'none',
title: '请选择车型!'
})
return false;
}
if (!this.data.userForms.buy_time) {
wx.showToast({
icon: 'none',
title: '请选择上牌时间!'
})
return false;
}
if (!this.data.userForms.city_name) {
wx.showToast({
icon: 'none',
title: '请选择城市!'
})
return false;
}
if (!this.data.userForms.mileage) {
wx.showToast({
icon: 'none',
title: '请输入行驶里程!'
})
return false;
}
if (Number(this.data.userForms.mileage) > 100) {
wx.showToast({
icon: 'none',
title: '行驶里程不能超过100万公里!'
})
return false;
}
if (!this.data.userForms.phone) {
wx.showToast({
icon: 'none',
title: '请输入手机号码!'
})
return false;
}
let reg = /^1(3|4|5|7|8|9)\d{9}$/;
if (!reg.test(this.data.userForms.phone)) {
wx.showToast({
icon: 'none',
title: '手机号码格式不正确!'
})
return false;
}
let data = {
phone: this.data.userForms.phone
}
_this.setData({
disabled: true
}, () => {
wx.request({
url: app.globalData.urlSpecial + 'main-customers/get-new-sms',
data: data,
success: function(res) {
res = res.data
if (res.message === 'ok' && res.data && res.data.code) {
_this.setData({
smsCode: res.data.code,
}, () => {
_this.countDown();
})
} else if (res.message === 'ok' && res.data && res.data.error === 1) {
wx.showToast({
icon: 'none',
title: res.data.msg
})
_this.setData({
disabled: false
}, () => {})
}
},
fail: function(res) {
wx.showToast({
icon: 'none',
title: '获取失败,请稍后重试!'
})
}
})
})
// 输入手机号 
phoneInput: function(e) {
let phone = e.detail.value
this.setData({
['userForms.phone']: phone
})
},
if (phone.length === 11) {
wx.setStorageSync('phone', phone)
// 获取手机号
getPhone: function(e) {
let _this = this
let errMsg = e.detail.errMsg
if (errMsg === 'getPhoneNumber:ok') {
if (app.globalData.session_key) {
let data = {
session_key: app.globalData.session_key,
encrypted_data: e.detail.encryptedData,
iv: e.detail.iv,
app_id: app.globalData.app_id
}
},
// 获取手机号
getPhone: function(e) {
let _this = this
let errMsg = e.detail.errMsg
if (errMsg === 'getPhoneNumber:ok') {
if (app.globalData.session_key) {
let data = {
session_key: app.globalData.session_key,
encrypted_data: e.detail.encryptedData,
iv: e.detail.iv,
app_id: app.globalData.app_id
}
wx.request({
url: app.globalData.url + 'decode-phone',
data: data,
method: 'POST',
success: function(res) {
if (res.data.message !== '解密失败') {
let phone = res.data.purePhoneNumber
_this.setData({
['userForms.phone']: phone,
showPhoneInput: true
})
wx.setStorageSync('phone', phone)
} else {
wx.showToast({
icon: 'none',
title: '获取失败,请稍后重试!'
})
}
}
})
wx.request({
url: app.globalData.url + 'decode-phone',
data: data,
method: 'POST',
success: function(res) {
if (res.data.message !== '解密失败') {
let phone = res.data.purePhoneNumber
_this.setData({
['userForms.phone']: phone,
['userForms.pre_phone']: phone,
})
wx.setStorageSync('phone', phone)
} else {
_this.login(e)
wx.showToast({
icon: 'none',
title: '获取失败,请稍后重试!'
})
}
} else if (errMsg === 'getPhoneNumber:fail user deny') {
this.setData({
['userForms.phone']: '',
showPhoneInput: true
})
}
},
// 重新获取code
login: function(e) {
let _this = this
wx.login({
}
})
} else {
_this.login(e)
}
} else if (errMsg === 'getPhoneNumber:fail user deny') {
this.setData({
['userForms.phone']: '',
['userForms.pre_phone']: '',
})
}
},
// 重新获取code
login: function(e) {
let _this = this
wx.login({
success: function(res) {
if (res.errMsg === 'login:ok') {
let data = {
code: res.code,
app_id: app.globalData.app_id
}
wx.request({
url: app.globalData.url + 'user-code',
data: data,
success: function(res) {
if (res.errMsg === 'login:ok') {
let data = {
code: res.code,
app_id: app.globalData.app_id
}
wx.request({
url: app.globalData.url + 'user-code',
data: data,
success: function(res) {
let data = {
session_key: res.data.session_key,
encrypted_data: e.detail.encryptedData,
iv: e.detail.iv,
app_id: app.globalData.app_id
}
wx.request({
url: app.globalData.url + 'decode-phone',
data: data,
method: 'POST',
success: function(res) {
if (res.data.message !== '解密失败') {
let phone = res.data.purePhoneNumber
_this.setData({
['userForms.phone']: phone,
showPhoneInput: true
})
wx.setStorageSync('phone', phone)
} else {
wx.showToast({
icon: 'none',
title: '获取失败,请稍后重试!'
})
}
}
})
}
let data = {
session_key: res.data.session_key,
encrypted_data: e.detail.encryptedData,
iv: e.detail.iv,
app_id: app.globalData.app_id
}
wx.request({
url: app.globalData.url + 'decode-phone',
data: data,
method: 'POST',
success: function (res) {
if (res.data.message !== '解密失败') {
let phone = res.data.purePhoneNumber
_this.setData({
['userForms.phone']: phone,
['userForms.pre_phone']: phone,
})
wx.setStorageSync('phone', phone)
} else {
wx.showToast({
icon: 'none',
title: '获取失败,请稍后重试!'
})
}
}
})
}
})
},
// 检测是否为空
checkValue: function() {
if (!this.data.userForms.specification_name) {
wx.showToast({
icon: 'none',
title: '请选择车型!'
})
return false;
}
if (!this.data.userForms.buy_time) {
wx.showToast({
icon: 'none',
title: '请选择上牌时间!'
})
return false;
}
if (!this.data.userForms.city_name) {
wx.showToast({
icon: 'none',
title: '请选择城市!'
})
return false;
}
if (!this.data.userForms.mileage) {
wx.showToast({
icon: 'none',
title: '请输入行驶里程!'
})
return false;
}
if (Number(this.data.userForms.mileage) > 100) {
wx.showToast({
icon: 'none',
title: '行驶里程不能超过100万公里!'
})
return false;
}
if (!this.data.userForms.phone) {
wx.showToast({
icon: 'none',
title: '请输入手机号码!'
})
return false;
}
let reg = /^1(3|4|5|7|8|9)\d{9}$/;
if (!reg.test(this.data.userForms.phone)) {
wx.showToast({
icon: 'none',
title: '手机号码格式不正确!'
})
return false;
})
}
}
})
},
// 检测是否为空
checkValue: function() {
if (!this.data.userForms.specification_name) {
wx.showToast({
icon: 'none',
title: '请选择车型!'
})
return false;
}
if (!this.data.userForms.buy_time) {
wx.showToast({
icon: 'none',
title: '请选择上牌时间!'
})
return false;
}
if (!this.data.userForms.city_name) {
wx.showToast({
icon: 'none',
title: '请选择城市!'
})
return false;
}
if (!this.data.userForms.mileage) {
wx.showToast({
icon: 'none',
title: '请输入行驶里程!'
})
return false;
}
if (Number(this.data.userForms.mileage) > 100) {
wx.showToast({
icon: 'none',
title: '行驶里程不能超过100万公里!'
})
return false;
}
if (!this.data.userForms.phone) {
wx.showToast({
icon: 'none',
title: '请输入手机号码!'
})
return false;
}
let reg = /^1(3|4|5|7|8|9)\d{9}$/;
if (!reg.test(this.data.userForms.phone)) {
wx.showToast({
icon: 'none',
title: '手机号码格式不正确!'
})
return false;
}
this.terminalAvailable(app.globalData.tiantianpaiche_cityList, '天天拍车');
let terminal_length = this.data.terminal_names.length;
let kaixun_terminal_index = this.data.terminal_names.indexOf('上海铠寻');
if (!this.data.inputSmsCode) {
wx.showToast({
icon: 'none',
title: '请输入短信验证码!'
})
return false;
}
if (this.data.userForms.city_name === '上海' && kaixun_terminal_index < 0) {
this.data.terminal_names[terminal_length] = '上海铠寻'
} else if (this.data.userForms.city_name !== '上海' && kaixun_terminal_index > 0) {
this.data.terminal_names.splice(kaixun_terminal_index, 1);
}
if ((this.data.inputSmsCode != this.data.smsCode)) {
wx.showToast({
icon: 'none',
title: '短信验证码不正确!'
})
return false;
}
this.terminalAvailable(app.globalData.chezhibao_cityList, '车置宝');
this.terminalAvailable(app.globalData.tiantianpaiche_cityList, '天天拍车');
this.terminalAvailable(app.globalData.renrenche_cityList, '人人车');
let terminal_length = this.data.terminal_names.length;
let kaixun_terminal_index = this.data.terminal_names.indexOf('上海铠寻');
return true;
},
if (this.data.userForms.city_name === '上海' && kaixun_terminal_index < 0) {
this.data.terminal_names[terminal_length] = '上海铠寻'
} else if (this.data.userForms.city_name !== '上海' && kaixun_terminal_index > 0) {
this.data.terminal_names.splice(kaixun_terminal_index, 1);
}
// 城市是否覆盖 是否选择推送
terminalAvailable: function(cityList, name) {
let terminal_length = this.data.terminal_names.length;
let index = cityList.indexOf(this.data.userForms.city_name);
let terminal_index = this.data.terminal_names.indexOf(name);
this.terminalAvailable(app.globalData.chezhibao_cityList, '车置宝');
if (index < 0 && terminal_index > -1) {
this.data.terminal_names.splice(terminal_index, 1);
} else if (index > -1 && terminal_index < 0) {
this.data.terminal_names[terminal_length] = name
}
},
this.terminalAvailable(app.globalData.renrenche_cityList, '人人车');
// 估价
submit: function() {
let _this = this;
if (this.checkValue()) {
wx.showLoading({
title: '估价中',
mask: true
})
_this.data.terminal_names.push('瓜子二手车', '精真估')
_this.setData({
terminal_names: _this.data.terminal_names
}, () => {
_this.storeCar();
})
}
},
return true;
},
// 存储车
storeCar: function() {
let _this = this;
wx.request({
url: app.globalData.url + 'cars',
method: 'POST',
data: _this.data.userForms,
success: function(res) {
let data = res.data;
if (data.message === 'ok') {
let carInfo = data.data;
wx.setStorageSync('carInfo', carInfo)
let created_at = new Date(carInfo.created_at).getTime()
if (Date.now() - created_at < 3000) { // 新车
_this.sellCar();
} else { // 已存在
_this.evaluate();
}
} else {
wx.showToast({
icon: 'none',
title: '请求错误,请稍后重试!'
})
}
},
fail: function() {
wx.showToast({
icon: 'none',
title: '请求错误,请稍后重试!'
})
},
complete: function() {}
})
},
// 城市是否覆盖 是否选择推送
terminalAvailable: function(cityList, name) {
let terminal_length = this.data.terminal_names.length;
let index = cityList.indexOf(this.data.userForms.city_name);
let terminal_index = this.data.terminal_names.indexOf(name);
// 卖车接口
sellCar: function() {
let _this = this;
wx.request({
url: app.globalData.url + 'distributions/push-to-terminals',
data: {
car_id: wx.getStorageSync('carInfo').id,
terminal_names: this.data.terminal_names
},
method: "POST",
success: function(res) {
if (res.data.message === 'ok') {
_this.evaluate();
} else {
wx.showToast({
icon: 'none',
title: '请求错误,请稍后重试!'
})
}
},
fail: function() {
wx.showToast({
icon: 'none',
title: '请求错误,请稍后重试!'
})
},
complete: function() {}
if (index < 0 && terminal_index > -1) {
this.data.terminal_names.splice(terminal_index, 1);
} else if (index > -1 && terminal_index < 0) {
this.data.terminal_names[terminal_length] = name
}
},
// 估价
submit: function() {
let _this = this;
if (this.checkValue()) {
wx.showLoading({
title: '估价中',
mask: true
})
_this.data.terminal_names.push('瓜子二手车', '精真估')
_this.setData({
terminal_names: _this.data.terminal_names
}, () => {
_this.storeCar();
})
}
},
// 存储车
storeCar: function() {
let _this = this;
wx.request({
url: app.globalData.url + 'cars',
method: 'POST',
data: _this.data.userForms,
success: function(res) {
let data = res.data;
if (data.message === 'ok') {
let carInfo = data.data;
wx.setStorageSync('carInfo', carInfo)
let created_at = new Date(carInfo.created_at).getTime()
if (Date.now() - created_at < 3000) { // 新车
_this.sellCar();
} else { // 已存在
_this.evaluate();
}
} else {
wx.showToast({
icon: 'none',
title: '请求错误,请稍后重试!'
})
}
},
fail: function() {
wx.showToast({
icon: 'none',
title: '请求错误,请稍后重试!'
})
},
// 估值接口
evaluate: function() {
let _this = this;
let model_id = this.data.userForms.specification_id;
let city_id = this.data.userForms.city_id;
let data = {
model_id,
road_haul: this.data.userForms.mileage * 10000,
license_year: this.data.userForms.buy_time.substr(0, 4),
license_month: this.data.userForms.buy_time.substr(5, 2),
city_id,
key: 'lc0710',
sign: md5(model_id + '' + city_id + 'aespol').toLowerCase()
},
complete: function() {}
})
},
// 卖车接口
sellCar: function() {
let _this = this;
wx.request({
url: app.globalData.url + 'distributions/push-to-terminals',
data: {
car_id: wx.getStorageSync('carInfo').id,
terminal_names: this.data.terminal_names
},
method: "POST",
success: function(res) {
if (res.data.message === 'ok') {
_this.evaluate();
} else {
wx.showToast({
icon: 'none',
title: '请求错误,请稍后重试!'
})
}
wx.request({
url: app.globalData.url + 'assess/assess',
data: data,
success: function(res) {
if (res.data.message !== '估值失败') {
let data = res.data;
wx.setStorageSync('valuation', data)
app.globalData.result = 'result'
wx.navigateTo({
url: '/pages/result/result',
})
} else {
wx.showToast({
icon: 'none',
title: '未查询到结果!'
})
}
},
fail: function() {
wx.showToast({
icon: 'none',
title: '请求错误,请稍后重试!'
})
},
complete: function() {
}
},
fail: function() {
wx.showToast({
icon: 'none',
title: '请求错误,请稍后重试!'
})
},
// 分享
onShareAppMessage: function() {
return {
title: "爱车估值",
path: "/pages/index/index"
};
},
complete: function() {}
})
},
// 估值接口
evaluate: function() {
let _this = this;
let model_id = this.data.userForms.specification_id;
let city_id = this.data.userForms.city_id;
let data = {
model_id,
road_haul: this.data.userForms.mileage * 10000,
license_year: this.data.userForms.buy_time.substr(0, 4),
license_month: this.data.userForms.buy_time.substr(5, 2),
city_id,
key: 'lc0710',
sign: md5(model_id + '' + city_id + 'aespol').toLowerCase()
}
wx.request({
url: app.globalData.url + 'assess/assess',
data: data,
success: function(res) {
if (res.data.message !== '估值失败') {
let data = res.data;
wx.setStorageSync('valuation', data)
app.globalData.result = 'result'
wx.navigateTo({
url: '/pages/result/result',
})
} else {
wx.showToast({
icon: 'none',
title: '未查询到结果!'
})
}
},
fail: function() {
wx.showToast({
icon: 'none',
title: '请求错误,请稍后重试!'
})
},
complete: function() {
}
})
},
// 分享
onShareAppMessage: function() {
return {
title: "爱车估值",
path: "/pages/index/index"
};
}
})
\ No newline at end of file
......@@ -68,6 +68,17 @@
<button bindgetphonenumber="getPhone" id="get-phone" openType="getPhoneNumber" size="mini" type="primary" wx:else>11位手机号</button> -->
</view>
</view>
<view class="weui-cell weui-cell_input form-input-item">
<view class="weui-cell__hd">
<view class="weui-label">验 证 码</view>
</view>
<view class="weui-cell__bd">
<input bindinput="smsCodeInput" maxlength="6" class="weui-input text-right" placeholder="请输入短信验证码" type="digit" value="{{inputSmsCode}}"></input>
</view>
<view class="weui-cell__ft">
<button bindtap="sendSmsCode" id="get-smsCode" class="{{disabled ? 'disabled': ''}}" size="mini" type="primary" disabled="{{disabled}}">{{btnText}}</button>
</view>
</view>
</view>
</view>
<view class="weui-cell submit-section">
......
......@@ -139,4 +139,21 @@ page {
.weui-input {
color: #39424D;
text-align: right;
}
#get-smsCode {
display: block;
padding: 3px 5px;
margin-left: 30rpx;
width: 180rpx;
line-height: 2;
background: #fe560e;
color:#fff;
border-color: white;
font-size: 26rpx;
text-align: center;
}
button.disabled {
background: #cec5c0 !important;
}
\ No newline at end of file
......@@ -3,593 +3,761 @@ const utils = require('../../utils/util.js')
Page({
data: {
userForms: {
link: app.globalData.link,
specification_id: '',
specification_name: '',
buy_time: '',
mileage: '',
city_id: '',
city_name: '',
phone: ''
},
startTime: '',
endTime: '',
provinceList: [],
province: '',
province_index: '',
cityList: [],
city_index: '',
showPhoneInput: false,
isShow: false,
collapseText: '展开',
valuation: {},
carInfo: {},
terminal_names: [],
partner: [{
id: 0,
logo: '../../images/shop_tiantianpaiche.png',
name: '天天拍车',
selected: true,
des: '全国性二手车竞拍平台,买家在线竞拍,覆盖全国50多个主要城市,免费上门检测,最快一天成交!'
},
{
id: 1,
logo: '../../images/shop_guazi.png',
name: '瓜子二手车',
selected: true,
des: '提供保卖服务。专注个人二手车交易,个人卖主直接把车卖给个人买家!'
},
{
id: 2,
logo: '../../images/shop_chezhibao.png',
name: '车置宝',
selected: true,
des: '一个专注收车的网站。通过全业务流程大数据驱动,可以提供免费上门检测服务。即日起在车置宝成功卖车,最高可享20000元卖车补贴。'
},
{
id: 3,
logo: '../../images/shop_renrenche.png',
name: '人人车',
selected: true,
des: '全程免费帮卖,免费上门评估,边开边卖,代办过户!最高多卖20%!'
}
],
data: {
userForms: {
link: app.globalData.link,
specification_id: '',
specification_name: '',
buy_time: '',
mileage: '',
city_id: '',
city_name: '',
phone: '',
pre_phone: ''
},
onShow: function() {
let _this = this
this.setData({
provinceList: app.globalData.provinceList,
province_index: wx.getStorageSync('province_index'),
city_index: wx.getStorageSync('city_index')
}, () => {
if (_this.data.provinceList.length === 0) {
_this.getProvinceList()
} else {
let index = wx.getStorageSync('province_index')
let id = wx.getStorageSync('province_id')
if (index) {
_this.setData({
province: _this.data.provinceList[index].name
})
_this.getCityList(id, _this)
}
}
})
let years = wx.getStorageSync('years')
let startTime, endTime
if (years.length > 4) {
startTime = years.substr(0, 4)
endTime = years.substr(-4, 4)
let today = utils.formatDate(new Date())
if (today.indexOf(endTime) > -1) {
endTime = today
} else {
endTime = endTime + '-12-31'
inputSmsCode: '',
smsCode: '',
disabled: false,
totalTime: 120,
timer: null,
btnText: '获取验证码',
startTime: '',
endTime: '',
provinceList: [],
province: '',
province_index: '',
cityList: [],
city_index: '',
showPhoneInput: false,
isShow: false,
collapseText: '展开',
valuation: {},
carInfo: {},
terminal_names: [],
partner: [{
id: 0,
logo: '../../images/shop_tiantianpaiche.png',
name: '天天拍车',
selected: true,
des: '全国性二手车竞拍平台,买家在线竞拍,覆盖全国50多个主要城市,免费上门检测,最快一天成交!'
},
{
id: 1,
logo: '../../images/shop_guazi.png',
name: '瓜子二手车',
selected: true,
des: '提供保卖服务。专注个人二手车交易,个人卖主直接把车卖给个人买家!'
},
{
id: 2,
logo: '../../images/shop_chezhibao.png',
name: '车置宝',
selected: true,
des: '一个专注收车的网站。通过全业务流程大数据驱动,可以提供免费上门检测服务。即日起在车置宝成功卖车,最高可享20000元卖车补贴。'
},
{
id: 3,
logo: '../../images/shop_renrenche.png',
name: '人人车',
selected: true,
des: '全程免费帮卖,免费上门评估,边开边卖,代办过户!最高多卖20%!'
}
],
},
onShow: function() {
let _this = this
if (this.timer) {
clearInterval(this.timer)
}
this.setData({
provinceList: app.globalData.provinceList,
province_index: wx.getStorageSync('province_index'),
city_index: wx.getStorageSync('city_index'),
inputSmsCode: '',
smsCode: '',
disabled: false,
totalTime: 120,
timer: null,
btnText: '获取验证码'
}, () => {
if (_this.data.provinceList.length === 0) {
_this.getProvinceList()
} else {
let index = wx.getStorageSync('province_index')
let id = wx.getStorageSync('province_id')
if (index) {
_this.setData({
province: _this.data.provinceList[index].name
})
_this.getCityList(id, _this)
}
}
})
let years = wx.getStorageSync('years')
let startTime, endTime
if (years.length > 4) {
startTime = years.substr(0, 4)
endTime = years.substr(-4, 4)
let today = utils.formatDate(new Date())
if (today.indexOf(endTime) > -1) {
endTime = today
} else {
endTime = endTime + '-12-31'
}
this.setData({
startTime: startTime + '-01-01',
endTime: endTime
})
}
this.data.terminal_names = this.data.partner.map(item => item.name)
this.getItem('specification_id')
this.getItem('specification_name')
this.getItem('city_id')
this.getItem('city_name')
this.getItem('buy_time')
this.getItem('mileage')
this.getItem('phone')
let province = wx.getStorageSync('province')
this.setData({
province: province ? province : ''
})
},
// 获取省份
getProvinceList: function() {
let _this = this;
wx.request({
url: app.globalData.url + 'assess/provinces',
success: function(res) {
if (res.data && res.data.length > 0) {
let data = res.data
let arr = []
for (let key in data) {
if (data[key].id === 32) {
continue
}
this.setData({
startTime: startTime + '-01-01',
endTime: endTime
arr.push(data[key])
}
_this.setData({
provinceList: arr
})
}
}
})
},
// 城市列表
getCityList: function(parent_id, _this) {
wx.request({
url: app.globalData.url + 'assess/cities',
data: {
parent_id
},
success: function(res) {
if (res.errMsg === 'request:ok') {
let data = res.data
_this.setData({
cityList: data,
}, () => {
let index = wx.getStorageSync('city_index') || '0'
_this.setData({
['userForms.city_name']: _this.data.cityList[index].name
})
let city_id = _this.data.cityList[index].id;
let city_name = _this.data.cityList[index].name;
_this.setData({
['userForms.city_id']: city_id,
['userForms.city_name']: city_name,
})
wx.setStorageSync('city_id', city_id)
wx.setStorageSync('city_name', city_name)
})
}
this.data.terminal_names = this.data.partner.map(item => item.name)
this.getItem('specification_id')
this.getItem('specification_name')
this.getItem('city_id')
this.getItem('city_name')
this.getItem('buy_time')
this.getItem('mileage')
this.getItem('phone')
let province = wx.getStorageSync('province')
this.setData({
province: province ? province : ''
}
})
},
// 选择省份
changeProvince: function(e) {
let _this = this
let index = e.detail.value
let parent_id = this.data.provinceList[index].id
this.getCityList(parent_id, _this)
let province = this.data.provinceList[index].name;
let province_id = this.data.provinceList[index].id;
wx.setStorageSync('province', province)
wx.setStorageSync('province_id', province_id)
wx.setStorageSync('province_index', index)
this.setData({
province: province,
city_index: '0'
}, () => {
wx.setStorageSync('city_index', '0')
})
},
// 选择城市
changeCity: function(e) {
let index = e.detail.value
let city_id = this.data.cityList[index].id;
let city_name = this.data.cityList[index].name;
this.setData({
['userForms.city_id']: city_id,
['userForms.city_name']: city_name,
})
wx.setStorageSync('city_id', city_id)
wx.setStorageSync('city_name', city_name)
wx.setStorageSync('city_index', index)
},
// 选择品牌
selectBrand: function() {
app.globalData.enter = 'sell-car'
wx.navigateTo({
url: '/pages/car-select/brand',
})
},
// 更新值
getItem(item) {
let _this = this;
let data = wx.getStorageSync(item)
this.setData({
['userForms.' + item]: data ? data : ''
}, () => {
if (item === 'phone' && data) {
_this.setData({
showPhoneInput: true
})
}
})
},
// 选择日期
changeDate: function(e) {
let time = e.detail.value;
this.setData({
['userForms.buy_time']: time
})
wx.setStorageSync('buy_time', time)
},
// 输入行驶里程
mileageInput: function(e) {
let mileage = e.detail.value
this.setData({
['userForms.mileage']: mileage
})
wx.setStorageSync('mileage', mileage)
},
// 输入手机号 
phoneInput: function (e) {
let pre_phone = this.data.userForms.pre_phone
let phone = e.detail.value
if (pre_phone != phone) {
this.setData({
showSmsCode: true
})
} else if (pre_phone == phone) {
this.setData({
showSmsCode: false
})
wx.setStorageSync('phone', phone)
}
},
// 获取省份
getProvinceList: function() {
let _this = this;
this.setData({
['userForms.phone']: phone
})
// if (phone.length === 11) {
// wx.setStorageSync('phone', phone)
// }
},
// 输入验证码
smsCodeInput: function (e) {
let code = e.detail.value
this.setData({
inputSmsCode: code
})
},
// 倒计时
countDown: function () {
let _this = this;
_this.timer = setInterval(function () {
_this.data.totalTime--;
_this.data.btnText = _this.data.totalTime + '秒';
if (_this.data.totalTime < 0) {
clearInterval(_this.timer)
_this.setData({
totalTime: 120,
btnText: '重新获取'
})
} else {
_this.setData({
totalTime: _this.data.totalTime,
btnText: _this.data.btnText
})
}
}, 1000)
},
// 发送短信验证码
sendSmsCode: function (e) {
let _this = this
if (!this.data.userForms.specification_name) {
wx.showToast({
icon: 'none',
title: '请选择车型!'
})
return false;
}
if (!this.data.userForms.buy_time) {
wx.showToast({
icon: 'none',
title: '请选择上牌时间!'
})
return false;
}
if (!this.data.userForms.city_name) {
wx.showToast({
icon: 'none',
title: '请选择城市!'
})
return false;
}
if (!this.data.userForms.mileage) {
wx.showToast({
icon: 'none',
title: '请输入行驶里程!'
})
return false;
}
if (Number(this.data.userForms.mileage) > 100) {
wx.showToast({
icon: 'none',
title: '行驶里程不能超过100万公里!'
})
return false;
}
if (!this.data.userForms.phone) {
wx.showToast({
icon: 'none',
title: '请输入手机号码!'
})
return false;
}
let reg = /^1(3|4|5|7|8|9)\d{9}$/;
if (!reg.test(this.data.userForms.phone)) {
wx.showToast({
icon: 'none',
title: '手机号码格式不正确!'
})
return false;
}
let data = {
phone: this.data.userForms.phone
}
_this.setData({
disabled: true
}, () => {
wx.request({
url: app.globalData.urlSpecial + 'main-customers/get-new-sms',
data: data,
success: function (res) {
res = res.data
if (res.message === 'ok' && res.data && res.data.code) {
_this.setData({
smsCode: res.data.code,
}, () => {
_this.countDown();
})
} else if (res.message === 'ok' && res.data && res.data.error === 1) {
wx.showToast({
icon: 'none',
title: res.data.msg
})
_this.setData({
disabled: false
}, () => { })
}
},
fail: function (res) {
wx.showToast({
icon: 'none',
title: '获取失败,请稍后重试!'
})
}
})
})
},
// 获取手机号
getPhone: function (e) {
let _this = this
let errMsg = e.detail.errMsg
if (errMsg === 'getPhoneNumber:ok') {
if (app.globalData.session_key) {
let data = {
session_key: app.globalData.session_key,
encrypted_data: e.detail.encryptedData,
iv: e.detail.iv,
app_id: app.globalData.app_id
}
wx.request({
url: app.globalData.url + 'assess/provinces',
success: function(res) {
if (res.data && res.data.length > 0) {
let data = res.data
let arr = []
for (let key in data) {
if (data[key].id === 32) {
continue
}
arr.push(data[key])
}
_this.setData({
provinceList: arr
})
}
url: app.globalData.url + 'decode-phone',
data: data,
method: 'POST',
success: function (res) {
if (res.data.message !== '解密失败') {
let phone = res.data.purePhoneNumber
_this.setData({
['userForms.phone']: phone,
['userForms.pre_phone']: phone,
})
wx.setStorageSync('phone', phone)
} else {
wx.showToast({
icon: 'none',
title: '获取失败,请稍后重试!'
})
}
}
})
},
// 城市列表
getCityList: function(parent_id, _this) {
wx.request({
url: app.globalData.url + 'assess/cities',
data: {
parent_id
},
success: function(res) {
if (res.errMsg === 'request:ok') {
let data = res.data
} else {
_this.login(e)
}
} else if (errMsg === 'getPhoneNumber:fail user deny') {
this.setData({
['userForms.phone']: '',
['userForms.pre_phone']: '',
})
}
},
// 重新获取code
login: function (e) {
let _this = this
wx.login({
success: function (res) {
if (res.errMsg === 'login:ok') {
let data = {
code: res.code,
app_id: app.globalData.app_id
}
wx.request({
url: app.globalData.url + 'user-code',
data: data,
success: function (res) {
let data = {
session_key: res.data.session_key,
encrypted_data: e.detail.encryptedData,
iv: e.detail.iv,
app_id: app.globalData.app_id
}
wx.request({
url: app.globalData.url + 'decode-phone',
data: data,
method: 'POST',
success: function (res) {
if (res.data.message !== '解密失败') {
let phone = res.data.purePhoneNumber
_this.setData({
cityList: data,
}, () => {
let index = wx.getStorageSync('city_index') || '0'
_this.setData({
['userForms.city_name']: _this.data.cityList[index].name
})
let city_id = _this.data.cityList[index].id;
let city_name = _this.data.cityList[index].name;
_this.setData({
['userForms.city_id']: city_id,
['userForms.city_name']: city_name,
})
wx.setStorageSync('city_id', city_id)
wx.setStorageSync('city_name', city_name)
['userForms.phone']: phone,
['userForms.pre_phone']: phone,
})
wx.setStorageSync('phone', phone)
} else {
wx.showToast({
icon: 'none',
title: '获取失败,请稍后重试!'
})
}
}
})
}
})
},
// 选择省份
changeProvince: function(e) {
let _this = this
let index = e.detail.value
let parent_id = this.data.provinceList[index].id
this.getCityList(parent_id, _this)
let province = this.data.provinceList[index].name;
let province_id = this.data.provinceList[index].id;
wx.setStorageSync('province', province)
wx.setStorageSync('province_id', province_id)
wx.setStorageSync('province_index', index)
this.setData({
province: province,
city_index: '0'
}, () => {
wx.setStorageSync('city_index', '0')
})
},
// 选择城市
changeCity: function(e) {
let index = e.detail.value
let city_id = this.data.cityList[index].id;
let city_name = this.data.cityList[index].name;
this.setData({
['userForms.city_id']: city_id,
['userForms.city_name']: city_name,
})
wx.setStorageSync('city_id', city_id)
wx.setStorageSync('city_name', city_name)
wx.setStorageSync('city_index', index)
},
// 选择品牌
selectBrand: function() {
app.globalData.enter = 'sell-car'
wx.navigateTo({
url: '/pages/car-select/brand',
})
},
// 更新值
getItem(item) {
let _this = this;
let data = wx.getStorageSync(item)
this.setData({
['userForms.' + item]: data ? data : ''
}, () => {
if (item === 'phone' && data) {
_this.setData({
showPhoneInput: true
})
}
})
},
// 选择日期
changeDate: function(e) {
let time = e.detail.value;
this.setData({
['userForms.buy_time']: time
})
wx.setStorageSync('buy_time', time)
},
// 输入行驶里程
mileageInput: function(e) {
let mileage = e.detail.value
this.setData({
['userForms.mileage']: mileage
})
wx.setStorageSync('mileage', mileage)
},
// 输入手机号 
phoneInput: function(e) {
let phone = e.detail.value
this.setData({
['userForms.phone']: phone
})
if (phone.length === 11) {
wx.setStorageSync('phone', phone)
})
}
},
// 获取手机号
getPhone: function(e) {
let _this = this
let errMsg = e.detail.errMsg
if (errMsg === 'getPhoneNumber:ok') {
if (app.globalData.session_key) {
let data = {
session_key: app.globalData.session_key,
encrypted_data: e.detail.encryptedData,
iv: e.detail.iv,
app_id: app.globalData.app_id
}
wx.request({
url: app.globalData.url + 'decode-phone',
data: data,
method: 'POST',
success: function(res) {
if (res.data.message !== '解密失败') {
let phone = res.data.purePhoneNumber
_this.setData({
['userForms.phone']: phone,
})
wx.setStorageSync('phone', phone)
} else {
wx.showToast({
icon: 'none',
title: '获取失败,请稍后重试!'
})
}
}
})
} else {
_this.login(e)
}
} else if (errMsg === 'getPhoneNumber:fail user deny') {
this.setData({
['userForms.phone']: '',
showPhoneInput: true
})
}
})
},
// 是否勾选
handleSelect: function(e) {
let index = e.currentTarget.dataset.index;
let selected = e.currentTarget.dataset.selected;
let item = 'partner[' + index + '].selected';
this.setData({
[item]: !selected
}, () => {
let list = []
for (let key in this.data.partner) {
let item = this.data.partner[key]
if (item.selected) {
list.push(item.name)
}
},
// 重新获取code
login: function(e) {
let _this = this
wx.login({
success: function(res) {
if (res.errMsg === 'login:ok') {
let data = {
code: res.code,
app_id: app.globalData.app_id
}
wx.request({
url: app.globalData.url + 'user-code',
data: data,
success: function(res) {
let data = {
session_key: res.data.session_key,
encrypted_data: e.detail.encryptedData,
iv: e.detail.iv,
app_id: app.globalData.app_id
}
wx.request({
url: app.globalData.url + 'decode-phone',
data: data,
method: 'POST',
success: function(res) {
if (res.data.message !== '解密失败') {
let phone = res.data.purePhoneNumber
_this.setData({
['userForms.phone']: phone,
})
wx.setStorageSync('phone', phone)
} else {
wx.showToast({
icon: 'none',
title: '获取失败,请稍后重试!'
})
}
}
})
}
})
}
}
})
},
// 是否勾选
handleSelect: function(e) {
let index = e.currentTarget.dataset.index;
let selected = e.currentTarget.dataset.selected;
let item = 'partner[' + index + '].selected';
}
this.setData({
terminal_names: list
})
})
},
// 是否展示
showCollapse: function() {
this.setData({
isShow: !this.data.isShow
}, () => {
if (this.data.isShow) {
this.setData({
[item]: !selected
}, () => {
let list = []
for (let key in this.data.partner) {
let item = this.data.partner[key]
if (item.selected) {
list.push(item.name)
}
}
this.setData({
terminal_names: list
})
collapseText: '收起'
})
},
// 是否展示
showCollapse: function() {
} else {
this.setData({
isShow: !this.data.isShow
}, () => {
if (this.data.isShow) {
this.setData({
collapseText: '收起'
})
} else {
this.setData({
collapseText: '展开'
})
}
collapseText: '展开'
})
},
}
})
},
// 检测是否为空
checkValue: function() {
if (!this.data.userForms.specification_name) {
wx.showToast({
icon: 'none',
title: '请选择车型!'
})
return false;
}
if (!this.data.userForms.buy_time) {
wx.showToast({
icon: 'none',
title: '请选择上牌时间!'
})
return false;
}
if (!this.data.userForms.city_name) {
wx.showToast({
icon: 'none',
title: '请选择城市!'
})
return false;
}
if (!this.data.userForms.mileage) {
wx.showToast({
icon: 'none',
title: '请输入行驶里程!'
})
return false;
}
if (Number(this.data.userForms.mileage) > 100) {
wx.showToast({
icon: 'none',
title: '行驶里程不能超过100万公里!'
})
return false;
}
if (!this.data.userForms.phone) {
wx.showToast({
icon: 'none',
title: '请输入手机号码!'
})
return false;
}
let reg = /^1(3|4|5|7|8|9)\d{9}$/;
if (!reg.test(this.data.userForms.phone)) {
wx.showToast({
icon: 'none',
title: '手机号码格式不正确!'
})
return false;
}
// 检测是否为空
checkValue: function() {
if (!this.data.userForms.specification_name) {
wx.showToast({
icon: 'none',
title: '请选择车型!'
})
return false;
}
if (!this.data.userForms.buy_time) {
wx.showToast({
icon: 'none',
title: '请选择上牌时间!'
})
return false;
}
if (!this.data.userForms.city_name) {
wx.showToast({
icon: 'none',
title: '请选择城市!'
})
return false;
}
if (!this.data.userForms.mileage) {
wx.showToast({
icon: 'none',
title: '请输入行驶里程!'
})
return false;
}
if (Number(this.data.userForms.mileage) > 100) {
wx.showToast({
icon: 'none',
title: '行驶里程不能超过100万公里!'
})
return false;
}
if (!this.data.userForms.phone) {
wx.showToast({
icon: 'none',
title: '请输入手机号码!'
})
return false;
}
let reg = /^1(3|4|5|7|8|9)\d{9}$/;
if (!reg.test(this.data.userForms.phone)) {
wx.showToast({
icon: 'none',
title: '手机号码格式不正确!'
})
return false;
}
if (!this.data.inputSmsCode) {
wx.showToast({
icon: 'none',
title: '请输入短信验证码!'
})
return false;
}
if (this.data.terminal_names.length === 0) {
wx.showToast({
icon: 'none',
title: '至少选择一个卖车平台!'
})
return false;
}
if ((this.data.inputSmsCode != this.data.smsCode)) {
wx.showToast({
icon: 'none',
title: '短信验证码不正确!'
})
return false;
}
this.terminalAvailable(app.globalData.tiantianpaiche_cityList, '天天拍车');
if (this.data.terminal_names.length === 0) {
wx.showToast({
icon: 'none',
title: '至少选择一个卖车平台!'
})
return false;
}
let terminal_length = this.data.terminal_names.length;
let kaixun_terminal_index = this.data.terminal_names.indexOf('上海铠寻');
this.terminalAvailable(app.globalData.tiantianpaiche_cityList, '天天拍车');
if (this.data.userForms.city_name === '上海' && kaixun_terminal_index < 0) {
this.data.terminal_names[terminal_length] = '上海铠寻'
} else if (this.data.userForms.city_name !== '上海' && kaixun_terminal_index > 0) {
this.data.terminal_names.splice(kaixun_terminal_index, 1);
}
let terminal_length = this.data.terminal_names.length;
let kaixun_terminal_index = this.data.terminal_names.indexOf('上海铠寻');
this.terminalAvailable(app.globalData.chezhibao_cityList, '车置宝');
if (this.data.userForms.city_name === '上海' && kaixun_terminal_index < 0) {
this.data.terminal_names[terminal_length] = '上海铠寻'
} else if (this.data.userForms.city_name !== '上海' && kaixun_terminal_index > 0) {
this.data.terminal_names.splice(kaixun_terminal_index, 1);
}
this.terminalAvailable(app.globalData.renrenche_cityList, '人人车');
this.terminalAvailable(app.globalData.chezhibao_cityList, '车置宝');
return true;
},
this.terminalAvailable(app.globalData.renrenche_cityList, '人人车');
// 城市是否覆盖 是否选择推送
terminalAvailable: function(cityList, name) {
let terminal_length = this.data.terminal_names.length;
let index = cityList.indexOf(this.data.userForms.city_name);
let terminal_index = this.data.terminal_names.indexOf(name);
return true;
},
if (index < 0 && terminal_index > -1) {
this.data.terminal_names.splice(terminal_index, 1);
} else if (index > -1 && terminal_index < 0) {
this.data.terminal_names[terminal_length] = name
}
},
// 城市是否覆盖 是否选择推送
terminalAvailable: function(cityList, name) {
let terminal_length = this.data.terminal_names.length;
let index = cityList.indexOf(this.data.userForms.city_name);
let terminal_index = this.data.terminal_names.indexOf(name);
// 提交
submit: function() {
let _this = this;
if (this.checkValue()) {
wx.showLoading({
title: '卖车中',
mask: true
})
_this.data.terminal_names.push('精真估')
_this.setData({
terminal_names: _this.data.terminal_names
}, () => {
_this.storeCar();
})
if (index < 0 && terminal_index > -1) {
this.data.terminal_names.splice(terminal_index, 1);
} else if (index > -1 && terminal_index < 0) {
this.data.terminal_names[terminal_length] = name
}
},
// 提交
submit: function() {
let _this = this;
if (this.checkValue()) {
wx.showLoading({
title: '卖车中',
mask: true
})
_this.data.terminal_names.push('精真估')
_this.setData({
terminal_names: _this.data.terminal_names
}, () => {
_this.storeCar();
})
}
},
// 存储车
storeCar: function() {
let _this = this;
wx.request({
url: app.globalData.url + 'cars',
method: 'POST',
data: _this.data.userForms,
success: function(res) {
let data = res.data;
if (data.message === 'ok') {
let carInfo = data.data;
wx.setStorageSync('carInfo', carInfo)
let created_at = new Date(carInfo.created_at).getTime()
if (Date.now() - created_at < 3000) { // 新车
_this.sellCar();
} else { // 已存在
_this.updateStatus();
}
} else {
wx.showToast({
icon: 'none',
title: '请求错误,请稍后重试!'
})
}
},
// 存储车
storeCar: function() {
let _this = this;
wx.request({
url: app.globalData.url + 'cars',
method: 'POST',
data: _this.data.userForms,
success: function(res) {
let data = res.data;
if (data.message === 'ok') {
let carInfo = data.data;
wx.setStorageSync('carInfo', carInfo)
let created_at = new Date(carInfo.created_at).getTime()
if (Date.now() - created_at < 3000) { // 新车
_this.sellCar();
} else { // 已存在
_this.updateStatus();
}
} else {
wx.showToast({
icon: 'none',
title: '请求错误,请稍后重试!'
})
}
},
fail: function() {
wx.showToast({
icon: 'none',
title: '请求错误,请稍后重试!'
})
},
complete: function() {}
},
fail: function() {
wx.showToast({
icon: 'none',
title: '请求错误,请稍后重试!'
})
},
// 卖车接口
sellCar: function() {
let _this = this
wx.request({
url: app.globalData.url + 'distributions/push-to-terminals',
data: {
car_id: wx.getStorageSync('carInfo').id,
terminal_names: this.data.terminal_names
},
method: "POST",
success: function(res) {
if (res.data.message === 'ok') {
_this.updateStatus();
} else {
wx.showToast({
icon: 'none',
title: '请求错误,请稍后重试!'
})
}
},
fail: function() {
wx.showToast({
icon: 'none',
title: '请求错误,请稍后重试!'
})
},
complete: function() {}
},
complete: function() {}
})
},
// 卖车接口
sellCar: function() {
let _this = this
wx.request({
url: app.globalData.url + 'distributions/push-to-terminals',
data: {
car_id: wx.getStorageSync('carInfo').id,
terminal_names: this.data.terminal_names
},
method: "POST",
success: function(res) {
if (res.data.message === 'ok') {
_this.updateStatus();
} else {
wx.showToast({
icon: 'none',
title: '请求错误,请稍后重试!'
})
}
},
fail: function() {
wx.showToast({
icon: 'none',
title: '请求错误,请稍后重试!'
})
},
// 更新卖车状态
updateStatus: function() {
let _this = this;
wx.request({
url: app.globalData.url + 'distributions/update-sale-type',
data: {
sale_type: 1,
car_id: wx.getStorageSync('carInfo').id
},
method: "POST",
success: function(res) {
if (res.data.message === 'ok') {
app.globalData.enter = 'sell-car'
wx.navigateTo({
url: '/pages/submit/submit',
})
} else {
wx.showToast({
icon: 'none',
title: '请求错误,请稍后重试!'
})
}
},
fail: function() {
wx.showToast({
icon: 'none',
title: '请求错误,请稍后重试!'
})
},
complete: function() {}
},
complete: function() {}
})
},
// 更新卖车状态
updateStatus: function() {
let _this = this;
wx.request({
url: app.globalData.url + 'distributions/update-sale-type',
data: {
sale_type: 1,
car_id: wx.getStorageSync('carInfo').id
},
method: "POST",
success: function(res) {
if (res.data.message === 'ok') {
app.globalData.enter = 'sell-car'
wx.navigateTo({
url: '/pages/submit/submit',
})
} else {
wx.showToast({
icon: 'none',
title: '请求错误,请稍后重试!'
})
}
},
fail: function() {
wx.showToast({
icon: 'none',
title: '请求错误,请稍后重试!'
})
},
// 分享
onShareAppMessage: function() {
return {
title: "高价卖车",
path: "/pages/sellcar/sellcar"
};
}
},
complete: function() {}
})
},
// 分享
onShareAppMessage: function() {
return {
title: "高价卖车",
path: "/pages/sellcar/sellcar"
};
}
})
\ No newline at end of file
......@@ -68,6 +68,17 @@
<button bindgetphonenumber="getPhone" id="get-phone" openType="getPhoneNumber" size="mini" type="primary" wx:else>11位手机号</button> -->
</view>
</view>
<view class="weui-cell weui-cell_input form-input-item">
<view class="weui-cell__hd">
<view class="weui-label">验 证 码</view>
</view>
<view class="weui-cell__bd">
<input bindinput="smsCodeInput" maxlength="6" class="weui-input text-right" placeholder="请输入短信验证码" type="digit" value="{{inputSmsCode}}"></input>
</view>
<view class="weui-cell__ft">
<button bindtap="sendSmsCode" id="get-smsCode" class="{{disabled ? 'disabled': ''}}" size="mini" type="primary" disabled="{{disabled}}">{{btnText}}</button>
</view>
</view>
</view>
</view>
......
......@@ -238,3 +238,20 @@ page {
width: 202rpx;
height: 32rpx;
}
#get-smsCode {
display: block;
padding: 3px 5px;
margin-left: 30rpx;
width: 180rpx;
line-height: 2;
background: #fe560e;
color:#fff;
border-color: white;
font-size: 26rpx;
text-align: center;
}
button.disabled {
background: #cec5c0 !important;
}
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment