<!--pages/oneclicksales/oneclicksales.wxml-->
<form bindsubmit="submitMsg" >
<view>
<label class="weui-label"><label style="color:red;">*</label>昵称:</label>
<input name="nickname" value="{{nickname}}" placeholder="请填写昵称"></input>
<button open-type='getUserInfo' lang="zh_CN" bindgetuserinfo="getUserInfo" class="weui-btn mini-btn" type="primary" size="mini">获取昵称</button>
</view>
<view>
<label class="weui-label"><label style="color:red;">*</label>手机号:</label>
<input name="mobile" value="{{mobile}}" value="{{mobile}}" placeholder="请填写手机号"></input>
<button class="weui-btn mini-btn" type="primary" size="mini" open-type="getPhoneNumber" bindgetphonenumber="getPhoneNumber">获取手机号</button>
</view>
<view>
<label class="weui-label"><label style="color:red;">*</label>真实姓名:</label>
<input name="real_name" placeholder="请填写真实姓名"></input>
<label class="weui-label"><label style="color:red;">*</label>身份证号:</label>
<input name="idcard" placeholder="请填写身份证号"></input>
</view>
<view>
<label class="weui-label">驾照申请时间:</label>
<picker mode="date" value="{{license_time}}" end="{{endday}}" name='license_time' bindchange="bindreg_time">
<text wx:if="{{!license_time}}">请选择时间</text>
<rich-text wx:esle>{{license_time}}</rich-text>
</picker>
</view>
<view>
<view class='driver'>
<label>驾照照片</label>
<view class='driver_cate'>
<view wx:for="{{picArray}}" wx:key="{{key}}">
<image src='/images/del.png' class='del' data-index='{{index}}' catchtap='del'></image>
<image src='{{item}}' data-src="{{item}}" catchtap='previewImage'></image>
</view>
<view class='add' bindtap="chooseImg"> + </view>
</view>
</view>
</view>
<view class="tr" wx:for="{{list}}">
<checkbox-group bindchange="checkboxChange">
<label class="checkbox">
<checkbox value="{{item.Id}}" />{{item.F_FullName}}
</label>
</checkbox-group>
</view>
<button class="weui-btn" hover-class="none" formType="submit">一键成为销售</button>
</form>
// pages/oneclicksales/oneclicksales.js
var WXBizDataCrypt = require('../../utils/cryptojs-master/RdWXBizDataCrypt.js');
const app = getApp()
var checkvalue
Page({
/**
* 页面的初始数据
*/
data: {
//户型 这是一个本地的对象,然后绑定到页面上
list:[],
picArray: [],
site_url: [],
},
checkboxChange(e) {
console.log('checkbox发生change事件,携带value值为:', e.detail.value)
checkvalue = e.detail.value;
},
//当前图片显示的事件
previewImage: function (e) {
var current = e.target.dataset.src;
wx.previewImage({
current: current, // 当前显示图片的http链接
urls: this.data.picArray // 需要预览的图片http链接列表
})
},
//删除图片的事件
del: function (e) {
let index = e.currentTarget.dataset.index;
let pic = this.data.picArray;
pic.splice(index, 1);
let site_url = this.data.site_url;
site_url.splice(index, 1);
this.setData({
picArray: pic,
site_url: site_url
})
},
//行驶证照片上传
chooseImg: function (e) {
let pic = this.data.picArray
var _this = this;
var arr;
wx.chooseImage({
count: 2,
sizeType: ['compressed'], // 可以指定是原图还是压缩图,默认二者都有
sourceType: ['album', 'camera'], // 可以指定来源是相册还是相机,默认二者都有
success: function (res) {
arr = res.tempFilePaths;
for (let x = 0; x < arr.length; x++) {
wx.uploadFile({
url: getApp().globalData.api_url + 'api/dyhl_api_token/upimage',
filePath: res.tempFilePaths[x],
name: 'file',
success: function (img) {
var obj = JSON.parse(img.data);
let data = (typeof (obj) == "string" ? JSON.parse(obj) : obj).data;
console.log(_this.data.picArray);
console.log('图片地址'+data.http_url);
let picArray = _this.data.picArray;
picArray.push(data.http_url);
console.log(picArray);
let site_url = _this.data.site_url;
site_url.push(data.site_url);
_this.setData({
site_url: site_url,
picArray: picArray
})
},
})
}
}
})
},
//选中时间的事件
bindreg_time: function (e) {
this.setData({
license_time: e.detail.value
})
},
//获取昵称
getUserInfo: function (e) {
var _this = this;
if(e.detail.userInfo){
console.log(e.detail.userInfo);
this.setData({
nickname:String(e.detail.userInfo.nickName),
})
this._updateUserInfo(e.detail.userInfo);
}
},
//获取昵称调用的后台API
_updateUserInfo: function (userInfo) {
var _this = this;
wx.request({
url:'https://wxxcxnet.shijiagouche.com/api/dyhl_user/userinfo',
data: {
token: null,
openid: app.globalData.openid,
nickname: userInfo.nickName,
sex: userInfo.gender,
province: userInfo.province,
city: userInfo.city,
country: userInfo.country,
headimgurl: userInfo.avatarUrl,
unionid: ''
},
header: {
"Content-Type": "application/x-www-form-urlencoded"
},
method: "POST",
success: function (res) {
}
})
},
//点击获取手机号码按钮
getPhoneNumber (e) {
var myEventDetail = { isRegister:false}; // detail对象,提供给事件监听函数
var myEventOption = {}; // 触发事件的选项
if (typeof (e.detail.encryptedData) == "undefined") { //获取手机号失败
myEventDetail.isRegister=false;
} else{
myEventDetail.isRegister=true;
myEventDetail.encryptedData = e.detail.encryptedData;
myEventDetail.iv = e.detail.iv;
}
this.triggerEvent('visitorRegisterPhoneEvent', myEventDetail, myEventOption)
var appId = app.globalData.appid;
let sessionKey = app.globalData.sessionKey;
var pc = new WXBizDataCrypt(appId, sessionKey);
var de_data = pc.decryptData(e.detail.encryptedData, e.detail.iv)
this.setData({
mobile:de_data.purePhoneNumber,
})
this.register(de_data.purePhoneNumber);
},
//获取手机号调用的后台API
register: function (phone) {
var _this = this;
wx.request({
url: api_url + 'api/dyhl_user/AddClue',
data: {
token: app.globalData.token,
openid: app.globalData.openid,
mobile: phone,
BelongToSaler:formid
},
header: {
"Content-Type": "application/x-www-form-urlencoded"
},
method: "POST",
success: function (res) {
app.hideLoading();
let data = typeof (res.data) == "string" ? JSON.parse(res.data) : res.data;
if (data.code != 0) {
wx.showModal({
title: '提示',
content: data.msg,
confirmColor: '#ff696a',
showCancel: false
})
}
else {
wx.showModal({
title: '提示',
content: '注册成功',
confirmColor: '#ff696a',
showCancel: false
})
}
}
})
},
//申请事件
submitMsg: function (e) {
var _this = this;
//字段验证
if (e.detail.value.real_name == '') {
wx.showToast({
title: '真实姓名不能为空!',
icon: 'none',
duration: 1000
})
return false;
}
//身份证具有非空验证和正则表达式验证
var reg = /(^\d{15}$)|(^\d{18}$)|(^\d{17}(\d|X|x)$)/;
if (reg.test(e.detail.value.idcard) === false) {
wx.showToast({
title: '身份证不能为空或格式不正确!',
icon: 'none',
duration: 1000
})
return false;
}
console.log('驾照时间'+e.detail.value.license_time);
console.log('驾照照片'+_this.data.site_url);
app.showLoading('发布中...');
return;
wx.request({
//url: api_url + 'api/dyhl_user/Oneclicksales',
url:'http://localhost:10297/api/dyhl_user/Oneclicksales',
data: {
token: app.globalData.token,
openid: app.globalData.openid,
termId: checkvalue
},
header: {
"Content-Type": "application/x-www-form-urlencoded"
},
method: "POST",
success: function (res) {
app.hideLoading();
console.log(res);
let data = typeof (res.data) == "string" ? JSON.parse(res.data) : res.data;
console.log(data);
if (data.code == 0) {
wx.switchTab({
url: "/pages/home/home"
})
wx.navigateBack({
delta: 1
})
}
}
})
},
/**
* 生命周期函数--监听页面加载
*/
onLoad: function (options) {
var that = this;
wx.request({
url: "http://localhost:10297/api/dyhl_user/GetIterm",
data: {
a: "" //参数
},
header: {
"Content-Type": "applicatiSon/x-www-form-urlencoded"
},
method: "GET",
success: function (res) {
let data = (typeof (res.data) == "string" ? JSON.parse(res.data) : res.data);
console.log(data);
that.setData({
list: data, //把json数据赋值给变量pic_array_hx
})
}
});
},
/**
* 生命周期函数--监听页面初次渲染完成
*/
onReady: function () {
},
/**
* 生命周期函数--监听页面显示
*/
onShow: function () {
},
/**
* 生命周期函数--监听页面隐藏
*/
onHide: function () {
},
/**
* 生命周期函数--监听页面卸载
*/
onUnload: function () {
},
/**
* 页面相关事件处理函数--监听用户下拉动作
*/
onPullDownRefresh: function () {
},
/**
* 页面上拉触底事件的处理函数
*/
onReachBottom: function () {
},
/**
* 用户点击右上角分享
*/
onShareAppMessage: function () {
}
})