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