C端小程序
Não pode escolher mais do que 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.

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