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

480 lines
14KB

  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. app.globalData.nowPage = 4;
  54. if (options.sourcePage){
  55. this.data.optionsData = options.sourcePage;
  56. }
  57. if (app.globalData.openid) {
  58. this.loadFun();
  59. } else {
  60. app.globalData.openidSuccessFuc = this.loadFun;
  61. }
  62. },
  63. loadFun: function () {
  64. this.getUserInfo();
  65. if (app.globalData.myCenterData) {
  66. this.setData({
  67. provinceArr: app.globalData.myCenterData.provinceArr,
  68. storeArr: app.globalData.myCenterData.storeArr,
  69. provinceValue: app.globalData.myCenterData.provinceValue,
  70. storeValue: app.globalData.myCenterData.storeValue,
  71. isRegister: app.globalData.isRegister
  72. })
  73. this.data.subscribeData.province = this.data.provinceArr[this.data.provinceValue].province;
  74. this.data.subscribeData.agentDetail = this.data.storeArr[this.data.storeValue].agent_detail;
  75. this.data.subscribeData.agent_code = this.data.storeArr[this.data.storeValue].agent_code;
  76. }
  77. if (!app.globalData.isRegister) {
  78. this.getOrderInfo();
  79. }
  80. if (app.globalData.userInfoData) {
  81. this.data.userData.avatarUrl = app.globalData.userInfoData.avatarUrl;
  82. this.data.userData.nickName = app.globalData.userInfoData.nickName;
  83. this.setData({
  84. userData: this.data.userData
  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. return app.sharePack();
  123. },
  124. selectChange:function(e){
  125. this.setData({
  126. selectNow: e.currentTarget.dataset.value
  127. })
  128. if (e.currentTarget.dataset.value == 1) {
  129. this.getTaskProgress();
  130. } else if (e.currentTarget.dataset.value == 2) {
  131. this.getMyAwardList();
  132. } else if (e.currentTarget.dataset.value == 3){
  133. this.data.parames.page = 0;
  134. this.setData({
  135. parames: this.data.parames,
  136. shareFriendList:[]
  137. })
  138. this.getShareList();
  139. }
  140. },
  141. selectTask: function (e) {
  142. if (e.currentTarget.dataset.type==2){
  143. return;
  144. }
  145. this.setData({
  146. taskNow: e.currentTarget.dataset.type
  147. })
  148. },
  149. selectRecord: function (e) {
  150. if (this.data.recordNow == e.currentTarget.dataset.type) {
  151. return;
  152. }
  153. this.setData({
  154. recordList:[],
  155. recordNow: e.currentTarget.dataset.type
  156. })
  157. this.getMyAwardList();
  158. },
  159. getUserLocation: function (e) {
  160. wx.getLocation({
  161. type: 'gcj02', //wgs84
  162. success: (res) => {
  163. this.getDistributorList(res.longitude, res.latitude);
  164. },
  165. fail: (res) => {
  166. this.getDistributorList("", "");
  167. },
  168. complete: (res) => {
  169. this.setData({
  170. siteSelect: true,
  171. })
  172. }
  173. })
  174. },
  175. getDistributorList: function (longitude, latitude) {//获取经销商列表
  176. app.wxRequest(app.globalData.urlRoot + "agent/getAgentList", { longitude: longitude, latitude: latitude }, res => {
  177. if (res.code == 200) {
  178. app.globalData.myCenterData = {};
  179. this.setData({
  180. provinceArr: res.data.list,
  181. storeArr: res.data.list[res.data.nearData.provinceIndex].children,
  182. provinceValue: res.data.nearData.provinceIndex,
  183. storeValue: res.data.nearData.cityIndex
  184. })
  185. this.data.subscribeData.province = this.data.provinceArr[this.data.provinceValue].province;
  186. this.data.subscribeData.agentDetail = this.data.storeArr[this.data.storeValue].agent_detail;
  187. this.data.subscribeData.agent_code = this.data.storeArr[this.data.storeValue].agent_code;
  188. app.globalData.myCenterData.provinceArr = res.data.list;
  189. app.globalData.myCenterData.storeArr = res.data.list[res.data.nearData.provinceIndex].children;
  190. app.globalData.myCenterData.provinceValue = res.data.nearData.provinceIndex;
  191. app.globalData.myCenterData.storeValue = res.data.nearData.cityIndex;
  192. } else {
  193. wx.showToast({
  194. title: res.msg,
  195. icon: "none"
  196. })
  197. }
  198. }, this);
  199. },
  200. provinceChane: function (e) {//选中省
  201. this.setData({
  202. provinceValue: e.detail.value,
  203. storeArr: this.data.provinceArr[e.detail.value].children,
  204. storeValue: 0
  205. })
  206. this.data.subscribeData.province = this.data.provinceArr[this.data.provinceValue].province;
  207. this.data.subscribeData.agentDetail = this.data.storeArr[this.data.storeValue].agent_detail;
  208. this.data.subscribeData.agent_code = this.data.storeArr[this.data.storeValue].agent_code;
  209. },
  210. storeChane: function (e) {//选中店铺
  211. this.setData({
  212. storeValue: e.detail.value,
  213. })
  214. this.data.subscribeData.agentDetail = this.data.storeArr[this.data.storeValue].agent_detail;
  215. this.data.subscribeData.agent_code = this.data.storeArr[this.data.storeValue].agent_code;
  216. },
  217. getCode: function (e) {//获取验证码
  218. if (!app.mobileVerify(this.data.subscribeData.mobile)) {
  219. if (this.data.subscribeData.mobile) {
  220. wx.showToast({
  221. title: '请输入正确的电话',
  222. icon: 'none'
  223. })
  224. } else {
  225. wx.showToast({
  226. title: '请输入电话',
  227. icon: 'none'
  228. })
  229. }
  230. return;
  231. }
  232. if (!this.data.sendCode) {
  233. return;
  234. }
  235. this.data.sendCode = false;
  236. app.wxRequest(app.globalData.urlRoot + "captcha/sendCaptcha", { mobile: this.data.subscribeData.mobile }, res => {
  237. this.data.sendCode = true;
  238. if (res.code == 200) {
  239. this.countDown();
  240. wx.showToast({
  241. title: '验证码获取成功',
  242. icon: "none"
  243. })
  244. this.setData({
  245. verificationCode: 60
  246. })
  247. } else {
  248. wx.showToast({
  249. title: res.msg,
  250. icon: "none"
  251. })
  252. }
  253. }, this)
  254. },
  255. countDown: function () {//倒计时
  256. setTimeout(() => {
  257. this.setData({
  258. verificationCode: this.data.verificationCode - 1
  259. })
  260. if (this.data.verificationCode > 0) {
  261. this.countDown();
  262. } else {
  263. this.setData({
  264. verificationCode: "获取验证码"
  265. })
  266. this.data.sendCode = true;
  267. }
  268. }, 1000);
  269. },
  270. getRealname: function (e) {//获取用户输入的姓名
  271. this.data.subscribeData.realname = e.detail.value;
  272. },
  273. getMobile: function (e) {//获取用户输入的电话
  274. this.data.subscribeData.mobile = e.detail.value;
  275. },
  276. getCaptcha: function (e) {//获取用户输入的验证码
  277. this.data.subscribeData.captcha = e.detail.value;
  278. },
  279. subscribeFun: function (e) {//预约鉴赏
  280. if(!this.data.subscribeData.realname){
  281. wx.showToast({
  282. title: '请输入姓名',
  283. icon:"none"
  284. })
  285. return;
  286. }
  287. if (!this.data.subscribeData.mobile) {
  288. wx.showToast({
  289. title: '请输入电话',
  290. icon: "none"
  291. })
  292. return;
  293. }
  294. if (!this.data.subscribeData.captcha) {
  295. wx.showToast({
  296. title: '请输入验证码',
  297. icon: "none"
  298. })
  299. return;
  300. }
  301. if (!this.data.sendCode) {
  302. return;
  303. }
  304. this.data.sendCode = false;
  305. app.wxRequest(app.globalData.urlRoot + "userInfo/submitOrderInfo", this.data.subscribeData, res => {
  306. this.data.sendCode = true;
  307. if (res.code == 200) {
  308. wx.showToast({
  309. title: '预约成功'
  310. })
  311. this.setData({
  312. isRegister: true
  313. })
  314. app.globalData.isRegister = true;
  315. app.globalData.userMobile = this.data.subscribeData.mobile;
  316. } else {
  317. wx.showToast({
  318. title: res.msg,
  319. icon: "none"
  320. })
  321. }
  322. }, this, "POST")
  323. },
  324. getUserWxMsg:function(e){//通过微信获取用户信息
  325. if (e.detail.errMsg == "getUserInfo:ok") {
  326. this.data.userData.avatarUrl = e.detail.userInfo.avatarUrl;
  327. this.data.userData.nickName = e.detail.userInfo.nickName;
  328. this.data.userData.userLevel = 0;
  329. this.setData({
  330. userData: this.data.userData,
  331. isLogin: true
  332. })
  333. app.globalData.userInfoData = {};
  334. app.globalData.userInfoData.avatarUrl = e.detail.userInfo.avatarUrl;
  335. app.globalData.userInfoData.nickName = e.detail.userInfo.nickName;
  336. wx.setStorageSync('userInfoData', {
  337. avatarUrl: e.detail.userInfo.avatarUrl,
  338. nickName: e.detail.userInfo.nickName
  339. })
  340. app.submitUserMsg(e.detail.userInfo.avatarUrl, e.detail.userInfo.nickName);
  341. }
  342. },
  343. getUserInfo:function(e){//获取个人信息
  344. app.wxRequest(app.globalData.urlRoot + 'userInfo/getUserInfo', {}, res => {
  345. if(res.code==200){
  346. if (res.data) {
  347. this.data.userData.userLevel = res.data.userLevel;
  348. if (!app.globalData.userInfoData) {
  349. this.data.userData.avatarUrl = res.data.avatarUrl;
  350. this.data.userData.nickName = res.data.nickName;
  351. app.globalData.userInfoData = {};
  352. app.globalData.userInfoData.avatarUrl = res.data.avatarUrl;
  353. app.globalData.userInfoData.nickName = res.data.nickName;
  354. wx.setStorageSync('userInfoData', {
  355. avatarUrl: res.data.avatarUrl,
  356. nickName: res.data.nickName
  357. })
  358. }
  359. this.setData({
  360. userData: this.data.userData,
  361. isLogin: true
  362. })
  363. }
  364. }
  365. },this)
  366. },
  367. getTaskProgress: function () {//获取任务完成度 1每日任务
  368. app.wxRequest(app.globalData.urlRoot + "task/getTaskProgress", { taskType: this.data.taskNow},res=>{
  369. if(res.code==200){
  370. this.setData({
  371. taskList:res.data
  372. })
  373. }
  374. },this)
  375. },
  376. lookDesc:function(e){//查看奖品详情
  377. this.setData({
  378. descFrameShow: !this.data.descFrameShow,
  379. lookDescId: e.currentTarget.dataset.value || e.currentTarget.dataset.value==0 ? e.currentTarget.dataset.value:null
  380. })
  381. },
  382. lookRule: function (e) {//查看奖品详情
  383. this.setData({
  384. ruleShow: e.currentTarget.dataset.value
  385. })
  386. },
  387. getShareList: function () {//星探小分队
  388. app.wxRequest(app.globalData.urlRoot + "share/getFriendRegisterList", this.data.parames,res=>{
  389. if(res.code==200){
  390. for(let i=0;i<res.data.length;i++){
  391. this.data.shareFriendList.push(res.data[i]);
  392. }
  393. this.setData({
  394. shareFriendList: this.data.shareFriendList
  395. })
  396. if (res.data.length<this.data.parames.count){
  397. this.setData({
  398. noData: true
  399. })
  400. }
  401. }
  402. },this);
  403. },
  404. getOrderInfo: function () {//查询是否已注册
  405. app.wxRequest(app.globalData.urlRoot + "userInfo/getOrderInfo", {}, res => {
  406. if (res.code == 200) {
  407. if (res.data) {
  408. this.setData({
  409. isRegister: true
  410. })
  411. app.globalData.isRegister = true;
  412. app.globalData.userMobile = res.data.mobile;
  413. } else {
  414. if (app.globalData.userMobile) {
  415. this.data.subscribeData.mobile = app.globalData.userMobile;
  416. this.setData({
  417. phoneInputShow: true,
  418. subscribeData: this.data.subscribeData
  419. })
  420. this.getUserLocation();
  421. }
  422. }
  423. } else {
  424. console.log(res.msg)
  425. }
  426. }, this);
  427. },
  428. scrolltolower:function(){//星探小分队滚动条触底时执行
  429. if(!this.data.noData){
  430. this.data.parames.page+=1;
  431. this.getShareList();
  432. }
  433. },
  434. getMyAwardList: function () {//获取获奖记录
  435. app.wxRequest(app.globalData.urlRoot + "award/getMyAwardList", { awardType: this.data.recordNow},res=>{
  436. if(res.code == 200){
  437. this.setData({
  438. recordList:res.data
  439. })
  440. }
  441. },this)
  442. },
  443. getUserPhone: function (e) {//获取用户手机号
  444. this.setData({
  445. phoneInputShow: true
  446. })
  447. if (!app.globalData.myCenterData) {
  448. this.getUserLocation();//获取用户当前位置
  449. }
  450. if (e.detail.errMsg == 'getPhoneNumber:ok') {
  451. app.getMobile(e.detail.encryptedData, e.detail.iv, res => {
  452. if (res.code == 200) {
  453. this.data.subscribeData.mobile = res.data.decodeData.phoneNumber;
  454. this.setData({
  455. subscribeData: this.data.subscribeData
  456. })
  457. } else {
  458. wx.showToast({
  459. title: res.msg,
  460. icon: "none"
  461. })
  462. }
  463. }, this);
  464. }
  465. }
  466. })