C端小程序
25개 이상의 토픽을 선택하실 수 없습니다. Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

418 lines
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.creditProductList;
  293. // var url = config.api.couponChannelList;
  294. // 请求接口
  295. Http.get({
  296. url: url,
  297. data: param,
  298. }).then(res => {
  299. console.log(res)
  300. /**
  301. * 加载完成
  302. */
  303. if (pageNum >= res.data.pages) {
  304. if (res.data.pages == 0) {
  305. that.setData({
  306. allow_load: true,
  307. loading: false,
  308. content: ""
  309. });
  310. } else {
  311. that.setData({
  312. allow_load: false,
  313. loading: true,
  314. content: "——— 再拉裤子就掉了啦 ———",
  315. });
  316. }
  317. }
  318. if (pageNum == 1) {
  319. that.setData({
  320. lists: [],
  321. })
  322. }
  323. var tmpArr = that.data.lists || [];
  324. // tmpArr = [...tmpArr, ...res.data.list];
  325. tmpArr.push.apply(tmpArr, res.data.list);
  326. that.setData({
  327. lists: tmpArr
  328. })
  329. wx.stopPullDownRefresh();
  330. })
  331. .catch(err => {
  332. wx.stopPullDownRefresh();
  333. wx.showToast({
  334. title: err.message,
  335. icon: 'none',
  336. duration: 2000,
  337. mask: false
  338. });
  339. })
  340. setTimeout(function () {
  341. that.setData({
  342. loading: false,
  343. })
  344. }, 1400);
  345. } else {
  346. that.setData({
  347. loading: true,
  348. content: "——— 再拉裤子就掉了啦 ———"
  349. })
  350. setTimeout(function () {
  351. that.setData({
  352. loading: false,
  353. })
  354. }, 1400)
  355. }
  356. },
  357. checkUserPhone() {
  358. const that = this
  359. Http.get({
  360. url: config.api.checkPhoneStatus
  361. }).then(res => {
  362. that.setData({
  363. isPhone: true
  364. })
  365. console.log(this.data.isPhone, 'isPhone');
  366. }).catch(err => {
  367. that.setData({
  368. isPhone: false
  369. })
  370. console.log(this.data.isPhone, 'isPhone');
  371. })
  372. },
  373. /**
  374. *
  375. * @param goto拼团券详情
  376. */
  377. invite: function (e) {
  378. let couponChannelId = e.currentTarget.dataset.id;
  379. let couponId = e.currentTarget.dataset.couponid;
  380. if (couponChannelId && couponId) {
  381. wx.navigateTo({
  382. url: `/pages/coupon/detail/index?couponChannelId=${couponChannelId}&couponId=${couponId}`
  383. })
  384. }
  385. },
  386. //加载更多
  387. onReachBottom: function () {
  388. let that = this;
  389. that.data.page++;
  390. that.setData({
  391. page: that.data.page
  392. });
  393. that.getList(that.data.page, that.data.flag);
  394. },
  395. /**
  396. * 刷新
  397. */
  398. onPullDownRefresh: function (e) {
  399. let that = this;
  400. that.setData({
  401. sort: '',
  402. sortColumn: '',
  403. sortOrder: '',
  404. userCredit: '',
  405. page: 1,
  406. allow_load: true,
  407. })
  408. that.getList(1);
  409. that.getPoints();
  410. }
  411. })