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.

223 line
5.2 KiB

  1. var config = require("../../config/config.js");
  2. var app = getApp();
  3. const Http = require("../../utils/HttpBasics");
  4. const QR = require("../../utils/memberqrcode.js");
  5. const imgurl = require("../../utils/imgurl");
  6. Page({
  7. /**
  8. * 页面的初始数据
  9. */
  10. data: {
  11. bannerUrl: imgurl.banner.url,
  12. redirectUrl: imgurl.redirect.url,
  13. qrcodeUrl: imgurl.qrcode.url,
  14. editUrl: imgurl.edit.url,
  15. activeUrl: imgurl.active.url,
  16. dingUrl: imgurl.ding.url,
  17. quansUrl: imgurl.quans.url,
  18. cardiconUrl: imgurl.cardicon.url,
  19. cheUrl: imgurl.che.url,
  20. giftUrl: imgurl.gift.url,
  21. canIUse: wx.canIUse('official-account'),
  22. flag: 'hidden',
  23. score:'0',
  24. name:"",
  25. birthdate:"",
  26. sex:"",
  27. showEdit:false,
  28. ismember:false,
  29. showQrcode:false,
  30. canvasHidden: false,
  31. maskHidden: true,
  32. imagePath: '',
  33. showmemberqrcode: false,
  34. placeholder: ''//默认二维码生成文本
  35. },
  36. /**
  37. * 跳转到成长值的页面
  38. */
  39. gotograde:function(){
  40. wx.navigateTo({
  41. url: '/pages/czdetail/czdetail',
  42. })
  43. },
  44. // getrun:function(){
  45. // let that = this;
  46. // wx.getWeRunData({
  47. // success: function (res) {
  48. // Http.post({
  49. // url: config.api.getWeRunData,
  50. // data: {
  51. // encryptedData: res.encryptedData,
  52. // iv: res.iv
  53. // }
  54. // }).then(res => {
  55. // that.setData({
  56. // step: res.data.stepInfoList[30].step
  57. // })
  58. // })
  59. // }
  60. // })
  61. // },
  62. /**
  63. *
  64. */
  65. // getxinghao:function(){
  66. // wx.getSystemInfo({
  67. // success:function(res){
  68. // wx.showModal({
  69. // content: res.brand,
  70. // })
  71. // }
  72. // })
  73. // },
  74. navigateTo() {
  75. wx.navigateTo({
  76. url: `/pages/login/index`
  77. });
  78. },
  79. showVersion: function() {
  80. /**
  81. * 长按显示版本号
  82. */
  83. let that = this;
  84. if (that.data.flag == 'hidden') {
  85. that.setData({
  86. flag: 'show'
  87. });
  88. }
  89. },
  90. gotoedit:function(){
  91. wx.navigateTo({
  92. url: '/pages/edit/edit',
  93. })
  94. },
  95. /**
  96. * 生命周期函数--监听页面显示
  97. */
  98. onShow: function() {
  99. let that = this;
  100. let num = wx.getStorageSync('couponNum');
  101. wx.hideTabBarRedDot({
  102. index: 2
  103. });
  104. if (num == 'couponNum1') {
  105. wx.setStorage({
  106. key: 'couponNum',
  107. data: "couponNum1",
  108. })
  109. that.setData({
  110. couponNum: "couponNum1"
  111. })
  112. } else if (num == 'couponNum') {
  113. that.setData({
  114. couponNum: "couponNum"
  115. })
  116. };
  117. Http.get({
  118. url: config.api.getScore,
  119. data: {}
  120. }).then(res=>{
  121. if (res.data.address && res.data.name && res.data.sex && res.data.birthdate){
  122. that.setData({
  123. showEdit:true
  124. })
  125. }
  126. that.setData({
  127. score: res.data.score,
  128. levelName: res.data.levelName,
  129. })
  130. if (res.data.nickName){
  131. that.setData({
  132. ismember:true,
  133. memberId: res.data.id
  134. })
  135. var size = this.setCanvasSize();
  136. var initUrl = JSON.stringify({flagid:res.data.id});
  137. that.createQrCode(initUrl, "mycanvas1", size.w, size.h);
  138. }
  139. })
  140. .catch(err => {
  141. wx.showModal({
  142. title: '提示',
  143. content: err.errMsg,
  144. showCancel:false
  145. })
  146. })
  147. //暂时注释
  148. // that.getrun();
  149. // 判断是否显示特享礼遇
  150. Http.get({
  151. url: config.api.scoreLevelInfo,
  152. data: {}
  153. })
  154. .then(res=>{
  155. // if true 则开启特享礼遇
  156. if (res.data.discountEnable){
  157. that.setData({
  158. discountEnable:true
  159. })
  160. }
  161. else{
  162. that.setData({
  163. discountEnable: false
  164. })
  165. }
  166. })
  167. },
  168. hideQrcode:function(){
  169. let that = this;
  170. that.setData({
  171. showQrcode: false
  172. })
  173. },
  174. //适配不同屏幕大小的canvas
  175. setCanvasSize: function () {
  176. var size = {};
  177. try {
  178. var res = wx.getSystemInfoSync();
  179. var scale = 750 / 500;
  180. //不同屏幕下canvas的适配比例;设计稿是750宽
  181. var width = res.windowWidth / scale;
  182. var height = width;
  183. //canvas画布为正方形
  184. size.w = width;
  185. size.h = height;
  186. } catch (e) {
  187. // Do something when catch error
  188. console.log("获取设备信息失败" + e);
  189. }
  190. return size;
  191. },
  192. createQrCode: function (url, canvasId, cavW, cavH) {
  193. //调用插件中的draw方法,绘制二维码图片
  194. QR.api.draw(url, canvasId, cavW, cavH);
  195. },
  196. qrcode: function (e) {
  197. var that = this;
  198. that.setData({
  199. showQrcode:true
  200. })
  201. wx.showToast({
  202. title: '生成中...',
  203. icon: 'loading',
  204. duration: 2000
  205. });
  206. var st = setTimeout(function () {
  207. wx.hideToast()
  208. var size = that.setCanvasSize();
  209. var url = JSON.stringify({ flagid:that.data.memberId});
  210. that.createQrCode(url, "mycanvas1", size.w, size.h);
  211. that.setData({
  212. maskHidden: true
  213. });
  214. clearTimeout(st);
  215. }, 1000)
  216. },
  217. close: function () {
  218. this.setData({
  219. showmemberqrcode: false,
  220. })
  221. }
  222. });