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.

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