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.

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