C端小程序
Nelze vybrat více než 25 témat Téma musí začínat písmenem nebo číslem, může obsahovat pomlčky („-“) a může být dlouhé až 35 znaků.

234 řádky
5.4 KiB

  1. var config = require("../../config/config.js");
  2. const Http = require("../../utils/HttpBasics");
  3. const imgurl = require("../../utils/imgurl");
  4. Page({
  5. /**
  6. * 页面的初始数据
  7. */
  8. data: {
  9. bannerUrl: imgurl.banner.url,
  10. loadingUrl: imgurl.loading.url,
  11. nodata: imgurl.nodata.url,
  12. wmhome: imgurl.wmhome.url,
  13. barcode: imgurl.barcode.url,
  14. list: [],
  15. lists: [],
  16. myLists: [],
  17. page: 1, // 设置加载的第几次,默认是第一次
  18. pageSize: 10, //返回数据的个数
  19. searchLoadingComplete: false, //“没有数据”的变量,默认false,隐藏
  20. allow_load: true, // 是否允许继续加载标识 默认 true 允许,false 加载完成
  21. myorder: false,
  22. actUrl: imgurl.act.url,
  23. loading: true,
  24. content: '数据正在加载中',
  25. reloadIf: false,
  26. creditAmount: 0,
  27. },
  28. goback: function () {
  29. wx.switchTab({
  30. url: '/pages/main/index',
  31. })
  32. },
  33. onLoad: function (options) {
  34. let that = this;
  35. var todayDate = new Date().getTime();
  36. that.getPoints();
  37. that.setData({
  38. optionsData: options,
  39. todayDate: todayDate
  40. })
  41. if (options && options.from == 'myhtml') {
  42. that.getmyList();
  43. }
  44. else {
  45. that.getList(1);
  46. that.setData({
  47. lists: null
  48. })
  49. }
  50. },
  51. onShow() {
  52. let that = this;
  53. if (this.data.reloadIf) {
  54. wx.setNavigationBarTitle({
  55. title: '积分商城'
  56. })
  57. that.getList(1);
  58. that.setData({
  59. lists: null
  60. })
  61. }
  62. },
  63. // 获得积分,渲染页面
  64. getPoints(){
  65. let that = this;
  66. Http.get({
  67. url: config.api.integralList,
  68. data: {
  69. pageNum: 1,
  70. pageSize: 1,
  71. }
  72. }).then(res => {
  73. console.log(res.data.list[0]),
  74. wx.stopPullDownRefresh();
  75. that.setData({
  76. creditAmount: res.data.list[0].creditAmount,
  77. });
  78. })
  79. .catch(err => {
  80. wx.stopPullDownRefresh();
  81. wx.showToast({
  82. title: err.errMsg,
  83. icon: 'none',
  84. duration: 2000,
  85. mask: false
  86. });
  87. })
  88. },
  89. gotojifen(){
  90. wx.navigateTo({
  91. url: '/pages/integralmall/integraHistory/index',
  92. })
  93. },
  94. getmemberId: function (token) {
  95. let that = this;
  96. Http.get({
  97. url: config.api.getScore,
  98. data: {
  99. token: token
  100. }
  101. }).then(res => {
  102. that.setData({
  103. levelName: res.data.levelName,
  104. upgradePercent: res.data.upgradePercent,
  105. upgradeScore: res.data.upgradeScore,
  106. credit: res.data.credit ? res.data.credit : 0,
  107. score: res.data.score
  108. })
  109. if (res.data.nickName) {
  110. that.setData({
  111. ismember: true,
  112. memberId: res.data.id
  113. })
  114. var initUrl = JSON.stringify({
  115. flagid: res.data.id
  116. });
  117. }
  118. })
  119. .catch(err => {
  120. wx.showModal({
  121. title: '提示',
  122. content: err.message,
  123. showCancel: false
  124. })
  125. })
  126. },
  127. getList(pageNum) {
  128. var that = this;
  129. console.log(pageNum)
  130. if (that.data.allow_load) {
  131. that.setData({
  132. loading: true,
  133. content: '小主,我在玩命加载中...'
  134. })
  135. var param = {};
  136. var param = {
  137. pageNum: pageNum,
  138. pageSize: 10,
  139. targetAd: 50
  140. };
  141. var url = config.api.couponChannelList;
  142. // 请求接口
  143. Http.get({
  144. url: url,
  145. data: param
  146. }).then(res => {
  147. console.log(res)
  148. /**
  149. * 加载完成
  150. */
  151. if (pageNum >= res.data.pages) {
  152. if (res.data.pages == 0 || res.data.pages == 1) {
  153. that.setData({
  154. allow_load: true,
  155. loading: false,
  156. content: ""
  157. });
  158. } else {
  159. that.setData({
  160. allow_load: false,
  161. loading: true,
  162. content: "——— 再拉裤子就掉了啦 ———",
  163. });
  164. }
  165. }
  166. if (pageNum == 1) {
  167. that.setData({
  168. lists: [],
  169. })
  170. }
  171. var tmpArr = that.data.lists;
  172. tmpArr.push.apply(tmpArr, res.data.list);
  173. that.setData({
  174. lists: tmpArr
  175. })
  176. wx.stopPullDownRefresh();
  177. })
  178. .catch(err => {
  179. wx.stopPullDownRefresh();
  180. wx.showToast({
  181. title: err.message,
  182. icon: 'none',
  183. duration: 2000,
  184. mask: false
  185. });
  186. })
  187. setTimeout(function () {
  188. that.setData({
  189. loading: false,
  190. })
  191. }, 1400);
  192. } else {
  193. that.setData({
  194. loading: true,
  195. content: "——— 再拉裤子就掉了啦 ———"
  196. })
  197. setTimeout(function () {
  198. that.setData({
  199. loading: false,
  200. })
  201. }, 1400)
  202. }
  203. },
  204. /**
  205. *
  206. * @param goto拼团券详情
  207. */
  208. invite: function (e) {
  209. let couponChannelId = e.currentTarget.dataset.id;
  210. let couponId = e.currentTarget.dataset.couponid;
  211. if (couponChannelId && couponId) {
  212. wx.navigateTo({
  213. url: `/pages/coupon/detail/index?couponChannelId=${couponChannelId}&couponId=${couponId}`
  214. })
  215. }
  216. },
  217. //加载更多
  218. onReachBottom: function () {
  219. let that = this;
  220. that.data.page++;
  221. that.setData({
  222. page: that.data.page
  223. });
  224. that.getList(that.data.page, that.data.flag);
  225. },
  226. /**
  227. * 刷新
  228. */
  229. onPullDownRefresh: function (e) {
  230. let that = this;
  231. that.getList(1);
  232. that.getPoints();
  233. }
  234. })