东风启辰小程序端
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.

296 lines
7.9KB

  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.scene,//好友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. return app.sharePack();
  78. },
  79. getCode: function (e) {//获取验证码
  80. if (!app.mobileVerify(this.data.subscribeData.mobile)) {
  81. if (this.data.subscribeData.mobile) {
  82. wx.showToast({
  83. title: '请输入正确的电话',
  84. icon: 'none'
  85. })
  86. } else {
  87. wx.showToast({
  88. title: '请输入电话',
  89. icon: 'none'
  90. })
  91. }
  92. return;
  93. }
  94. if (!this.data.sendCode) {
  95. return;
  96. }
  97. this.data.sendCode = false;
  98. app.wxRequest(app.globalData.urlRoot + "captcha/sendCaptcha", { mobile: this.data.subscribeData.mobile }, res => {
  99. if (res.code == 200) {
  100. this.countDown();
  101. wx.showToast({
  102. title: '验证码获取成功',
  103. icon: "none"
  104. })
  105. this.setData({
  106. verificationCode: 60
  107. })
  108. } else {
  109. this.data.sendCode = true;
  110. wx.showToast({
  111. title: res.msg,
  112. icon: "none"
  113. })
  114. }
  115. }, this)
  116. },
  117. countDown: function () {//倒计时
  118. setTimeout(() => {
  119. this.setData({
  120. verificationCode: this.data.verificationCode - 1
  121. })
  122. if (this.data.verificationCode > 0) {
  123. this.countDown();
  124. } else {
  125. this.setData({
  126. verificationCode: "获取验证码"
  127. })
  128. this.data.sendCode = true;
  129. }
  130. }, 1000);
  131. },
  132. getRealname: function (e) {//获取用户输入的姓名
  133. this.data.subscribeData.realname = e.detail.value;
  134. },
  135. getMobile: function (e) {//获取用户输入的电话
  136. this.data.subscribeData.mobile = e.detail.value;
  137. },
  138. getCaptcha: function (e) {//获取用户输入的验证码
  139. this.data.subscribeData.captcha = e.detail.value;
  140. },
  141. getUserPhone: function (e) {//获取用户手机号
  142. this.setData({
  143. phoneInputShow: true
  144. })
  145. if (!app.globalData.indexData.provinceArr) {
  146. this.getUserLocation();//获取用户当前位置
  147. }
  148. if (e.detail.errMsg == 'getPhoneNumber:ok') {
  149. app.getMobile(e.detail.encryptedData, e.detail.iv, res => {
  150. if (res.code == 200) {
  151. if (res.data) {
  152. this.data.subscribeData.mobile = res.data.decodeData.phoneNumber;
  153. this.setData({
  154. subscribeData: this.data.subscribeData
  155. })
  156. }
  157. } else {
  158. wx.showToast({
  159. title: res.msg,
  160. icon: "none"
  161. })
  162. }
  163. }, this);
  164. }
  165. },
  166. getUserLocation: function (e) {
  167. wx.getLocation({
  168. type: 'wgs84', //
  169. success: (res) => {
  170. // console.log(res);
  171. this.getDistributorList(res.longitude, res.latitude);
  172. },
  173. fail: (res) => {
  174. this.getDistributorList("", "");
  175. },
  176. complete: (res) => {
  177. this.setData({
  178. siteSelect: true,
  179. })
  180. }
  181. })
  182. },
  183. getDistributorList: function (longitude, latitude) {//获取经销商列表
  184. app.wxRequest(app.globalData.urlRoot + "agent/getAgentList", { longitude: longitude, latitude: latitude }, res => {
  185. if (res.code == 200) {
  186. this.setData({
  187. provinceArr: res.data.list,
  188. storeArr: res.data.list[res.data.nearData.provinceIndex].children,
  189. provinceValue: res.data.nearData.provinceIndex,
  190. storeValue: res.data.nearData.cityIndex
  191. })
  192. this.data.subscribeData.province = this.data.provinceArr[this.data.provinceValue].province;
  193. this.data.subscribeData.agentDetail = this.data.storeArr[this.data.storeValue].agent_detail;
  194. this.data.subscribeData.agent_code = this.data.storeArr[this.data.storeValue].agent_code;
  195. app.globalData.indexData.provinceArr = res.data.list;
  196. app.globalData.indexData.storeArr = res.data.list[res.data.nearData.provinceIndex].children;
  197. app.globalData.indexData.provinceValue = res.data.nearData.provinceIndex;
  198. app.globalData.indexData.storeValue = res.data.nearData.cityIndex;
  199. } else {
  200. wx.showToast({
  201. title: res.msg,
  202. icon: "none"
  203. })
  204. }
  205. }, this);
  206. },
  207. provinceChane: function (e) {//选中省
  208. this.setData({
  209. provinceValue: e.detail.value,
  210. storeArr: this.data.provinceArr[e.detail.value].children,
  211. storeValue: 0
  212. })
  213. this.data.subscribeData.province = this.data.provinceArr[this.data.provinceValue].province;
  214. this.data.subscribeData.agentDetail = this.data.storeArr[this.data.storeValue].agent_detail;
  215. this.data.subscribeData.agent_code = this.data.storeArr[this.data.storeValue].agent_code;
  216. },
  217. storeChane: function (e) {//选中店铺
  218. this.setData({
  219. storeValue: e.detail.value,
  220. })
  221. this.data.subscribeData.agentDetail = this.data.storeArr[this.data.storeValue].agent_detail;
  222. this.data.subscribeData.agent_code = this.data.storeArr[this.data.storeValue].agent_code;
  223. },
  224. agreementState:function(){//协议
  225. this.setData({
  226. isAgreement: !this.data.isAgreement
  227. })
  228. },
  229. subscribeFun: function (e) {//预约鉴赏
  230. if (!this.data.subscribeData.realname) {
  231. wx.showToast({
  232. title: '请输入姓名',
  233. icon: "none"
  234. })
  235. return;
  236. }
  237. if (!this.data.subscribeData.mobile) {
  238. wx.showToast({
  239. title: '请输入电话',
  240. icon: "none"
  241. })
  242. return;
  243. }
  244. if (!this.data.subscribeData.captcha) {
  245. wx.showToast({
  246. title: '请输入验证码',
  247. icon: "none"
  248. })
  249. return;
  250. }
  251. if (!this.data.isAgreement) {
  252. wx.showToast({
  253. title: '请同意协议',
  254. icon: "none"
  255. })
  256. return;
  257. }
  258. if (!this.data.appointment) {
  259. return;
  260. }
  261. this.data.appointment = false;
  262. app.wxRequest(app.globalData.urlRoot + "userInfo/submitOrderInfo", this.data.subscribeData, res => {
  263. this.data.appointment = true;
  264. if (res.code == 200) {
  265. wx.showToast({
  266. title: '预约成功'
  267. })
  268. app.globalData.isRegister = true;
  269. app.globalData.userMobile = this.data.subscribeData.mobile;
  270. wx.redirectTo({
  271. url: "../myCenter/myCenter"
  272. })
  273. } else {
  274. wx.showToast({
  275. title: res.msg,
  276. icon: "none"
  277. })
  278. }
  279. }, this, "POST")
  280. }
  281. })