index.js 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160
  1. const app = getApp();
  2. const util = require("../../../utils/util.js")
  3. Page({
  4. data: {
  5. ctx: false,
  6. hidden: true,
  7. showcamara: false,
  8. type:'card',
  9. phone:'',
  10. studyUser :{
  11. cardId:"352202198709031536",
  12. cardImg:"",
  13. nickname:"吕君喜",
  14. phone:'18850724428',
  15. openid:'',
  16. identify:0,
  17. session_key:'',
  18. cardBackImg:""
  19. }
  20. },
  21. onShow: function () {
  22. app.getUserInfo( studyUser =>{
  23. this.setData({studyUser})
  24. })
  25. },
  26. wxLogin(){
  27. let that = this
  28. wx.login({
  29. success(wxres) {
  30. if( !wxres.code){
  31. util.showMsg("登入失败")
  32. }else{
  33. that.doLoginByCode( wxres.code )
  34. }
  35. }
  36. })
  37. },
  38. doLoginByCode( code ){
  39. app.formPost( "Auth.WxLoginByCode", {code}).then( (res)=>{
  40. if( res.code == 200){
  41. this.setData( {userInfo: res.data})
  42. app.setUserInfo( res.data )
  43. wx.navigateBack({
  44. delta: 1
  45. })
  46. }
  47. })
  48. },
  49. doIdentify( e ){
  50. let that = this
  51. wx.login({
  52. success(wxres) {
  53. if (wxres.code) {
  54. that.doRegister( wxres.code, e.detail.value )
  55. }
  56. }
  57. })
  58. },
  59. doRegister( code, info ){
  60. let param = {
  61. code: code,
  62. phone: info.phone,
  63. cardId: info.cardId,
  64. nickname: info.nickname,
  65. }
  66. app.formPost( 'Auth.Register', param).then( res =>{
  67. if( res.code == 200 ){
  68. let studyUser= res.data
  69. app.setUserInfo( studyUser )
  70. util.showSuccess("实名认证成功")
  71. this.setData({studyUser})
  72. }else{
  73. util.showMsg( res.msg )
  74. }
  75. })
  76. },
  77. onReady: function (res) {
  78. var ctx = wx.createCameraContext('myCamera')
  79. this.setData({ ctx: ctx })
  80. },
  81. previewImage: function (e) {
  82. var current = e.target.dataset.src;
  83. wx.previewImage({
  84. current: current,
  85. urls: [current]
  86. })
  87. } ,
  88. takeCard(){
  89. this.setData( {showcamara:true, type:'card'})
  90. },
  91. takeCardBack(){
  92. this.setData( {showcamara:true, type:'cardBack'})
  93. },
  94. identify( err, {url} ){
  95. if( err != 200 || !url ) {
  96. util.showMsg("图片上传失败")
  97. return
  98. }
  99. util.showBusy("识别图片中")
  100. let info = this.data.info
  101. let showcamara= false
  102. app.formPost('Auth.wxUploadImg', {url}).then(res => {
  103. util.showBusy("上传成功")
  104. Object.assign( info, res)
  105. this.setData({info,showcamara})
  106. })
  107. },
  108. chooseImg: function () {
  109. var that = this
  110. wx.chooseImage({
  111. count: 1,
  112. sizeType: ['compressed'],
  113. sourceType: ['album'],
  114. success: function (res) {
  115. that.setData( {showcamara:false})
  116. util.showSuccess("图片上传中")
  117. util.uploadFile( res.tempFilePaths[0], that.identify )
  118. },
  119. fail:(res)=>{
  120. console.log( res)
  121. util.showMsg("图片选择失败")
  122. }
  123. })
  124. },
  125. takePhoto() {
  126. var that = this
  127. var ctx = this.data.ctx
  128. ctx.takePhoto({
  129. quality: 'low',
  130. success: (res) => {
  131. app.message("图片上传中")
  132. that.setData( {showcamara:false})
  133. var tempImagePath = res.tempImagePath
  134. util.uploadFile( tempImagePath, that.identify )
  135. },
  136. fail: (res)=> {
  137. app.message("图片上传中", "error")
  138. }
  139. })
  140. },
  141. onConfirm( e ){
  142. let {phone} = e.detail.value
  143. let info = this.data.info
  144. let {card_img, card_back_img} = this.data.info
  145. if( !card_img ) return util.showMsg( "身份证正面有误");
  146. if( !card_back_img ) return util.showMsg( "身份证背面有误");
  147. if( !phone || phone.length != 11 ) return util.showMsg( "手机号码有误");
  148. util.http( '/maker/identifyMaker', {phone}, (err,res)=>{
  149. if( err!= 0 ) return;
  150. info.identify = 1
  151. app.identifyUser( )
  152. this.setData({info})
  153. })
  154. },
  155. goBack() {
  156. this.setData({showcamara:false})
  157. }
  158. })