applyLeader.js 5.0 KB

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