myMember.js 11 KB

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