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.

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