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

index.js 5.7KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198
  1. //index.js
  2. //获取应用实例
  3. const app = getApp()
  4. Page({
  5. data: {
  6. imgUrl: app.globalData.urlStatic,//图片路径
  7. phoneInputShow:false,//是否显示电话输入框
  8. siteSelect: false,//是否显示位置选择框
  9. provinceArr:[],//省
  10. provinceValue: 0,//选中的省下标
  11. storeArr:[],//店铺
  12. storeValue:0,//选中的店铺下标
  13. swiperCurrent:1,//swiper选中的元素下标
  14. verificationCode: '获取验证码',//验证码文案
  15. sendCode: true,
  16. subscribeData:{
  17. realname:"",//姓名
  18. mobile:"",//手机号
  19. captcha:"",//验证码
  20. province:"",//省份
  21. agentDetail: "",//经销商详细信息
  22. parentOpenid: "",//好友openid
  23. }
  24. },
  25. onLoad: function () {
  26. this.getUserLocation();//获取用户当前位置
  27. },
  28. provinceChane: function (e) {//选中省
  29. this.setData({
  30. provinceValue: e.detail.value,
  31. storeArr: this.data.provinceArr[e.detail.value].children,
  32. storeValue:0
  33. })
  34. this.data.subscribeData.province = this.data.provinceArr[this.data.provinceValue].province;
  35. this.data.subscribeData.agentDetail = this.data.storeArr[this.data.storeValue].agent_detail;
  36. },
  37. storeChane: function (e) {//选中店铺
  38. this.setData({
  39. storeValue: e.detail.value,
  40. })
  41. this.data.subscribeData.agentDetail = this.data.storeArr[this.data.storeValue].agent_detail;
  42. },
  43. getUserPhone:function(e){//获取用户手机号
  44. this.setData({
  45. phoneInputShow: true
  46. })
  47. if (e.detail.errMsg=='getPhoneNumber:ok'){
  48. this.setData({
  49. siteSelect: true,
  50. })
  51. app.wxRequest(app.globalData.urlRoot + "userInfo/getUserPhoneNumber", { encryptedData: e.detail.encryptedData, iv: e.detail.iv }, res => {
  52. if (res.code == 200) {
  53. this.data.subscribeData.mobile = res.data.decodeData.phoneNumber;
  54. this.setData({
  55. subscribeData: this.data.subscribeData
  56. })
  57. } else {
  58. wx.showToast({
  59. title: res.msg,
  60. icon: "none"
  61. })
  62. }
  63. }, this,"POST");
  64. }else{
  65. this.setData({
  66. siteSelect: true,
  67. })
  68. }
  69. },
  70. getUserLocation:function(e){
  71. wx.getLocation({
  72. type: 'gcj02', //wgs84
  73. success:(res)=>{
  74. // console.log(res);
  75. this.getDistributorList(res.longitude, res.latitude);
  76. },
  77. fail:(res)=>{
  78. this.getDistributorList("", "");
  79. }
  80. })
  81. },
  82. prevImg(){//上一张图片
  83. if (this.data.swiperCurrent>0) {
  84. this.setData({
  85. swiperCurrent: this.data.swiperCurrent-=1,
  86. })
  87. }
  88. },
  89. nextImg() {//下一张图片
  90. if (this.data.swiperCurrent < 3) {
  91. this.setData({
  92. swiperCurrent: this.data.swiperCurrent+=1,
  93. })
  94. }
  95. },
  96. swiperChange(e){//通过鼠标滑动改变swiper时
  97. if (e.detail.source == "touch"){
  98. this.setData({
  99. swiperCurrent: e.detail.current,
  100. })
  101. }
  102. },
  103. getDistributorList: function (longitude, latitude){//获取经销商列表
  104. app.wxRequest(app.globalData.urlRoot + "agent/getAgentList", { longitude: longitude, latitude: latitude}, res => {
  105. if (res.code == 200) {
  106. this.setData({
  107. provinceArr: res.data.list,
  108. storeArr: res.data.list[res.data.nearData.provinceIndex].children,
  109. provinceValue: res.data.nearData.provinceIndex,
  110. storeValue: res.data.nearData.cityIndex
  111. })
  112. this.data.subscribeData.province = this.data.provinceArr[this.data.provinceValue].province;
  113. this.data.subscribeData.agentDetail = this.data.storeArr[this.data.storeValue].agent_detail;
  114. } else {
  115. wx.showToast({
  116. title: res.msg,
  117. icon: "none"
  118. })
  119. }
  120. }, this);
  121. },
  122. getCode: function (e) {//获取验证码
  123. if (!app.mobileVerify(this.data.subscribeData.mobile)) {
  124. if (this.data.subscribeData.mobile){
  125. wx.showToast({
  126. title: '请输入正确的电话',
  127. icon: 'none'
  128. })
  129. }else{
  130. wx.showToast({
  131. title: '请输入电话',
  132. icon: 'none'
  133. })
  134. }
  135. return;
  136. }
  137. if (!this.data.sendCode){
  138. return;
  139. }
  140. app.wxRequest(app.globalData.urlRoot + "captcha/sendCaptcha", { mobile:'18831849567'},res=>{
  141. console.log(res);
  142. if (res.code == 200) {
  143. this.countDown();
  144. wx.showToast({
  145. title: '验证码获取成功',
  146. icon: "none"
  147. })
  148. this.setData({
  149. verificationCode:60
  150. })
  151. this.data.sendCode = false;
  152. }else{
  153. wx.showToast({
  154. title: res.msg,
  155. icon: "none"
  156. })
  157. }
  158. },this)
  159. },
  160. countDown: function () {//倒计时
  161. setTimeout(() => {
  162. this.setData({
  163. verificationCode: this.data.verificationCode - 1
  164. })
  165. if (this.data.verificationCode > 0) {
  166. this.countDown();
  167. } else {
  168. this.setData({
  169. verificationCode: "获取验证码"
  170. })
  171. this.data.sendCode = true;
  172. }
  173. }, 1000);
  174. },
  175. getRealname: function (e) {//获取用户输入的姓名
  176. this.data.subscribeData.realname = e.detail.value;
  177. },
  178. getMobile: function (e) {//获取用户输入的电话
  179. this.data.subscribeData.mobile = e.detail.value;
  180. },
  181. getCaptcha: function (e) {//获取用户输入的验证码
  182. this.data.subscribeData.captcha = e.detail.value;
  183. },
  184. subscribeFun: function (e) {//预约鉴赏
  185. console.log(this.data.subscribeData);
  186. app.wxRequest(app.globalData.urlRoot + "userInfo/submitOrderInfo", this.data.subscribeData, res => {
  187. console.log(res);
  188. if (res.code == 200) {
  189. } else {
  190. wx.showToast({
  191. title: res.msg,
  192. icon: "none"
  193. })
  194. }
  195. }, this, "POST")
  196. },
  197. })