C端小程序
Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.

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