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.

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