myMember.js 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474
  1. // pages/myMember/myMember.js
  2. let App = getApp();
  3. let util = require("../../utils/util.js");
  4. var WxParse = require("../../wxParse/wxParse.js");
  5. Page({
  6. /**
  7. * 页面的初始数据
  8. */
  9. data: {
  10. appAssetsUrl: App.appAssetsUrl,
  11. appAssetsUrl2: App.appAssetsUrl2,
  12. appAssetsUrl3: App.appAssetsUrl3,
  13. bottomLeft: App.bottomLeft,
  14. params: {
  15. type: "wx",
  16. },
  17. bottom: 0,
  18. //判断 禁用
  19. checked: true,
  20. disable: false,
  21. statusBarHeight: "",
  22. stHeight: "",
  23. statusBarMH: "",
  24. detail: "",
  25. user: {},
  26. agree: true,
  27. activeTitle: false,
  28. wgFillInfo: {},
  29. memberPoints: {},
  30. isDeductiblePrice: null,
  31. taskCode: null,
  32. isDeduction: false,
  33. currentImg: null,
  34. integral: null,
  35. isDev: true,
  36. memberNotice: '',
  37. botCheck: 0
  38. },
  39. // 自定义高度处理
  40. height() {
  41. const { platform, statusBarHeight } = wx.getSystemInfoSync();
  42. let height = statusBarHeight + 4; //ios 24px
  43. let mH = statusBarHeight + 4;
  44. if (platform.toLowerCase() == "android") {
  45. height += 4; //android 28px
  46. mH += 4;
  47. }
  48. height = height + 38;
  49. // 胶囊高度 32px 下边框6px height 状态栏高度
  50. this.setData({
  51. stHeight: height - mH + "px",
  52. statusBarHeight: height + "px",
  53. statusBarMH: mH + "px",
  54. });
  55. },
  56. // 判断是否开发huanjing
  57. env(){
  58. let that = this
  59. App._post_form('wgfillinfo/apiSelectwgfillinfo', 'application/json',
  60. null,
  61. function (res) {
  62. if (res.code === 0) {
  63. // that.setData({
  64. // isDev: res.wgFillInfo.isDev
  65. // })
  66. if(res.wgFillInfo.isDev) {
  67. wx.switchTab({
  68. url: '/pages/home/index/index'
  69. })
  70. }
  71. }
  72. }
  73. )
  74. },
  75. goback() {
  76. wx.navigateBack({
  77. delta: 1,
  78. });
  79. },
  80. /**
  81. * 查询用户数据根据id
  82. */
  83. PushVipInfo() {
  84. let _this = this;
  85. let id = util.getUserId();
  86. if (id) {
  87. let params = {
  88. id,
  89. };
  90. App._post_form(
  91. "member/apiSelectMeberInfo",
  92. "application/json",
  93. params,
  94. function (res) {
  95. if (res.code === 0) {
  96. wx.setStorageSync("USER", res.member);
  97. _this.setData({
  98. detail: res.member,
  99. });
  100. if (res.member.memberState != 2) {
  101. _this.setData({
  102. currentImg: 2,
  103. taskCode: "LIFELONG",
  104. });
  105. }
  106. } else {
  107. wx.removeStorageSync("USER");
  108. wx.navigateTo({
  109. url: "/pages/login",
  110. });
  111. }
  112. }
  113. );
  114. }
  115. },
  116. getVipSelect() {
  117. let _this = this
  118. App._get("wgfillinfo/apiSelectwgfillinfo", {}, (res) => {
  119. if (res.code === 0) {
  120. this.setData({
  121. wgFillInfo: res.wgFillInfo,
  122. });
  123. WxParse.wxParse('memberNotice', 'html', res.wgFillInfo.memberNotice, _this, 0);
  124. }
  125. });
  126. },
  127. getPointDeduction() {
  128. let code;
  129. if (this.data.detail.memberState == 0) {
  130. if (this.data.currentImg == 1) {
  131. code = 4;
  132. } else if (this.data.currentImg == 2) {
  133. code = 5;
  134. }
  135. } else if (this.data.detail.memberState == 1) {
  136. code = 6;
  137. }
  138. App._get(
  139. "member/memberPointDeduction",
  140. {
  141. id: this.data.detail.id,
  142. code: code,
  143. },
  144. (res) => {
  145. if (res.code == 0) {
  146. this.setData({
  147. memberPoints: res.data,
  148. });
  149. }
  150. }
  151. );
  152. },
  153. changeVip(e) {
  154. console.log(e, 123);
  155. if (this.data.detail.memberState == e.currentTarget.dataset.currentimg) {
  156. wx.showToast({
  157. icon: "none",
  158. title: "已是当前VIP",
  159. });
  160. return false;
  161. } else if (this.data.detail.memberState == 2) {
  162. wx.showToast({
  163. icon: "none",
  164. title: "已是终身VIP",
  165. });
  166. return false;
  167. }
  168. let taskCode;
  169. if (e.currentTarget.dataset.currentimg == 1) {
  170. taskCode = "ANNUAL_FEE";
  171. } else {
  172. taskCode = "LIFELONG";
  173. }
  174. this.setData({
  175. currentImg: e.currentTarget.dataset.currentimg,
  176. taskCode: taskCode,
  177. });
  178. },
  179. switchChange(e) {
  180. console.log(e, 1111);
  181. this.setData({
  182. isDeductiblePrice: e.detail.value ? 1 : 0,
  183. });
  184. },
  185. confirmPay() {
  186. wx.showLoading({
  187. title: "正在处理...",
  188. mask: true,
  189. });
  190. let _this = this;
  191. _this.setData({
  192. params: {
  193. id: util.getUserId(),
  194. code: _this.data.taskCode,
  195. isDeductiblePrice: _this.data.isDeductiblePrice == 1 ? 1 : 0,
  196. },
  197. });
  198. App._post_form(
  199. "member/apiOpenVip",
  200. "application/json",
  201. _this.data.params,
  202. function (result) {
  203. if (result.code === 0) {
  204. wx.hideLoading();
  205. let money = _this.data.isDeductiblePrice
  206. ? _this.data.memberPoints.actualPrice
  207. : _this.data.memberPoints.money;
  208. if (money == 0) {
  209. wx.showModal({
  210. title: "提示",
  211. content: "开通会员成功!",
  212. showCancel: false,
  213. success(res) {
  214. if (res.confirm) {
  215. wx.navigateBack({
  216. delta: 1,
  217. });
  218. }
  219. },
  220. });
  221. return;
  222. }
  223. wx.showActionSheet({
  224. itemList: ["微信支付"],
  225. success(res) {
  226. if (res.tapIndex === 0) {
  227. wx.requestPayment({
  228. timeStamp: result.map.timestamp,
  229. nonceStr: result.map.nonce_str,
  230. package: "prepay_id=" + result.map.prepay_id,
  231. signType: "MD5",
  232. paySign: result.map.sign,
  233. success: function (res) {
  234. if (res) {
  235. //此处客户端支付完成,开始查询业务订单支付结果
  236. wx.showLoading({
  237. title: "正在处理...",
  238. mask: true,
  239. });
  240. App._get(
  241. "order/orderInformation",
  242. {
  243. businessId: _this.data.memberPoints.businessId,
  244. businessType: 1,
  245. memberId: util.getUserId(),
  246. },
  247. function (res) {
  248. if (res.code === 0) {
  249. wx.hideLoading();
  250. // _this.setData({
  251. // integral: res.data.scoreValue,
  252. // });
  253. // _this.popup3.showPopup();
  254. wx.showModal({
  255. title: "提示",
  256. content: "开通会员成功!",
  257. showCancel: false,
  258. success(res) {
  259. if (res.confirm) {
  260. wx.navigateBack({
  261. delta: 1,
  262. });
  263. }
  264. },
  265. });
  266. }
  267. }
  268. );
  269. }
  270. },
  271. fail: function (res) {
  272. wx.hideLoading();
  273. wx.showToast({
  274. title: "开通失败!",
  275. icon: "none",
  276. });
  277. },
  278. });
  279. }
  280. },
  281. fail(res) {},
  282. });
  283. } else {
  284. wx.showModal({
  285. title: "温馨提示",
  286. content: result.msg,
  287. showCancel: false,
  288. });
  289. }
  290. }
  291. );
  292. this.popup2.hidePopup();
  293. },
  294. _error() {
  295. console.log("返回");
  296. this.popup3.hidePopup();
  297. },
  298. _success() {
  299. console.log("查看");
  300. this.popup3.hidePopup();
  301. },
  302. _error2() {
  303. console.log("返回");
  304. this.popup2.hidePopup();
  305. },
  306. _success2() {
  307. console.log("查看");
  308. this.popup2.hidePopup();
  309. },
  310. upgrade() {
  311. // this.popup3.showPopup()
  312. if (!util.UserLoginStatus()) {
  313. return;
  314. }
  315. if (!this.data.currentImg) {
  316. wx.showToast({
  317. icon: "none",
  318. title: "请选择会员体系",
  319. });
  320. return false;
  321. }
  322. if (!this.data.agree) {
  323. wx.showToast({
  324. title: "请先勾选并同意《无界校园会员协议》",
  325. icon: "none",
  326. });
  327. return;
  328. }
  329. this.getPointDeduction();
  330. this.getTask();
  331. this.popup2.showPopup();
  332. return;
  333. },
  334. getTask() {
  335. App._get("taskconfig/list", {}, (res) => {
  336. if (res.code === 0) {
  337. let taskCode;
  338. if (this.data.detail.memberState == 0) {
  339. if (this.data.currentImg == 1) {
  340. taskCode = "ANNUAL_FEE";
  341. } else if (this.data.currentImg == 2) {
  342. taskCode = "LIFELONG";
  343. }
  344. } else if (this.data.detail.memberState == 1) {
  345. taskCode = "MALE_UP";
  346. }
  347. this.setData({
  348. taskCode: taskCode,
  349. });
  350. }
  351. });
  352. },
  353. /**
  354. * 生命周期函数--监听页面加载
  355. */
  356. onLoad: function (options) {
  357. this.PushVipInfo();
  358. this.height();
  359. this.data.params.id = util.getUserId();
  360. wx.setNavigationBarTitle({
  361. title: "青雲慧",
  362. });
  363. this.getVipSelect();
  364. },
  365. /**
  366. * 生命周期函数--监听页面初次渲染完成
  367. */
  368. onReady: function () {
  369. this.popup2 = this.selectComponent("#popup2");
  370. this.popup3 = this.selectComponent("#popup3");
  371. let that = this
  372. let query = wx.createSelectorQuery();
  373. // query.select('#bot-box').boundingClientRect(rect=>{
  374. // let height = rect.height;
  375. // console.log(height,'bot-heught')
  376. // console.log(rect)
  377. // that.setData({
  378. // botCheck: height,
  379. // })
  380. // }).exec();
  381. },
  382. toMembershipAgreement() {
  383. wx.navigateTo({
  384. url: "/membershipAgreement/index",
  385. });
  386. },
  387. /**
  388. * 生命周期函数--监听页面显示
  389. */
  390. onShow: function () {
  391. if (this.data.bottom === 1) {
  392. this.setData({
  393. bottom: 0,
  394. });
  395. }
  396. this.env()
  397. },
  398. /**
  399. * 生命周期函数--监听页面隐藏
  400. */
  401. onHide: function () {},
  402. /**
  403. * 生命周期函数--监听页面卸载
  404. */
  405. onUnload: function () {},
  406. /**
  407. * 页面相关事件处理函数--监听用户下拉动作
  408. */
  409. onPullDownRefresh: function () {
  410. if (this.data.bottom === 1) {
  411. this.setData({
  412. bottom: 0,
  413. });
  414. }
  415. },
  416. /**
  417. * 页面上拉触底事件的处理函数
  418. */
  419. onReachBottom: function () {
  420. this.setData({
  421. bottom: 1,
  422. });
  423. },
  424. checkboxChange(e) {
  425. this.setData({
  426. agree: e.detail.value.length > 0,
  427. });
  428. },
  429. /**
  430. * 用户点击右上角分享
  431. */
  432. onShareAppMessage: function () {},
  433. onPageScroll: function (e) {
  434. if (
  435. e.scrollTop >= this.data.stHeight.split("px")[0] &&
  436. this.data.activeTitle == false
  437. ) {
  438. this.setData({
  439. activeTitle: true,
  440. });
  441. }
  442. if (
  443. e.scrollTop < this.data.stHeight.split("px")[0] &&
  444. this.data.activeTitle == true
  445. ) {
  446. this.setData({
  447. activeTitle: false,
  448. });
  449. }
  450. },
  451. });