123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120 |
- const app = getApp();
- const util = require("../../../util/util.js")
- Page({
- data: {
- StatusBar: app.globalData.StatusBar,
- CustomBar: app.globalData.CustomBar,
- ctx: false,
- hidden: true,
- showcamara: false,
- type:'card',
- phone:'',
- info:{
- card_code:"",
- phone:"",
- name:""
- }
- },
- onLoad: function (options) {
- let info = this.data.info;
- app.getMakerInfo( res =>{
- Object.assign( info, res )
- let phone = info.phone||''
- this.setData( {info, phone })
- })
- },
- onReady: function (res) {
- var ctx = wx.createCameraContext('myCamera')
- this.setData({ ctx: ctx })
- },
- getInfo( ){
- util.http( '/wx/getMakerInfo', {}, (err,res)=>{
- if( err!= 0 ) return;
- console.log("http",err, res)
- let phone= res.info.phone||''
- this.setData({info: res.info,phone})
- })
- },
- previewImage: function (e) {
- var current = e.target.dataset.src;
- wx.previewImage({
- current: current,
- urls: [current]
- })
- } ,
- takeCard(){
- this.setData( {showcamara:true, type:'card'})
- },
- takeCardBack(){
- this.setData( {showcamara:true, type:'cardBack'})
- },
- identify( err, {url} ){
- if( err !=0 || !url ) {
- util.showMsg("图片上传失败")
- return
- }
- util.showBusy("识别图片中")
- let info = this.data.info
- let method=this.data.type=='card'?'/maker/addMakerCard':'/maker/addMakerBackCard';
- let showcamara= false
- util.http( method, {url}, (err,res)=>{
- if( err!= 0 ) return;
- util.showBusy("上传成功")
- Object.assign( info, res)
- this.setData({info,showcamara})
- })
- },
- chooseImg: function () {
- var that = this
- wx.chooseImage({
- count: 1,
- sizeType: ['compressed'],
- sourceType: ['album'],
- success: function (res) {
- that.setData( {showcamara:false})
- util.showBusy("图片上传中")
- util.uploadFile( res.tempFilePaths[0], that.identify )
- },
- fail:(res)=>{
- console.log( res)
- util.showMsg("图片选择失败")
- }
- })
- },
- takePhoto() {
- var that = this
- var ctx = this.data.ctx
- ctx.takePhoto({
- quality: 'low',
- success: (res) => {
- util.showSuccess("图片上传中")
- that.setData( {showcamara:false})
- var tempImagePath = res.tempImagePath
- util.uploadFile( tempImagePath, that.identify )
- },
- fail: (res)=> {
- app.showMsg('拍照失败')
- }
- })
- },
- onConfirm( e ){
- let {phone} = e.detail.value
- let info = this.data.info
- let {card_img, card_back_img} = this.data.info
- if( !card_img ) return util.showMsg( "身份证正面有误");
- if( !card_back_img ) return util.showMsg( "身份证背面有误");
- if( !phone || phone.length != 11 ) return util.showMsg( "手机号码有误");
- util.http( '/maker/identifyMaker', {phone}, (err,res)=>{
- if( err!= 0 ) return;
- info.identify = 1
- app.identifyUser( )
- this.setData({info})
- })
- },
- goBack() {
- wx.navigateBack({
- delta: 1
- })
- }
- })
|