authorizeBox.js 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  1. // components/authorizeBox/authorizeBox.js
  2. import {
  3. xcxPhoneNumber,
  4. xcxsmbd
  5. } from "../../apis/index"
  6. Component({
  7. /**
  8. * 组件的属性列表
  9. */
  10. properties: {
  11. },
  12. /**
  13. * 组件的初始数据
  14. */
  15. data: {
  16. show: false,
  17. animation: '',
  18. name: '',
  19. idcard: ''
  20. },
  21. /**
  22. * 组件的方法列表
  23. */
  24. methods: {
  25. none() {
  26. return
  27. },
  28. name(e) {
  29. let that = this
  30. that.setData({
  31. name: e.detail.value
  32. })
  33. },
  34. idcard(e) {
  35. let that = this
  36. that.setData({
  37. idcard: e.detail.value
  38. })
  39. },
  40. getPhoneNumber(e) {
  41. let that = this
  42. let name = that.data.name
  43. let idcard = that.data.idcard
  44. let publicId = wx.getStorageSync('PUBLIC_ID')
  45. if (!e.detail.code) {
  46. wx.showToast({
  47. title: '用户拒绝',
  48. icon: "none",
  49. duration: 3000
  50. })
  51. that.hide()
  52. } else {
  53. if (name.length < 2 || idcard.length != 18) {
  54. wx.showToast({
  55. title: '请检查姓名或者身份证号码是否填写准确',
  56. icon: "none",
  57. duration: 5000
  58. })
  59. } else {
  60. wx.showLoading({
  61. title: '正在绑定...',
  62. })
  63. xcxPhoneNumber({
  64. code: e.detail.code
  65. }).then((res) => {
  66. if (res.code == 200) {
  67. let form = {
  68. xcxId: publicId.openid,
  69. unionid: publicId.unionid,
  70. sfzjhm: idcard,
  71. sjh: res.message,
  72. xm: name
  73. }
  74. xcxsmbd(form).then((res) => {
  75. wx.hideLoading()
  76. if (res.code == 200) {
  77. wx.showToast({
  78. title: res.msg || res.message,
  79. icon: "none",
  80. duration: 3000
  81. })
  82. that.triggerEvent('success', true)
  83. that.hide()
  84. } else {
  85. wx.showToast({
  86. title: res.msg || res.message,
  87. icon: "none",
  88. duration: 5000
  89. })
  90. }
  91. })
  92. } else {
  93. wx.hideLoading()
  94. wx.showToast({
  95. title: res.msg || res.message,
  96. icon: "none",
  97. duration: 5000
  98. })
  99. }
  100. })
  101. }
  102. }
  103. },
  104. close() {
  105. let that = this
  106. that.hide()
  107. },
  108. show() {
  109. let that = this
  110. that.setData({
  111. show: true
  112. })
  113. setTimeout(() => {
  114. that.setData({
  115. animation: 'showAuthorizeBox'
  116. })
  117. }, 50);
  118. },
  119. hide() {
  120. let that = this
  121. that.setData({
  122. animation: ''
  123. })
  124. setTimeout(() => {
  125. that.setData({
  126. show: false
  127. })
  128. }, 350);
  129. }
  130. }
  131. })