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

535 lines
16KB

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