QRcode.js 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186
  1. const app = getApp();
  2. Page({
  3. data: {
  4. // 设置上传案例图片的最大数目
  5. maxImages: 1,
  6. // 上传的案例图片集合
  7. QrcodeImages:[],
  8. // 案例图片数目是否达到了最大数目
  9. QrcodeImagesNum: false,
  10. Qrcodeimg: true,
  11. qrcode:"", // 二维码图片
  12. wx_user:"", // 微信号
  13. initial: [], //初始信息
  14. SubmissionHidden: true,
  15. },
  16. /**
  17. * 生命周期函数--监听页面加载
  18. */
  19. onLoad: function (options) {
  20. var that = this;
  21. // 获取信息
  22. let initial_url = 'my/wxqrcode/wxqrcodechange';
  23. let initial_data = {
  24. };
  25. app.postRequest(initial_url, initial_data, function (res) {
  26. if (res.code == 201) {
  27. console.log(res.data);
  28. that.setData({
  29. initial: res.data, // 初始数据
  30. initialcode: res, //获取未上传状态
  31. })
  32. }
  33. if (res.data.status == 2) { //如果审核未通过 显示提交按钮
  34. that.setData({
  35. SubmissionHidden: false
  36. })
  37. } else if (res.code != 201) {
  38. that.setData({
  39. SubmissionHidden: false
  40. })
  41. } else {
  42. that.setData({
  43. SubmissionHidden: true
  44. })
  45. }
  46. })
  47. },
  48. // 上传手持身份证
  49. Qrcodeclick: function (e) {
  50. var _this = this;
  51. wx.chooseImage({
  52. count: 1,
  53. sizeType: ['original', 'compressed'],
  54. sourceType: ['album', 'camera'],
  55. success(res) {
  56. // console.log(res.tempFilePaths[0]);
  57. // tempFilePath可以作为img标签的src属性显示图片
  58. _this.setData({
  59. QrcodeImages: res.tempFilePaths,
  60. QrcodeImagesNum: true,
  61. Qrcodeimg: false,
  62. qrcode: res.tempFilePaths[0],
  63. });
  64. }
  65. })
  66. },
  67. //获取微信号
  68. WeChatNumber: function (e) {
  69. var wx_user = e.detail.value;
  70. // console.log(wx_user);
  71. this.setData({
  72. wx_user: wx_user
  73. });
  74. },
  75. // 最后提交认证
  76. Preservation: function (e) {
  77. // console.log(this.data.qrcode)
  78. // console.log(this.data.wx_user)
  79. var _this = this;
  80. if (this.data.qrcode != '') {
  81. wx.uploadFile({
  82. url: app.globalData.url + 'my/wxqrcode/setwxqrcode',
  83. filePath: this.data.qrcode,
  84. name: 'qrcode',
  85. formData: {
  86. key: wx.getStorageSync('access_key'),
  87. token: wx.getStorageSync('access_token'),
  88. 'wx_user': this.data.wx_user,
  89. },
  90. success: function (res) {
  91. var data = JSON.parse(res.data);
  92. if (data.code == 201) {
  93. wx.showToast({
  94. title: '上传成功',
  95. icon: 'success',
  96. duration: 2000
  97. })
  98. _this.onLoad();
  99. return;
  100. }
  101. var _qrcode = '上传失败'
  102. getApp().Tips(_qrcode);
  103. }, fail: function (d) {
  104. }
  105. })
  106. } else if (this.data.wx_user != '') {
  107. let setwxqrcode_url = 'my/wxqrcode/setwxqrcode';
  108. let setwxqrcode_data = {
  109. 'wx_user': this.data.wx_user,
  110. };
  111. app.postRequest(setwxqrcode_url, setwxqrcode_data, function (res) {
  112. if (res.code == 201) {
  113. wx.showToast({
  114. title: '上传成功',
  115. icon: 'success',
  116. duration: 2000
  117. })
  118. _this.onLoad();
  119. return;
  120. }
  121. var _qrcode = '上传失败'
  122. getApp().Tips(_qrcode);
  123. })
  124. }else{
  125. var _qrcode = '微信二维码与微信号,任选一项进行完善'
  126. getApp().Tips(_qrcode);
  127. }
  128. },
  129. })