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