东风启辰小程序端
Ви не можете вибрати більше 25 тем Теми мають розпочинатися з літери або цифри, можуть містити дефіси (-) і не повинні перевищувати 35 символів.

279 lines
7.4KB

  1. // pages/perfectMsg/perfectMsg.js
  2. const app = getApp();
  3. Page({
  4. /**
  5. * 页面的初始数据
  6. */
  7. data: {
  8. imgUrl: app.globalData.urlStatic,//图片路径
  9. selectType:2,//选中的手机号类型
  10. marginT: 0,
  11. verificationCode:"获取验证码",
  12. sendCode:true,
  13. mobile2:"",
  14. submitData:{
  15. realName:"",//姓名
  16. mobile:"",//手机号
  17. province:"",//经销商省份
  18. city:"",//经销商城市
  19. agent_code:"",//经销商编码
  20. agentDetail:"",//经销商详情
  21. addressDetail:"",//地址详情
  22. scene:"",//场景值名称
  23. captcha:"",//验证码(若非微信绑定手机号需要传入)
  24. },
  25. provinceDataAll: null,//地区所有数据
  26. provinceDataArr: [[""], [""]],//省市数据
  27. provinceDataValue: [0, 0],//选中的省市下标
  28. nowProvince: "",//选中的省市文字
  29. storeArr: [],//专营店数据
  30. storeValue: 0,//选中的专营店下标
  31. },
  32. /**
  33. * 生命周期函数--监听页面加载
  34. */
  35. onLoad: function (options) {
  36. app.globalData.nowPage = 3;
  37. if (app.globalData.openid) {
  38. this.loadFun();
  39. } else {
  40. app.globalData.openidSuccessFuc = this.loadFun;
  41. }
  42. if (app.globalData.userPhoneType == "ios") {
  43. this.setData({
  44. marginT: -20
  45. })
  46. }
  47. },
  48. loadFun:function(){
  49. if (app.globalData.userMobile) {
  50. this.data.submitData.mobile = app.globalData.userMobile;
  51. this.setData({
  52. submitData: this.data.submitData
  53. })
  54. }
  55. this.getAddress();
  56. },
  57. /**
  58. * 生命周期函数--监听页面初次渲染完成
  59. */
  60. onReady: function () {
  61. },
  62. /**
  63. * 生命周期函数--监听页面显示
  64. */
  65. onShow: function () {
  66. },
  67. /**
  68. * 生命周期函数--监听页面隐藏
  69. */
  70. onHide: function () {
  71. },
  72. /**
  73. * 生命周期函数--监听页面卸载
  74. */
  75. onUnload: function () {
  76. },
  77. /**
  78. * 页面相关事件处理函数--监听用户下拉动作
  79. */
  80. onPullDownRefresh: function () {
  81. },
  82. /**
  83. * 页面上拉触底事件的处理函数
  84. */
  85. onReachBottom: function () {
  86. },
  87. /**
  88. * 用户点击右上角分享
  89. */
  90. onShareAppMessage: function () {
  91. },
  92. enterLucky:function(){//每日抽奖
  93. wx.navigateTo({
  94. url: '/pages/luckyStar/luckyStar'
  95. })
  96. },
  97. ruleControl:function(){//规则显示控制
  98. this.setData({
  99. ruleShow:!this.data.ruleShow
  100. })
  101. },
  102. chooseType:function(e){//选中的手机号类型
  103. this.setData({
  104. selectType:e.currentTarget.dataset.type
  105. })
  106. },
  107. getAddressDetail: function (e) {//获取详细地址
  108. this.data.submitData.addressDetail = e.detail.value;
  109. },
  110. getRealName:function(e){//获取用户输入的姓名
  111. this.data.submitData.realName = e.detail.value;
  112. },
  113. getMobile:function(e){//获取用户输入的电话
  114. this.data.mobile2 = e.detail.value;
  115. },
  116. getCaptcha: function (e) {//获取用户输入的验证码
  117. this.data.submitData.captcha = e.detail.value;
  118. },
  119. getCode: function (e) {//获取验证码
  120. if (!app.mobileVerify(this.data.mobile2)) {
  121. if (this.data.mobile2) {
  122. wx.showToast({
  123. title: '请输入正确的电话',
  124. icon: 'none'
  125. })
  126. } else {
  127. wx.showToast({
  128. title: '请输入电话',
  129. icon: 'none'
  130. })
  131. }
  132. return;
  133. }
  134. if (!this.data.sendCode) {
  135. return;
  136. }
  137. this.data.sendCode = false;
  138. app.wxRequest(app.globalData.urlRoot + "captcha/sendCaptcha", { mobile: this.data.mobile2 }, res => {
  139. if (res.code == 200) {
  140. this.countDown();
  141. wx.showToast({
  142. title: '验证码获取成功',
  143. icon: "none"
  144. })
  145. this.setData({
  146. verificationCode: 60
  147. })
  148. } else {
  149. this.data.sendCode = true;
  150. wx.showToast({
  151. title: res.msg,
  152. icon: "none"
  153. })
  154. }
  155. }, this)
  156. },
  157. countDown: function () {//倒计时
  158. setTimeout(() => {
  159. this.setData({
  160. verificationCode: this.data.verificationCode - 1
  161. })
  162. if (this.data.verificationCode > 0) {
  163. this.countDown();
  164. } else {
  165. this.setData({
  166. verificationCode: "获取验证码"
  167. })
  168. this.data.sendCode = true;
  169. }
  170. }, 1000);
  171. },
  172. getAddress: function () {//获取地址
  173. app.wxRequest(app.globalData.urlRoot + "address/getAddressV2", {}, res => {
  174. console.log(res);
  175. if (res.code == 200) {
  176. if (res.data) {
  177. this.data.submitData.realName = res.data.realName;
  178. this.data.submitData.mobile = res.data.mobile;
  179. this.data.submitData.province = res.data.province;
  180. this.data.submitData.city = res.data.city;
  181. this.data.submitData.addressDetail = res.data.addressDetail;
  182. this.setData({
  183. submitData: this.data.submitData
  184. })
  185. if(!res.data.agentDetail){
  186. this.getUserLocation();//获取用户当前位置
  187. }
  188. }
  189. } else {
  190. wx.showToast({
  191. title: res.msg,
  192. icon: "none"
  193. })
  194. }
  195. }, this);
  196. },
  197. getUserLocation: function (e) {//获取用户地理位置
  198. wx.getLocation({
  199. type: 'wgs84', //wgs84 gcj02
  200. success: (res) => {
  201. this.getDistributorList(res.longitude, res.latitude);
  202. },
  203. fail: (res) => {
  204. this.getDistributorList("", "");
  205. }
  206. })
  207. },
  208. getDistributorList: function (longitude, latitude) {//获取经销商列表
  209. app.wxRequest(app.globalData.urlRoot + "agent/getAgentList", { longitude: longitude, latitude: latitude }, res => {
  210. if (res.code == 200) {
  211. //整理数据
  212. var datas = res.data;
  213. var province = [];
  214. var city = [];
  215. for (let i = 0; i < res.data.list.length; i++) {
  216. province.push(res.data.list[i].province);
  217. }
  218. for (let j = 0; j < res.data.list[res.data.nearData.provinceIndex].children.length; j++) {
  219. city.push(res.data.list[res.data.nearData.provinceIndex].children[j].city)
  220. }
  221. //将数据赋值给变量
  222. this.setData({
  223. provinceDataAll: res.data.list,
  224. provinceDataArr: [province, city],
  225. provinceDataValue: [res.data.nearData.provinceIndex, res.data.nearData.cityIndex],
  226. nowProvince: province[res.data.nearData.provinceIndex] + " " + city[res.data.nearData.cityIndex],
  227. storeArr: res.data.list[res.data.nearData.provinceIndex].children[res.data.nearData.cityIndex].children,
  228. storeValue: res.data.nearData.agentIndex
  229. })
  230. } else {
  231. wx.showToast({
  232. title: res.msg,
  233. icon: "none"
  234. })
  235. }
  236. }, this);
  237. },
  238. provinceDataChange: function (e) {
  239. if (e.detail.column == 0) {
  240. var city = [];
  241. for (let i = 0; i < this.data.provinceDataAll[e.detail.value].children.length; i++) {
  242. city.push(this.data.provinceDataAll[e.detail.value].children[i].city);
  243. }
  244. this.data.provinceDataArr[1] = city;
  245. this.setData({
  246. provinceDataArr: this.data.provinceDataArr
  247. })
  248. }
  249. },
  250. provinceDataChane: function (e) {
  251. this.setData({
  252. provinceDataValue: e.detail.value,
  253. nowProvince: this.data.provinceDataArr[0][e.detail.value[0]] + " " + this.data.provinceDataArr[1][e.detail.value[1]],
  254. storeArr: this.data.provinceDataAll[e.detail.value[0]].children[e.detail.value[1]].children,
  255. storeValue: 0
  256. })
  257. },
  258. storeChane: function (e) {
  259. this.setData({
  260. storeValue: e.detail.value
  261. })
  262. }
  263. })