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

449 lines
13KB

  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. app.wxRequest(app.globalData.urlRoot + "captcha/sendCaptcha", { mobile: this.data.subscribeData.mobile}, res => {
  228. if (res.code == 200) {
  229. this.countDown();
  230. wx.showToast({
  231. title: '验证码获取成功',
  232. icon: "none"
  233. })
  234. this.setData({
  235. verificationCode: 60
  236. })
  237. this.data.sendCode = false;
  238. } else {
  239. wx.showToast({
  240. title: res.msg,
  241. icon: "none"
  242. })
  243. }
  244. }, this)
  245. },
  246. countDown: function () {//倒计时
  247. setTimeout(() => {
  248. this.setData({
  249. verificationCode: this.data.verificationCode - 1
  250. })
  251. if (this.data.verificationCode > 0) {
  252. this.countDown();
  253. } else {
  254. this.setData({
  255. verificationCode: "获取验证码"
  256. })
  257. this.data.sendCode = true;
  258. }
  259. }, 1000);
  260. },
  261. getRealname: function (e) {//获取用户输入的姓名
  262. this.data.subscribeData.realname = e.detail.value;
  263. },
  264. getMobile: function (e) {//获取用户输入的电话
  265. this.data.subscribeData.mobile = e.detail.value;
  266. },
  267. getCaptcha: function (e) {//获取用户输入的验证码
  268. this.data.subscribeData.captcha = e.detail.value;
  269. },
  270. subscribeFun: function (e) {//预约鉴赏
  271. if(!this.data.subscribeData.realname){
  272. wx.showToast({
  273. title: '请输入姓名',
  274. icon:"none"
  275. })
  276. return;
  277. }
  278. if (!this.data.subscribeData.mobile) {
  279. wx.showToast({
  280. title: '请输入电话',
  281. icon: "none"
  282. })
  283. return;
  284. }
  285. if (!this.data.subscribeData.captcha) {
  286. wx.showToast({
  287. title: '请输入验证码',
  288. icon: "none"
  289. })
  290. return;
  291. }
  292. app.wxRequest(app.globalData.urlRoot + "userInfo/submitOrderInfo", this.data.subscribeData, res => {
  293. if (res.code == 200) {
  294. wx.showToast({
  295. title: '预约成功'
  296. })
  297. this.setData({
  298. isRegister: true
  299. })
  300. app.globalData.isRegister = true;
  301. app.globalData.userMobile = this.data.subscribeData.mobile;
  302. } else {
  303. wx.showToast({
  304. title: res.msg,
  305. icon: "none"
  306. })
  307. }
  308. }, this, "POST")
  309. },
  310. getUserWxMsg:function(e){//通过微信获取用户信息
  311. if (e.detail.errMsg == "getUserInfo:ok") {
  312. this.data.userData.avatarUrl = e.detail.userInfo.avatarUrl;
  313. this.data.userData.nickName = e.detail.userInfo.nickName;
  314. this.data.userData.userLevel = 0;
  315. this.setData({
  316. userData: this.data.userData,
  317. isLogin: true
  318. })
  319. app.globalData.userInfoData = {};
  320. app.globalData.userInfoData.avatarUrl = e.detail.userInfo.avatarUrl;
  321. app.globalData.userInfoData.nickName = e.detail.userInfo.nickName;
  322. app.submitUserMsg(e.detail.userInfo.avatarUrl, e.detail.userInfo.nickName);
  323. }
  324. },
  325. getUserInfo:function(e){//获取个人信息
  326. app.wxRequest(app.globalData.urlRoot + 'userInfo/getUserInfo', {}, res => {
  327. if(res.code==200){
  328. // res.data.userLevel = 3;
  329. if (res.data) {
  330. this.data.userData.avatarUrl = res.data.avatarUrl;
  331. this.data.userData.nickName = res.data.nickName;
  332. this.data.userData.userLevel = res.data.userLevel;
  333. this.setData({
  334. userData: this.data.userData,
  335. isLogin: true
  336. })
  337. app.globalData.userInfoData = {};
  338. app.globalData.userInfoData.avatarUrl = res.data.avatarUrl;
  339. app.globalData.userInfoData.nickName = res.data.nickName;
  340. }
  341. }
  342. },this)
  343. },
  344. getTaskProgress: function () {//获取任务完成度 1每日任务
  345. app.wxRequest(app.globalData.urlRoot + "task/getTaskProgress", { taskType: this.data.taskNow},res=>{
  346. if(res.code==200){
  347. this.setData({
  348. taskList:res.data
  349. })
  350. }
  351. },this)
  352. },
  353. lookDesc:function(e){//查看奖品详情
  354. this.setData({
  355. descFrameShow: !this.data.descFrameShow,
  356. lookDescId: e.currentTarget.dataset.value || e.currentTarget.dataset.value==0 ? e.currentTarget.dataset.value:null
  357. })
  358. },
  359. lookRule: function (e) {//查看奖品详情
  360. this.setData({
  361. ruleShow: e.currentTarget.dataset.value
  362. })
  363. },
  364. getShareList: function () {//星探小分队
  365. app.wxRequest(app.globalData.urlRoot + "share/getFriendRegisterList", this.data.parames,res=>{
  366. if(res.code==200){
  367. for(let i=0;i<res.data.length;i++){
  368. this.data.shareFriendList.push(res.data[i]);
  369. }
  370. this.setData({
  371. shareFriendList: this.data.shareFriendList
  372. })
  373. if (res.data.length<this.data.parames.count){
  374. this.setData({
  375. noData: true
  376. })
  377. }
  378. }
  379. },this);
  380. },
  381. getOrderInfo: function () {//查询是否已注册
  382. app.wxRequest(app.globalData.urlRoot + "userInfo/getOrderInfo", {}, res => {
  383. if (res.code == 200) {
  384. if (res.data) {
  385. this.setData({
  386. isRegister: true
  387. })
  388. app.globalData.isRegister = true;
  389. app.globalData.userMobile = res.data.mobile;
  390. }
  391. } else {
  392. console.log(res.msg)
  393. }
  394. }, this);
  395. },
  396. scrolltolower:function(){//星探小分队滚动条触底时执行
  397. if(!this.data.noData){
  398. this.data.parames.page+=1;
  399. this.getShareList();
  400. }
  401. },
  402. getMyAwardList: function () {//获取获奖记录
  403. app.wxRequest(app.globalData.urlRoot + "award/getMyAwardList", { awardType: this.data.recordNow},res=>{
  404. console.log(res);
  405. if(res.code == 200){
  406. this.setData({
  407. recordList:res.data
  408. })
  409. }
  410. },this)
  411. },
  412. getUserPhone: function (e) {//获取用户手机号
  413. this.setData({
  414. phoneInputShow: true
  415. })
  416. if (!app.globalData.myCenterData) {
  417. this.getUserLocation();//获取用户当前位置
  418. }
  419. if (e.detail.errMsg == 'getPhoneNumber:ok') {
  420. app.wxRequest(app.globalData.urlRoot + "userInfo/getUserPhoneNumber", { encryptedData: e.detail.encryptedData, iv: e.detail.iv }, res => {
  421. if (res.code == 200) {
  422. this.data.subscribeData.mobile = res.data.decodeData.phoneNumber;
  423. this.setData({
  424. subscribeData: this.data.subscribeData
  425. })
  426. } else {
  427. wx.showToast({
  428. title: res.msg,
  429. icon: "none"
  430. })
  431. }
  432. }, this, "POST");
  433. }
  434. }
  435. })