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.

311 lines
7.3 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. sort:imgurl.sort.url,
  34. up:imgurl.up.url,
  35. down:imgurl.down.url
  36. },
  37. qrcodeH: function () {
  38. var that = this;
  39. let memberId = that.data.memberId;
  40. if (memberId) {
  41. wx.navigateTo({
  42. url: '/pages/specialcourtesy/specialcourtesy'
  43. })
  44. }
  45. },
  46. goback: function () {
  47. wx.switchTab({
  48. url: '/index/index',
  49. })
  50. },
  51. onLoad: function (options) {
  52. let that = this;
  53. var todayDate = new Date().getTime();
  54. that.getPoints();
  55. that.setData({
  56. optionsData: options,
  57. todayDate: todayDate
  58. })
  59. if (options && options.from == 'myhtml') {
  60. that.getmyList();
  61. }
  62. else {
  63. that.getList(1);
  64. that.setData({
  65. lists: null
  66. })
  67. }
  68. },
  69. onShow() {
  70. let that = this;
  71. if (this.data.reloadIf) {
  72. wx.setNavigationBarTitle({
  73. title: '积分商城'
  74. })
  75. that.getList(1);
  76. that.setData({
  77. lists: null
  78. })
  79. };
  80. Http.get({
  81. url: config.api.getScore,
  82. data: {}
  83. }).then(res => {
  84. if (res.data.address && res.data.name && res.data.sex && res.data.birthdate) {
  85. that.setData({
  86. showEdit: true
  87. })
  88. }
  89. that.setData({
  90. score: res.data.score,
  91. levelName: res.data.levelName,
  92. upgradePercent: res.data.upgradePercent,
  93. upgradeScore: res.data.upgradeScore,
  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. .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. //我可换购
  189. canSort(){
  190. },
  191. //所需积分
  192. need(e){
  193. var that = this;
  194. // if()
  195. console.log(e.target)
  196. let clickNum = []
  197. that.setData({
  198. sort :imgurl.down.url
  199. })
  200. },
  201. getList(pageNum) {
  202. var that = this;
  203. if (that.data.allow_load) {
  204. that.setData({
  205. loading: true,
  206. content: '小主,我在玩命加载中...'
  207. })
  208. var param = {};
  209. var param = {
  210. pageNum: pageNum,
  211. pageSize: 10,
  212. targetAd: 50
  213. };
  214. var url = config.api.couponChannelList;
  215. // 请求接口
  216. Http.get({
  217. url: url,
  218. data: param
  219. }).then(res => {
  220. console.log(res)
  221. /**
  222. * 加载完成
  223. */
  224. if (pageNum >= res.data.pages) {
  225. if (res.data.pages == 0 || res.data.pages == 1) {
  226. that.setData({
  227. allow_load: true,
  228. loading: false,
  229. content: ""
  230. });
  231. } else {
  232. that.setData({
  233. allow_load: false,
  234. loading: true,
  235. content: "——— 再拉裤子就掉了啦 ———",
  236. });
  237. }
  238. }
  239. if (pageNum == 1) {
  240. that.setData({
  241. lists: [],
  242. })
  243. }
  244. var tmpArr = that.data.lists;
  245. tmpArr.push.apply(tmpArr, res.data.list);
  246. that.setData({
  247. lists: tmpArr
  248. })
  249. wx.stopPullDownRefresh();
  250. })
  251. .catch(err => {
  252. wx.stopPullDownRefresh();
  253. wx.showToast({
  254. title: err.message,
  255. icon: 'none',
  256. duration: 2000,
  257. mask: false
  258. });
  259. })
  260. setTimeout(function () {
  261. that.setData({
  262. loading: false,
  263. })
  264. }, 1400);
  265. } else {
  266. that.setData({
  267. loading: true,
  268. content: "——— 再拉裤子就掉了啦 ———"
  269. })
  270. setTimeout(function () {
  271. that.setData({
  272. loading: false,
  273. })
  274. }, 1400)
  275. }
  276. },
  277. /**
  278. *
  279. * @param goto拼团券详情
  280. */
  281. invite: function (e) {
  282. let couponChannelId = e.currentTarget.dataset.id;
  283. let couponId = e.currentTarget.dataset.couponid;
  284. if (couponChannelId && couponId) {
  285. wx.navigateTo({
  286. url: `/pages/coupon/detail/index?couponChannelId=${couponChannelId}&couponId=${couponId}`
  287. })
  288. }
  289. },
  290. //加载更多
  291. onReachBottom: function () {
  292. let that = this;
  293. that.data.page++;
  294. that.setData({
  295. page: that.data.page
  296. });
  297. that.getList(that.data.page, that.data.flag);
  298. },
  299. /**
  300. * 刷新
  301. */
  302. onPullDownRefresh: function (e) {
  303. let that = this;
  304. that.getList(1);
  305. that.getPoints();
  306. }
  307. })