consultant.js 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231
  1. const app = getApp()
  2. Page({
  3. data: {
  4. startdate: new Date(),
  5. userInfo: {},
  6. consultanturl: undefined,
  7. date: "请输入您的预产期",
  8. datecss: 'dateinput1',
  9. phone: '',
  10. hasUserInfo: false,
  11. canIUse: wx.canIUse('button.open-type.getUserInfo'),
  12. consultants: ''
  13. },
  14. //事件处理函数
  15. bindViewTap: function() {
  16. wx.navigateTo({
  17. url: '../logs/logs'
  18. })
  19. },
  20. onLoad: function() {
  21. console.log(app.globalData.userphone)
  22. if (app.globalData.userphone == "" || app.globalData.userphone == null || app.globalData.userphone == 'undefined') {
  23. app.ifAuthorization();
  24. } else {
  25. if (app.globalData.userphone.split(" ").join("").length != 0) {
  26. this.setData({
  27. phone: app.globalData.userphone
  28. })
  29. } else {
  30. this.setData({
  31. phone: "请输入您的手机号"
  32. })
  33. }
  34. }
  35. var that = this
  36. wx.request({
  37. url: app.globalData.url + '/getConsultant',
  38. method: 'get',
  39. success: function(res) {
  40. that.setData({
  41. consultanturl: res.data.wi_url
  42. })
  43. },
  44. fail() {
  45. app.timeOut()
  46. }
  47. })
  48. if (app.globalData.userInfo) {
  49. this.setData({
  50. userInfo: app.globalData.userInfo,
  51. hasUserInfo: true
  52. })
  53. } else if (this.data.canIUse) {
  54. // 由于 getUserInfo 是网络请求,可能会在 Page.onLoad 之后才返回
  55. // 所以此处加入 callback 以防止这种情况
  56. app.userInfoReadyCallback = res => {
  57. this.setData({
  58. userInfo: res.userInfo,
  59. hasUserInfo: true
  60. })
  61. }
  62. } else {
  63. // 在没有 open-type=getUserInfo 版本的兼容处理
  64. wx.getUserInfo({
  65. success: res => {
  66. app.globalData.userInfo = res.userInfo
  67. this.setData({
  68. userInfo: res.userInfo,
  69. hasUserInfo: true
  70. })
  71. },
  72. fail() {
  73. app.timeOut()
  74. }
  75. })
  76. }
  77. let _this = this;
  78. _this.setData({
  79. navH: app.globalData.navHeight
  80. })
  81. },
  82. getUserInfo: function(e) {
  83. app.globalData.userInfo = e.detail.userInfo
  84. this.setData({
  85. userInfo: e.detail.userInfo,
  86. hasUserInfo: true
  87. })
  88. },
  89. bindDateChange: function(e) {
  90. if (e.detail.value != "请输入您的预产期") {
  91. this.setData({
  92. date: e.detail.value,
  93. datecss: 'dateinput2'
  94. })
  95. }
  96. },
  97. phoneInput: function(e) {
  98. this.setData({
  99. phone: e.detail.value
  100. })
  101. },
  102. confirm: function(e) {
  103. var that = this
  104. var myphone = /^(((13[0-9]{1})|(15[0-9]{1})|(18[0-9]{1})|(17[0-9]{1}))+\d{8})$/;
  105. var mydate = /^(\d+)-(\d{1,2})-(\d{1,2})$/;
  106. if (!myphone.test(this.data.phone)) {
  107. wx.showToast({
  108. title: '手机号输入错误',
  109. icon: 'none',
  110. duration: 1500
  111. })
  112. } else if (!mydate.test(this.data.date)) {
  113. wx.showToast({
  114. title: '预产期输入错误',
  115. icon: 'none',
  116. duration: 1500
  117. })
  118. } else {
  119. var duedate = new Date();
  120. var year = duedate.getFullYear();
  121. var month = duedate.getMonth() + 1;
  122. var strDate = duedate.getDate();
  123. var seperator1 = "-";
  124. var bookingdate = this.data.date;
  125. wx.showLoading({
  126. title: '保存中......',
  127. icon: 'loading',
  128. duration: 5500
  129. })
  130. wx.request({
  131. url: app.globalData.url + '/getDcIntroducerConsultants',
  132. method: 'get',
  133. data: {
  134. dig_introducer_phone: app.globalData.introducer
  135. },
  136. success: function(res) {
  137. if (res.data != null) {
  138. that.setData({
  139. consultants: res.data
  140. })
  141. }
  142. wx.request({
  143. url: app.globalData.url + '/insertCustomerBooking',
  144. method: 'post',
  145. header: {
  146. "Content-Type": "application/x-www-form-urlencoded"
  147. },
  148. data: {
  149. bk_phone: that.data.phone,
  150. bk_duedate: that.data.date,
  151. bk_date: year + seperator1 + month + seperator1 + strDate,
  152. bk_type: 4,
  153. bk_introducer_phone: app.globalData.introducer,
  154. bk_introducer_consultant: that.data.consultants
  155. },
  156. success: function(res) {
  157. var date = new Date();
  158. var year = date.getFullYear();
  159. var month = ("0" + (date.getMonth() + 1)).slice(-2);;
  160. var strDate = ("0" + (date.getDate())).slice(-2);
  161. var hours = ("0" + (date.getHours())).slice(-2);
  162. var minutes = ("0" + (date.getMinutes())).slice(-2);
  163. var seconds = ("0" + (date.getSeconds())).slice(-2);
  164. var eh_time = year + '-' + month + '-' + strDate + ' ' + hours + ':' + minutes + ':' + seconds;
  165. if (res.data > 1) {
  166. wx.hideLoading()
  167. wx.showToast({
  168. title: '亲,您今天已经预约过了',
  169. icon: 'none',
  170. duration: 1500
  171. })
  172. } else {
  173. wx.showToast({
  174. title: '预约成功!',
  175. icon: 'success',
  176. duration: 1500
  177. })
  178. // 发送消息
  179. wx.request({
  180. url: app.globalData.url + '/WXSendBookingMessage',
  181. method: 'post',
  182. header: {
  183. "Content-Type": "application/x-www-form-urlencoded"
  184. },
  185. data: {
  186. bk_phone: that.data.phone,
  187. bk_type: 4,
  188. bk_date: eh_time,
  189. bk_duedate: bookingdate,
  190. bk_introducer_phone: app.globalData.introducer,
  191. bk_introducer_consultant: that.data.consultants
  192. }
  193. })
  194. wx.request({
  195. url: app.globalData.url + '/insertDcIntroduceLog',
  196. method: 'post',
  197. header: {
  198. "Content-Type": "application/x-www-form-urlencoded"
  199. },
  200. data: {
  201. xul_openid: app.globalData.openid,
  202. xul_phone: app.globalData.userphone,
  203. xul_event: 3,
  204. xul_introducer_phone: app.globalData.introducer
  205. }
  206. })
  207. }
  208. that.setData({
  209. date: "请输入您的预产期",
  210. phone: that.data.phone
  211. })
  212. },
  213. fail() {
  214. app.timeOut()
  215. }
  216. })
  217. },
  218. fail() {
  219. app.timeOut()
  220. }
  221. })
  222. }
  223. },
  224. onShareAppMessage: function() {
  225. return {
  226. title: '悦所-专属顾问',
  227. path: '/pages/index/index?skip=1&path=/pages/consultant/consultant'
  228. }
  229. }
  230. })