东风启辰小程序端
Nie możesz wybrać więcej, niż 25 tematów Tematy muszą się zaczynać od litery lub cyfry, mogą zawierać myślniki ('-') i mogą mieć do 35 znaków.

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