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

667 lines
19KB

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