C端小程序
選択できるのは25トピックまでです。 トピックは、先頭が英数字で、英数字とダッシュ('-')を使用した35文字以内のものにしてください。

236 行
5.5 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. that.setData({
  73. score: res.data.score,
  74. levelName: res.data.levelName,
  75. upgradePercent: res.data.upgradePercent,
  76. upgradeScore: res.data.upgradeScore
  77. })
  78. if (res.data.nickName) {
  79. that.setData({
  80. ismember: true,
  81. memberId: res.data.id
  82. })
  83. var size = this.setCanvasSize();
  84. var initUrl = JSON.stringify({
  85. flagid: res.data.id
  86. });
  87. that.createQrCode(initUrl, "mycanvas1", size.w, size.h);
  88. }
  89. })
  90. .catch(err => {
  91. wx.showModal({
  92. title: '提示',
  93. content: err.errMsg,
  94. showCancel: false
  95. })
  96. })
  97. },
  98. // 获得积分,渲染页面
  99. getPoints(){
  100. let that = this;
  101. Http.get({
  102. url: config.api.integralList,
  103. data: {
  104. pageNum: 1,
  105. pageSize: 1,
  106. }
  107. }).then(res => {
  108. wx.stopPullDownRefresh();
  109. that.setData({
  110. creditAmount: res.data.list[0].creditAmount,
  111. });
  112. })
  113. .catch(err => {
  114. wx.stopPullDownRefresh();
  115. wx.showToast({
  116. title: err.errMsg,
  117. icon: 'none',
  118. duration: 2000,
  119. mask: false
  120. });
  121. })
  122. },
  123. gotojifen(){
  124. wx.navigateTo({
  125. url: '/pages/integralmall/integraHistory/index',
  126. })
  127. },
  128. getList(pageNum) {
  129. var that = this;
  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. })