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

419 lines
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.getUserLocation();//获取用户当前位置
  233. }
  234. }else{
  235. this.getUserLocation();//获取用户当前位置
  236. this.setData({
  237. isUserAddress:false
  238. })
  239. }
  240. } else {
  241. wx.showToast({
  242. title: res.msg,
  243. icon: "none"
  244. })
  245. }
  246. }, this);
  247. },
  248. getUserLocation: function (e) {//获取用户地理位置
  249. wx.getLocation({
  250. type: 'wgs84', //wgs84 gcj02
  251. success: (res) => {
  252. this.getDistributorList(res.longitude, res.latitude);
  253. },
  254. fail: (res) => {
  255. this.getDistributorList("", "");
  256. }
  257. })
  258. },
  259. getDistributorList: function (longitude, latitude) {//获取经销商列表
  260. app.wxRequest(app.globalData.urlRoot + "agent/getAgentList", { longitude: longitude, latitude: latitude }, res => {
  261. if (res.code == 200) {
  262. //整理数据
  263. var datas = res.data;
  264. var province = [];
  265. var city = [];
  266. for (let i = 0; i < res.data.list.length; i++) {
  267. province.push(res.data.list[i].province);
  268. }
  269. for (let j = 0; j < res.data.list[res.data.nearData.provinceIndex].children.length; j++) {
  270. city.push(res.data.list[res.data.nearData.provinceIndex].children[j].city)
  271. }
  272. //将数据赋值给变量
  273. var storeArr = res.data.list[res.data.nearData.provinceIndex].children[res.data.nearData.cityIndex].children;
  274. var storeValue = res.data.nearData.agentIndex;
  275. this.data.submitData.agentDetail = storeArr[storeValue].agent_detail;
  276. this.data.submitData.agent_code = storeArr[storeValue].agent_code;
  277. this.data.submitData.province = province[res.data.nearData.provinceIndex];
  278. this.data.submitData.city = city[res.data.nearData.cityIndex];
  279. this.setData({
  280. provinceDataAll: res.data.list,
  281. provinceDataArr: [province, city],
  282. provinceDataValue: [res.data.nearData.provinceIndex, res.data.nearData.cityIndex],
  283. nowProvince: province[res.data.nearData.provinceIndex] + " " + city[res.data.nearData.cityIndex],
  284. storeArr: storeArr,
  285. storeValue: storeValue
  286. })
  287. } else {
  288. wx.showToast({
  289. title: res.msg,
  290. icon: "none"
  291. })
  292. }
  293. }, this);
  294. },
  295. provinceDataChange: function (e) {
  296. if (e.detail.column == 0) {
  297. var city = [];
  298. for (let i = 0; i < this.data.provinceDataAll[e.detail.value].children.length; i++) {
  299. city.push(this.data.provinceDataAll[e.detail.value].children[i].city);
  300. }
  301. this.data.provinceDataArr[1] = city;
  302. this.setData({
  303. provinceDataArr: this.data.provinceDataArr
  304. })
  305. }
  306. },
  307. provinceDataChane: function (e) {
  308. this.setData({
  309. provinceDataValue: e.detail.value,
  310. nowProvince: this.data.provinceDataArr[0][e.detail.value[0]] + " " + this.data.provinceDataArr[1][e.detail.value[1]],
  311. storeArr: this.data.provinceDataAll[e.detail.value[0]].children[e.detail.value[1]].children,
  312. storeValue: 0
  313. })
  314. },
  315. storeChane: function (e) {
  316. this.setData({
  317. storeValue: e.detail.value
  318. })
  319. },
  320. submitUserMsg:function(){//数据提交
  321. if (!this.data.submitData.realName) {
  322. wx.showToast({
  323. title: '请输入姓名',
  324. icon: "none"
  325. })
  326. return;
  327. }
  328. if (!this.data.mobile2 && this.data.selectType==2) {
  329. wx.showToast({
  330. title: '请输入电话',
  331. icon: "none"
  332. })
  333. return;
  334. }
  335. if (this.data.selectType == 2) {
  336. if (!this.data.submitData.captcha) {
  337. wx.showToast({
  338. title: '请输入验证码',
  339. icon: "none"
  340. })
  341. return;
  342. }
  343. }
  344. if(this.data.httpState){
  345. return;
  346. }
  347. this.data.httpState = true;
  348. this.data.submitData.province = this.data.provinceDataArr[0][this.data.provinceDataValue[0]];
  349. this.data.submitData.city = this.data.provinceDataArr[1][this.data.provinceDataValue[1]];
  350. this.data.submitData.agent_code = this.data.storeArr[this.data.storeValue].agent_code;
  351. this.data.submitData.agentDetail = this.data.storeArr[this.data.storeValue].agent_detail;
  352. this.data.submitData.scene = app.globalData.sceneSource;
  353. if(this.data.isUserAddress){
  354. this.updateAddress();
  355. }else{
  356. this.addAddress();
  357. }
  358. },
  359. addAddress: function () {//添加地址
  360. var mobile = this.data.submitData.mobile;
  361. if(this.data.selectType==2){
  362. this.data.submitData.mobile = this.data.mobile2;
  363. }
  364. app.wxRequest(app.globalData.urlRoot + "address/addAddressV2", this.data.submitData, res => {
  365. this.data.httpState = false;
  366. if (res.code == 200) {
  367. this.windowTipControl();
  368. }else{
  369. this.data.submitData.mobile = mobile;
  370. wx.showToast({
  371. title: res.msg,
  372. })
  373. }
  374. }, this, "POST")
  375. },
  376. updateAddress: function () {//更新地址
  377. var mobile = this.data.submitData.mobile;
  378. if(this.data.selectType==2){
  379. this.data.submitData.mobile = this.data.mobile2;
  380. }
  381. app.wxRequest(app.globalData.urlRoot + "address/updateAddressV2", this.data.submitData, res => {
  382. this.data.httpState = false;
  383. if (res.code == 200) {
  384. this.windowTipControl();
  385. }else{
  386. this.data.submitData.mobile = mobile;
  387. wx.showToast({
  388. title: res.msg,
  389. })
  390. }
  391. }, this, "POST");
  392. },
  393. windowTipControl:function(){
  394. this.setData({
  395. windowTipShow:!this.data.windowTipShow
  396. })
  397. },
  398. enterGuess:function(){//去竞猜
  399. wx.redirectTo({
  400. url: '/pages/guessSecondPrize/guessSecondPrize',
  401. })
  402. }
  403. })