C端小程序
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

267 lines
6.2 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. })
  76. if (res.data.nickName) {
  77. that.setData({
  78. ismember: true,
  79. memberId: res.data.id
  80. })
  81. var size = this.setCanvasSize();
  82. var initUrl = JSON.stringify({
  83. flagid: res.data.id
  84. });
  85. that.createQrCode(initUrl, "mycanvas1", size.w, size.h);
  86. }
  87. })
  88. .catch(err => {
  89. wx.showModal({
  90. title: '提示',
  91. content: err.errMsg,
  92. showCancel: false
  93. })
  94. })
  95. },
  96. // 获得积分,渲染页面
  97. getPoints(){
  98. let that = this;
  99. Http.get({
  100. url: config.api.integralList,
  101. data: {
  102. pageNum: 1,
  103. pageSize: 1,
  104. }
  105. }).then(res => {
  106. console.log(res.data.list[0]),
  107. wx.stopPullDownRefresh();
  108. that.setData({
  109. creditAmount: res.data.list[0].creditAmount,
  110. });
  111. })
  112. .catch(err => {
  113. wx.stopPullDownRefresh();
  114. wx.showToast({
  115. title: err.errMsg,
  116. icon: 'none',
  117. duration: 2000,
  118. mask: false
  119. });
  120. })
  121. },
  122. gotojifen(){
  123. wx.navigateTo({
  124. url: '/pages/integralmall/integraHistory/index',
  125. })
  126. },
  127. getmemberId: function (token) {
  128. let that = this;
  129. Http.get({
  130. url: config.api.getScore,
  131. data: {
  132. token: token
  133. }
  134. }).then(res => {
  135. that.setData({
  136. levelName: res.data.levelName,
  137. upgradePercent: res.data.upgradePercent,
  138. upgradeScore: res.data.upgradeScore,
  139. credit: res.data.credit ? res.data.credit : 0,
  140. score: res.data.score
  141. })
  142. if (res.data.nickName) {
  143. that.setData({
  144. ismember: true,
  145. memberId: res.data.id
  146. })
  147. var initUrl = JSON.stringify({
  148. flagid: res.data.id
  149. });
  150. }
  151. })
  152. .catch(err => {
  153. wx.showModal({
  154. title: '提示',
  155. content: err.message,
  156. showCancel: false
  157. })
  158. })
  159. },
  160. getList(pageNum) {
  161. var that = this;
  162. console.log(pageNum)
  163. if (that.data.allow_load) {
  164. that.setData({
  165. loading: true,
  166. content: '小主,我在玩命加载中...'
  167. })
  168. var param = {};
  169. var param = {
  170. pageNum: pageNum,
  171. pageSize: 10,
  172. targetAd: 50
  173. };
  174. var url = config.api.couponChannelList;
  175. // 请求接口
  176. Http.get({
  177. url: url,
  178. data: param
  179. }).then(res => {
  180. console.log(res)
  181. /**
  182. * 加载完成
  183. */
  184. if (pageNum >= res.data.pages) {
  185. if (res.data.pages == 0 || res.data.pages == 1) {
  186. that.setData({
  187. allow_load: true,
  188. loading: false,
  189. content: ""
  190. });
  191. } else {
  192. that.setData({
  193. allow_load: false,
  194. loading: true,
  195. content: "——— 再拉裤子就掉了啦 ———",
  196. });
  197. }
  198. }
  199. if (pageNum == 1) {
  200. that.setData({
  201. lists: [],
  202. })
  203. }
  204. var tmpArr = that.data.lists;
  205. tmpArr.push.apply(tmpArr, res.data.list);
  206. that.setData({
  207. lists: tmpArr
  208. })
  209. wx.stopPullDownRefresh();
  210. })
  211. .catch(err => {
  212. wx.stopPullDownRefresh();
  213. wx.showToast({
  214. title: err.message,
  215. icon: 'none',
  216. duration: 2000,
  217. mask: false
  218. });
  219. })
  220. setTimeout(function () {
  221. that.setData({
  222. loading: false,
  223. })
  224. }, 1400);
  225. } else {
  226. that.setData({
  227. loading: true,
  228. content: "——— 再拉裤子就掉了啦 ———"
  229. })
  230. setTimeout(function () {
  231. that.setData({
  232. loading: false,
  233. })
  234. }, 1400)
  235. }
  236. },
  237. /**
  238. *
  239. * @param goto拼团券详情
  240. */
  241. invite: function (e) {
  242. let couponChannelId = e.currentTarget.dataset.id;
  243. let couponId = e.currentTarget.dataset.couponid;
  244. if (couponChannelId && couponId) {
  245. wx.navigateTo({
  246. url: `/pages/coupon/detail/index?couponChannelId=${couponChannelId}&couponId=${couponId}`
  247. })
  248. }
  249. },
  250. //加载更多
  251. onReachBottom: function () {
  252. let that = this;
  253. that.data.page++;
  254. that.setData({
  255. page: that.data.page
  256. });
  257. that.getList(that.data.page, that.data.flag);
  258. },
  259. /**
  260. * 刷新
  261. */
  262. onPullDownRefresh: function (e) {
  263. let that = this;
  264. that.getList(1);
  265. that.getPoints();
  266. }
  267. })