applyLeader.js 4.7 KB

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