You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 

310 lines
7.3 KiB

// pages/report/report.js
const app = getApp()
const utils = require('../../utils/util')
const axios = require('../../api/index')
let timer = null;
Page({
/**
* 页面的初始数据
*/
data: {
imageServerUrl: getApp().globalData.imageServerUrl,
name: null, //姓名
gender: null, //性别
id_card: null, //身份证号码
issued_address: null, //签发地址
front_url: null, //正面
back_url: null, //反面
time: 0,
is_select: false,
// detail: false
detail: {state:30}
},
select_fn() {
this.setData({
is_select: !this.data.is_select
})
},
upload(e) {
axios.getAuthToken().then(res => {
let type = e.currentTarget.dataset.type,
{
access_token
} = res.data;
this.OcrIdCard(access_token, type).then(res => {
let data = res.data.words_result
if (type == 'front') {
this.setData({
name: data['姓名'].words,
id_card: data['公民身份号码'].words,
gender: data['性别'].words,
})
} else {
this.setData({
issued_address: data['签发机关'].words,
})
}
})
})
},
authentication() {
if (this.check_data()) return
wx.requestSubscribeMessage({
tmplIds: ['dm1yuO5nVqiRQyMWcS4VZOjOZY5rDCjhiqiUcueyMJc'],
complete: res => {
wx.showLoading({
title: '正在提交...',
})
let {
name,
gender,
id_card,
issued_address,
front_url,
back_url,
code,
id
} = this.data, data = {
name,
gender,
idCard: id_card,
issuedAddress: issued_address,
positivePhoto: front_url,
reversePhoto: back_url,
verifyCode: code,
},url = 'api/v1/certification';
let method="post"
if(id){
data.id = id;
url = 'api/v1/certification/update'
method="put"
// url = 'api/authentication/'+id
}
axios.autonym({
url,
data,
method
}).then(res => {
console.log(res)
if(res.code == 0 ){
wx.showToast({
title: res.msg || '提交失败',
icon: 'none'
});
return
}
wx.hideLoading()
wx.showToast({
title: '提交成功',
duration: 1500
})
this.get_status()
}).catch(err => {
wx.hideLoading()
wx.showToast({
title: err.msg || '提交失败,请重试',
icon: 'none',
duration: 1500
})
})
}
})
},
check_data() {
let {
name,
id_card,
front_url,
back_url,
is_select
} = this.data, str = '';
if (!name && !id_card) {
str = '请上传身份证'
} else if (!front_url) {
str = '请上传身份证的正面'
} else if (!back_url) {
str = '请上传身份证的反面'
} else if (!is_select) {
str = '请勾选最下方的协议'
}
if (str) {
wx.showToast({
title: str,
icon: 'none',
duration: 1500
})
}
return str
},
bind_input(e) {
this.setData({
[e.target.dataset.type]: e.detail.value
})
},
OcrIdCard(access_token, type) {
var that = this;
return new Promise(function (resolve, reject) {
//识别身份证
wx.chooseImage({
count: 1,
sizeType: ['compressed'],
sourceType: ['album', 'camera'],
success: res => {
//核心代码
wx.getFileSystemManager().readFile({
filePath: res.tempFilePaths[0],
encoding: 'base64', //编码格式
success: ans => {
wx.showLoading({
title: '识别中'
})
wx.request({
url: 'https://aip.baidubce.com/rest/2.0/ocr/v1/idcard?access_token=' + access_token,
method: 'POST',
header: {
'Content-Type': 'application/x-www-form-urlencoded'
},
data: {
image: ans.data,
id_card_side: type,
detect_direction: true
},
success: _res => {
if (_res.data.image_status != 'normal') {
wx.showToast({
title: '上传文件有误,请检查正确后重新上传',
icon: 'none',
duration: 1500
})
return
}
let filePath = res.tempFilePaths[0];
utils.upLoadFileCos(filePath, ((err,res) => {
if(err){
wx.showToast({
title: message || '上传失败',
icon: 'none'
})
return
}
wx.hideLoading();
that.setData({
[`${type}_url`]: res.headers.Location
})
}))
resolve(_res)
},
fail(_res) {
wx.hideLoading();
wx.showToast({
title: '请求出错',
})
reject(_res)
}
})
}
})
}
})
})
},
// 获取实名认证状态
get_status() {
axios.getCertification().then(res => {
wx.hideLoading()
console.log(res)
if(res.code == 0 ) {
this.setData({
detail: null
})
return
}
if(res.data.state == 20 ){
console.log(123456)
wx.showModal({
title: '温馨提示',
content: '您好,您上传的身份信息未能通过核验,为无效身份,请您重新上传清晰可辨识的身份证照片,如有疑问,请联系客服:13172630803',
showCancel: false,
confirmColor: '#3476FE'
})
this.setData({
id: res.data.id || 0,
})
return
}
let { name, idCard, positivePhoto, reversePhoto, gender, id} = res.data;
this.setData({
id: id || 0,
detail: res.data,
name,
gender,
id_card: idCard,
front_url: positivePhoto,
back_url: reversePhoto,
})
}).catch(err => {
wx.hideLoading()
})
},
/**
* 生命周期函数--监听页面加载
*/
onLoad: function (options) {
wx.showLoading({
title: '加载中...',
mask: true
})
this.get_status()
},
/**
* 生命周期函数--监听页面初次渲染完成
*/
onReady: function () {
},
/**
* 生命周期函数--监听页面显示
*/
onShow: function () {
},
/**
* 生命周期函数--监听页面隐藏
*/
onHide: function () {
},
/**
* 生命周期函数--监听页面卸载
*/
onUnload: function () {
},
/**
* 页面相关事件处理函数--监听用户下拉动作
*/
onPullDownRefresh: function () {
},
/**
* 页面上拉触底事件的处理函数
*/
onReachBottom: function () {
},
/**
* 用户点击右上角分享
*/
})