C端小程序
25개 이상의 토픽을 선택하실 수 없습니다. Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

295 lines
7.0 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: '/index/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. 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. .catch(err => {
  101. wx.showModal({
  102. title: '提示',
  103. content: err.message,
  104. showCancel: false
  105. })
  106. })
  107. },
  108. //适配不同屏幕大小的canvas
  109. setCanvasSize: function () {
  110. var size = {};
  111. try {
  112. var res = wx.getSystemInfoSync();
  113. var scale = 750 / 500;
  114. //不同屏幕下canvas的适配比例;设计稿是750宽
  115. var width = res.windowWidth / scale;
  116. var height = width;
  117. //canvas画布为正方形
  118. size.w = width;
  119. size.h = height;
  120. } catch (e) {
  121. // Do something when catch error
  122. console.log("获取设备信息失败" + e);
  123. }
  124. return size;
  125. },
  126. createQrCode: function (url, canvasId, cavW, cavH) {
  127. //调用插件中的draw方法,绘制二维码图片
  128. QR.api.draw(url, canvasId, cavW, cavH);
  129. },
  130. qrcode: function (e) {
  131. var that = this;
  132. that.setData({
  133. showQrcode: true
  134. })
  135. wx.showToast({
  136. title: '生成中...',
  137. icon: 'loading',
  138. duration: 2000
  139. });
  140. var st = setTimeout(function () {
  141. wx.hideToast()
  142. var size = that.setCanvasSize();
  143. var url = JSON.stringify({
  144. END: "C",
  145. TYPE: "memberCode",
  146. ID: that.data.memberId,
  147. })
  148. that.createQrCode(url, "mycanvas1", size.w, size.h);
  149. that.setData({
  150. maskHidden: true
  151. });
  152. clearTimeout(st);
  153. }, 1000)
  154. },
  155. // 获得积分,渲染页面
  156. getPoints(){
  157. let that = this;
  158. Http.get({
  159. url: config.api.integralList,
  160. data: {
  161. pageNum: 1,
  162. pageSize: 1,
  163. }
  164. }).then(res => {
  165. wx.stopPullDownRefresh();
  166. that.setData({
  167. creditAmount: res.data.list[0].creditAmount,
  168. });
  169. })
  170. .catch(err => {
  171. wx.stopPullDownRefresh();
  172. wx.showToast({
  173. title: err.errMsg,
  174. icon: 'none',
  175. duration: 2000,
  176. mask: false
  177. });
  178. })
  179. },
  180. gotojifen(){
  181. wx.navigateTo({
  182. url: '/pages/integralmall/integraHistory/index',
  183. })
  184. },
  185. getList(pageNum) {
  186. var that = this;
  187. if (that.data.allow_load) {
  188. that.setData({
  189. loading: true,
  190. content: '小主,我在玩命加载中...'
  191. })
  192. var param = {};
  193. var param = {
  194. pageNum: pageNum,
  195. pageSize: 10,
  196. targetAd: 50
  197. };
  198. var url = config.api.couponChannelList;
  199. // 请求接口
  200. Http.get({
  201. url: url,
  202. data: param
  203. }).then(res => {
  204. console.log(res)
  205. /**
  206. * 加载完成
  207. */
  208. if (pageNum >= res.data.pages) {
  209. if (res.data.pages == 0 || res.data.pages == 1) {
  210. that.setData({
  211. allow_load: true,
  212. loading: false,
  213. content: ""
  214. });
  215. } else {
  216. that.setData({
  217. allow_load: false,
  218. loading: true,
  219. content: "——— 再拉裤子就掉了啦 ———",
  220. });
  221. }
  222. }
  223. if (pageNum == 1) {
  224. that.setData({
  225. lists: [],
  226. })
  227. }
  228. var tmpArr = that.data.lists;
  229. tmpArr.push.apply(tmpArr, res.data.list);
  230. that.setData({
  231. lists: tmpArr
  232. })
  233. wx.stopPullDownRefresh();
  234. })
  235. .catch(err => {
  236. wx.stopPullDownRefresh();
  237. wx.showToast({
  238. title: err.message,
  239. icon: 'none',
  240. duration: 2000,
  241. mask: false
  242. });
  243. })
  244. setTimeout(function () {
  245. that.setData({
  246. loading: false,
  247. })
  248. }, 1400);
  249. } else {
  250. that.setData({
  251. loading: true,
  252. content: "——— 再拉裤子就掉了啦 ———"
  253. })
  254. setTimeout(function () {
  255. that.setData({
  256. loading: false,
  257. })
  258. }, 1400)
  259. }
  260. },
  261. /**
  262. *
  263. * @param goto拼团券详情
  264. */
  265. invite: function (e) {
  266. let couponChannelId = e.currentTarget.dataset.id;
  267. let couponId = e.currentTarget.dataset.couponid;
  268. if (couponChannelId && couponId) {
  269. wx.navigateTo({
  270. url: `/pages/coupon/detail/index?couponChannelId=${couponChannelId}&couponId=${couponId}`
  271. })
  272. }
  273. },
  274. //加载更多
  275. onReachBottom: function () {
  276. let that = this;
  277. that.data.page++;
  278. that.setData({
  279. page: that.data.page
  280. });
  281. that.getList(that.data.page, that.data.flag);
  282. },
  283. /**
  284. * 刷新
  285. */
  286. onPullDownRefresh: function (e) {
  287. let that = this;
  288. that.getList(1);
  289. that.getPoints();
  290. }
  291. })