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

524 line
15KB

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