C端小程序
選択できるのは25トピックまでです。 トピックは、先頭が英数字で、英数字とダッシュ('-')を使用した35文字以内のものにしてください。

351 行
8.2 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. userCredit: that.data.creditAmount,
  197. })
  198. that.getList(1)
  199. }
  200. if (that.data.creditAmount == 0){
  201. wx.showToast({
  202. title: '快去补充积分吧!',
  203. icon: 'none',
  204. duration: 2000,
  205. mask: false
  206. });
  207. }
  208. },
  209. //所需积分
  210. need: function () {
  211. var that = this;
  212. var hid = this.data.hidden;
  213. if (hid == true) {
  214. hid = false;
  215. that.setData({
  216. sort :imgurl.up.url,
  217. sortOrder: 'desc',
  218. sortColumn: 'creditPrice'
  219. })
  220. that.getList(1)
  221. }
  222. else {
  223. hid = true;
  224. that.setData({
  225. sort: imgurl.down.url,
  226. sortOrder: 'asc',
  227. sortColumn: 'creditPrice'
  228. })
  229. that.getList(1)
  230. }
  231. this.setData({
  232. hidden: hid // 改变状态
  233. })
  234. },
  235. getList(pageNum) {
  236. var that = this;
  237. if (that.data.allow_load) {
  238. that.setData({
  239. loading: true,
  240. content: '小主,我在玩命加载中...'
  241. })
  242. var param = {
  243. pageNum: pageNum,
  244. pageSize: 10,
  245. targetAd: 50,
  246. sortColumn: that.data.sortColumn,
  247. sortOrder: that.data.sortOrder,
  248. userCredit: that.data.userCredit
  249. };
  250. var url = config.api.couponChannelList;
  251. // 请求接口
  252. Http.get({
  253. url: url,
  254. data: param,
  255. }).then(res => {
  256. console.log(res)
  257. /**
  258. * 加载完成
  259. */
  260. if (pageNum >= res.data.pages) {
  261. if (res.data.pages == 0 || res.data.pages == 1) {
  262. that.setData({
  263. allow_load: true,
  264. loading: false,
  265. content: ""
  266. });
  267. } else {
  268. that.setData({
  269. allow_load: false,
  270. loading: true,
  271. content: "——— 再拉裤子就掉了啦 ———",
  272. });
  273. }
  274. }
  275. if (pageNum == 1) {
  276. that.setData({
  277. lists: [],
  278. })
  279. }
  280. var tmpArr = that.data.lists;
  281. // tmpArr = [...tmpArr, ...res.data.list];
  282. tmpArr.push.apply(tmpArr, res.data.list);
  283. that.setData({
  284. lists: tmpArr
  285. })
  286. wx.stopPullDownRefresh();
  287. })
  288. .catch(err => {
  289. wx.stopPullDownRefresh();
  290. wx.showToast({
  291. title: err.message,
  292. icon: 'none',
  293. duration: 2000,
  294. mask: false
  295. });
  296. })
  297. setTimeout(function () {
  298. that.setData({
  299. loading: false,
  300. })
  301. }, 1400);
  302. } else {
  303. that.setData({
  304. loading: true,
  305. content: "——— 再拉裤子就掉了啦 ———"
  306. })
  307. setTimeout(function () {
  308. that.setData({
  309. loading: false,
  310. })
  311. }, 1400)
  312. }
  313. },
  314. /**
  315. *
  316. * @param goto拼团券详情
  317. */
  318. invite: function (e) {
  319. let couponChannelId = e.currentTarget.dataset.id;
  320. let couponId = e.currentTarget.dataset.couponid;
  321. if (couponChannelId && couponId) {
  322. wx.navigateTo({
  323. url: `/pages/coupon/detail/index?couponChannelId=${couponChannelId}&couponId=${couponId}`
  324. })
  325. }
  326. },
  327. //加载更多
  328. onReachBottom: function () {
  329. let that = this;
  330. that.data.page++;
  331. that.setData({
  332. page: that.data.page
  333. });
  334. that.getList(that.data.page, that.data.flag);
  335. },
  336. /**
  337. * 刷新
  338. */
  339. onPullDownRefresh: function (e) {
  340. let that = this;
  341. that.setData({
  342. sort: '',
  343. sortColumn: '',
  344. sortOrder: '',
  345. userCredit: ''
  346. })
  347. that.getList(1);
  348. that.getPoints();
  349. }
  350. })