C端小程序
Du kan inte välja fler än 25 ämnen Ämnen måste starta med en bokstav eller siffra, kan innehålla bindestreck ('-') och vara max 35 tecken långa.

299 rader
7.1 KiB

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