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

678 lines
20KB

  1. // pages/myCenter/myCenter.js
  2. const app = getApp()
  3. Page({
  4. /**
  5. * 页面的初始数据
  6. */
  7. data: {
  8. imgUrl: app.globalData.urlStatic,//图片路径
  9. isAddress:false,
  10. placing:false,
  11. buyState:false,
  12. buyStateTime:"",
  13. isAgreement: true,//是否同意协议
  14. phoneInputShow: false,//是否显示电话输入框
  15. siteSelect: false,//是否显示位置选择框
  16. isLogin:false,//登录状态
  17. selectNow:0,//现在的选项
  18. taskNow:1,//现在的任务类型
  19. recordNow: 1,//现在的记录类型
  20. taskList: [],//任务列表
  21. shareFriendList:[],//星探小分队列表
  22. recordList:[],//获奖记录列表
  23. provinceArr: [],//省
  24. provinceValue: 0,//选中的省下标
  25. storeArr: [],//店铺
  26. storeValue: 0,//选中的店铺下标
  27. verificationCode: '获取验证码',//验证码文案
  28. sendCode: true,
  29. appointment: true,
  30. subscribeData: {
  31. realname: "",//姓名
  32. mobile: "",//手机号
  33. captcha: "",//验证码
  34. province: "",//省份
  35. agent_code: "",//经销商编码
  36. agentDetail: "",//经销商详细信息
  37. parentOpenid: app.globalData.friendOpenid,//好友openid
  38. },
  39. userData:{
  40. avatarUrl: null,
  41. nickName: null,
  42. userLevel: 1
  43. },
  44. descFrameShow:false,//是否显示奖品详情
  45. ruleShow: false,//是否显示星探等级规则
  46. // isRegister: false,//查询是否已注册
  47. parames:{
  48. page:1,
  49. count:20
  50. },
  51. noData:false,
  52. optionsData:null,
  53. lookDescId: null,
  54. agreement: false,//是否显示协议
  55. addressShow:false,
  56. mycenterTipWindow:0,
  57. barNums:0,
  58. getState:true
  59. },
  60. /**
  61. * 生命周期函数--监听页面加载
  62. */
  63. onLoad: function (options) {
  64. app.globalData.nowPage = 4;
  65. if (options.sourcePage){
  66. this.data.optionsData = options.sourcePage;
  67. }
  68. if (app.globalData.openid) {
  69. this.loadFun();
  70. } else {
  71. app.globalData.openidSuccessFuc = this.loadFun;
  72. }
  73. },
  74. loadFun: function () {
  75. this.getUserInfo();
  76. this.getAddress();
  77. if (app.globalData.userMobile) {
  78. this.data.subscribeData.mobile = app.globalData.userMobile;
  79. this.setData({
  80. phoneInputShow: true,
  81. subscribeData: this.data.subscribeData
  82. })
  83. }
  84. if (app.globalData.myCenterData) {
  85. this.setData({
  86. provinceArr: app.globalData.myCenterData.provinceArr,
  87. storeArr: app.globalData.myCenterData.storeArr,
  88. provinceValue: app.globalData.myCenterData.provinceValue,
  89. storeValue: app.globalData.myCenterData.storeValue,
  90. // isRegister: app.globalData.isRegister
  91. })
  92. this.data.subscribeData.province = this.data.provinceArr[this.data.provinceValue].province;
  93. this.data.subscribeData.agentDetail = this.data.storeArr[this.data.storeValue].agent_detail;
  94. this.data.subscribeData.agent_code = this.data.storeArr[this.data.storeValue].agent_code;
  95. }
  96. // if (!app.globalData.isRegister) {
  97. // this.getOrderInfo();
  98. // }
  99. if (app.globalData.userInfoData) {
  100. this.data.userData.avatarUrl = app.globalData.userInfoData.avatarUrl;
  101. this.data.userData.nickName = app.globalData.userInfoData.nickName;
  102. this.data.userData.userLevel = app.globalData.userInfoData.userLevel;
  103. this.setData({
  104. isLogin: true,
  105. userData: this.data.userData
  106. })
  107. }
  108. },
  109. /**
  110. * 生命周期函数--监听页面初次渲染完成
  111. */
  112. onReady: function () {
  113. },
  114. /**
  115. * 生命周期函数--监听页面显示
  116. */
  117. onShow: function () {
  118. if (app.globalData.getBuyState) {
  119. this.getBuyStates();
  120. } else {
  121. app.globalData.buyStateSuccessFuc = this.getBuyStates;
  122. }
  123. this.data.subscribeData.parentOpenid = app.globalData.friendOpenid;
  124. },
  125. getBuyStates: function () {
  126. this.setData({
  127. buyState: app.globalData.getBuyState.success,
  128. buyStateTime: app.globalData.getBuyState.cdate
  129. })
  130. },
  131. /**
  132. * 生命周期函数--监听页面隐藏
  133. */
  134. onHide: function () {
  135. },
  136. /**
  137. * 生命周期函数--监听页面卸载
  138. */
  139. onUnload: function () {
  140. },
  141. /**
  142. * 页面相关事件处理函数--监听用户下拉动作
  143. */
  144. onPullDownRefresh: function () {
  145. },
  146. /**
  147. * 页面上拉触底事件的处理函数
  148. */
  149. onReachBottom: function () {
  150. },
  151. /**
  152. * 用户点击右上角分享
  153. */
  154. onShareAppMessage: function () {
  155. return app.sharePack();
  156. },
  157. selectChange:function(e){
  158. this.setData({
  159. selectNow: e.currentTarget.dataset.value
  160. })
  161. if (e.currentTarget.dataset.value == 1) {
  162. this.getTaskProgress();
  163. } else if (e.currentTarget.dataset.value == 2) {
  164. this.getMyAwardList();
  165. } else if (e.currentTarget.dataset.value == 3){
  166. this.data.parames.page = 0;
  167. this.setData({
  168. parames: this.data.parames,
  169. shareFriendList:[]
  170. })
  171. this.getShareList();
  172. }
  173. },
  174. selectTask: function (e) {
  175. this.setData({
  176. taskNow: e.currentTarget.dataset.type
  177. })
  178. if (this.data.taskNow==2){
  179. this.getFriendBuCarNum();
  180. }
  181. },
  182. getFriendBuCarNum:function(){
  183. app.wxRequest(app.globalData.urlRoot +"/share/getFriendBuCarNum",{},res=>{
  184. if(res.code==200){
  185. this.setData({
  186. barNums: res.data.total
  187. })
  188. }
  189. },this);
  190. },
  191. selectRecord: function (e) {
  192. if (this.data.recordNow == e.currentTarget.dataset.type) {
  193. return;
  194. }
  195. this.setData({
  196. recordList:[],
  197. recordNow: e.currentTarget.dataset.type
  198. })
  199. this.getMyAwardList();
  200. },
  201. getUserLocation: function (e) {
  202. wx.getLocation({
  203. type: 'gcj02', //wgs84
  204. success: (res) => {
  205. this.getDistributorList(res.longitude, res.latitude);
  206. },
  207. fail: (res) => {
  208. this.getDistributorList("", "");
  209. },
  210. complete: (res) => {
  211. this.setData({
  212. siteSelect: true,
  213. })
  214. }
  215. })
  216. },
  217. getDistributorList: function (longitude, latitude) {//获取经销商列表
  218. app.wxRequest(app.globalData.urlRoot + "agent/getAgentList", { longitude: longitude, latitude: latitude }, res => {
  219. if (res.code == 200) {
  220. app.globalData.myCenterData = {};
  221. this.setData({
  222. provinceArr: res.data.list,
  223. storeArr: res.data.list[res.data.nearData.provinceIndex].children,
  224. provinceValue: res.data.nearData.provinceIndex,
  225. storeValue: res.data.nearData.cityIndex
  226. })
  227. this.data.subscribeData.province = this.data.provinceArr[this.data.provinceValue].province;
  228. this.data.subscribeData.agentDetail = this.data.storeArr[this.data.storeValue].agent_detail;
  229. this.data.subscribeData.agent_code = this.data.storeArr[this.data.storeValue].agent_code;
  230. app.globalData.myCenterData.provinceArr = res.data.list;
  231. app.globalData.myCenterData.storeArr = res.data.list[res.data.nearData.provinceIndex].children;
  232. app.globalData.myCenterData.provinceValue = res.data.nearData.provinceIndex;
  233. app.globalData.myCenterData.storeValue = res.data.nearData.cityIndex;
  234. } else {
  235. wx.showToast({
  236. title: res.msg,
  237. icon: "none"
  238. })
  239. }
  240. }, this);
  241. },
  242. provinceChane: function (e) {//选中省
  243. this.setData({
  244. provinceValue: e.detail.value,
  245. storeArr: this.data.provinceArr[e.detail.value].children,
  246. storeValue: 0
  247. })
  248. this.data.subscribeData.province = this.data.provinceArr[this.data.provinceValue].province;
  249. this.data.subscribeData.agentDetail = this.data.storeArr[this.data.storeValue].agent_detail;
  250. this.data.subscribeData.agent_code = this.data.storeArr[this.data.storeValue].agent_code;
  251. },
  252. storeChane: function (e) {//选中店铺
  253. this.setData({
  254. storeValue: e.detail.value,
  255. })
  256. this.data.subscribeData.agentDetail = this.data.storeArr[this.data.storeValue].agent_detail;
  257. this.data.subscribeData.agent_code = this.data.storeArr[this.data.storeValue].agent_code;
  258. },
  259. getCode: function (e) {//获取验证码
  260. if (!app.mobileVerify(this.data.subscribeData.mobile)) {
  261. if (this.data.subscribeData.mobile) {
  262. wx.showToast({
  263. title: '请输入正确的电话',
  264. icon: 'none'
  265. })
  266. } else {
  267. wx.showToast({
  268. title: '请输入电话',
  269. icon: 'none'
  270. })
  271. }
  272. return;
  273. }
  274. if (!this.data.sendCode) {
  275. return;
  276. }
  277. this.data.sendCode = false;
  278. app.wxRequest(app.globalData.urlRoot + "captcha/sendCaptcha", { mobile: this.data.subscribeData.mobile }, res => {
  279. if (res.code == 200) {
  280. this.countDown();
  281. wx.showToast({
  282. title: '验证码获取成功',
  283. icon: "none"
  284. })
  285. this.setData({
  286. verificationCode: 60
  287. })
  288. } else {
  289. this.data.sendCode = true;
  290. wx.showToast({
  291. title: res.msg,
  292. icon: "none"
  293. })
  294. }
  295. }, this)
  296. },
  297. countDown: function () {//倒计时
  298. setTimeout(() => {
  299. this.setData({
  300. verificationCode: this.data.verificationCode - 1
  301. })
  302. if (this.data.verificationCode > 0) {
  303. this.countDown();
  304. } else {
  305. this.setData({
  306. verificationCode: "获取验证码"
  307. })
  308. this.data.sendCode = true;
  309. }
  310. }, 1000);
  311. },
  312. getRealname: function (e) {//获取用户输入的姓名
  313. this.data.subscribeData.realname = e.detail.value;
  314. },
  315. getMobile: function (e) {//获取用户输入的电话
  316. this.data.subscribeData.mobile = e.detail.value;
  317. },
  318. getCaptcha: function (e) {//获取用户输入的验证码
  319. this.data.subscribeData.captcha = e.detail.value;
  320. },
  321. subscribeFun: function (e) {//预约鉴赏
  322. if(!this.data.subscribeData.realname){
  323. wx.showToast({
  324. title: '请输入姓名',
  325. icon:"none"
  326. })
  327. return;
  328. }
  329. if (!this.data.subscribeData.mobile) {
  330. wx.showToast({
  331. title: '请输入电话',
  332. icon: "none"
  333. })
  334. return;
  335. }
  336. if (!this.data.subscribeData.captcha) {
  337. wx.showToast({
  338. title: '请输入验证码',
  339. icon: "none"
  340. })
  341. return;
  342. }
  343. if (!this.data.isAgreement) {
  344. wx.showToast({
  345. title: '请同意协议',
  346. icon: 'none'
  347. })
  348. return;
  349. }
  350. if (!this.data.appointment) {
  351. return;
  352. }
  353. this.data.appointment = false;
  354. app.wxRequest(app.globalData.urlRoot + "userInfo/submitOrderInfo", this.data.subscribeData, res => {
  355. this.data.appointment = true;
  356. if (res.code == 200) {
  357. wx.showToast({
  358. title: '预约成功'
  359. })
  360. this.data.subscribeData.realname = "";
  361. this.data.subscribeData.captcha = "";
  362. this.setData({
  363. subscribeData: this.data.subscribeData,
  364. verificationCode: '获取验证码',
  365. })
  366. this.setData({
  367. siteSelect: false
  368. })
  369. // this.setData({
  370. // isRegister: true
  371. // })
  372. // app.globalData.isRegister = true;
  373. app.globalData.userMobile = this.data.subscribeData.mobile;
  374. } else {
  375. wx.showToast({
  376. title: res.msg,
  377. icon: "none"
  378. })
  379. }
  380. }, this, "POST")
  381. },
  382. getUserWxMsg:function(e){//通过微信获取用户信息
  383. if (e.detail.errMsg == "getUserInfo:ok") {
  384. this.data.userData.avatarUrl = e.detail.userInfo.avatarUrl;
  385. this.data.userData.nickName = e.detail.userInfo.nickName;
  386. this.setData({
  387. userData: this.data.userData,
  388. isLogin: true
  389. })
  390. app.submitUserMsg(e.detail.userInfo.avatarUrl, e.detail.userInfo.nickName);
  391. }
  392. },
  393. getUserInfo:function(e){//获取个人信息
  394. app.wxRequest(app.globalData.urlRoot + 'userInfo/getUserInfo', {}, res => {
  395. if(res.code==200){
  396. if (res.data && res.data.avatarUrl) {
  397. if (!app.globalData.userInfoData) {
  398. this.data.userData.avatarUrl = res.data.avatarUrl;
  399. this.data.userData.nickName = res.data.nickName;
  400. this.data.userData.userLevel = res.data.userLevel;
  401. app.globalData.userInfoData = {};
  402. app.globalData.userInfoData.avatarUrl = res.data.avatarUrl;
  403. app.globalData.userInfoData.nickName = res.data.nickName;
  404. app.globalData.userInfoData.userLevel = res.data.userLevel;
  405. wx.setStorageSync('userInfoData', {
  406. avatarUrl: res.data.avatarUrl,
  407. nickName: res.data.nickName,
  408. userLevel: res.data.userLevel,
  409. })
  410. } else if (app.globalData.userInfoData){
  411. if (app.globalData.userInfoData.userLevel != res.data.userLevel) {
  412. this.data.userData.userLevel = res.data.userLevel;
  413. app.globalData.userInfoData.userLevel = res.data.userLevel;
  414. wx.setStorageSync('userInfoData', app.globalData.userInfoData);
  415. }
  416. if (app.globalData.userInfoData.avatarUrl != res.data.avatarUrl) {
  417. this.data.userData.avatarUrl = res.data.avatarUrl;
  418. app.globalData.userInfoData.avatarUrl = res.data.avatarUrl;
  419. wx.setStorageSync('userInfoData', app.globalData.userInfoData);
  420. }
  421. if (app.globalData.userInfoData.nickName != res.data.nickName) {
  422. this.data.userData.nickName = res.data.nickName;
  423. app.globalData.userInfoData.nickName = res.data.nickName;
  424. wx.setStorageSync('userInfoData', app.globalData.userInfoData);
  425. }
  426. }
  427. this.setData({
  428. userData: this.data.userData
  429. })
  430. if (!app.globalData.userInfoData){
  431. this.setData({
  432. isLogin: true
  433. })
  434. }
  435. }
  436. }
  437. },this)
  438. },
  439. getTaskProgress: function () {//获取任务完成度 1每日任务
  440. app.wxRequest(app.globalData.urlRoot + "task/getTaskProgress", { taskType: this.data.taskNow},res=>{
  441. if(res.code==200){
  442. if(res.data){
  443. for (let i = 0; i < res.data.taskData.length; i++) {
  444. res.data.taskData[i]['unlockNum'] = 0;
  445. for (let j = 0; j < res.data.taskData[i].childIdArr.length; j++) {
  446. if (res.data.taskData[i].childIdArr[j]) {
  447. res.data.taskData[i]['unlockNum'] += 1;
  448. }
  449. }
  450. }
  451. this.setData({
  452. taskList: res.data.taskData
  453. })
  454. }
  455. }
  456. },this)
  457. },
  458. lookDesc:function(e){//查看奖品详情
  459. if (this.data.descFrameShow){
  460. this.setData({
  461. descFrameShow: !this.data.descFrameShow,
  462. })
  463. return;
  464. }
  465. if (this.data.recordList[e.currentTarget.dataset.value].awardState == 0){
  466. this.setData({
  467. mycenterTipWindow:this.data.isAddress?2:1
  468. })
  469. } else {
  470. this.setData({
  471. descFrameShow: !this.data.descFrameShow,
  472. lookDescId: e.currentTarget.dataset.value || e.currentTarget.dataset.value == 0 ? e.currentTarget.dataset.value : null
  473. })
  474. }
  475. },
  476. lookRule: function (e) {//查看奖品详情
  477. this.setData({
  478. ruleShow: e.currentTarget.dataset.value
  479. })
  480. },
  481. getShareList: function () {//星探小分队
  482. app.wxRequest(app.globalData.urlRoot + "share/getFriendRegisterList", this.data.parames,res=>{
  483. if(res.code==200){
  484. for(let i=0;i<res.data.length;i++){
  485. this.data.shareFriendList.push(res.data[i]);
  486. }
  487. this.setData({
  488. shareFriendList: this.data.shareFriendList
  489. })
  490. if (res.data.length<this.data.parames.count){
  491. this.setData({
  492. noData: true
  493. })
  494. }
  495. }
  496. },this);
  497. },
  498. getOrderInfo: function () {//查询是否已注册
  499. app.wxRequest(app.globalData.urlRoot + "userInfo/getOrderInfo", {}, res => {
  500. if (res.code == 200) {
  501. if (res.data) {
  502. this.setData({
  503. isRegister: true
  504. })
  505. app.globalData.isRegister = true;
  506. app.globalData.userMobile = res.data.mobile;
  507. } else {
  508. if (app.globalData.userMobile) {
  509. this.data.subscribeData.mobile = app.globalData.userMobile;
  510. this.setData({
  511. phoneInputShow: true,
  512. subscribeData: this.data.subscribeData
  513. })
  514. }
  515. }
  516. } else {
  517. console.log(res.msg)
  518. }
  519. }, this);
  520. },
  521. scrolltolower:function(){//星探小分队滚动条触底时执行
  522. if(!this.data.noData){
  523. this.data.parames.page+=1;
  524. this.getShareList();
  525. }
  526. },
  527. getMyAwardList: function () {//获取获奖记录
  528. this.setData({
  529. getState:true
  530. })
  531. wx.showLoading({
  532. title: '获取数据中'
  533. })
  534. app.wxRequest(app.globalData.urlRoot + "award/getMyAwardList", { awardSource: this.data.recordNow }, res => {
  535. wx.hideLoading();
  536. this.setData({
  537. getState: false
  538. })
  539. if(res.code == 200){
  540. this.setData({
  541. recordList:res.data
  542. })
  543. }
  544. },this)
  545. },
  546. getUserPhone: function (e) {//获取用户手机号
  547. this.setData({
  548. phoneInputShow: true
  549. })
  550. if (e.detail.errMsg == 'getPhoneNumber:ok') {
  551. app.getMobile(e.detail.encryptedData, e.detail.iv, res => {
  552. if (res.code == 200) {
  553. if (res.data && res.data.decodeData){
  554. this.data.subscribeData.mobile = res.data.decodeData.phoneNumber;
  555. this.setData({
  556. subscribeData: this.data.subscribeData
  557. })
  558. }
  559. } else {
  560. wx.showToast({
  561. title: res.msg,
  562. icon: "none"
  563. })
  564. }
  565. }, this);
  566. }
  567. },
  568. addressControl: function () {//跳转到地址管理
  569. if (app.globalData.userInfoData) {
  570. this.data.userData.avatarUrl = app.globalData.userInfoData.avatarUrl;
  571. this.data.userData.nickName = app.globalData.userInfoData.nickName;
  572. this.setData({
  573. userData: this.data.userData
  574. })
  575. }
  576. this.setData({
  577. addressShow:!this.data.addressShow
  578. })
  579. if (this.data.isAddress== false){
  580. this.getAddress();
  581. }
  582. },
  583. agreementState: function () {//协议
  584. this.setData({
  585. isAgreement: !this.data.isAgreement
  586. })
  587. },
  588. agreementControl: function () {
  589. this.setData({
  590. agreement: !this.data.agreement
  591. })
  592. },
  593. lookMore:function(){
  594. wx.navigateTo({
  595. url: '/pages/moreType/moreType',
  596. })
  597. },
  598. showSite: function () {//显示地址选择框
  599. if (!this.data.siteSelect) {
  600. if (!app.globalData.myCenterData) {
  601. this.getUserLocation();//获取用户当前位置
  602. }else{
  603. this.setData({
  604. siteSelect:true
  605. })
  606. }
  607. }
  608. },
  609. placingControl: function () {
  610. if (app.globalData.getBuyState.success != this.data.buyState) {
  611. this.setData({
  612. buyState: app.globalData.getBuyState.success,
  613. buyStateTime: app.globalData.getBuyState.cdate
  614. })
  615. }
  616. this.setData({
  617. placing: !this.data.placing
  618. })
  619. },
  620. tipWindow:function(){
  621. this.setData({
  622. mycenterTipWindow:0
  623. })
  624. },
  625. lookAddress:function(){
  626. this.addressControl();
  627. },
  628. copyExchangeCode:function(){
  629. var text = this.data.recordList[this.data.lookDescId].couponCode || this.data.recordList[this.data.lookDescId].productCode || "";
  630. this.contentCopy(text);
  631. },
  632. contentCopy:function(text){//内容复制
  633. wx.setClipboardData({
  634. data: text
  635. })
  636. },
  637. getAddress: function () {//获取地址
  638. app.wxRequest(app.globalData.urlRoot + "address/getAddress", {}, res => {
  639. if (res.code == 200) {
  640. if (res.data) {
  641. this.data.isAddress = true;
  642. }
  643. } else {
  644. wx.showToast({
  645. title: res.msg,
  646. icon: "none"
  647. })
  648. }
  649. }, this);
  650. },
  651. starGo:function(){//去完成
  652. wx.reLaunch({
  653. url: '/pages/star/star',
  654. })
  655. },
  656. enterLucky:function(){
  657. wx.reLaunch({
  658. url: '/pages/luckyStar/luckyStar',
  659. })
  660. },
  661. enterEvery:function(){
  662. wx.navigateTo({
  663. url: '/pages/everyday/everyday',
  664. })
  665. }
  666. })