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

440 line
12KB

  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: "",//好友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. },
  48. /**
  49. * 生命周期函数--监听页面加载
  50. */
  51. onLoad: function (options) {
  52. if (options.sourcePage){
  53. this.data.optionsData = options.sourcePage;
  54. }
  55. if (app.globalData.openid) {
  56. this.loadFun();
  57. } else {
  58. app.globalData.openidSuccessFuc = this.loadFun;
  59. }
  60. },
  61. loadFun: function () {
  62. this.getUserInfo();
  63. this.getTaskProgress();
  64. this.getShareList();
  65. this.getMyAwardList();
  66. if (app.globalData.myCenterData) {
  67. this.setData({
  68. provinceArr: app.globalData.myCenterData.provinceArr,
  69. storeArr: app.globalData.myCenterData.storeArr,
  70. provinceValue: app.globalData.myCenterData.provinceValue,
  71. storeValue: app.globalData.myCenterData.storeValue,
  72. isRegister: app.globalData.isRegister
  73. })
  74. this.data.subscribeData.province = this.data.provinceArr[this.data.provinceValue].province;
  75. this.data.subscribeData.agentDetail = this.data.storeArr[this.data.storeValue].agent_detail;
  76. this.data.subscribeData.agent_code = this.data.storeArr[this.data.storeValue].agent_code;
  77. }else{
  78. app.globalData.myCenterData = {};
  79. this.getOrderInfo();
  80. }
  81. if (this.data.optionsData){
  82. if (this.data.optionsData == "home") {
  83. this.setData({
  84. selectNow: 2
  85. })
  86. }
  87. }
  88. },
  89. /**
  90. * 生命周期函数--监听页面初次渲染完成
  91. */
  92. onReady: function () {
  93. },
  94. /**
  95. * 生命周期函数--监听页面显示
  96. */
  97. onShow: function () {
  98. },
  99. /**
  100. * 生命周期函数--监听页面隐藏
  101. */
  102. onHide: function () {
  103. },
  104. /**
  105. * 生命周期函数--监听页面卸载
  106. */
  107. onUnload: function () {
  108. },
  109. /**
  110. * 页面相关事件处理函数--监听用户下拉动作
  111. */
  112. onPullDownRefresh: function () {
  113. },
  114. /**
  115. * 页面上拉触底事件的处理函数
  116. */
  117. onReachBottom: function () {
  118. },
  119. /**
  120. * 用户点击右上角分享
  121. */
  122. onShareAppMessage: function () {
  123. },
  124. selectChange:function(e){
  125. this.setData({
  126. selectNow: e.currentTarget.dataset.value
  127. })
  128. if (e.currentTarget.dataset.value==3){
  129. this.data.parames.page=0;
  130. this.data.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. this.setData({
  171. provinceArr: res.data.list,
  172. storeArr: res.data.list[res.data.nearData.provinceIndex].children,
  173. provinceValue: res.data.nearData.provinceIndex,
  174. storeValue: res.data.nearData.cityIndex
  175. })
  176. this.data.subscribeData.province = this.data.provinceArr[this.data.provinceValue].province;
  177. this.data.subscribeData.agentDetail = this.data.storeArr[this.data.storeValue].agent_detail;
  178. this.data.subscribeData.agent_code = this.data.storeArr[this.data.storeValue].agent_code;
  179. app.globalData.myCenterData.provinceArr = res.data.list;
  180. app.globalData.myCenterData.storeArr = res.data.list[res.data.nearData.provinceIndex].children;
  181. app.globalData.myCenterData.provinceValue = res.data.nearData.provinceIndex;
  182. app.globalData.myCenterData.storeValue = res.data.nearData.cityIndex;
  183. } else {
  184. wx.showToast({
  185. title: res.msg,
  186. icon: "none"
  187. })
  188. }
  189. }, this);
  190. },
  191. provinceChane: function (e) {//选中省
  192. this.setData({
  193. provinceValue: e.detail.value,
  194. storeArr: this.data.provinceArr[e.detail.value].children,
  195. storeValue: 0
  196. })
  197. this.data.subscribeData.province = this.data.provinceArr[this.data.provinceValue].province;
  198. this.data.subscribeData.agentDetail = this.data.storeArr[this.data.storeValue].agent_detail;
  199. this.data.subscribeData.agent_code = this.data.storeArr[this.data.storeValue].agent_code;
  200. },
  201. storeChane: function (e) {//选中店铺
  202. this.setData({
  203. storeValue: e.detail.value,
  204. })
  205. this.data.subscribeData.agentDetail = this.data.storeArr[this.data.storeValue].agent_detail;
  206. this.data.subscribeData.agent_code = this.data.storeArr[this.data.storeValue].agent_code;
  207. },
  208. getCode: function (e) {//获取验证码
  209. if (!app.mobileVerify(this.data.subscribeData.mobile)) {
  210. if (this.data.subscribeData.mobile) {
  211. wx.showToast({
  212. title: '请输入正确的电话',
  213. icon: 'none'
  214. })
  215. } else {
  216. wx.showToast({
  217. title: '请输入电话',
  218. icon: 'none'
  219. })
  220. }
  221. return;
  222. }
  223. if (!this.data.sendCode) {
  224. return;
  225. }
  226. app.wxRequest(app.globalData.urlRoot + "captcha/sendCaptcha", { mobile: this.data.subscribeData.mobile}, res => {
  227. if (res.code == 200) {
  228. this.countDown();
  229. wx.showToast({
  230. title: '验证码获取成功',
  231. icon: "none"
  232. })
  233. this.setData({
  234. verificationCode: 60
  235. })
  236. this.data.sendCode = false;
  237. } else {
  238. wx.showToast({
  239. title: res.msg,
  240. icon: "none"
  241. })
  242. }
  243. }, this)
  244. },
  245. countDown: function () {//倒计时
  246. setTimeout(() => {
  247. this.setData({
  248. verificationCode: this.data.verificationCode - 1
  249. })
  250. if (this.data.verificationCode > 0) {
  251. this.countDown();
  252. } else {
  253. this.setData({
  254. verificationCode: "获取验证码"
  255. })
  256. this.data.sendCode = true;
  257. }
  258. }, 1000);
  259. },
  260. getRealname: function (e) {//获取用户输入的姓名
  261. this.data.subscribeData.realname = e.detail.value;
  262. },
  263. getMobile: function (e) {//获取用户输入的电话
  264. this.data.subscribeData.mobile = e.detail.value;
  265. },
  266. getCaptcha: function (e) {//获取用户输入的验证码
  267. this.data.subscribeData.captcha = e.detail.value;
  268. },
  269. subscribeFun: function (e) {//预约鉴赏
  270. if(!this.data.subscribeData.realname){
  271. wx.showToast({
  272. title: '请输入姓名',
  273. icon:"none"
  274. })
  275. return;
  276. }
  277. if (!this.data.subscribeData.mobile) {
  278. wx.showToast({
  279. title: '请输入电话',
  280. icon: "none"
  281. })
  282. return;
  283. }
  284. if (!this.data.subscribeData.captcha) {
  285. wx.showToast({
  286. title: '请输入验证码',
  287. icon: "none"
  288. })
  289. return;
  290. }
  291. app.wxRequest(app.globalData.urlRoot + "userInfo/submitOrderInfo", this.data.subscribeData, res => {
  292. if (res.code == 200) {
  293. wx.showToast({
  294. title: '预约成功'
  295. })
  296. this.setData({
  297. isRegister: true
  298. })
  299. app.globalData.isRegister = true;
  300. app.globalData.userMobile = this.data.subscribeData.mobile;
  301. } else {
  302. wx.showToast({
  303. title: res.msg,
  304. icon: "none"
  305. })
  306. }
  307. }, this, "POST")
  308. },
  309. getUserWxMsg:function(e){//通过微信获取用户信息
  310. if (e.detail.errMsg == "getUserInfo:ok") {
  311. this.data.userData.avatarUrl = e.detail.userInfo.avatarUrl;
  312. this.data.userData.nickName = e.detail.userInfo.nickName;
  313. this.data.userData.userLevel = 0;
  314. this.setData({
  315. userData: this.data.userData,
  316. isLogin: true
  317. })
  318. app.wxRequest(app.globalData.urlRoot + "userInfo/updateUserInfo", { avatarUrl: e.detail.userInfo.avatarUrl, nickName: e.detail.userInfo.nickName},res=>{},this,"POST")
  319. }
  320. },
  321. getUserInfo:function(e){//获取个人信息
  322. app.wxRequest(app.globalData.urlRoot + 'userInfo/getUserInfo', {}, res => {
  323. if(res.code==200){
  324. // res.data.userLevel = 3;
  325. if(res.data.avatarUrl){
  326. this.data.userData.avatarUrl = res.data.avatarUrl;
  327. this.data.userData.nickName = res.data.nickName;
  328. this.data.userData.userLevel = res.data.userLevel;
  329. this.setData({
  330. userData:this.data.userData,
  331. isLogin:true
  332. })
  333. }
  334. }
  335. },this)
  336. },
  337. getTaskProgress: function () {//获取任务完成度 1每日任务
  338. app.wxRequest(app.globalData.urlRoot + "task/getTaskProgress", { taskType: this.data.taskNow},res=>{
  339. if(res.code==200){
  340. this.setData({
  341. taskList:res.data
  342. })
  343. }
  344. },this)
  345. },
  346. lookDesc:function(e){//查看奖品详情
  347. this.setData({
  348. descFrameShow: e.currentTarget.dataset.value
  349. })
  350. },
  351. lookRule: function (e) {//查看奖品详情
  352. this.setData({
  353. ruleShow: e.currentTarget.dataset.value
  354. })
  355. },
  356. getShareList: function () {//星探小分队
  357. app.wxRequest(app.globalData.urlRoot + "share/getFriendRegisterList", this.data.parames,res=>{
  358. if(res.code==200){
  359. for(let i=0;i<res.data.length;i++){
  360. this.data.shareFriendList.push(res.data[i]);
  361. }
  362. this.setData({
  363. shareFriendList: this.data.shareFriendList
  364. })
  365. if (res.data.length<this.data.parames.count){
  366. this.setData({
  367. noData: true
  368. })
  369. }
  370. }
  371. },this);
  372. },
  373. getOrderInfo: function () {//查询是否已注册
  374. app.wxRequest(app.globalData.urlRoot + "userInfo/getOrderInfo", {}, res => {
  375. if (res.code == 200) {
  376. if (res.data) {
  377. this.setData({
  378. isRegister: true
  379. })
  380. app.globalData.isRegister = true;
  381. app.globalData.userMobile = res.data.mobile;
  382. }
  383. } else {
  384. console.log(res.msg)
  385. }
  386. }, this);
  387. },
  388. scrolltolower:function(){//星探小分队滚动条触底时执行
  389. if(!this.data.noData){
  390. this.data.parames.page+=1;
  391. this.getShareList();
  392. }
  393. },
  394. getMyAwardList: function () {//获取获奖记录
  395. app.wxRequest(app.globalData.urlRoot + "award/getMyAwardList", { awardType: this.data.recordNow},res=>{
  396. console.log(res);
  397. if(res.code == 200){
  398. this.setData({
  399. recordList:res.data
  400. })
  401. }
  402. },this)
  403. },
  404. getUserPhone: function (e) {//获取用户手机号
  405. this.setData({
  406. phoneInputShow: true
  407. })
  408. this.getUserLocation();//获取用户当前位置
  409. if (e.detail.errMsg == 'getPhoneNumber:ok') {
  410. app.wxRequest(app.globalData.urlRoot + "userInfo/getUserPhoneNumber", { encryptedData: e.detail.encryptedData, iv: e.detail.iv }, res => {
  411. if (res.code == 200) {
  412. this.data.subscribeData.mobile = res.data.decodeData.phoneNumber;
  413. this.setData({
  414. subscribeData: this.data.subscribeData
  415. })
  416. } else {
  417. wx.showToast({
  418. title: res.msg,
  419. icon: "none"
  420. })
  421. }
  422. }, this, "POST");
  423. }
  424. }
  425. })