dcpromotion.js 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193
  1. //index.js
  2. //获取应用实例
  3. const app = getApp()
  4. const config = require('../../utils/config.js');
  5. Page({
  6. data: {
  7. startdate: new Date(),
  8. date: "请输入您的预产期",
  9. phone: '',
  10. name: '',
  11. objectArray: [],
  12. promotionShow: '',
  13. promotionID: '',
  14. imgpath: '',
  15. dcphone: ''
  16. },
  17. phoneInput: function (e) {
  18. this.setData({
  19. phone: e.detail.value
  20. })
  21. },
  22. nameInput: function (e) {
  23. this.setData({
  24. name: e.detail.value
  25. })
  26. },
  27. bindDateChange: function (e) {
  28. this.setData({
  29. date: e.detail.value
  30. })
  31. },
  32. onLoad: function (options) {
  33. if (options.phone != null) {
  34. this.setData({
  35. dcphone: options.phone
  36. })
  37. }
  38. var that = this
  39. wx.request({
  40. url: app.globalData.url + '/getBranches',
  41. method: 'get',
  42. success: function (res) {
  43. that.setData({
  44. objectArray: res.data
  45. })
  46. },fail() {
  47. app.timeOut()
  48. }
  49. })
  50. wx.request({
  51. url: app.globalData.url + '/getPromotionDC',
  52. method: 'get',
  53. success: function (res) {
  54. that.setData({
  55. imgpath: res.data.pd_headimg,
  56. promotionID: res.data.id
  57. })
  58. wx.getLocation({
  59. type: 'wgs84',
  60. success: function (res) {
  61. let latitude = res.latitude
  62. let longitude = res.longitude
  63. // let latitude = '31.314453'
  64. // let longitude = '120.654302'
  65. wx.request({
  66. url: `https://apis.map.qq.com/ws/geocoder/v1/?location=${latitude},${longitude}&key=${config.key}`,
  67. success: res => {
  68. wx.request({
  69. url: app.globalData.url + '/checkMkt',
  70. method: 'get',
  71. data: {
  72. branche_code: res.data.result.ad_info.city_code.substring(3, 6) + '000'
  73. },
  74. success: function (res) {
  75. if (res.data.length == 1) {
  76. var obj = that.data.objectArray.find(function (obj) {
  77. return obj.branche_code === res.data[0].branche_code
  78. })
  79. that.setData({
  80. promotionShow: that.data.objectArray.indexOf(obj)
  81. })
  82. } else {
  83. that.setData({
  84. promotionShow: 1
  85. })
  86. }
  87. },
  88. fail() {
  89. app.timeOut()
  90. }
  91. })
  92. },
  93. fail: (res) => {
  94. //获取城市失败
  95. }
  96. })
  97. },
  98. fail: (res) => {
  99. // 获取位置失败
  100. }
  101. })
  102. }, fail() {
  103. app.timeOut()
  104. }
  105. })
  106. let _this = this;
  107. _this.setData({
  108. navH: app.globalData.navHeight
  109. })
  110. },
  111. bindPickerChange: function (e) {
  112. var that = this
  113. var obj = that.data.objectArray[e.detail.value]
  114. that.setData({
  115. promotionShow: e.detail.value
  116. })
  117. },
  118. confirm: function (e) {
  119. var that = this
  120. var myphone = /^(((13[0-9]{1})|(15[0-9]{1})|(18[0-9]{1})|(17[0-9]{1}))+\d{8})$/;
  121. var mydate = /^(\d+)-(\d{1,2})-(\d{1,2})$/;
  122. if (!myphone.test(this.data.phone)) {
  123. wx.showToast({
  124. title: '手机号输入错误',
  125. icon: 'none',
  126. duration: 1500
  127. })
  128. } else if (!mydate.test(this.data.date)) {
  129. wx.showToast({
  130. title: '预产期输入错误',
  131. icon: 'none',
  132. duration: 1500
  133. })
  134. } else if (this.data.objectArray[this.data.promotionShow].branche_code == null || this.data.objectArray[this.data.promotionShow].branche_code == '') {
  135. wx.showToast({
  136. title: '请选择您参加的活动',
  137. icon: 'none',
  138. duration: 1500
  139. })
  140. } else {
  141. var duedate = new Date();
  142. var year = duedate.getFullYear();
  143. var month = duedate.getMonth() + 1;
  144. var strDate = duedate.getDate();
  145. var seperator1 = "-";
  146. var hours = ("0" + (duedate.getHours())).slice(-2);
  147. var minutes = ("0" + (duedate.getMinutes())).slice(-2);
  148. var seconds = ("0" + (duedate.getSeconds())).slice(-2);
  149. wx.showLoading({
  150. title: '保存中......',
  151. icon: 'loading',
  152. duration: 5500
  153. })
  154. wx.request({
  155. url: app.globalData.url + '/insertPromotionDCUserInfo',
  156. method: 'post',
  157. header: { "Content-Type": "application/x-www-form-urlencoded" },
  158. data: {
  159. pd_phone: this.data.phone,
  160. pd_duedate: this.data.date,
  161. pd_city: this.data.objectArray[this.data.promotionShow].branche_code,
  162. pd_date: year + seperator1 + month + seperator1 + strDate + ' ' + hours + ':' + minutes + ':' + seconds,
  163. pd_prom_id: this.data.promotionID,
  164. pd_dc_phone: this.data.dcphone
  165. },
  166. success: function (res) {
  167. wx.hideLoading()
  168. if (res.data == 1) {
  169. wx.navigateTo({
  170. url: '/pages/dcpromotion/dcpresult/dcpresult'
  171. })
  172. } else {
  173. wx.showToast({
  174. title: '亲,您今天已经预约过了',
  175. icon: 'none',
  176. duration: 1500
  177. })
  178. }
  179. },
  180. fail() {
  181. app.timeOut()
  182. }
  183. })
  184. this.setData({
  185. date: "请输入您的预产期",
  186. phone: app.globalData.userphone,
  187. name: null
  188. })
  189. }
  190. }
  191. //事件处理函数
  192. })