upgrade.js 8.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310
  1. var app = getApp();
  2. var util = require('../../utils/util.js');
  3. var status = require('../../utils/index.js');
  4. Page({
  5. mixins: [require('../../mixin/compoentCartMixin.js')],
  6. data: {
  7. classification: {
  8. tabs: [],
  9. activeIndex: 0
  10. },
  11. rushList: [],
  12. loadMore: true,
  13. loadText: "加载中...",
  14. loadOver: false,
  15. showEmpty: false,
  16. is_show_vipgoods: 1
  17. },
  18. pageNum:1,
  19. canLoad: 1,
  20. /**
  21. * 生命周期函数--监听页面加载
  22. */
  23. onLoad: function (options) {
  24. status.setNavBgColor();
  25. this.getData();
  26. this.getList();
  27. },
  28. /**
  29. * 授权成功回调
  30. */
  31. authSuccess: function () {
  32. let that = this;
  33. wx.showLoading();
  34. this.pageNum = 1;
  35. that.setData({
  36. needAuth: false,
  37. showAuthModal: false,
  38. classification: {
  39. tabs: [],
  40. activeIndex: 0
  41. },
  42. rushList: [],
  43. loadMore: true,
  44. loadText: "加载中...",
  45. loadOver: false,
  46. showEmpty: false
  47. });
  48. },
  49. /**
  50. * 授权成功回调
  51. */
  52. authSuccess: function () {
  53. let url = '/lionfish_comshop/moduleA/vip/upgrade';
  54. app.globalData.navBackUrl = url;
  55. wx.redirectTo({ url })
  56. },
  57. /**
  58. * 生命周期函数--监听页面显示
  59. */
  60. onShow: function () {
  61. let that = this;
  62. util.check_login_new().then((res) => {
  63. if (!res) {
  64. that.setData({
  65. needAuth: true
  66. })
  67. } else {
  68. this.setData({ needAuth: false });
  69. (0, status.cartNum)('', true).then((res) => {
  70. res.code == 0 && that.setData({ cartNum: res.data })
  71. });
  72. }
  73. })
  74. },
  75. getData: function(){
  76. wx.showLoading();
  77. var token = wx.getStorageSync('token');
  78. let that = this;
  79. app.util.request({
  80. 'url': 'entry/wxapp/user',
  81. 'data': {
  82. controller: 'vipcard.get_vipcard_baseinfo',
  83. token: token
  84. },
  85. dataType: 'json',
  86. success: function (res) {
  87. wx.hideLoading();
  88. if (res.data.code == 0) {
  89. let {
  90. member_info,
  91. card_equity_list,
  92. card_list,
  93. is_open_vipcard_buy,
  94. modify_vipcard_name,
  95. is_vip_card_member,
  96. vipcard_unopen_headbg,
  97. vipcard_effect_headbg,
  98. vipcard_afterefect_headbg,
  99. vipcard_buy_pagenotice,
  100. vipcard_equity_notice,
  101. is_show_vipgoods,
  102. category_list
  103. // del_vip_day
  104. } = res.data.data;
  105. wx.setNavigationBarTitle({ title: modify_vipcard_name || '会员中心' })
  106. let params = {
  107. classification: {}
  108. };
  109. category_list = category_list || [];
  110. if (category_list.length > 0) {
  111. category_list.unshift({
  112. name: '全部',
  113. id: 0
  114. })
  115. params.isShowClassification = true;
  116. params.classification.tabs = category_list;
  117. } else {
  118. params.isShowClassification = false;
  119. }
  120. card_list.map(item=>{
  121. let expire_day = item.expire_day.split('.');
  122. return item.expire_day = expire_day[0];
  123. })
  124. that.setData({
  125. member_info,
  126. card_equity_list,
  127. card_list,
  128. is_open_vipcard_buy,
  129. modify_vipcard_name,
  130. is_vip_card_member,
  131. vipcard_unopen_headbg,
  132. vipcard_effect_headbg,
  133. vipcard_afterefect_headbg,
  134. vipcard_equity_notice,
  135. del_vip_day: res.data.del_vip_day || '',
  136. is_show_vipgoods,
  137. ...params
  138. })
  139. } else {
  140. app.util.message('未登录', 'switchTo:/lionfish_comshop/pages/user/me', 'error');
  141. }
  142. }
  143. })
  144. },
  145. choosecard: function (t) {
  146. this.setData({
  147. selectid: t.currentTarget.dataset.id
  148. });
  149. },
  150. submitpay: function (t) {
  151. if (wx.getStorageSync("token")) {
  152. var rech_id = this.data.selectid, token = wx.getStorageSync("token");
  153. if (void 0 == rech_id) return wx.showToast({
  154. icon: "none",
  155. title: "请选择要开通的会员类型"
  156. });
  157. app.util.request({
  158. url: "entry/wxapp/user",
  159. data: {
  160. controller: "vipcard.wxcharge",
  161. token,
  162. rech_id
  163. },
  164. dataType: "json",
  165. success: function (res) {
  166. if(res.data.is_zero_pay==1) {
  167. wx.showToast({
  168. title: "支付成功",
  169. icon: "none",
  170. duration: 2000,
  171. success: function () {
  172. setTimeout(function () {
  173. wx.redirectTo({
  174. url: "/lionfish_comshop/moduleA/vip/upgrade"
  175. });
  176. }, 2000);
  177. }
  178. });
  179. } else {
  180. wx.requestPayment({
  181. appId: res.data.appId,
  182. timeStamp: res.data.timeStamp,
  183. nonceStr: res.data.nonceStr,
  184. package: res.data.package,
  185. signType: res.data.signType,
  186. paySign: res.data.paySign,
  187. success: function (wxres) {
  188. wx.showToast({
  189. title: "支付成功",
  190. icon: "none",
  191. duration: 2000,
  192. success: function () {
  193. setTimeout(function () {
  194. wx.redirectTo({
  195. url: "/lionfish_comshop/moduleA/vip/upgrade"
  196. });
  197. }, 2000);
  198. }
  199. });
  200. },
  201. fail: function (error) {
  202. wx.showToast({
  203. icon: "none",
  204. title: "支付失败,请重试!"
  205. });
  206. }
  207. })
  208. }
  209. }
  210. });
  211. } else{
  212. this.setData({
  213. needAuth: true
  214. });
  215. }
  216. },
  217. /**
  218. * 监控分类导航
  219. */
  220. classificationChange: function (t) {
  221. wx.showLoading();
  222. var that = this;
  223. this.pageNum = 1;
  224. this.canLoad = 1;
  225. this.setData({
  226. rushList: [],
  227. loadMore: true,
  228. loadText: "加载中...",
  229. loadOver: false,
  230. showEmpty: false,
  231. "classification.activeIndex": t.detail.e,
  232. classificationId: t.detail.a
  233. }, function () {
  234. that.getList();
  235. });
  236. },
  237. /**
  238. * 获取商品列表
  239. */
  240. getList: function () {
  241. let that = this;
  242. let token = wx.getStorageSync('token');
  243. let gid = that.data.classificationId;
  244. let community = wx.getStorageSync('community');
  245. let head_id = community.communityId || 0;
  246. this.canLoad==1 && (that.canLoad=0), app.util.request({
  247. url: 'entry/wxapp/index',
  248. data: {
  249. controller: 'vipcard.get_vipgoods_list',
  250. pageNum: this.pageNum,
  251. gid,
  252. token,
  253. head_id
  254. },
  255. dataType: 'json',
  256. success: function (res) {
  257. wx.hideLoading();
  258. wx.stopPullDownRefresh();
  259. if (res.data.code == 0) {
  260. let oldRushList = that.data.rushList;
  261. let h = {}, list = res.data.list;
  262. if (that.pageNum == 1 && list.length == 0) h.showEmpty = true;
  263. if(list.length < 10) h.loadMore = false;
  264. let rushList = oldRushList.concat(list);
  265. let rdata = res.data;
  266. let reduction = { full_money: rdata.full_money, full_reducemoney: rdata.full_reducemoney, is_open_fullreduction: rdata.is_open_fullreduction }
  267. h.rushList = rushList;
  268. h.reduction = reduction;
  269. h.loadOver = true;
  270. h.loadText = that.data.loadMore ? "加载中..." : "没有更多商品了~";
  271. console.log(h)
  272. that.setData(h, function () {
  273. that.pageNum += 1;
  274. })
  275. } else if (res.data.code == 1) {
  276. let s = { loadMore: false }
  277. if (that.pageNum == 1) s.showEmpty = true;
  278. that.setData(s);
  279. } else if (res.data.code == 2) {
  280. //no login
  281. that.setData({ needAuth: true })
  282. }
  283. console.log('that.canLoad', that.canLoad);
  284. that.canLoad=1;
  285. }
  286. })
  287. },
  288. /**
  289. * 页面上拉触底事件的处理函数
  290. */
  291. onReachBottom: function () {
  292. console.log('这是我的底线', this.canLoad);
  293. this.data.loadMore && (this.canLoad==1) && (this.setData({ loadOver: false }), this.getList());
  294. }
  295. })