东风启辰小程序端
Du kannst nicht mehr als 25 Themen auswählen Themen müssen entweder mit einem Buchstaben oder einer Ziffer beginnen. Sie können Bindestriche („-“) enthalten und bis zu 35 Zeichen lang sein.

413 Zeilen
12KB

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