fillTel.js 9.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344
  1. const app = getApp();
  2. Page({
  3. /**
  4. * 页面的初始数据
  5. */
  6. data: {
  7. nickname: '', //姓名
  8. photo: '', //头像
  9. sex: '', // 性别
  10. age: '', // 年龄
  11. height: '', // 身高
  12. province: '', // 市
  13. city: '', // 市
  14. area: '', // 区
  15. education: '', // 学历
  16. marry: '', // 婚史
  17. income: '', // 收入
  18. occupation: '', // 职业
  19. openid:'', //授权
  20. wx_id:'', //微信ID
  21. user: '', //手机
  22. password: '', //密码
  23. code: '', //验证码
  24. codeid: '', //验证码ID
  25. text: '获取验证码', //倒计时
  26. currentTime: 61, //倒计时
  27. phone: '', //获取到的手机栏中的值
  28. disabled: false, //按钮是否禁用
  29. color: '', //获取验证码的颜色
  30. },
  31. /**
  32. * 生命周期函数--监听页面加载
  33. */
  34. onLoad: function (options) {
  35. var that = this
  36. // 获取区域ID
  37. var _openid = 0;
  38. try {
  39. var value = wx.getStorageSync('openid')
  40. if (value) {
  41. _openid = value
  42. that.setData({
  43. openid: _openid
  44. })
  45. }
  46. console.log(_openid);
  47. } catch (e) {
  48. // Do something when catch error
  49. }
  50. // 获取区域ID
  51. var _wx_id = 0;
  52. try {
  53. var value = wx.getStorageSync('wx_id')
  54. if (value) {
  55. _wx_id = value
  56. that.setData({
  57. wx_id: _wx_id
  58. })
  59. }
  60. console.log(_wx_id);
  61. } catch (e) {
  62. // Do something when catch error
  63. }
  64. // console.log(that.options.nickname)
  65. that.setData({
  66. nickname: that.options.nickname, //姓名
  67. photo: that.options.photo, //头像
  68. sex: that.options.sex, // 性别
  69. age: that.options.age, // 年龄
  70. height: that.options.height, // 身高
  71. province: that.options.province, // 市
  72. city: that.options.city, // 市
  73. area: that.options.area, // 区
  74. education: that.options.education, // 学历
  75. marry: that.options.marry, // 婚史
  76. income: that.options.income, // 收入
  77. occupation: that.options.occupation, // 收入
  78. });
  79. },
  80. // 获取手机号
  81. Telephone: function (e) {
  82. var user = e.detail.value;
  83. console.log(user);
  84. this.setData({
  85. user: user
  86. });
  87. },
  88. //获取密码
  89. password: function (e) {
  90. var password = e.detail.value;
  91. console.log(password);
  92. this.setData({
  93. password: password
  94. });
  95. },
  96. //获取验证码
  97. getCode: function (e) {
  98. var code = e.detail.value;
  99. console.log(code);
  100. this.setData({
  101. code: code
  102. });
  103. },
  104. //完成事件
  105. complete: function (e) {
  106. console.log(this)
  107. let user = this.data.user; //手机
  108. let password = this.data.password; //密码
  109. let code = this.data.code; //验证码
  110. var complete = null;
  111. if (user == ''){
  112. complete ='请输入手机号码';
  113. } else if (user.trim().length != 11 || ! /^1[23456789]\d{9}$/.test(user)) {
  114. complete = '手机号码格式不对';
  115. } else if (password==''){
  116. complete = '请设置密码';
  117. }
  118. else if (code == ''){
  119. complete = '请输入验证码';
  120. } else if (code.trim().length != 4 || ! /^[0-9]\d{3}$/.test(code)) {
  121. complete = '验证码4位数';
  122. }else{
  123. var _this = this
  124. console.log(this.data.nickname)
  125. let income_url = 'public/signup';
  126. let income_data = {
  127. nickname: this.data.nickname, //姓名
  128. photo: this.data.photo, //头像
  129. sex: this.data.sex, // 性别
  130. age: this.data.age, // 年龄
  131. height: this.data.height, // 身高
  132. province: this.data.province, // 市
  133. city: this.data.city, // 市
  134. area: this.data.area, // 区
  135. education: this.data.education, // 学历
  136. marry: this.data.marry, // 婚史
  137. income: this.data.income, // 收入
  138. user: this.data.user, //手机
  139. password: this.data.password, //密码
  140. openid: this.data.openid, //openid
  141. wx_id: this.data.wx_id, //微信ID
  142. occupation: this.data.occupation, //职业
  143. code: this.data.code, //验证码
  144. codeid: this.data.codeid, //验证码ID
  145. };
  146. app.postRequest(income_url, income_data,function (res) {
  147. // console.log(income_data.photo);
  148. if(res.code==201){
  149. console.log(res.msg);
  150. wx.showModal({
  151. title: '提示',
  152. content: res.msg,
  153. showCancel: false,
  154. })
  155. wx.uploadFile({
  156. url: app.globalData.url+ 'public/photo',
  157. filePath: income_data.photo,
  158. name: 'photo',
  159. formData: {
  160. 'uid': res.data.uid
  161. },
  162. success: function (res) {
  163. }, fail: function (d) {
  164. }
  165. })
  166. wx.navigateTo({ // 跳转登陆页面
  167. url: '/pages/Landpage/Land/Land'
  168. })
  169. } else if (res.code == 301){
  170. wx.showModal({
  171. title: '提示',
  172. content: res.msg,
  173. showCancel: false,
  174. })
  175. }
  176. })
  177. } //判断结束
  178. // 完成事件 用来提示用户输入手机、密码、验证码
  179. if (complete != null) {
  180. wx.showModal({
  181. title: '提示',
  182. content: complete,
  183. showCancel: false,
  184. })
  185. return;
  186. };
  187. },
  188. // 获取验证码事件
  189. getVerificationCode(res) {
  190. var that = this
  191. var phone = that.data.user;
  192. var currentTime = that.data.currentTime //把手机号跟倒计时值变例成js值
  193. var warn = null; //warn为当手机号为空或格式不正确时提示用户的文字,默认为空
  194. if (phone == '') {
  195. warn = "号码不能为空";
  196. } else if (phone.trim().length != 11 || ! /^1[23456789]\d{9}$/.test(phone)) {
  197. warn = "手机号格式不正确";
  198. } else { //验证号码格式正确走下面
  199. // 获取验证码ajax
  200. let code_url = 'public/verificationcode';
  201. let code_data = {
  202. mobile:this.data.user,
  203. type: 1,
  204. source: 1,
  205. };
  206. app.postRequest(code_url, code_data, function (res) {
  207. if (res.code == 201) {
  208. // console.log(res.data.id);
  209. that.setData({
  210. codeid: res.data.id, // 微信ID
  211. disabled: true,
  212. color: '#ccc',
  213. })
  214. //当手机号正确的时候提示用户短信验证码已经发送
  215. wx.showToast({
  216. title: '短信验证码已发送',
  217. icon: 'none',
  218. duration: 2000
  219. });
  220. //设置一分钟的倒计时
  221. var interval = setInterval(function () {
  222. currentTime--; //每执行一次让倒计时秒数减一
  223. that.setData({
  224. text: "重新发送(" + currentTime + 's)', //按钮文字变成倒计时对应秒数
  225. })
  226. //如果当秒数小于等于0时 停止计时器 且按钮文字变成重新发送 且按钮变成可用状态 倒计时的秒数也要恢复成默认秒数 即让获取验证码的按钮恢复到初始化状态只改变按钮文字
  227. if (currentTime <= 0) {
  228. clearInterval(interval)
  229. that.setData({
  230. text: '重新发送',
  231. currentTime: 61,
  232. disabled: false,
  233. color: '#FF9BCA'
  234. })
  235. }
  236. }, 1000);
  237. return;
  238. }
  239. var _qrcode = res.data.mobile[0]
  240. getApp().Tips(_qrcode);
  241. })
  242. };
  243. //判断 当提示错误信息文字不为空 即手机号输入有问题时提示用户错误信息 并且提示完之后一定要让按钮为可用状态 因为点击按钮时设置了只要点击了按钮就让按钮禁用的情况
  244. if (warn != null) {
  245. wx.showModal({
  246. title: '填写手机号码',
  247. content: warn,
  248. showCancel: false,
  249. })
  250. that.setData({
  251. disabled: false,
  252. color: '#FF9BCA'
  253. })
  254. return;
  255. };
  256. },
  257. })