东风启辰小程序端
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

receiveRegister.js 7.9KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294
  1. // pages/receiveRegister/receiveRegister.js
  2. const app = getApp()
  3. Page({
  4. /**
  5. * 页面的初始数据
  6. */
  7. data: {
  8. imgUrl: app.globalData.urlStatic,//图片路径
  9. isAgreement:true,//是否同意协议
  10. phoneInputShow: false,//是否显示电话输入框
  11. verificationCode: '获取验证码',//验证码文案
  12. sendCode: true,
  13. appointment:true,
  14. provinceArr: [],//省
  15. provinceValue: 0,//选中的省下标
  16. storeArr: [],//店铺
  17. storeValue: 0,//选中的店铺下标
  18. siteSelect: false,//是否显示位置选择框
  19. subscribeData: {
  20. realname: "",//姓名
  21. mobile: "",//手机号
  22. captcha: "",//验证码
  23. province: "",//省份
  24. agent_code: "",//经销商编码
  25. agentDetail: "",//经销商详细信息
  26. parentOpenid: app.globalData.friendOpenid,//好友openid
  27. },
  28. },
  29. /**
  30. * 生命周期函数--监听页面加载
  31. */
  32. onLoad: function (options) {
  33. app.globalData.nowPage = 2;
  34. if (app.globalData.userMobile) {
  35. this.data.subscribeData.mobile = app.globalData.userMobile;
  36. this.setData({
  37. phoneInputShow: true,
  38. subscribeData: this.data.subscribeData
  39. })
  40. this.getUserLocation();
  41. }
  42. },
  43. /**
  44. * 生命周期函数--监听页面初次渲染完成
  45. */
  46. onReady: function () {
  47. },
  48. /**
  49. * 生命周期函数--监听页面显示
  50. */
  51. onShow: function () {
  52. },
  53. /**
  54. * 生命周期函数--监听页面隐藏
  55. */
  56. onHide: function () {
  57. },
  58. /**
  59. * 生命周期函数--监听页面卸载
  60. */
  61. onUnload: function () {
  62. },
  63. /**
  64. * 页面相关事件处理函数--监听用户下拉动作
  65. */
  66. onPullDownRefresh: function () {
  67. },
  68. /**
  69. * 页面上拉触底事件的处理函数
  70. */
  71. onReachBottom: function () {
  72. },
  73. /**
  74. * 用户点击右上角分享
  75. */
  76. onShareAppMessage: function () {
  77. },
  78. getCode: function (e) {//获取验证码
  79. if (!app.mobileVerify(this.data.subscribeData.mobile)) {
  80. if (this.data.subscribeData.mobile) {
  81. wx.showToast({
  82. title: '请输入正确的电话',
  83. icon: 'none'
  84. })
  85. } else {
  86. wx.showToast({
  87. title: '请输入电话',
  88. icon: 'none'
  89. })
  90. }
  91. return;
  92. }
  93. if (!this.data.sendCode) {
  94. return;
  95. }
  96. this.data.sendCode = false;
  97. app.wxRequest(app.globalData.urlRoot + "captcha/sendCaptcha", { mobile: this.data.subscribeData.mobile }, res => {
  98. if (res.code == 200) {
  99. this.countDown();
  100. wx.showToast({
  101. title: '验证码获取成功',
  102. icon: "none"
  103. })
  104. this.setData({
  105. verificationCode: 60
  106. })
  107. } else {
  108. this.data.sendCode = true;
  109. wx.showToast({
  110. title: res.msg,
  111. icon: "none"
  112. })
  113. }
  114. }, this)
  115. },
  116. countDown: function () {//倒计时
  117. setTimeout(() => {
  118. this.setData({
  119. verificationCode: this.data.verificationCode - 1
  120. })
  121. if (this.data.verificationCode > 0) {
  122. this.countDown();
  123. } else {
  124. this.setData({
  125. verificationCode: "获取验证码"
  126. })
  127. this.data.sendCode = true;
  128. }
  129. }, 1000);
  130. },
  131. getRealname: function (e) {//获取用户输入的姓名
  132. this.data.subscribeData.realname = e.detail.value;
  133. },
  134. getMobile: function (e) {//获取用户输入的电话
  135. this.data.subscribeData.mobile = e.detail.value;
  136. },
  137. getCaptcha: function (e) {//获取用户输入的验证码
  138. this.data.subscribeData.captcha = e.detail.value;
  139. },
  140. getUserPhone: function (e) {//获取用户手机号
  141. this.setData({
  142. phoneInputShow: true
  143. })
  144. if (!app.globalData.indexData.provinceArr) {
  145. this.getUserLocation();//获取用户当前位置
  146. }
  147. if (e.detail.errMsg == 'getPhoneNumber:ok') {
  148. app.getMobile(e.detail.encryptedData, e.detail.iv, res => {
  149. if (res.code == 200) {
  150. this.data.subscribeData.mobile = res.data.decodeData.phoneNumber;
  151. this.setData({
  152. subscribeData: this.data.subscribeData
  153. })
  154. } else {
  155. wx.showToast({
  156. title: res.msg,
  157. icon: "none"
  158. })
  159. }
  160. }, this);
  161. }
  162. },
  163. getUserLocation: function (e) {
  164. wx.getLocation({
  165. type: 'wgs84', //
  166. success: (res) => {
  167. // console.log(res);
  168. this.getDistributorList(res.longitude, res.latitude);
  169. },
  170. fail: (res) => {
  171. this.getDistributorList("", "");
  172. },
  173. complete: (res) => {
  174. this.setData({
  175. siteSelect: true,
  176. })
  177. }
  178. })
  179. },
  180. getDistributorList: function (longitude, latitude) {//获取经销商列表
  181. app.wxRequest(app.globalData.urlRoot + "agent/getAgentList", { longitude: longitude, latitude: latitude }, res => {
  182. if (res.code == 200) {
  183. this.setData({
  184. provinceArr: res.data.list,
  185. storeArr: res.data.list[res.data.nearData.provinceIndex].children,
  186. provinceValue: res.data.nearData.provinceIndex,
  187. storeValue: res.data.nearData.cityIndex
  188. })
  189. this.data.subscribeData.province = this.data.provinceArr[this.data.provinceValue].province;
  190. this.data.subscribeData.agentDetail = this.data.storeArr[this.data.storeValue].agent_detail;
  191. this.data.subscribeData.agent_code = this.data.storeArr[this.data.storeValue].agent_code;
  192. app.globalData.indexData.provinceArr = res.data.list;
  193. app.globalData.indexData.storeArr = res.data.list[res.data.nearData.provinceIndex].children;
  194. app.globalData.indexData.provinceValue = res.data.nearData.provinceIndex;
  195. app.globalData.indexData.storeValue = res.data.nearData.cityIndex;
  196. } else {
  197. wx.showToast({
  198. title: res.msg,
  199. icon: "none"
  200. })
  201. }
  202. }, this);
  203. },
  204. provinceChane: function (e) {//选中省
  205. this.setData({
  206. provinceValue: e.detail.value,
  207. storeArr: this.data.provinceArr[e.detail.value].children,
  208. storeValue: 0
  209. })
  210. this.data.subscribeData.province = this.data.provinceArr[this.data.provinceValue].province;
  211. this.data.subscribeData.agentDetail = this.data.storeArr[this.data.storeValue].agent_detail;
  212. this.data.subscribeData.agent_code = this.data.storeArr[this.data.storeValue].agent_code;
  213. },
  214. storeChane: function (e) {//选中店铺
  215. this.setData({
  216. storeValue: e.detail.value,
  217. })
  218. this.data.subscribeData.agentDetail = this.data.storeArr[this.data.storeValue].agent_detail;
  219. this.data.subscribeData.agent_code = this.data.storeArr[this.data.storeValue].agent_code;
  220. },
  221. agreementState:function(){//协议
  222. this.setData({
  223. isAgreement: !this.data.isAgreement
  224. })
  225. },
  226. subscribeFun: function (e) {//预约鉴赏
  227. if (!this.data.subscribeData.realname) {
  228. wx.showToast({
  229. title: '请输入姓名',
  230. icon: "none"
  231. })
  232. return;
  233. }
  234. if (!this.data.subscribeData.mobile) {
  235. wx.showToast({
  236. title: '请输入电话',
  237. icon: "none"
  238. })
  239. return;
  240. }
  241. if (!this.data.subscribeData.captcha) {
  242. wx.showToast({
  243. title: '请输入验证码',
  244. icon: "none"
  245. })
  246. return;
  247. }
  248. if (!this.data.isAgreement) {
  249. wx.showToast({
  250. title: '请同意协议',
  251. icon: "none"
  252. })
  253. return;
  254. }
  255. if (!this.data.appointment) {
  256. return;
  257. }
  258. this.data.appointment = false;
  259. app.wxRequest(app.globalData.urlRoot + "userInfo/submitOrderInfo", this.data.subscribeData, res => {
  260. this.data.appointment = true;
  261. if (res.code == 200) {
  262. wx.showToast({
  263. title: '预约成功'
  264. })
  265. app.globalData.isRegister = true;
  266. app.globalData.userMobile = this.data.subscribeData.mobile;
  267. wx.redirectTo({
  268. url: "../myCenter/myCenter"
  269. })
  270. } else {
  271. wx.showToast({
  272. title: res.msg,
  273. icon: "none"
  274. })
  275. }
  276. }, this, "POST")
  277. }
  278. })