东风启辰小程序端
您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

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