index.js 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315
  1. // index.js
  2. // 获取应用实例
  3. const app = getApp()
  4. const util = require('../../utils/jmsUtil.js');
  5. const user = require('../../utils/user.js');
  6. const jms = require('../../api/jms.js');
  7. Page({
  8. data: {
  9. isChecked:false,
  10. userInfo: {},
  11. mobile: '',
  12. captcha: '', //验证码
  13. code: '', //小程序登录code
  14. jmsMobile: '',
  15. jmsCaptcha: '',
  16. loginType: '2' //1一键登录 2:验证登录
  17. },
  18. onShareAppMessage: function () {
  19. var path = '/pages/index/index';
  20. return {
  21. title: "鲸致生活-服务者小程序",
  22. path: path,
  23. imageUrl: '/static/images/logo.png'
  24. }
  25. },
  26. onLoad(options) {
  27. // this.getLoginCode();
  28. },
  29. onLoginChange(e) {
  30. console.log(e);
  31. this.setData({
  32. loginType:e.detail
  33. });
  34. },
  35. goShelter() {
  36. wx.navigateTo({
  37. url: '/pages/shelter/index',
  38. })
  39. },
  40. onShow() {
  41. let that = this;
  42. //验证是否登陆过
  43. user.checkLogin().then(res => {
  44. app.globalData.hasLogin = true;
  45. let userInfo = wx.getStorageSync('userInfo');
  46. // 兼职人员
  47. wx.redirectTo({
  48. url: '/pages/temp/serviceOrder/serviceOrder',
  49. })
  50. }).catch(res => {
  51. // that.getLoginCode();
  52. })
  53. },
  54. getLoginCode() {
  55. let that = this;
  56. user.login().then(res => {
  57. console.info(res)
  58. that.setData({
  59. code: res.code
  60. })
  61. })
  62. },
  63. getPhoneNumber: function (e) {
  64. if(!this.data.isChecked){
  65. wx.showToast({
  66. title: '请点击下方用户协议',
  67. icon: 'none',
  68. duration: 3000
  69. });
  70. return;
  71. }
  72. console.log(e);
  73. var that = this;
  74. //------执行Login---------
  75. util.request(jms.AuthRegister, {
  76. code: e.detail.code,
  77. loginType: 1
  78. }, 'POST').then(function (res) {
  79. console.info(res)
  80. if (res.errno === 0) {
  81. //存储用户信息
  82. console.info("登录成功1")
  83. app.globalData.hasLogin = true;
  84. wx.setStorageSync('userInfo', res.data.fraUser);
  85. wx.setStorageSync('token', res.data.token);
  86. wx.showToast({
  87. title: '授权登录成功',
  88. icon: 'success',
  89. duration: 2000,
  90. complete: function () {
  91. wx.redirectTo({
  92. url: '/pages/temp/serviceOrder/serviceOrder',
  93. })
  94. }
  95. })
  96. } else {
  97. console.info(res);
  98. // that.getLoginCode();
  99. wx.showToast({
  100. title: res.errmsg,
  101. duration: 3000,
  102. icon: 'none'
  103. });
  104. }
  105. });
  106. //-----------------是否授权,授权通过进入主页面,授权拒绝则停留在登陆界面
  107. if (e.detail.errMsg == 'getPhoneNumber:fail user deny') { //用户点击拒绝
  108. wx.showModal({
  109. title: '警告',
  110. content: '您点击了拒绝授权,功能无法使用!!!',
  111. showCancel: false,
  112. confirmText: '确定',
  113. success: function (res) {
  114. // 用户没有授权成功,不需要改变 isHide 的值
  115. if (res.confirm) {
  116. wx.redirectTo({
  117. url: '/pages/temp/serviceOrder/serviceOrder',
  118. });
  119. };
  120. }
  121. })
  122. }
  123. },
  124. bindMobileInput(e) {
  125. this.setData({
  126. mobile: e.detail.value
  127. });
  128. },
  129. bindcaptchaInput(e) {
  130. this.setData({
  131. captcha: e.detail.value
  132. });
  133. },
  134. goInvite() {
  135. wx.navigateTo({
  136. url: '/pages/upgrade/invite/invite',
  137. })
  138. },
  139. goTemp() {
  140. wx.navigateTo({
  141. url: '/pages/temp/login/login',
  142. });
  143. },
  144. bindJmsMobileInput(e) {
  145. this.setData({
  146. jmsMobile: e.detail.value
  147. });
  148. },
  149. bindJmsCaptchaInput(e) {
  150. this.setData({
  151. jmsCaptcha: e.detail.value
  152. });
  153. },
  154. getJmsCaptcha() {
  155. if (this.data.jmsMobile.length != 11 || this.data.jmsMobile.startsWith("1") == false) {
  156. wx.showToast({
  157. title: '请输入正确手机号',
  158. icon: 'none',
  159. duration: 3000
  160. });
  161. return;
  162. }
  163. util.request(jms.AuthCaptcha, {
  164. tel: this.data.jmsMobile
  165. }, "GET").then(res => {
  166. if (res.errno == 0)
  167. wx.showToast({
  168. title: '验证码发送成功',
  169. duration: 3000
  170. });
  171. else
  172. wx.showToast({
  173. title: res.errmsg,
  174. duration: 3000,
  175. icon: 'none'
  176. });
  177. }).catch(res => {
  178. console.info('getCaptcha error')
  179. wx.showToast({
  180. title: res.errmsg,
  181. icon: 'none',
  182. duration: 3000
  183. });
  184. })
  185. },
  186. loginTemp() {
  187. if(!this.data.isChecked){
  188. wx.showToast({
  189. title: '请点击下方用户协议',
  190. icon: 'none',
  191. duration: 3000
  192. });
  193. return;
  194. }
  195. if (this.data.jmsMobile.length != 11 || this.data.jmsMobile.startsWith("1") == false) {
  196. wx.showToast({
  197. title: '请输入正确手机号',
  198. icon: 'none',
  199. duration: 3000
  200. });
  201. return;
  202. } else if (this.data.jmsCaptcha == '') {
  203. wx.showToast({
  204. title: '请输入验证码',
  205. icon: 'none',
  206. duration: 3000
  207. });
  208. return;
  209. } else {
  210. //登录
  211. util.request(jms.AuthRegister, {
  212. tel: this.data.jmsMobile,
  213. verifyCode: this.data.jmsCaptcha,
  214. loginType:2
  215. }, 'POST').then(res => {
  216. //存储用户信息
  217. console.info("登录成功")
  218. if (res.errno == 0) {
  219. app.globalData.hasLogin = true;
  220. let user = res.data.fraUser;
  221. wx.setStorageSync('userInfo', user);
  222. wx.setStorageSync('token', res.data.token);
  223. app.globalData.userInfo=user;
  224. wx.redirectTo({
  225. url: '/pages/temp/serviceOrder/serviceOrder',
  226. });
  227. } else if (res.errno === 301) {
  228. wx.showModal({
  229. title: '提示',
  230. content: '您还未注册,是否现在去注册?',
  231. // showCancel:false,
  232. complete: (res) => {
  233. if (res.cancel) {
  234. }
  235. if (res.confirm) {
  236. wx.navigateTo({
  237. url: '/pages/temp/register/register',
  238. })
  239. }
  240. }
  241. })
  242. } else {
  243. // util.showErrorToast(res.errmsg);
  244. wx.showToast({
  245. title: res.errmsg,
  246. icon: 'none',
  247. duration: 3000
  248. });
  249. }
  250. }).catch(err => {
  251. })
  252. }
  253. },
  254. bindJmsMobileInput(e) {
  255. this.setData({
  256. jmsMobile: e.detail.value
  257. });
  258. },
  259. bindJmsCaptchaInput(e) {
  260. this.setData({
  261. jmsCaptcha: e.detail.value
  262. });
  263. },
  264. goRegister() {
  265. wx.navigateTo({
  266. url: '/pages/temp/register/register',
  267. })
  268. },
  269. checkProBtn() {
  270. wx.navigateTo({
  271. url: '/pages/temp/jzxhAppletsUserPro/jzxhAppletsUserPro'
  272. })
  273. },
  274. checkChange(e){
  275. this.setData({
  276. isChecked: e.detail,
  277. });
  278. },
  279. })