291 lines
9.8 KiB
JavaScript
291 lines
9.8 KiB
JavaScript
var app = getApp();
|
||
import { postRequest, getRequest, putRequest } from '../../utils/js/request'
|
||
import { queryLogin, queryInfo, signIn } from '../../utils/js/locales'
|
||
Page({
|
||
data: {
|
||
backgroundColor: '',
|
||
refund: '1',
|
||
selectFile: '',
|
||
uplaodFile: '',
|
||
|
||
corporation_name: '',
|
||
unified_tax_code: '',
|
||
business_licence: '',
|
||
contacts_name: '',
|
||
contacts_mobile: '',
|
||
enterprise: [],
|
||
|
||
name: '',
|
||
card_number: '',
|
||
id_main: '',
|
||
id_extra: '',
|
||
id_card: [],
|
||
|
||
isfront: '', // 上传的图片类型
|
||
openState: false, // 开户状态
|
||
},
|
||
/** 生命周期函数--监听页面加载 */
|
||
onLoad: function (options) {
|
||
this.setData({
|
||
openState: false,
|
||
selectFile: this.selectFile.bind(this),
|
||
uplaodFile: this.uplaodFile.bind(this),
|
||
uplaodFileEnterprise: this.uplaodFileEnterprise.bind(this),
|
||
backgroundColor: app.globalData.systemConfiguration.backgroundColor,
|
||
|
||
corporation_name: app.globalData.member_info.name,
|
||
name: app.globalData.operator_info.name
|
||
})
|
||
// 查询认证信息
|
||
// this.queryAuthenticationInformation()
|
||
},
|
||
|
||
onShow: function () {
|
||
const { corporation_name, name, } = this.data;
|
||
let enterprise = app.globalData.authentication.enterprise
|
||
let personal = app.globalData.authentication.personal
|
||
this.setData({
|
||
corporation_name: corporation_name ? corporation_name : enterprise.corporation_name,
|
||
unified_tax_code: enterprise.unified_tax_code,
|
||
business_licence: enterprise.business_licence,
|
||
enterprise: enterprise.enterprise,
|
||
name: name ? name : personal.name,
|
||
card_number: personal.card_number,
|
||
id_main: personal.id_main,
|
||
id_extra: personal.id_extra,
|
||
id_card: personal.id_card
|
||
})
|
||
},
|
||
// 查询认证信息 目前缺少 身份证号 企业统一税号 等
|
||
// queryAuthenticationInformation() {
|
||
// getRequest('/v1/m/my/cert',{}).then(res => {
|
||
// console.log(res)
|
||
// }).catch(err => {
|
||
// wx.hideLoading();
|
||
// signIn(err);
|
||
// })
|
||
// },
|
||
|
||
// 选择认证类型
|
||
radioChange(e) {
|
||
this.setData({ refund: e.detail.value })
|
||
},
|
||
// 选择图片时的过滤函数,返回true表示图片有效, 返回false可以阻止某次文件上传
|
||
selectFile(files) {
|
||
let tempFiles = files.tempFiles
|
||
if (tempFiles[0].size > (7 * 1024 * 1024)) {
|
||
wx.showToast({ title: '请选择小于7MB的图片', icon: 'none', duration: 2000 })
|
||
return false
|
||
}
|
||
},
|
||
// 上传企业执照图片,
|
||
uplaodFileEnterprise(files) {
|
||
// 文件上传的函数,返回一个promise
|
||
return new Promise((resolve, reject) => {
|
||
let tempFilePaths = files.tempFilePaths;
|
||
let that = this;
|
||
wx.showLoading({ title: '正在上传...', mask: true })
|
||
wx.uploadFile({
|
||
url: 'https://tokamak.amtcloud.cn/uploader/v1/upload', //需要用HTTPS,同时在微信公众平台后台添加服务器地址
|
||
filePath: tempFilePaths[0], //上传的文件本地地址
|
||
name: 'file',
|
||
success: function(res) {
|
||
let data = JSON.parse(res.data);
|
||
if (data.Code === 0) {
|
||
let _data = data.Data
|
||
that.setData({ business_licence: _data[0].Preview, enterprise: [ { url: _data[0].Preview } ] });
|
||
that.ocrLicense(_data[0].Preview);
|
||
resolve(_data)
|
||
} else {
|
||
wx.showToast({ icon: 'none', title: '上传失败', duration: 2000 })
|
||
reject(res)
|
||
}
|
||
},
|
||
fail: function(err) {
|
||
wx.hideLoading();
|
||
wx.showToast({ icon: 'none', title: '上传失败', duration: 2000 })
|
||
}
|
||
})
|
||
})
|
||
},
|
||
// 营业执照ocR
|
||
ocrLicense(preview) {
|
||
let that = this;
|
||
getRequest(`/v1/di/ocr/license?imageurl=${preview}`,{}).then(res => {
|
||
that.setData({
|
||
corporation_name: res.data.Name,
|
||
unified_tax_code: res.data.RegNum
|
||
})
|
||
wx.hideLoading();
|
||
}).catch(err => {
|
||
wx.hideLoading();
|
||
})
|
||
},
|
||
// 上传身份证照图片,
|
||
uplaodFile(files) {
|
||
// 文件上传的函数,返回一个promise
|
||
return new Promise((resolve, reject) => {
|
||
let tempFilePaths = files.tempFilePaths;
|
||
let that = this;
|
||
wx.showLoading({ title: '正在上传...', mask: true })
|
||
wx.uploadFile({
|
||
url: 'https://tokamak.amtcloud.cn/uploader/v1/upload',
|
||
filePath: tempFilePaths[0], //上传的文件本地地址
|
||
name: 'file',
|
||
success: function(res) {
|
||
wx.hideLoading();
|
||
let data = JSON.parse(res.data);
|
||
if (data.Code === 0) {
|
||
let _data = data.Data
|
||
that.setData({ id_main: _data[0].Preview, id_extra: _data[0].Preview, id_card: [ { url: _data[0].Preview } ] });
|
||
resolve(_data)
|
||
} else {
|
||
wx.showToast({ icon: 'none', title: '上传失败', duration: 2000 })
|
||
reject(res)
|
||
}
|
||
},
|
||
fail: function(err) {
|
||
wx.hideLoading();
|
||
wx.showToast({ icon: 'none', title: '上传失败', duration: 2000 })
|
||
}
|
||
})
|
||
})
|
||
},
|
||
// 图片上传失败的事件
|
||
uploadError(e) {
|
||
console.log('upload error', e.detail)
|
||
},
|
||
// 图片上传成功的事件
|
||
uploadSuccess(e) {
|
||
wx.showToast({ icon: 'none', title: '上传图片失败,请删除后重新上传!', duration: 3000 })
|
||
},
|
||
// 删除图片
|
||
binddelete(e) {
|
||
if (this.data.refund === '1') {
|
||
this.setData({ business_licence: '', enterprise: [] })
|
||
} else {
|
||
this.setData({ id_main: '', id_extra: '', id_card: [] })
|
||
}
|
||
},
|
||
inputCorporationName(e) {
|
||
this.setData({ corporation_name: e.detail.value })
|
||
},
|
||
inputUnifiedTaxCode(e) {
|
||
this.setData({ unified_tax_code: e.detail.value })
|
||
},
|
||
inputContactsName(e) {
|
||
this.setData({ contacts_name: e.detail.value })
|
||
},
|
||
inputContactsMobile(e) {
|
||
this.setData({ contacts_mobile: e.detail.value })
|
||
},
|
||
inputName(e) {
|
||
this.setData({ name: e.detail.value })
|
||
},
|
||
inputCardNumber(e) {
|
||
this.setData({ card_number: e.detail.value })
|
||
},
|
||
|
||
// 提交
|
||
submit() {
|
||
const { refund, corporation_name, unified_tax_code, contacts_name, business_licence, name, card_number, id_main, id_extra } = this.data;
|
||
let that = this;
|
||
if (refund === '1') { // 认证公司企业
|
||
if (!business_licence) return wx.showToast({ icon: 'none', title: '请上传营业执照!', duration: 2000 })
|
||
if (!corporation_name) return wx.showToast({ icon: 'none', title: '请输入企业名称!', duration: 2000 })
|
||
if (!unified_tax_code) return wx.showToast({ icon: 'none', title: '请输入纳税人识别号!', duration: 2000 })
|
||
if (!contacts_name) return wx.showToast({ icon: 'none', title: '请输入联系人姓名!', duration: 2000 })
|
||
let data = {
|
||
corporation_name,
|
||
// main_business: [businessList[main_business]],
|
||
unified_tax_code,
|
||
business_licence,
|
||
contacts_name,
|
||
}
|
||
wx.showLoading({ title: '认证中' })
|
||
if (app.globalData.member_info.name && (app.globalData.member_info.name !== '')) {
|
||
putRequest('/v1/m/cert/enterprise', data).then(res => {
|
||
setTimeout(function() {
|
||
queryLogin(app);
|
||
}, 2000)
|
||
setTimeout(function() {
|
||
queryInfo(app);
|
||
wx.hideLoading();
|
||
app.globalData.authentication.enterprise = {
|
||
corporation_name: corporation_name,
|
||
unified_tax_code: unified_tax_code,
|
||
business_licence: business_licence,
|
||
enterprise: [ { url: business_licence } ]
|
||
}
|
||
that.setData({ openState: true })
|
||
}, 3000);
|
||
}).catch(err => {
|
||
signIn(err);
|
||
wx.hideLoading();
|
||
})
|
||
} else {
|
||
postRequest('/v1/m/cert/enterprise', data).then(res => {
|
||
setTimeout(function() {
|
||
queryLogin(app);
|
||
}, 2000)
|
||
setTimeout(function() {
|
||
queryInfo(app);
|
||
wx.hideLoading();
|
||
app.globalData.authentication.enterprise = {
|
||
corporation_name: corporation_name,
|
||
unified_tax_code: unified_tax_code,
|
||
business_licence: business_licence,
|
||
enterprise: [ { url: business_licence } ]
|
||
}
|
||
that.setData({ openState: true })
|
||
}, 3000);
|
||
}).catch(err => {
|
||
signIn(err);
|
||
wx.hideLoading();
|
||
})
|
||
}
|
||
} else if (refund === '2') { // 认证个人
|
||
if (!id_main) return wx.showToast({ icon: 'none', title: '请上传身份证正面!', duration: 2000 })
|
||
if (!id_extra) return wx.showToast({ icon: 'none', title: '请上传身份证反面!', duration: 2000 })
|
||
if (!name) return wx.showToast({ icon: 'none', title: '请输入姓名!', duration: 2000 })
|
||
if (!card_number) return wx.showToast({ icon: 'none', title: '请输入身份证号!', duration: 2000 })
|
||
let data = {
|
||
name: name,
|
||
card_number: card_number,
|
||
id_main: id_main,
|
||
id_extra: id_extra,
|
||
}
|
||
wx.showLoading({ title: '认证中' })
|
||
postRequest('/v1/m/cert/personal', data).then(res => {
|
||
setTimeout(function() {
|
||
queryLogin(app);
|
||
}, 2000)
|
||
setTimeout(function() {
|
||
queryInfo(app);
|
||
wx.hideLoading();
|
||
app.globalData.authentication.personal = {
|
||
name: name,
|
||
card_number: card_number,
|
||
id_main: id_main,
|
||
id_extra: id_extra,
|
||
id_card: [ { url: id_main } ]
|
||
}
|
||
that.setData({ openState: true })
|
||
}, 3000);
|
||
}).catch(err => {
|
||
signIn(err);
|
||
wx.hideLoading();
|
||
})
|
||
}
|
||
},
|
||
// 去开平安银行户
|
||
openAccount() {
|
||
let that = this;
|
||
app.globalData.behaviorRecord = 1;
|
||
setTimeout(function() {
|
||
that.setData({ openState: false })
|
||
wx.navigateBack({ delta: 1 })
|
||
}, 1000)
|
||
}
|
||
|
||
}) |