东风启辰小程序端
Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.

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