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.

236 line
5.6 KiB

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