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.

238 line
5.6 KiB

  1. const extConfig = wx.getExtConfigSync ? wx.getExtConfigSync() : {}
  2. let appVersion;
  3. if (Object.keys(extConfig).length == 0) {
  4. appVersion = 'C.3.3.8';
  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. console.log(extConfig.appVersion)
  107. console.log(appVersion)
  108. that.setData({
  109. appVersion: extConfig.appVersion ? extConfig.appVersion : appVersion
  110. })
  111. let num = wx.getStorageSync('couponNum');
  112. let num1 = wx.getStorageSync('couponNum2');
  113. wx.hideTabBarRedDot({
  114. index: 2
  115. });
  116. wx.hideTabBarRedDot({
  117. index: 3
  118. });
  119. if (num == 'couponNum1') {
  120. wx.setStorage({
  121. key: 'couponNum',
  122. data: "couponNum1",
  123. })
  124. that.setData({
  125. couponNum: "couponNum1"
  126. })
  127. } else if (num == 'couponNum') {
  128. that.setData({
  129. couponNum: "couponNum"
  130. })
  131. };
  132. if (num1 == 'couponNum3') {
  133. wx.setStorage({
  134. key: 'couponNum2',
  135. data: "couponNum3",
  136. })
  137. that.setData({
  138. couponNum2: "couponNum3"
  139. })
  140. } else if (num1 == 'couponNum2') {
  141. that.setData({
  142. couponNum2: "couponNum2"
  143. })
  144. };
  145. Http.get({
  146. url: config.api.getScore,
  147. data: {}
  148. }).then(res=>{
  149. if (res.data.address && res.data.name && res.data.sex && res.data.birthdate){
  150. that.setData({
  151. showEdit:true
  152. })
  153. }
  154. that.setData({
  155. score: res.data.score,
  156. levelName: res.data.levelName,
  157. })
  158. if (res.data.nickName){
  159. that.setData({
  160. ismember:true,
  161. memberId: res.data.id
  162. })
  163. var size = this.setCanvasSize();
  164. var initUrl = JSON.stringify({flagid:res.data.id});
  165. that.createQrCode(initUrl, "mycanvas1", size.w, size.h);
  166. }
  167. })
  168. .catch(err => {
  169. wx.showModal({
  170. title: '提示',
  171. content: err.errMsg,
  172. showCancel:false
  173. })
  174. })
  175. //暂时注释
  176. // that.getrun();
  177. },
  178. hideQrcode:function(){
  179. let that = this;
  180. that.setData({
  181. showQrcode: false
  182. })
  183. },
  184. //适配不同屏幕大小的canvas
  185. setCanvasSize: function () {
  186. var size = {};
  187. try {
  188. var res = wx.getSystemInfoSync();
  189. var scale = 750 / 500;
  190. //不同屏幕下canvas的适配比例;设计稿是750宽
  191. var width = res.windowWidth / scale;
  192. var height = width;
  193. //canvas画布为正方形
  194. size.w = width;
  195. size.h = height;
  196. } catch (e) {
  197. // Do something when catch error
  198. console.log("获取设备信息失败" + e);
  199. }
  200. return size;
  201. },
  202. createQrCode: function (url, canvasId, cavW, cavH) {
  203. //调用插件中的draw方法,绘制二维码图片
  204. QR.api.draw(url, canvasId, cavW, cavH);
  205. },
  206. qrcode: function (e) {
  207. var that = this;
  208. that.setData({
  209. showQrcode:true
  210. })
  211. wx.showToast({
  212. title: '生成中...',
  213. icon: 'loading',
  214. duration: 2000
  215. });
  216. var st = setTimeout(function () {
  217. wx.hideToast()
  218. var size = that.setCanvasSize();
  219. var url = JSON.stringify({
  220. END:"C",
  221. TYPE:"memberCode",
  222. ID: that.data.memberId,
  223. })
  224. that.createQrCode(url, "mycanvas1", size.w, size.h);
  225. that.setData({
  226. maskHidden: true
  227. });
  228. clearTimeout(st);
  229. }, 1000)
  230. },
  231. close: function () {
  232. this.setData({
  233. showmemberqrcode: false,
  234. })
  235. }
  236. });