myMember.js 11 KB

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