adminInfo.js 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152
  1. const app = getApp();
  2. Page({
  3. data: {
  4. region: ['省', '市', '区'],
  5. companyInfo: {},
  6. mobileClick: false,
  7. emailClick: false,
  8. codeBtnTxt: "发送验证码",
  9. codeBtnEmailTxt:'发送验证码'
  10. },
  11. onLoad(options) {
  12. this.setData({
  13. companyInfo: options.info ? JSON.parse(options.info) : {},
  14. isCreateOrEdit:options.info ? true : false,
  15. })
  16. },
  17. RegionChange: function (e) {
  18. this.setData({
  19. region: e.detail.value
  20. })
  21. },
  22. setMobile(e) {
  23. this.setData({
  24. mobile: e.detail.value
  25. })
  26. },
  27. setEmail(e) {
  28. this.setData({
  29. email: e.detail.value
  30. })
  31. },
  32. sendCodeMobile(e) {
  33. //验证手机号
  34. var myreg = /^[1][0-9]{10}$/;
  35. if (!myreg.test(this.data.mobile)) {
  36. app.showToptip(this, "worning", "手机号输入有误")
  37. return;
  38. }
  39. var that = this;
  40. wx.showLoading({
  41. title: '发送中...',
  42. mask: true
  43. })
  44. app.requestP({
  45. url: "/sms/getSmsCodeByMobile",
  46. needToken: false,
  47. contentType: ' application/json',
  48. data: {
  49. mobile: that.data.mobile,
  50. }
  51. }).then((res) => {
  52. app.showToptip(that, "success", "发送成功")
  53. that.data.lastSendTime = Date.now()
  54. that.setData({
  55. mobileClick: false
  56. })
  57. //定时器触发倒计时,
  58. var times = 60
  59. var i = setInterval(function () {
  60. times--
  61. if (times == 0) {
  62. that.setData({
  63. mobileClick: true,
  64. codeBtnTxt: "获取验证码",
  65. })
  66. clearInterval(i)
  67. } else {
  68. that.setData({
  69. codeBtnTxt: "重新获取" + times + "S",
  70. })
  71. }
  72. }, 1000)
  73. }).catch(function (r) {
  74. app.showToptip(that, "error", r.data.msg)
  75. })
  76. },
  77. sendCodeEmail() {
  78. //验证手机号
  79. // var myreg = /^[1][0-9]{10}$/;
  80. // if (!myreg.test(this.data.email)) {
  81. // app.showToptip(this, "worning", "手机号输入有误")
  82. // return;
  83. // }
  84. var that = this;
  85. wx.showLoading({
  86. title: '发送中...',
  87. mask: true
  88. })
  89. app.requestP({
  90. url: "/sms/getEmailGetAuthCode",
  91. needToken: false,
  92. contentType: ' application/json',
  93. data: {
  94. email: that.data.email,
  95. }
  96. }).then((res) => {
  97. app.showToptip(that, "success", "发送成功")
  98. that.data.lastSendTime = Date.now()
  99. that.setData({
  100. emailClick: false
  101. })
  102. //定时器触发倒计时,
  103. var times = 60
  104. var i = setInterval(function () {
  105. times--
  106. if (times == 0) {
  107. that.setData({
  108. emailClick: true,
  109. codeBtnEmailTxt: "获取验证码",
  110. })
  111. clearInterval(i)
  112. } else {
  113. that.setData({
  114. codeBtnEmailTxt: "重新获取" + times + "S",
  115. })
  116. }
  117. }, 1000)
  118. }).catch(function (r) {
  119. app.showToptip(that, "error", r.data.msg)
  120. })
  121. },
  122. formSubmit(e){
  123. var that = this;
  124. var value = e.detail.value;
  125. const {companyName,managerName,managerPhone,phoneCode,managerEmail,emailCode,address} = value;
  126. if(companyName&&managerName&&managerEmail&&managerPhone&&phoneCode&&emailCode&&address){
  127. app.requestP({
  128. url:that.data.isCreateOrEdit ?'/company/editCompany' :'/company/createCompany',
  129. method:'post',
  130. contentType:'application/json',
  131. data:{
  132. name:companyName,
  133. managerName,
  134. managerPhone,
  135. phoneCode,
  136. managerEmail,
  137. emailCode,
  138. address
  139. }
  140. }).then(res=>{
  141. app.showToptip(that,'success',res.data.msg);
  142. wx.navigateBack({
  143. delta: 1,
  144. })
  145. }).catch(err=>{
  146. app.showToptip(that,'error',err.data.msg);
  147. })
  148. }else{
  149. app.showToptip(that,'error','企业信息不能为空');
  150. }
  151. },
  152. })