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

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