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.

257 lines
6.0 KiB

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