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

399 lines
11KB

  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. provinceArr: [],//省
  16. provinceValue: 0,//选中的省下标
  17. storeArr: [],//店铺
  18. storeValue: 0,//选中的店铺下标
  19. verificationCode: '获取验证码',//验证码文案
  20. sendCode: true,
  21. subscribeData: {
  22. realname: "",//姓名
  23. mobile: "",//手机号
  24. captcha: "",//验证码
  25. province: "",//省份
  26. agent_code: "",//经销商编码
  27. agentDetail: "",//经销商详细信息
  28. parentOpenid: "",//好友openid
  29. },
  30. userData:{
  31. avatarUrl: null,
  32. nickName: null,
  33. userLevel: 0
  34. },
  35. descFrameShow:false,//是否显示奖品详情
  36. ruleShow: false,//是否显示星探等级规则
  37. isRegister: false,//查询是否已注册
  38. parames:{
  39. page:1,
  40. count:20
  41. },
  42. noData:false,
  43. optionsData:null
  44. },
  45. /**
  46. * 生命周期函数--监听页面加载
  47. */
  48. onLoad: function (options) {
  49. if (options.sourcePage){
  50. this.data.optionsData = options.sourcePage;
  51. }
  52. if (app.globalData.openid) {
  53. this.loadFun();
  54. } else {
  55. app.globalData.openidSuccessFuc = this.loadFun;
  56. }
  57. },
  58. loadFun: function () {
  59. this.getUserInfo();
  60. this.getTaskProgress();
  61. this.getShareList();
  62. if (app.globalData.myCenterData) {
  63. this.setData({
  64. provinceArr: app.globalData.indexData.provinceArr,
  65. storeArr: app.globalData.indexData.storeArr,
  66. provinceValue: app.globalData.indexData.provinceValue,
  67. storeValue: app.globalData.indexData.storeValue,
  68. isRegister: app.globalData.isRegister
  69. })
  70. this.data.subscribeData.province = this.data.provinceArr[this.data.provinceValue].province;
  71. this.data.subscribeData.agentDetail = this.data.storeArr[this.data.storeValue].agent_detail;
  72. this.data.subscribeData.agent_code = this.data.storeArr[this.data.storeValue].agent_code;
  73. }else{
  74. app.globalData.myCenterData = {};
  75. this.getUserLocation();
  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==3){
  126. this.data.parames.page=0;
  127. this.data.getShareList = [];
  128. }
  129. },
  130. selectTask: function (e) {
  131. if (e.currentTarget.dataset.type==2){
  132. return;
  133. }
  134. this.setData({
  135. taskNow: e.currentTarget.dataset.type
  136. })
  137. },
  138. selectRecord: function (e) {
  139. this.setData({
  140. recordNow: e.currentTarget.dataset.type
  141. })
  142. },
  143. getUserLocation: function (e) {
  144. wx.getLocation({
  145. type: 'gcj02', //wgs84
  146. success: (res) => {
  147. this.getDistributorList(res.longitude, res.latitude);
  148. },
  149. fail: (res) => {
  150. this.getDistributorList("", "");
  151. }
  152. })
  153. },
  154. getDistributorList: function (longitude, latitude) {//获取经销商列表
  155. app.wxRequest(app.globalData.urlRoot + "agent/getAgentList", { longitude: longitude, latitude: latitude }, res => {
  156. if (res.code == 200) {
  157. this.setData({
  158. provinceArr: res.data.list,
  159. storeArr: res.data.list[res.data.nearData.provinceIndex].children,
  160. provinceValue: res.data.nearData.provinceIndex,
  161. storeValue: res.data.nearData.cityIndex
  162. })
  163. this.data.subscribeData.province = this.data.provinceArr[this.data.provinceValue].province;
  164. this.data.subscribeData.agentDetail = this.data.storeArr[this.data.storeValue].agent_detail;
  165. this.data.subscribeData.agent_code = this.data.storeArr[this.data.storeValue].agent_code;
  166. app.globalData.myCenterData.provinceArr = res.data.list;
  167. app.globalData.myCenterData.storeArr = res.data.list[res.data.nearData.provinceIndex].children;
  168. app.globalData.myCenterData.provinceValue = res.data.nearData.provinceIndex;
  169. app.globalData.myCenterData.storeValue = res.data.nearData.cityIndex;
  170. } else {
  171. wx.showToast({
  172. title: res.msg,
  173. icon: "none"
  174. })
  175. }
  176. }, this);
  177. },
  178. provinceChane: function (e) {//选中省
  179. this.setData({
  180. provinceValue: e.detail.value,
  181. storeArr: this.data.provinceArr[e.detail.value].children,
  182. storeValue: 0
  183. })
  184. this.data.subscribeData.province = this.data.provinceArr[this.data.provinceValue].province;
  185. this.data.subscribeData.agentDetail = this.data.storeArr[this.data.storeValue].agent_detail;
  186. this.data.subscribeData.agent_code = this.data.storeArr[this.data.storeValue].agent_code;
  187. },
  188. storeChane: function (e) {//选中店铺
  189. this.setData({
  190. storeValue: e.detail.value,
  191. })
  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. getCode: function (e) {//获取验证码
  196. if (!app.mobileVerify(this.data.subscribeData.mobile)) {
  197. if (this.data.subscribeData.mobile) {
  198. wx.showToast({
  199. title: '请输入正确的电话',
  200. icon: 'none'
  201. })
  202. } else {
  203. wx.showToast({
  204. title: '请输入电话',
  205. icon: 'none'
  206. })
  207. }
  208. return;
  209. }
  210. if (!this.data.sendCode) {
  211. return;
  212. }
  213. app.wxRequest(app.globalData.urlRoot + "captcha/sendCaptcha", { mobile: '18831849567' }, res => {
  214. console.log(res);
  215. if (res.code == 200) {
  216. this.countDown();
  217. wx.showToast({
  218. title: '验证码获取成功',
  219. icon: "none"
  220. })
  221. this.setData({
  222. verificationCode: 60
  223. })
  224. this.data.sendCode = false;
  225. } else {
  226. wx.showToast({
  227. title: res.msg,
  228. icon: "none"
  229. })
  230. }
  231. }, this)
  232. },
  233. countDown: function () {//倒计时
  234. setTimeout(() => {
  235. this.setData({
  236. verificationCode: this.data.verificationCode - 1
  237. })
  238. if (this.data.verificationCode > 0) {
  239. this.countDown();
  240. } else {
  241. this.setData({
  242. verificationCode: "获取验证码"
  243. })
  244. this.data.sendCode = true;
  245. }
  246. }, 1000);
  247. },
  248. getRealname: function (e) {//获取用户输入的姓名
  249. this.data.subscribeData.realname = e.detail.value;
  250. },
  251. getMobile: function (e) {//获取用户输入的电话
  252. this.data.subscribeData.mobile = e.detail.value;
  253. },
  254. getCaptcha: function (e) {//获取用户输入的验证码
  255. this.data.subscribeData.captcha = e.detail.value;
  256. },
  257. subscribeFun: function (e) {//预约鉴赏
  258. if(!this.data.subscribeData.realname){
  259. wx.showToast({
  260. title: '请输入姓名',
  261. icon:"none"
  262. })
  263. return;
  264. }
  265. if (!this.data.subscribeData.mobile) {
  266. wx.showToast({
  267. title: '请输入电话',
  268. icon: "none"
  269. })
  270. return;
  271. }
  272. if (!this.data.subscribeData.captcha) {
  273. wx.showToast({
  274. title: '请输入验证码',
  275. icon: "none"
  276. })
  277. return;
  278. }
  279. app.wxRequest(app.globalData.urlRoot + "userInfo/submitOrderInfo", this.data.subscribeData, res => {
  280. if (res.code == 200) {
  281. wx.showToast({
  282. title: '预约成功'
  283. })
  284. this.setData({
  285. isRegister: true
  286. })
  287. app.globalData.isRegister = true;
  288. app.globalData.userMobile = this.data.subscribeData.mobile;
  289. } else {
  290. wx.showToast({
  291. title: res.msg,
  292. icon: "none"
  293. })
  294. }
  295. }, this, "POST")
  296. },
  297. getUserWxMsg:function(e){//通过微信获取用户信息
  298. if (e.detail.errMsg == "getUserInfo:ok") {
  299. this.data.userData.avatarUrl = e.detail.userInfo.avatarUrl;
  300. this.data.userData.nickName = e.detail.userInfo.nickName;
  301. this.data.userData.userLevel = 0;
  302. this.setData({
  303. userData: this.data.userData,
  304. isLogin: true
  305. })
  306. app.wxRequest(app.globalData.urlRoot + "userInfo/updateUserInfo", { avatarUrl: e.detail.userInfo.avatarUrl, nickName: e.detail.userInfo.nickName},res=>{},this,"POST")
  307. }
  308. },
  309. getUserInfo:function(e){//获取个人信息
  310. app.wxRequest(app.globalData.urlRoot + 'userInfo/getUserInfo', {}, res => {
  311. if(res.code==200){
  312. // res.data.userLevel = 3;
  313. if(res.data.avatarUrl){
  314. this.data.userData.avatarUrl = res.data.avatarUrl;
  315. this.data.userData.nickName = res.data.nickName;
  316. this.data.userData.userLevel = res.data.userLevel;
  317. this.setData({
  318. userData:this.data.userData,
  319. isLogin:true
  320. })
  321. }
  322. }
  323. },this)
  324. },
  325. getTaskProgress: function () {//获取任务完成度 1每日任务
  326. app.wxRequest(app.globalData.urlRoot + "task/getTaskProgress", { taskType: this.data.taskNow},res=>{
  327. if(res.code==200){
  328. this.setData({
  329. taskList:res.data
  330. })
  331. }
  332. },this)
  333. },
  334. lookDesc:function(e){//查看奖品详情
  335. this.setData({
  336. descFrameShow: e.currentTarget.dataset.value
  337. })
  338. },
  339. lookRule: function (e) {//查看奖品详情
  340. this.setData({
  341. ruleShow: e.currentTarget.dataset.value
  342. })
  343. },
  344. getShareList: function () {//星探小分队
  345. app.wxRequest(app.globalData.urlRoot + "share/getFriendRegisterList", this.data.parames,res=>{
  346. console.log(res);
  347. if(res.code==200){
  348. for(let i=0;i<res.data.length;i++){
  349. this.data.shareFriendList.push(res.data[i]);
  350. }
  351. this.setData({
  352. shareFriendList: this.data.shareFriendList
  353. })
  354. if (res.data.length<this.data.parames.count){
  355. this.setData({
  356. noData: true
  357. })
  358. }
  359. console.log(this.data.shareFriendList);
  360. }
  361. },this);
  362. },
  363. getOrderInfo: function () {//查询是否已注册
  364. app.wxRequest(app.globalData.urlRoot + "userInfo/getOrderInfo", {}, res => {
  365. if (res.code == 200) {
  366. if (res.data) {
  367. this.setData({
  368. isRegister: true
  369. })
  370. app.globalData.isRegister = true;
  371. app.globalData.userMobile = res.data.mobile;
  372. }
  373. } else {
  374. console.log(res.msg)
  375. }
  376. }, this);
  377. },
  378. scrolltolower:function(){//星探小分队滚动条触底时执行
  379. if(!this.data.noData){
  380. this.data.parames.page+=1;
  381. this.getShareList();
  382. }
  383. }
  384. })