C端小程序
No puede seleccionar más de 25 temas Los temas deben comenzar con una letra o número, pueden incluir guiones ('-') y pueden tener hasta 35 caracteres de largo.

296 líneas
7.0 KiB

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