testsurprised.js 6.3 KB

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