applyLeader.js 4.4 KB

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