applyLeader.js 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173
  1. var _request = require('../../../../utils/request.js')
  2. var validator = require('../../../../utils/validator.js')
  3. var _handle = require('../../../../utils/handle.js')
  4. Page({
  5. data: {
  6. address: '请选择',
  7. region: ['北京市', '北京市', '东城区'],
  8. name: '',
  9. tel: 0,
  10. more: '',
  11. countdown: 0,
  12. yzm:'',
  13. remark:''
  14. },
  15. onLoad: function (options) {
  16. },
  17. getTel (val) {
  18. console.log(val)
  19. if (val.detail.encryptedData) {
  20. this.bindWxTel(val.detail)
  21. }
  22. },
  23. bindWxTel (res) {
  24. var str = JSON.stringify({
  25. encryptedData: res.encryptedData,
  26. iv: res.iv
  27. })
  28. var that = this
  29. var url = 'v1/wxuser/one_click/binding/phonumer'
  30. var params = {
  31. userinfo: str
  32. }
  33. var success = function (res) {
  34. console.log(res);
  35. }
  36. _request.$post(url, params, success)
  37. },
  38. getYzm (e) {
  39. _handle.setFormId(e)
  40. if (validator.telphone(this.data.tel)) {
  41. this.requireYzm()
  42. } else {
  43. wx.showToast({
  44. title: '手机号码格式不正确',
  45. icon: 'none',
  46. duration: 2000
  47. })
  48. }
  49. },
  50. startCountdown: function () {
  51. var smsRequestTime = wx.getStorageSync('sms_request_time')
  52. if (smsRequestTime) {
  53. var count = parseInt((60000 - (new Date() - smsRequestTime)) / 1000)
  54. this.setData({
  55. countdown: count
  56. })
  57. if (this.data.countdown > 0) {
  58. var timer = setInterval(() => {
  59. var countdown = this.data.countdown - 1
  60. this.setData({
  61. countdown: countdown
  62. })
  63. if (this.data.countdown <= 0) {
  64. clearInterval(timer)
  65. }
  66. }, 1000)
  67. // clearInterval(this.interval)
  68. }
  69. } else {
  70. }
  71. },
  72. requireYzm () {
  73. var that = this
  74. var url = 'v1/code/send'
  75. console.log(typeof(this.data.tel))
  76. var params = {
  77. tel: this.data.tel,
  78. valid_type: 'shop_application'
  79. }
  80. var success = function (res) {
  81. wx.setStorageSync('sms_request_time', Date.now())
  82. that.startCountdown()
  83. }
  84. _request.$post(url, params, success)
  85. },
  86. bindPhone (e) {
  87. this.setData({
  88. tel: e.detail.value
  89. })
  90. },
  91. bindYzm (e) {
  92. this.setData({
  93. yzm: e.detail.value
  94. })
  95. },
  96. bindName: function (e) {
  97. this.setData({
  98. name: e.detail.value
  99. })
  100. },
  101. bindMore: function (e) {
  102. this.setData({
  103. more: e.detail.value
  104. })
  105. },
  106. bindRemark: function (e) {
  107. this.setData({
  108. remark: e.detail.value
  109. })
  110. },
  111. validate () {
  112. var msg
  113. if (!validator.required(this.data.name)) {
  114. msg = '姓名不能为空'
  115. } else if (!validator.required(this.data.tel)) {
  116. msg = '联系电话不能为空'
  117. } else if (!validator.telphone(this.data.tel)) {
  118. msg = '手机号码格式不正确'
  119. } else if (this.data.address === '请选择') {
  120. msg = '请选择所在地区'
  121. } else if (!validator.required(this.data.more)) {
  122. msg = '详细地址不能为空'
  123. }
  124. return { isOk: !msg, msg }
  125. },
  126. save: function (e) {
  127. _handle.setFormId(e)
  128. var { isOk, msg } = this.validate()
  129. if (isOk) {
  130. this.shopApplication()
  131. } else {
  132. wx.showToast({
  133. title: msg,
  134. icon: 'none',
  135. duration: 2000
  136. })
  137. }
  138. },
  139. shopApplication () {
  140. var that = this
  141. var url = 'v1/user/shop_application'
  142. var params = {
  143. name: this.data.name,
  144. mobile: this.data.tel,
  145. code:this.data.yzm,
  146. province: this.data.region[0],
  147. city: this.data.region[1],
  148. district: this.data.region[2],
  149. address: this.data.more,
  150. remark: this.data.remark
  151. }
  152. var success = function (res) {
  153. wx.showToast({
  154. title: '申请成功@',
  155. icon: 'none',
  156. duration: 2000
  157. })
  158. }
  159. _request.$put(url, params, success)
  160. },
  161. bindRegionChange: function (e) {
  162. console.log(e)
  163. this.setData({
  164. region: e.detail.value,
  165. address: e.detail.value[0] + e.detail.value[1] + e.detail.value[2]
  166. })
  167. },
  168. onShareAppMessage: function (val) {
  169. return _request.share({
  170. sc: 'xcx_user_newaddress'
  171. })
  172. }
  173. })