东风启辰小程序端
No puede seleccionar más de 25 temas Los temas deben comenzar con una letra o número, pueden incluir guiones ('-') y pueden tener hasta 35 caracteres de largo.

461 líneas
13KB

  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. phoneInputShow: false,
  15. isUserAddress:true,//用户是否有地址
  16. submitData:{
  17. realName:"",//姓名
  18. mobile:"",//手机号
  19. province:"",//经销商省份
  20. city:"",//经销商城市
  21. agent_code:"",//经销商编码
  22. agentDetail:"",//经销商详情
  23. addressDetail:"",//地址详情
  24. scene:"",//场景值名称
  25. captcha:"",//验证码(若非微信绑定手机号需要传入)
  26. },
  27. provinceDataAll: null,//地区所有数据
  28. provinceDataArr: [[""], [""]],//省市数据
  29. provinceDataValue: [0, 0],//选中的省市下标
  30. nowProvince: "",//选中的省市文字
  31. storeArr: [],//专营店数据
  32. storeValue: 0,//选中的专营店下标
  33. httpState:false,//是否正在进行http请求
  34. windowTipShow:false,//是否显示完善信息后的弹窗
  35. isUserInfo:false,//是否有个人信息
  36. },
  37. /**
  38. * 生命周期函数--监听页面加载
  39. */
  40. onLoad: function (options) {
  41. app.globalData.nowPage = 3;
  42. if (app.globalData.openid) {
  43. this.loadFun();
  44. } else {
  45. app.globalData.openidSuccessFuc = this.loadFun;
  46. }
  47. if (app.globalData.userPhoneType == "ios") {
  48. this.setData({
  49. marginT: -20
  50. })
  51. }
  52. if(app.globalData.userInfoData && app.globalData.userInfoData.nickName){
  53. this.setData({
  54. isUserInfo:true
  55. })
  56. }
  57. },
  58. loadFun:function(){
  59. if (app.globalData.userMobile) {
  60. this.data.submitData.mobile = app.globalData.userMobile;
  61. this.setData({
  62. phoneInputShow: true,
  63. submitData: this.data.submitData
  64. })
  65. }
  66. this.getAddress();
  67. },
  68. /**
  69. * 生命周期函数--监听页面初次渲染完成
  70. */
  71. onReady: function () {
  72. },
  73. /**
  74. * 生命周期函数--监听页面显示
  75. */
  76. onShow: function () {
  77. },
  78. /**
  79. * 生命周期函数--监听页面隐藏
  80. */
  81. onHide: function () {
  82. },
  83. /**
  84. * 生命周期函数--监听页面卸载
  85. */
  86. onUnload: function () {
  87. },
  88. /**
  89. * 页面相关事件处理函数--监听用户下拉动作
  90. */
  91. onPullDownRefresh: function () {
  92. },
  93. /**
  94. * 页面上拉触底事件的处理函数
  95. */
  96. onReachBottom: function () {
  97. },
  98. /**
  99. * 用户点击右上角分享
  100. */
  101. onShareAppMessage: function () {
  102. },
  103. enterLucky:function(){//每日抽奖
  104. wx.navigateTo({
  105. url: '/pages/luckyStar/luckyStar'
  106. })
  107. },
  108. ruleControl:function(){//规则显示控制
  109. this.setData({
  110. ruleShow:!this.data.ruleShow
  111. })
  112. },
  113. chooseType:function(e){//选中的手机号类型
  114. if(e){
  115. this.setData({
  116. selectType:e.currentTarget.dataset.type
  117. })
  118. }else{
  119. this.setData({
  120. selectType:1
  121. })
  122. }
  123. },
  124. getAddressDetail: function (e) {//获取详细地址
  125. this.data.submitData.addressDetail = e.detail.value;
  126. this.setData({
  127. submitData:this.data.submitData
  128. })
  129. },
  130. getRealName:function(e){//获取用户输入的姓名
  131. this.data.submitData.realName = e.detail.value;
  132. this.setData({
  133. submitData:this.data.submitData
  134. })
  135. },
  136. getMobile:function(e){//获取用户输入的电话
  137. this.setData({
  138. mobile2:e.detail.value
  139. })
  140. },
  141. getCaptcha: function (e) {//获取用户输入的验证码
  142. this.data.submitData.captcha = e.detail.value;
  143. this.setData({
  144. submitData:this.data.submitData
  145. })
  146. },
  147. getCode: function (e) {//获取验证码
  148. if (!app.mobileVerify(this.data.mobile2)) {
  149. if (this.data.mobile2) {
  150. wx.showToast({
  151. title: '请输入正确的电话',
  152. icon: 'none'
  153. })
  154. } else {
  155. wx.showToast({
  156. title: '请输入电话',
  157. icon: 'none'
  158. })
  159. }
  160. return;
  161. }
  162. if (!this.data.sendCode) {
  163. return;
  164. }
  165. this.data.sendCode = false;
  166. app.wxRequest(app.globalData.urlRoot + "captcha/sendCaptcha", { mobile: this.data.mobile2 }, res => {
  167. if (res.code == 200) {
  168. this.countDown();
  169. wx.showToast({
  170. title: '验证码获取成功',
  171. icon: "none"
  172. })
  173. this.setData({
  174. verificationCode: 60
  175. })
  176. } else {
  177. this.data.sendCode = true;
  178. wx.showToast({
  179. title: res.msg,
  180. icon: "none"
  181. })
  182. }
  183. }, this)
  184. },
  185. countDown: function () {//倒计时
  186. setTimeout(() => {
  187. this.setData({
  188. verificationCode: this.data.verificationCode - 1
  189. })
  190. if (this.data.verificationCode > 0) {
  191. this.countDown();
  192. } else {
  193. this.setData({
  194. verificationCode: "获取验证码"
  195. })
  196. this.data.sendCode = true;
  197. }
  198. }, 1000);
  199. },
  200. getUserPhone: function (e) {//获取用户手机号
  201. if (e.detail.errMsg == 'getPhoneNumber:ok') {
  202. app.getMobile(e.detail.encryptedData, e.detail.iv, res => {
  203. if (res.code == 200) {
  204. this.setData({
  205. phoneInputShow: true
  206. })
  207. this.chooseType();
  208. if (res.data && res.data.decodeData) {
  209. this.data.submitData.mobile = res.data.decodeData.phoneNumber;
  210. this.setData({
  211. submitData: this.data.submitData
  212. })
  213. }
  214. } else {
  215. wx.showToast({
  216. title: res.msg,
  217. icon: "none"
  218. })
  219. }
  220. }, this);
  221. }
  222. },
  223. getAddress: function () {//获取地址
  224. app.wxRequest(app.globalData.urlRoot + "address/getAddressV2", {}, res => {
  225. console.log(res);
  226. if (res.code == 200) {
  227. if (res.data) {
  228. this.data.submitData.realName = res.data.realName;
  229. this.data.submitData.mobile = res.data.mobile;
  230. this.data.submitData.province = res.data.province;
  231. this.data.submitData.city = res.data.city;
  232. this.data.submitData.addressDetail = res.data.addressDetail;
  233. this.setData({
  234. submitData: this.data.submitData,
  235. mobile2:res.data.mobile
  236. })
  237. // if(!res.data.agentDetail){
  238. this.getDistributorList("","");
  239. // this.getUserLocation();//获取用户当前位置
  240. // }
  241. }else{
  242. this.getUserLocation();//获取用户当前位置
  243. this.setData({
  244. isUserAddress:false
  245. })
  246. }
  247. } else {
  248. wx.showToast({
  249. title: res.msg,
  250. icon: "none"
  251. })
  252. }
  253. }, this);
  254. },
  255. getUserLocation: function (e) {//获取用户地理位置
  256. wx.getLocation({
  257. type: 'wgs84', //wgs84 gcj02
  258. success: (res) => {
  259. this.getDistributorList(res.longitude, res.latitude);
  260. },
  261. fail: (res) => {
  262. this.getDistributorList("", "");
  263. }
  264. })
  265. },
  266. getDistributorList: function (longitude, latitude) {//获取经销商列表
  267. app.wxRequest(app.globalData.urlRoot + "agent/getAgentList", { longitude: longitude, latitude: latitude }, res => {
  268. if (res.code == 200) {
  269. //整理数据
  270. var datas = res.data;
  271. var province = [];
  272. var city = [];
  273. for (let i = 0; i < res.data.list.length; i++) {
  274. province.push(res.data.list[i].province);
  275. }
  276. if(this.data.submitData.province){
  277. for(let i=0;i<province.length;i++){
  278. if(province[i]==this.data.submitData.province){
  279. res.data.nearData.provinceIndex = i;
  280. }
  281. }
  282. }
  283. for (let j = 0; j < res.data.list[res.data.nearData.provinceIndex].children.length; j++) {
  284. city.push(res.data.list[res.data.nearData.provinceIndex].children[j].city)
  285. }
  286. if(this.data.submitData.city){
  287. for(let i=0;i<city.length;i++){
  288. if(city[i]==this.data.submitData.city){
  289. res.data.nearData.cityIndex = i;
  290. }
  291. }
  292. }
  293. if(this.data.submitData.agentDetail){
  294. for(let i=0;i<res.data.list[res.data.nearData.provinceIndex].children[res.data.nearData.cityIndex].children.length;i++){
  295. if(res.data.list[res.data.nearData.provinceIndex].children[res.data.nearData.cityIndex].children[i]==this.data.submitData.agentDetail){
  296. res.data.nearData.agentIndex = i;
  297. }
  298. }
  299. }else{
  300. res.data.nearData.agentIndex = 0;
  301. }
  302. //将数据赋值给变量
  303. var storeArr = res.data.list[res.data.nearData.provinceIndex].children[res.data.nearData.cityIndex].children;
  304. var storeValue = res.data.nearData.agentIndex;
  305. this.data.submitData.agentDetail = storeArr[storeValue].agent_detail;
  306. this.data.submitData.agent_code = storeArr[storeValue].agent_code;
  307. this.data.submitData.province = province[res.data.nearData.provinceIndex];
  308. this.data.submitData.city = city[res.data.nearData.cityIndex];
  309. this.setData({
  310. provinceDataAll: res.data.list,
  311. provinceDataArr: [province, city],
  312. provinceDataValue: [res.data.nearData.provinceIndex, res.data.nearData.cityIndex],
  313. nowProvince: province[res.data.nearData.provinceIndex] + " " + city[res.data.nearData.cityIndex],
  314. storeArr: storeArr,
  315. storeValue: storeValue
  316. })
  317. } else {
  318. wx.showToast({
  319. title: res.msg,
  320. icon: "none"
  321. })
  322. }
  323. }, this);
  324. },
  325. provinceDataChange: function (e) {
  326. if (e.detail.column == 0) {
  327. var city = [];
  328. for (let i = 0; i < this.data.provinceDataAll[e.detail.value].children.length; i++) {
  329. city.push(this.data.provinceDataAll[e.detail.value].children[i].city);
  330. }
  331. this.data.provinceDataArr[1] = city;
  332. this.setData({
  333. provinceDataArr: this.data.provinceDataArr
  334. })
  335. }
  336. },
  337. provinceDataChane: function (e) {
  338. this.setData({
  339. provinceDataValue: e.detail.value,
  340. nowProvince: this.data.provinceDataArr[0][e.detail.value[0]] + " " + this.data.provinceDataArr[1][e.detail.value[1]],
  341. storeArr: this.data.provinceDataAll[e.detail.value[0]].children[e.detail.value[1]].children,
  342. storeValue: 0
  343. })
  344. },
  345. storeChane: function (e) {
  346. this.setData({
  347. storeValue: e.detail.value
  348. })
  349. },
  350. submitUserMsg:function(){//数据提交
  351. if (!this.data.submitData.realName) {
  352. wx.showToast({
  353. title: '请输入姓名',
  354. icon: "none"
  355. })
  356. return;
  357. }
  358. if (!this.data.mobile2 && this.data.selectType==2) {
  359. wx.showToast({
  360. title: '请输入电话',
  361. icon: "none"
  362. })
  363. return;
  364. }
  365. if (this.data.selectType == 2) {
  366. if (!this.data.submitData.captcha) {
  367. wx.showToast({
  368. title: '请输入验证码',
  369. icon: "none"
  370. })
  371. return;
  372. }
  373. }
  374. if(this.data.httpState){
  375. return;
  376. }
  377. this.data.httpState = true;
  378. this.data.submitData.province = this.data.provinceDataArr[0][this.data.provinceDataValue[0]];
  379. this.data.submitData.city = this.data.provinceDataArr[1][this.data.provinceDataValue[1]];
  380. this.data.submitData.agent_code = this.data.storeArr[this.data.storeValue].agent_code;
  381. this.data.submitData.agentDetail = this.data.storeArr[this.data.storeValue].agent_detail;
  382. this.data.submitData.scene = app.globalData.sceneSource;
  383. if(this.data.isUserAddress){
  384. this.updateAddress();
  385. }else{
  386. this.addAddress();
  387. }
  388. },
  389. addAddress: function () {//添加地址
  390. var mobile = this.data.submitData.mobile;
  391. if(this.data.selectType==2){
  392. this.data.submitData.mobile = this.data.mobile2;
  393. }
  394. app.wxRequest(app.globalData.urlRoot + "address/addAddressV2", this.data.submitData, res => {
  395. this.data.httpState = false;
  396. if (res.code == 200) {
  397. this.windowTipControl();
  398. }else{
  399. this.data.submitData.mobile = mobile;
  400. wx.showToast({
  401. title: res.msg,
  402. })
  403. }
  404. }, this, "POST")
  405. },
  406. updateAddress: function () {//更新地址
  407. var mobile = this.data.submitData.mobile;
  408. if(this.data.selectType==2){
  409. this.data.submitData.mobile = this.data.mobile2;
  410. }
  411. app.wxRequest(app.globalData.urlRoot + "address/updateAddressV2", this.data.submitData, res => {
  412. this.data.httpState = false;
  413. if (res.code == 200) {
  414. this.windowTipControl();
  415. }else{
  416. this.data.submitData.mobile = mobile;
  417. wx.showToast({
  418. title: res.msg,
  419. })
  420. }
  421. }, this, "POST");
  422. },
  423. windowTipControl:function(){
  424. this.setData({
  425. windowTipShow:!this.data.windowTipShow
  426. })
  427. },
  428. enterGuess:function(){//去竞猜
  429. // wx.redirectTo({
  430. // url: '/pages/guessSecondPrize/guessSecondPrize',
  431. // })
  432. wx.redirectTo({
  433. url: '/pages/guessSecondPoster/guessSecondPoster',
  434. })
  435. },
  436. getUserWxMsg:function(e){//通过微信获取用户信息
  437. if (e.detail.errMsg == "getUserInfo:ok") {
  438. this.setData({
  439. isUserInfo:true
  440. })
  441. app.submitUserMsg(e.detail.userInfo.avatarUrl, e.detail.userInfo.nickName);
  442. this.enterGuess();
  443. }
  444. }
  445. })