东风启辰小程序端
選択できるのは25トピックまでです。 トピックは、先頭が英数字で、英数字とダッシュ('-')を使用した35文字以内のものにしてください。

443 行
12KB

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