index.js 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  1. const app = getApp();
  2. const util = require("../../../util/util.js")
  3. Page({
  4. data: {
  5. StatusBar: app.globalData.StatusBar,
  6. CustomBar: app.globalData.CustomBar,
  7. ctx: false,
  8. hidden: true,
  9. showcamara: false,
  10. type:'card',
  11. phone:'',
  12. info:{
  13. card_code:"",
  14. phone:"",
  15. name:""
  16. }
  17. },
  18. onLoad: function (options) {
  19. let info = this.data.info;
  20. app.getMakerInfo( res =>{
  21. Object.assign( info, res )
  22. let phone = info.phone||''
  23. this.setData( {info, phone })
  24. })
  25. },
  26. onReady: function (res) {
  27. var ctx = wx.createCameraContext('myCamera')
  28. this.setData({ ctx: ctx })
  29. },
  30. getInfo( ){
  31. util.http( '/wx/getMakerInfo', {}, (err,res)=>{
  32. if( err!= 0 ) return;
  33. console.log("http",err, res)
  34. let phone= res.info.phone||''
  35. this.setData({info: res.info,phone})
  36. })
  37. },
  38. previewImage: function (e) {
  39. var current = e.target.dataset.src;
  40. wx.previewImage({
  41. current: current,
  42. urls: [current]
  43. })
  44. } ,
  45. takeCard(){
  46. this.setData( {showcamara:true, type:'card'})
  47. },
  48. takeCardBack(){
  49. this.setData( {showcamara:true, type:'cardBack'})
  50. },
  51. identify( err, {url} ){
  52. if( err !=0 || !url ) {
  53. util.showMsg("图片上传失败")
  54. return
  55. }
  56. util.showBusy("识别图片中")
  57. let info = this.data.info
  58. let method=this.data.type=='card'?'/maker/addMakerCard':'/maker/addMakerBackCard';
  59. let showcamara= false
  60. util.http( method, {url}, (err,res)=>{
  61. if( err!= 0 ) return;
  62. util.showBusy("上传成功")
  63. Object.assign( info, res)
  64. this.setData({info,showcamara})
  65. })
  66. },
  67. chooseImg: function () {
  68. var that = this
  69. wx.chooseImage({
  70. count: 1,
  71. sizeType: ['compressed'],
  72. sourceType: ['album'],
  73. success: function (res) {
  74. that.setData( {showcamara:false})
  75. util.showBusy("图片上传中")
  76. util.uploadFile( res.tempFilePaths[0], that.identify )
  77. },
  78. fail:(res)=>{
  79. console.log( res)
  80. util.showMsg("图片选择失败")
  81. }
  82. })
  83. },
  84. takePhoto() {
  85. var that = this
  86. var ctx = this.data.ctx
  87. ctx.takePhoto({
  88. quality: 'low',
  89. success: (res) => {
  90. util.showSuccess("图片上传中")
  91. that.setData( {showcamara:false})
  92. var tempImagePath = res.tempImagePath
  93. util.uploadFile( tempImagePath, that.identify )
  94. },
  95. fail: (res)=> {
  96. app.showMsg('拍照失败')
  97. }
  98. })
  99. },
  100. onConfirm( e ){
  101. let {phone} = e.detail.value
  102. let info = this.data.info
  103. let {card_img, card_back_img} = this.data.info
  104. if( !card_img ) return util.showMsg( "身份证正面有误");
  105. if( !card_back_img ) return util.showMsg( "身份证背面有误");
  106. if( !phone || phone.length != 11 ) return util.showMsg( "手机号码有误");
  107. util.http( '/maker/identifyMaker', {phone}, (err,res)=>{
  108. if( err!= 0 ) return;
  109. info.identify = 1
  110. app.identifyUser( )
  111. this.setData({info})
  112. })
  113. },
  114. goBack() {
  115. wx.navigateBack({
  116. delta: 1
  117. })
  118. }
  119. })