index.js 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207
  1. // pages/splash/splash.js
  2. var app = getApp();
  3. Page({
  4. /**
  5. * 页面的初始数据
  6. */
  7. data: {
  8. bookTime: '',
  9. company: '',
  10. name: '',
  11. phone: '',
  12. plateSn: '',
  13. content: '',
  14. userId: 0,
  15. orgId: 0,
  16. },
  17. /**
  18. * 生命周期函数--监听页面加载
  19. */
  20. onLoad: function (options) {
  21. console.log(options);
  22. var userId = wx.getStorageSync("visitorToUserId")?Number(wx.getStorageSync("visitorToUserId")):0;
  23. var orgId = wx.getStorageSync("visitorOrgId")?Number(wx.getStorageSync("visitorOrgId")):0;
  24. if(userId <= 0 || orgId <= 0){
  25. wx.redirectTo({
  26. url: '/pages/splash/splash?type=visitor'
  27. });
  28. }else{
  29. this.setData({
  30. userId: userId,
  31. orgId: orgId
  32. });
  33. }
  34. },
  35. /**
  36. * 生命周期函数--监听页面初次渲染完成
  37. */
  38. onReady: function () {
  39. },
  40. /**
  41. * 生命周期函数--监听页面显示
  42. */
  43. onShow: function () {
  44. var that = this;
  45. app.ajaxReadyCallback = res => {
  46. var apiname = res.data.apiname;
  47. if (apiname == 'book'){
  48. wx.showToast({
  49. title: '提交成功',
  50. icon: 'none',
  51. duration: 2000
  52. })
  53. setTimeout(() =>{
  54. wx.navigateTo({
  55. url: '/pages/visitor/index'
  56. })
  57. },1000);
  58. }
  59. }
  60. },
  61. /**
  62. * 生命周期函数--监听页面隐藏
  63. */
  64. onHide: function () {
  65. },
  66. /**
  67. * 生命周期函数--监听页面卸载
  68. */
  69. onUnload: function () {
  70. },
  71. /**
  72. * 页面相关事件处理函数--监听用户下拉动作
  73. */
  74. onPullDownRefresh: function () {
  75. },
  76. /**
  77. * 页面上拉触底事件的处理函数
  78. */
  79. onReachBottom: function () {
  80. },
  81. /**
  82. * 用户点击右上角分享
  83. */
  84. onShareAppMessage: function () {
  85. },
  86. companyChange(e){
  87. this.setData({
  88. company: e.detail.value
  89. });
  90. },
  91. nameChange(e){
  92. this.setData({
  93. name: e.detail.value
  94. });
  95. },
  96. phoneChange(e){
  97. this.setData({
  98. phone: e.detail.value
  99. });
  100. },
  101. plateChange(e){
  102. this.setData({
  103. plateSn: e.detail.value
  104. });
  105. },
  106. contentChange(e){
  107. this.setData({
  108. content: e.detail.value
  109. });
  110. },
  111. onPickerChange3: function (e) {
  112. console.log(e.detail);
  113. this.setData({
  114. bookTime: e.detail.dateString
  115. })
  116. },
  117. goYY(){
  118. wx.navigateTo({
  119. url: '/pages/visitor/index'
  120. });
  121. },
  122. submitBtn(){
  123. if(!this.data.company){
  124. wx.showToast({
  125. title: "请输入单位",
  126. icon: 'none',
  127. duration: 2000
  128. })
  129. return;
  130. }
  131. if(!this.data.name){
  132. wx.showToast({
  133. title: "请输入姓名",
  134. icon: 'none',
  135. duration: 2000
  136. })
  137. return;
  138. }
  139. if(!this.data.phone){
  140. wx.showToast({
  141. title: "请输入电话",
  142. icon: 'none',
  143. duration: 2000
  144. })
  145. return;
  146. }
  147. if(!this.data.bookTime || this.data.bookTime=='选择时间'){
  148. wx.showToast({
  149. title: "请选择到访时间",
  150. icon: 'none',
  151. duration: 2000
  152. })
  153. return;
  154. }
  155. if(!this.data.content){
  156. wx.showToast({
  157. title: "请输入到访事由",
  158. icon: 'none',
  159. duration: 2000
  160. })
  161. return;
  162. }
  163. const param = {
  164. company: this.data.company,
  165. name: this.data.name,
  166. phone: this.data.phone,
  167. plateSn: this.data.plateSn,
  168. bookTime: this.data.bookTime,
  169. content: this.data.content,
  170. type: 3,
  171. fromUserId: this.data.userId,
  172. orgId: this.data.orgId
  173. }
  174. console.log(param);
  175. app.ajax2({
  176. url: app.globalData.visitorServerUrl + 'server/visitorOrder/order2',
  177. type: 'POST',
  178. apiname: 'book',
  179. data: param
  180. });
  181. }
  182. })