C端小程序
Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.

237 lignes
5.6 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. score: '0',
  28. },
  29. goback: function () {
  30. wx.switchTab({
  31. url: '/pages/main/index',
  32. })
  33. },
  34. onLoad: function (options) {
  35. let that = this;
  36. var todayDate = new Date().getTime();
  37. that.getPoints();
  38. that.setData({
  39. optionsData: options,
  40. todayDate: todayDate
  41. })
  42. if (options && options.from == 'myhtml') {
  43. that.getmyList();
  44. }
  45. else {
  46. that.getList(1);
  47. that.setData({
  48. lists: null
  49. })
  50. }
  51. },
  52. onShow() {
  53. let that = this;
  54. if (this.data.reloadIf) {
  55. wx.setNavigationBarTitle({
  56. title: '积分商城'
  57. })
  58. that.getList(1);
  59. that.setData({
  60. lists: null
  61. })
  62. };
  63. Http.get({
  64. url: config.api.getScore,
  65. data: {}
  66. }).then(res => {
  67. if (res.data.address && res.data.name && res.data.sex && res.data.birthdate) {
  68. that.setData({
  69. showEdit: true
  70. })
  71. }
  72. console.log(res.data,22222222222)
  73. that.setData({
  74. score: res.data.score,
  75. levelName: res.data.levelName,
  76. upgradePercent: res.data.upgradePercent,
  77. upgradeScore: res.data.upgradeScore
  78. })
  79. if (res.data.nickName) {
  80. that.setData({
  81. ismember: true,
  82. memberId: res.data.id
  83. })
  84. var size = this.setCanvasSize();
  85. var initUrl = JSON.stringify({
  86. flagid: res.data.id
  87. });
  88. that.createQrCode(initUrl, "mycanvas1", size.w, size.h);
  89. }
  90. })
  91. .catch(err => {
  92. wx.showModal({
  93. title: '提示',
  94. content: err.errMsg,
  95. showCancel: false
  96. })
  97. })
  98. },
  99. // 获得积分,渲染页面
  100. getPoints(){
  101. let that = this;
  102. Http.get({
  103. url: config.api.integralList,
  104. data: {
  105. pageNum: 1,
  106. pageSize: 1,
  107. }
  108. }).then(res => {
  109. console.log(res.data.list[0]),
  110. wx.stopPullDownRefresh();
  111. that.setData({
  112. creditAmount: res.data.list[0].creditAmount,
  113. });
  114. })
  115. .catch(err => {
  116. wx.stopPullDownRefresh();
  117. wx.showToast({
  118. title: err.errMsg,
  119. icon: 'none',
  120. duration: 2000,
  121. mask: false
  122. });
  123. })
  124. },
  125. gotojifen(){
  126. wx.navigateTo({
  127. url: '/pages/integralmall/integraHistory/index',
  128. })
  129. },
  130. getList(pageNum) {
  131. var that = this;
  132. console.log(pageNum)
  133. if (that.data.allow_load) {
  134. that.setData({
  135. loading: true,
  136. content: '小主,我在玩命加载中...'
  137. })
  138. var param = {};
  139. var param = {
  140. pageNum: pageNum,
  141. pageSize: 10,
  142. targetAd: 50
  143. };
  144. var url = config.api.couponChannelList;
  145. // 请求接口
  146. Http.get({
  147. url: url,
  148. data: param
  149. }).then(res => {
  150. console.log(res)
  151. /**
  152. * 加载完成
  153. */
  154. if (pageNum >= res.data.pages) {
  155. if (res.data.pages == 0 || res.data.pages == 1) {
  156. that.setData({
  157. allow_load: true,
  158. loading: false,
  159. content: ""
  160. });
  161. } else {
  162. that.setData({
  163. allow_load: false,
  164. loading: true,
  165. content: "——— 再拉裤子就掉了啦 ———",
  166. });
  167. }
  168. }
  169. if (pageNum == 1) {
  170. that.setData({
  171. lists: [],
  172. })
  173. }
  174. var tmpArr = that.data.lists;
  175. tmpArr.push.apply(tmpArr, res.data.list);
  176. that.setData({
  177. lists: tmpArr
  178. })
  179. wx.stopPullDownRefresh();
  180. })
  181. .catch(err => {
  182. wx.stopPullDownRefresh();
  183. wx.showToast({
  184. title: err.message,
  185. icon: 'none',
  186. duration: 2000,
  187. mask: false
  188. });
  189. })
  190. setTimeout(function () {
  191. that.setData({
  192. loading: false,
  193. })
  194. }, 1400);
  195. } else {
  196. that.setData({
  197. loading: true,
  198. content: "——— 再拉裤子就掉了啦 ———"
  199. })
  200. setTimeout(function () {
  201. that.setData({
  202. loading: false,
  203. })
  204. }, 1400)
  205. }
  206. },
  207. /**
  208. *
  209. * @param goto拼团券详情
  210. */
  211. invite: function (e) {
  212. let couponChannelId = e.currentTarget.dataset.id;
  213. let couponId = e.currentTarget.dataset.couponid;
  214. if (couponChannelId && couponId) {
  215. wx.navigateTo({
  216. url: `/pages/coupon/detail/index?couponChannelId=${couponChannelId}&couponId=${couponId}`
  217. })
  218. }
  219. },
  220. //加载更多
  221. onReachBottom: function () {
  222. let that = this;
  223. that.data.page++;
  224. that.setData({
  225. page: that.data.page
  226. });
  227. that.getList(that.data.page, that.data.flag);
  228. },
  229. /**
  230. * 刷新
  231. */
  232. onPullDownRefresh: function (e) {
  233. let that = this;
  234. that.getList(1);
  235. that.getPoints();
  236. }
  237. })