C端小程序
Du kannst nicht mehr als 25 Themen auswählen Themen müssen entweder mit einem Buchstaben oder einer Ziffer beginnen. Sie können Bindestriche („-“) enthalten und bis zu 35 Zeichen lang sein.

326 Zeilen
7.5 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:'',
  34. hidden:false
  35. },
  36. qrcodeH: function () {
  37. var that = this;
  38. let memberId = that.data.memberId;
  39. if (memberId) {
  40. wx.navigateTo({
  41. url: '/pages/specialcourtesy/specialcourtesy'
  42. })
  43. }
  44. },
  45. goback: function () {
  46. wx.switchTab({
  47. url: '/index/index',
  48. })
  49. },
  50. onLoad: function (options) {
  51. let that = this;
  52. var todayDate = new Date().getTime();
  53. that.getPoints();
  54. that.setData({
  55. optionsData: options,
  56. todayDate: todayDate
  57. })
  58. if (options && options.from == 'myhtml') {
  59. that.getmyList();
  60. }
  61. else {
  62. that.getList(1);
  63. that.setData({
  64. lists: null
  65. })
  66. }
  67. },
  68. onShow() {
  69. let that = this;
  70. if (this.data.reloadIf) {
  71. wx.setNavigationBarTitle({
  72. title: '积分商城'
  73. })
  74. that.getList(1);
  75. that.setData({
  76. lists: null
  77. })
  78. };
  79. Http.get({
  80. url: config.api.getScore,
  81. data: {}
  82. }).then(res => {
  83. if (res.data.address && res.data.name && res.data.sex && res.data.birthdate) {
  84. that.setData({
  85. showEdit: true
  86. })
  87. }
  88. that.setData({
  89. score: res.data.score,
  90. levelName: res.data.levelName,
  91. upgradePercent: res.data.upgradePercent,
  92. upgradeScore: res.data.upgradeScore,
  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. .catch(err => {
  103. wx.showModal({
  104. title: '提示',
  105. content: err.message,
  106. showCancel: false
  107. })
  108. })
  109. },
  110. //适配不同屏幕大小的canvas
  111. setCanvasSize: function () {
  112. var size = {};
  113. try {
  114. var res = wx.getSystemInfoSync();
  115. var scale = 750 / 500;
  116. //不同屏幕下canvas的适配比例;设计稿是750宽
  117. var width = res.windowWidth / scale;
  118. var height = width;
  119. //canvas画布为正方形
  120. size.w = width;
  121. size.h = height;
  122. } catch (e) {
  123. // Do something when catch error
  124. console.log("获取设备信息失败" + e);
  125. }
  126. return size;
  127. },
  128. createQrCode: function (url, canvasId, cavW, cavH) {
  129. //调用插件中的draw方法,绘制二维码图片
  130. QR.api.draw(url, canvasId, cavW, cavH);
  131. },
  132. qrcode: function (e) {
  133. var that = this;
  134. that.setData({
  135. showQrcode: true
  136. })
  137. wx.showToast({
  138. title: '生成中...',
  139. icon: 'loading',
  140. duration: 2000
  141. });
  142. var st = setTimeout(function () {
  143. wx.hideToast()
  144. var size = that.setCanvasSize();
  145. var url = JSON.stringify({
  146. END: "C",
  147. TYPE: "memberCode",
  148. ID: that.data.memberId,
  149. })
  150. that.createQrCode(url, "mycanvas1", size.w, size.h);
  151. that.setData({
  152. maskHidden: true
  153. });
  154. clearTimeout(st);
  155. }, 1000)
  156. },
  157. // 获得积分,渲染页面
  158. getPoints(){
  159. let that = this;
  160. Http.get({
  161. url: config.api.integralList,
  162. data: {
  163. pageNum: 1,
  164. pageSize: 1,
  165. }
  166. }).then(res => {
  167. wx.stopPullDownRefresh();
  168. that.setData({
  169. creditAmount: res.data.list[0].creditAmount,
  170. });
  171. })
  172. .catch(err => {
  173. wx.stopPullDownRefresh();
  174. wx.showToast({
  175. title: err.errMsg,
  176. icon: 'none',
  177. duration: 2000,
  178. mask: false
  179. });
  180. })
  181. },
  182. gotojifen(){
  183. wx.navigateTo({
  184. url: '/pages/integralmall/integraHistory/index',
  185. })
  186. },
  187. //我可换购
  188. canSort(){
  189. },
  190. //所需积分
  191. need: function (e) {
  192. console.log(this.data.hidden)
  193. var that = this;
  194. var hid = this.data.hidden;
  195. if (hid == true) {
  196. hid = false;
  197. that.setData({
  198. sort :imgurl.up.url
  199. })
  200. }
  201. else {
  202. hid = true;
  203. that.setData({
  204. sort: imgurl.down.url
  205. })
  206. }
  207. this.setData({
  208. hidden: hid // 改变状态
  209. })
  210. },
  211. //sortColumn=shopNumber&sortOrder=desc
  212. getList(pageNum) {
  213. var that = this;
  214. if (that.data.allow_load) {
  215. that.setData({
  216. loading: true,
  217. content: '小主,我在玩命加载中...'
  218. })
  219. var param = {};
  220. var param = {
  221. pageNum: pageNum,
  222. pageSize: 10,
  223. targetAd: 50
  224. };
  225. var url = config.api.couponChannelList;
  226. // 请求接口
  227. Http.get({
  228. url: url,
  229. data: param
  230. }).then(res => {
  231. console.log(res)
  232. /**
  233. * 加载完成
  234. */
  235. if (pageNum >= res.data.pages) {
  236. if (res.data.pages == 0 || res.data.pages == 1) {
  237. that.setData({
  238. allow_load: true,
  239. loading: false,
  240. content: ""
  241. });
  242. } else {
  243. that.setData({
  244. allow_load: false,
  245. loading: true,
  246. content: "——— 再拉裤子就掉了啦 ———",
  247. });
  248. }
  249. }
  250. if (pageNum == 1) {
  251. that.setData({
  252. lists: [],
  253. })
  254. }
  255. var tmpArr = that.data.lists;
  256. tmpArr.push.apply(tmpArr, res.data.list);
  257. that.setData({
  258. lists: tmpArr
  259. })
  260. wx.stopPullDownRefresh();
  261. })
  262. .catch(err => {
  263. wx.stopPullDownRefresh();
  264. wx.showToast({
  265. title: err.message,
  266. icon: 'none',
  267. duration: 2000,
  268. mask: false
  269. });
  270. })
  271. setTimeout(function () {
  272. that.setData({
  273. loading: false,
  274. })
  275. }, 1400);
  276. } else {
  277. that.setData({
  278. loading: true,
  279. content: "——— 再拉裤子就掉了啦 ———"
  280. })
  281. setTimeout(function () {
  282. that.setData({
  283. loading: false,
  284. })
  285. }, 1400)
  286. }
  287. },
  288. /**
  289. *
  290. * @param goto拼团券详情
  291. */
  292. invite: function (e) {
  293. let couponChannelId = e.currentTarget.dataset.id;
  294. let couponId = e.currentTarget.dataset.couponid;
  295. if (couponChannelId && couponId) {
  296. wx.navigateTo({
  297. url: `/pages/coupon/detail/index?couponChannelId=${couponChannelId}&couponId=${couponId}`
  298. })
  299. }
  300. },
  301. //加载更多
  302. onReachBottom: function () {
  303. let that = this;
  304. that.data.page++;
  305. that.setData({
  306. page: that.data.page
  307. });
  308. that.getList(that.data.page, that.data.flag);
  309. },
  310. /**
  311. * 刷新
  312. */
  313. onPullDownRefresh: function (e) {
  314. let that = this;
  315. that.getList(1);
  316. that.getPoints();
  317. that.setData({
  318. sort : ''
  319. })
  320. }
  321. })