C端小程序
您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

298 行
7.1 KiB

  1. const navigationBarHeight = (getApp().statusBarHeight + 50) + 'px'
  2. var config = require("../../config/config.js");
  3. const Http = require("../../utils/HttpBasics");
  4. const imgurl = require("../../utils/imgurl");
  5. const QR = require("../../utils/memberqrcode.js");
  6. Page({
  7. /**
  8. * 页面的初始数据
  9. */
  10. data: {
  11. navigationBarHeight,
  12. erweima: imgurl.erweima.url,
  13. bannerUrl: imgurl.banner.url,
  14. loadingUrl: imgurl.loading.url,
  15. nodata: imgurl.nodata.url,
  16. wmhome: imgurl.wmhome.url,
  17. barcode: imgurl.barcode.url,
  18. list: [],
  19. lists: [],
  20. myLists: [],
  21. page: 1, // 设置加载的第几次,默认是第一次
  22. pageSize: 10, //返回数据的个数
  23. searchLoadingComplete: false, //“没有数据”的变量,默认false,隐藏
  24. allow_load: true, // 是否允许继续加载标识 默认 true 允许,false 加载完成
  25. myorder: false,
  26. actUrl: imgurl.act.url,
  27. loading: true,
  28. content: '数据正在加载中',
  29. reloadIf: false,
  30. creditAmount: 0,
  31. score: '0',
  32. },
  33. qrcodeH: function () {
  34. var that = this;
  35. let memberId = that.data.memberId;
  36. if (memberId) {
  37. wx.navigateTo({
  38. url: '/pages/specialcourtesy/specialcourtesy'
  39. })
  40. }
  41. },
  42. goback: function () {
  43. wx.switchTab({
  44. url: '/pages/main/index',
  45. })
  46. },
  47. onLoad: function (options) {
  48. let that = this;
  49. var todayDate = new Date().getTime();
  50. that.getPoints();
  51. that.setData({
  52. optionsData: options,
  53. todayDate: todayDate
  54. })
  55. if (options && options.from == 'myhtml') {
  56. that.getmyList();
  57. }
  58. else {
  59. that.getList(1);
  60. that.setData({
  61. lists: null
  62. })
  63. }
  64. },
  65. onShow() {
  66. let that = this;
  67. if (this.data.reloadIf) {
  68. wx.setNavigationBarTitle({
  69. title: '积分商城'
  70. })
  71. that.getList(1);
  72. that.setData({
  73. lists: null
  74. })
  75. };
  76. Http.get({
  77. url: config.api.getScore,
  78. data: {}
  79. }).then(res => {
  80. if (res.data.address && res.data.name && res.data.sex && res.data.birthdate) {
  81. that.setData({
  82. showEdit: true
  83. })
  84. }
  85. that.setData({
  86. score: res.data.score,
  87. levelName: res.data.levelName,
  88. upgradePercent: res.data.upgradePercent,
  89. upgradeScore: res.data.upgradeScore
  90. })
  91. if (res.data.nickName) {
  92. that.setData({
  93. ismember: true,
  94. memberId: res.data.id
  95. })
  96. var size = this.setCanvasSize();
  97. var initUrl = JSON.stringify({
  98. flagid: res.data.id
  99. });
  100. that.createQrCode(initUrl, "mycanvas1", size.w, size.h);
  101. }
  102. })
  103. .catch(err => {
  104. wx.showModal({
  105. title: '提示',
  106. content: err.message,
  107. showCancel: false
  108. })
  109. })
  110. },
  111. //适配不同屏幕大小的canvas
  112. setCanvasSize: function () {
  113. var size = {};
  114. try {
  115. var res = wx.getSystemInfoSync();
  116. var scale = 750 / 500;
  117. //不同屏幕下canvas的适配比例;设计稿是750宽
  118. var width = res.windowWidth / scale;
  119. var height = width;
  120. //canvas画布为正方形
  121. size.w = width;
  122. size.h = height;
  123. } catch (e) {
  124. // Do something when catch error
  125. console.log("获取设备信息失败" + e);
  126. }
  127. return size;
  128. },
  129. createQrCode: function (url, canvasId, cavW, cavH) {
  130. //调用插件中的draw方法,绘制二维码图片
  131. QR.api.draw(url, canvasId, cavW, cavH);
  132. },
  133. qrcode: function (e) {
  134. var that = this;
  135. that.setData({
  136. showQrcode: true
  137. })
  138. wx.showToast({
  139. title: '生成中...',
  140. icon: 'loading',
  141. duration: 2000
  142. });
  143. var st = setTimeout(function () {
  144. wx.hideToast()
  145. var size = that.setCanvasSize();
  146. var url = JSON.stringify({
  147. END: "C",
  148. TYPE: "memberCode",
  149. ID: that.data.memberId,
  150. })
  151. that.createQrCode(url, "mycanvas1", size.w, size.h);
  152. that.setData({
  153. maskHidden: true
  154. });
  155. clearTimeout(st);
  156. }, 1000)
  157. },
  158. // 获得积分,渲染页面
  159. getPoints(){
  160. let that = this;
  161. Http.get({
  162. url: config.api.integralList,
  163. data: {
  164. pageNum: 1,
  165. pageSize: 1,
  166. }
  167. }).then(res => {
  168. wx.stopPullDownRefresh();
  169. that.setData({
  170. creditAmount: res.data.list[0].creditAmount,
  171. });
  172. })
  173. .catch(err => {
  174. wx.stopPullDownRefresh();
  175. wx.showToast({
  176. title: err.errMsg,
  177. icon: 'none',
  178. duration: 2000,
  179. mask: false
  180. });
  181. })
  182. },
  183. gotojifen(){
  184. wx.navigateTo({
  185. url: '/pages/integralmall/integraHistory/index',
  186. })
  187. },
  188. getList(pageNum) {
  189. var that = this;
  190. if (that.data.allow_load) {
  191. that.setData({
  192. loading: true,
  193. content: '小主,我在玩命加载中...'
  194. })
  195. var param = {};
  196. var param = {
  197. pageNum: pageNum,
  198. pageSize: 10,
  199. targetAd: 50
  200. };
  201. var url = config.api.couponChannelList;
  202. // 请求接口
  203. Http.get({
  204. url: url,
  205. data: param
  206. }).then(res => {
  207. console.log(res)
  208. /**
  209. * 加载完成
  210. */
  211. if (pageNum >= res.data.pages) {
  212. if (res.data.pages == 0 || res.data.pages == 1) {
  213. that.setData({
  214. allow_load: true,
  215. loading: false,
  216. content: ""
  217. });
  218. } else {
  219. that.setData({
  220. allow_load: false,
  221. loading: true,
  222. content: "——— 再拉裤子就掉了啦 ———",
  223. });
  224. }
  225. }
  226. if (pageNum == 1) {
  227. that.setData({
  228. lists: [],
  229. })
  230. }
  231. var tmpArr = that.data.lists;
  232. tmpArr.push.apply(tmpArr, res.data.list);
  233. that.setData({
  234. lists: tmpArr
  235. })
  236. wx.stopPullDownRefresh();
  237. })
  238. .catch(err => {
  239. wx.stopPullDownRefresh();
  240. wx.showToast({
  241. title: err.message,
  242. icon: 'none',
  243. duration: 2000,
  244. mask: false
  245. });
  246. })
  247. setTimeout(function () {
  248. that.setData({
  249. loading: false,
  250. })
  251. }, 1400);
  252. } else {
  253. that.setData({
  254. loading: true,
  255. content: "——— 再拉裤子就掉了啦 ———"
  256. })
  257. setTimeout(function () {
  258. that.setData({
  259. loading: false,
  260. })
  261. }, 1400)
  262. }
  263. },
  264. /**
  265. *
  266. * @param goto拼团券详情
  267. */
  268. invite: function (e) {
  269. let couponChannelId = e.currentTarget.dataset.id;
  270. let couponId = e.currentTarget.dataset.couponid;
  271. if (couponChannelId && couponId) {
  272. wx.navigateTo({
  273. url: `/pages/coupon/detail/index?couponChannelId=${couponChannelId}&couponId=${couponId}`
  274. })
  275. }
  276. },
  277. //加载更多
  278. onReachBottom: function () {
  279. let that = this;
  280. that.data.page++;
  281. that.setData({
  282. page: that.data.page
  283. });
  284. that.getList(that.data.page, that.data.flag);
  285. },
  286. /**
  287. * 刷新
  288. */
  289. onPullDownRefresh: function (e) {
  290. let that = this;
  291. that.getList(1);
  292. that.getPoints();
  293. }
  294. })