index.js 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  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. let info = this.data.info
  57. let method=this.data.type=='card'?'/maker/addMakerCard':'/maker/addMakerBackCard';
  58. let showcamara= false
  59. util.http( method, {url}, (err,res)=>{
  60. if( err!= 0 ) return;
  61. console.log("http",err, res)
  62. Object.assign( info, res)
  63. this.setData({info,showcamara})
  64. })
  65. },
  66. chooseImg: function () {
  67. var that = this
  68. wx.chooseImage({
  69. count: 1,
  70. sizeType: ['compressed'],
  71. sourceType: ['album'],
  72. success: function (res) {
  73. util.uploadFile( res.tempFilePaths[0], that.identify )
  74. }
  75. })
  76. },
  77. takePhoto() {
  78. var that = this
  79. var ctx = this.data.ctx
  80. that.setData({ hidden: false })
  81. ctx.takePhoto({
  82. quality: 'low',
  83. success: (res) => {
  84. var tempImagePath = res.tempImagePath
  85. util.uploadFile( tempImagePath, that.identify )
  86. },
  87. fail: function (res) {
  88. cosole.log('take error', res)
  89. that.setData({ hidden: true })
  90. app.showMsg('拍照失败')
  91. }
  92. })
  93. },
  94. onConfirm( e ){
  95. let {phone} = e.detail.value
  96. let info = this.data.info
  97. let {card_img, card_back_img} = this.data.info
  98. if( !card_img ) return util.showMsg( "身份证正面有误");
  99. if( !card_back_img ) return util.showMsg( "身份证背面有误");
  100. if( !phone || phone.length != 11 ) return util.showMsg( "手机号码有误");
  101. util.http( '/maker/identifyMaker', {phone}, (err,res)=>{
  102. if( err!= 0 ) return;
  103. this.setData({info})
  104. })
  105. },
  106. goBack() {
  107. wx.navigateBack({
  108. delta: 1
  109. })
  110. }
  111. })