promotionoffline.js 5.5 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. },
  16. phoneInput: function (e) {
  17. this.setData({
  18. phone: e.detail.value
  19. })
  20. },
  21. nameInput: function (e) {
  22. this.setData({
  23. name: e.detail.value
  24. })
  25. },
  26. bindDateChange: function (e) {
  27. this.setData({
  28. date: e.detail.value
  29. })
  30. },
  31. onLoad: function () {
  32. if (app.globalData.userphone == "" || app.globalData.userphone == null || app.globalData.userphone == undefined) {
  33. app.ifAuthorization();
  34. } else {
  35. if (app.globalData.userphone.split(" ").join("").length != 0) {
  36. this.setData({
  37. phone: app.globalData.userphone
  38. })
  39. } else {
  40. this.setData({
  41. phone: "请输入您的手机号"
  42. })
  43. }
  44. }
  45. var that = this
  46. wx.request({
  47. url: app.globalData.url + '/getWxPosition',
  48. method: 'get',
  49. success: function (res) {
  50. const temp = []
  51. for(var i = 0;i<res.data.length;i++){
  52. temp.push(res.data[i])
  53. }
  54. that.setData({
  55. objectArray: temp,
  56. imgpath: res.data[0].po_headimg
  57. })
  58. wx.getLocation({
  59. type: 'wgs84',
  60. success: function (res) {
  61. let latitude = res.latitude
  62. let longitude = res.longitude
  63. wx.request({
  64. url: `https://apis.map.qq.com/ws/geocoder/v1/?location=${latitude},${longitude}&key=${config.key}`,
  65. success: res => {
  66. wx.request({
  67. url: app.globalData.url + '/getValidPosition',
  68. method: 'get',
  69. data: {
  70. po_mkt: res.data.result.ad_info.adcode
  71. },
  72. success: function (res) {
  73. if (res.data.status == 1) {
  74. var obj = that.data.objectArray.find(function (obj) {
  75. return obj.id === res.data.data.id
  76. })
  77. that.setData({
  78. promotionShow: that.data.objectArray.indexOf(obj),
  79. imgpath: res.data.data.po_headimg
  80. })
  81. }
  82. },
  83. fail() {
  84. app.timeOut()
  85. }
  86. })
  87. },
  88. fail: (res) => {
  89. //获取城市失败
  90. }
  91. })
  92. },
  93. fail: (res) => {
  94. // 获取位置失败
  95. }
  96. })
  97. },
  98. fail() {
  99. app.timeOut()
  100. }
  101. })
  102. let _this = this;
  103. _this.setData({
  104. navH: app.globalData.navHeight
  105. })
  106. },
  107. bindPickerChange: function (e) {
  108. var that = this
  109. var obj = that.data.objectArray[e.detail.value]
  110. that.setData({
  111. promotionShow: e.detail.value,
  112. imgpath: obj.po_headimg
  113. })
  114. },
  115. confirm: function (e) {
  116. var that = this
  117. var myphone = /^(((13[0-9]{1})|(15[0-9]{1})|(18[0-9]{1})|(17[0-9]{1}))+\d{8})$/;
  118. var mydate = /^(\d+)-(\d{1,2})-(\d{1,2})$/;
  119. if (!myphone.test(this.data.phone)) {
  120. wx.showToast({
  121. title: '手机号输入错误',
  122. icon: 'none',
  123. duration: 1500
  124. })
  125. } else if (!mydate.test(this.data.date)) {
  126. wx.showToast({
  127. title: '预产期输入错误',
  128. icon: 'none',
  129. duration: 1500
  130. })
  131. } else if (this.data.name == null || this.data.name == ''){
  132. wx.showToast({
  133. title: '请输入您的姓名',
  134. icon: 'none',
  135. duration: 1500
  136. })
  137. } else if (this.data.objectArray[this.data.promotionShow].id == null || this.data.objectArray[this.data.promotionShow].id == ''){
  138. wx.showToast({
  139. title: '请选择您参加的活动',
  140. icon: 'none',
  141. duration: 1500
  142. })
  143. } else {
  144. var duedate = new Date();
  145. var year = duedate.getFullYear();
  146. var month = duedate.getMonth() + 1;
  147. var strDate = duedate.getDate();
  148. var seperator1 = "-";
  149. var hours = ("0" + (duedate.getHours())).slice(-2);
  150. var minutes = ("0" + (duedate.getMinutes())).slice(-2);
  151. var seconds = ("0" + (duedate.getSeconds())).slice(-2);
  152. wx.showLoading({
  153. title: '保存中......',
  154. icon: 'loading',
  155. duration: 5500
  156. })
  157. wx.request({
  158. url: app.globalData.url + '/insertPromotionUserInfo',
  159. method: 'post',
  160. header: { "Content-Type": "application/x-www-form-urlencoded" },
  161. data: {
  162. pu_username: this.data.name,
  163. pu_phone: this.data.phone,
  164. pu_duedate: this.data.date,
  165. pu_promotionid: this.data.objectArray[this.data.promotionShow].id,
  166. pu_date: year + seperator1 + month + seperator1 + strDate + ' ' + hours + ':' + minutes + ':' + seconds
  167. },
  168. success: function (res) {
  169. wx.hideLoading()
  170. if (res.data == 1) {
  171. wx.navigateTo({
  172. url: '/pages/promotion/promotionofflineresult/promotionofflineresult?status=yes'
  173. })
  174. } else {
  175. wx.navigateTo({
  176. url: '/pages/promotion/promotionofflineresult/promotionofflineresult?status=none'
  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. })