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.

338 lines
8.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. arrays:[],
  22. myLists: [],
  23. page: 1, // 设置加载的第几次,默认是第一次
  24. pageSize: 10, //返回数据的个数
  25. searchLoadingComplete: false, //“没有数据”的变量,默认false,隐藏
  26. allow_load: true, // 是否允许继续加载标识 默认 true 允许,false 加载完成
  27. myorder: false,
  28. actUrl: imgurl.act.url,
  29. loading: true,
  30. content: '数据正在加载中',
  31. reloadIf: false,
  32. creditAmount: 0,
  33. score: '0',
  34. sort:'',
  35. hidden:false,
  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: function () {
  193. console.log(this.data.hidden)
  194. var that = this;
  195. var hid = this.data.hidden;
  196. if (hid == true) {
  197. hid = false;
  198. that.setData({
  199. sort :imgurl.up.url
  200. })
  201. that.getList(1, 'creditPrice', 'desc')
  202. }
  203. else {
  204. hid = true;
  205. that.setData({
  206. sort: imgurl.down.url
  207. })
  208. that.getList(1, 'creditPrice', 'asc')
  209. }
  210. this.setData({
  211. hidden: hid // 改变状态
  212. })
  213. },
  214. getList(pageNum, sortColumn, sortOrder) {
  215. var that = this;
  216. if (that.data.allow_load) {
  217. that.setData({
  218. loading: true,
  219. content: '小主,我在玩命加载中...'
  220. })
  221. var param = {
  222. pageNum: pageNum,
  223. pageSize: 10,
  224. targetAd: 50,
  225. sortColumn: sortColumn,
  226. sortOrder: sortOrder
  227. };
  228. var url = config.api.couponChannelList;
  229. // 请求接口
  230. Http.get({
  231. url: url,
  232. data: param,
  233. }).then(res => {
  234. console.log(res)
  235. console.log(this.data.creditAmount)
  236. /**
  237. * 加载完成
  238. */
  239. if (pageNum >= res.data.pages) {
  240. if (res.data.pages == 0 || res.data.pages == 1) {
  241. that.setData({
  242. allow_load: true,
  243. loading: false,
  244. content: ""
  245. });
  246. } else {
  247. that.setData({
  248. allow_load: false,
  249. loading: true,
  250. content: "——— 再拉裤子就掉了啦 ———",
  251. });
  252. }
  253. }
  254. if (pageNum == 1) {
  255. that.setData({
  256. lists: [],
  257. })
  258. }
  259. var tmpArr = that.data.lists;
  260. // tmpArr = [...tmpArr, ...res.data.list];
  261. tmpArr.push.apply(tmpArr, res.data.list);
  262. that.setData({
  263. lists: tmpArr
  264. })
  265. // tmpArr.map(file => {
  266. // if (file.creditPrice <= that.data.creditAmount) {
  267. // that.data.arrays.push(file);
  268. // }
  269. // })
  270. // console.log(that.data.arrays)
  271. wx.stopPullDownRefresh();
  272. })
  273. .catch(err => {
  274. wx.stopPullDownRefresh();
  275. wx.showToast({
  276. title: err.message,
  277. icon: 'none',
  278. duration: 2000,
  279. mask: false
  280. });
  281. })
  282. setTimeout(function () {
  283. that.setData({
  284. loading: false,
  285. })
  286. }, 1400);
  287. } else {
  288. that.setData({
  289. loading: true,
  290. content: "——— 再拉裤子就掉了啦 ———"
  291. })
  292. setTimeout(function () {
  293. that.setData({
  294. loading: false,
  295. })
  296. }, 1400)
  297. }
  298. },
  299. /**
  300. *
  301. * @param goto拼团券详情
  302. */
  303. invite: function (e) {
  304. let couponChannelId = e.currentTarget.dataset.id;
  305. let couponId = e.currentTarget.dataset.couponid;
  306. if (couponChannelId && couponId) {
  307. wx.navigateTo({
  308. url: `/pages/coupon/detail/index?couponChannelId=${couponChannelId}&couponId=${couponId}`
  309. })
  310. }
  311. },
  312. //加载更多
  313. onReachBottom: function () {
  314. let that = this;
  315. that.data.page++;
  316. that.setData({
  317. page: that.data.page
  318. });
  319. that.getList(that.data.page, that.data.flag);
  320. },
  321. /**
  322. * 刷新
  323. */
  324. onPullDownRefresh: function (e) {
  325. let that = this;
  326. that.getList(1);
  327. that.getPoints();
  328. that.setData({
  329. sort : ''
  330. })
  331. }
  332. })