C端小程序
您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

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