cauth.js 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192
  1. // nova-travel/page/cauth/cauth.js
  2. var qiniuUploader = require("../../../../utils/qiniuUploader");
  3. var Parse = getApp().Parse;
  4. var company = getApp().globalData.company
  5. Page({
  6. /**
  7. * 页面的初始数据
  8. */
  9. data: {
  10. focus: false,
  11. fileList: [],
  12. fileList_1: [],
  13. uploadURL: "", //七牛参数
  14. domain: "", //七牛参数
  15. uptokenURL: "", //七牛参数
  16. optionId: "",
  17. auth: true,
  18. activeColor:getApp().globalData.activeColor,
  19. titleColor:getApp().globalData.titleColor
  20. },
  21. bindKeyInput(e) {
  22. this.setData({
  23. [e.currentTarget.dataset.prop]: e.detail.value
  24. })
  25. },
  26. submit() {
  27. const _this = this
  28. if (!this.data.name || !this.data.mobile || !this.data.id) {
  29. wx.showToast({
  30. title: '请填写完整信息',
  31. icon: 'none',
  32. duration: 2000
  33. })
  34. return
  35. }
  36. let name = /[\u4e00-\u9fa5]/,
  37. text = this.data.name;
  38. if (!name.test(text)) {
  39. wx.showToast({
  40. title: '请输入您的真实姓名',
  41. icon: 'none',
  42. duration: 2000
  43. })
  44. return
  45. }
  46. let str = this.data.mobile;
  47. let exist = /^1[34578]\d{9}$/.test(str);
  48. if (exist == false) {
  49. wx.showToast({
  50. title: '手机号码格式有误',
  51. icon: 'none',
  52. duration: 2000
  53. })
  54. return
  55. }
  56. let idReg = /(^\d{15}$)|(^\d{18}$)|(^\d{17}(\d|X|x)$)/gi
  57. let id = this.data.id
  58. if (!idReg.test(id)) {
  59. wx.showToast({
  60. title: '请输入正确的身份证号',
  61. icon: 'none',
  62. duration: 2000
  63. })
  64. return
  65. }
  66. wx.request({
  67. url: "https://server.fmode.cn/api/apig/idcard", //请求接口的url
  68. method: "POST", //请求方式
  69. data: {
  70. company: company,
  71. cardNo: id,
  72. realName: text
  73. }, //请求参数
  74. header: {
  75. "content-type": "application/json", // 默认值
  76. },
  77. success: (res) => {
  78. console.log(res.data);
  79. console.log(res.data.data.result);
  80. if (res.data.data.result.isok) {
  81. let User = Parse.Object.extend("_User")
  82. let user = new User()
  83. user.id = Parse.User.current().id
  84. user.set("authentication", {
  85. "id": _this.data.id,
  86. "name": _this.data.name,
  87. "mobile": _this.data.mobile
  88. })
  89. user.set('realname',_this.data.name)
  90. user.set('idcard',_this.data.id)
  91. user.save().then(res => {
  92. // 弹窗
  93. wx.showToast({
  94. title: '提交成功',
  95. icon: 'none',
  96. duration: 2000
  97. })
  98. // 重新拉取数据
  99. _this.getUserInfo()
  100. })
  101. } else {
  102. wx.showToast({
  103. title: '请输入正确的身份证号和姓名',
  104. icon: 'none',
  105. duration: 2000
  106. })
  107. }
  108. },
  109. })
  110. },
  111. getUserInfo() {
  112. const _this = this
  113. let User = new Parse.Query("_User")
  114. User.equalTo("objectId", Parse.User.current().id)
  115. User.first().then(res => {
  116. let user = res.toJSON()
  117. console.log(user)
  118. if (user.authentication && user.authentication.id) {
  119. console.log(user.authentication)
  120. user.authentication.id = user.authentication.id.replace(/^(.{3})(?:\d+)(.{4})$/, "$1***********$2")
  121. user.authentication.mobile = user.authentication.mobile.replace(/^(.{3})(?:\d+)(.{4})$/, "$1****$2")
  122. _this.setData({
  123. userInfo: user.authentication,
  124. auth: true
  125. })
  126. } else {
  127. _this.setData({
  128. auth: false
  129. })
  130. }
  131. })
  132. },
  133. /**
  134. * 生命周期函数--监听页面加载
  135. */
  136. onLoad: function (options) {
  137. this.getUserInfo()
  138. },
  139. /**
  140. * 生命周期函数--监听页面初次渲染完成
  141. */
  142. onReady: function () {
  143. },
  144. /**
  145. * 生命周期函数--监听页面显示
  146. */
  147. onShow: function () {
  148. },
  149. /**
  150. * 生命周期函数--监听页面隐藏
  151. */
  152. onHide: function () {
  153. },
  154. /**
  155. * 生命周期函数--监听页面卸载
  156. */
  157. onUnload: function () {
  158. },
  159. /**
  160. * 页面相关事件处理函数--监听用户下拉动作
  161. */
  162. onPullDownRefresh: function () {
  163. },
  164. /**
  165. * 页面上拉触底事件的处理函数
  166. */
  167. onReachBottom: function () {
  168. },
  169. /**
  170. * 用户点击右上角分享
  171. */
  172. onShareAppMessage: function () {
  173. }
  174. })