C端小程序
No puede seleccionar más de 25 temas Los temas deben comenzar con una letra o número, pueden incluir guiones ('-') y pueden tener hasta 35 caracteres de largo.

400 líneas
9.6 KiB

  1. var app = getApp();
  2. const navigationBarHeight = (getApp().statusBarHeight + 44) + 'px'
  3. const extConfig = wx.getExtConfigSync ? wx.getExtConfigSync() : {}
  4. let businessSwitch = extConfig.attr.businessSwitch
  5. let mch_id = extConfig.attr.mchId
  6. let ifStoreApp = extConfig.attr.ifStoreApp;
  7. const Http = require("../utils/HttpBasics");
  8. const imgurl = require("../utils/imgurl");
  9. var config = require("../config/config.js");
  10. const bgColor = require("../utils/bgColor.js")
  11. Page({
  12. /**
  13. * 页面的初始数据
  14. */
  15. data: {
  16. mch_id: mch_id,
  17. businessSwitch:businessSwitch,
  18. goUrl: "",
  19. templateId: [],
  20. aboutShow: false,
  21. navigationBarHeight,
  22. ifStoreApp: ifStoreApp,
  23. aboutUs: imgurl.aboutUs.url,
  24. rqCode: imgurl.barcode.url,
  25. banneColor: bgColor.colorFirst.user.banneColor,
  26. levelBg: bgColor.colorFirst.user.levelBg,
  27. view: bgColor.colorFirst.user.view,
  28. fenxiang: imgurl.fenxiang1.url,
  29. redirectUrl: imgurl.redirect.url,
  30. editUrl: imgurl.edit.url,
  31. activeUrl: imgurl.active.url,
  32. dingUrl: imgurl.ding.url,
  33. duihuan: imgurl.duihuan.url,
  34. shoppingAtlas: imgurl.shoppingAtlas.url,
  35. quansUrl: imgurl.quans.url,
  36. wmintegral: imgurl.wmintegral.url,
  37. cardiconUrl: imgurl.cardicon.url,
  38. myactivitygift: imgurl.myactivitygift.url,
  39. myactivity: imgurl.myactivity.url,
  40. cheUrl: imgurl.che.url,
  41. giftUrl: imgurl.gift.url,
  42. wmbarginicon: imgurl.wmbarginicon.url,
  43. wmspellgroup: imgurl.wmspellgroup.url,
  44. canIUse: wx.canIUse('official-account'),
  45. mineFlag: "",
  46. flag: 'hidden',
  47. score: '0',
  48. credit:'0',
  49. userId:"",
  50. memberName:"",
  51. memberLogo:"",
  52. curPhone: '',
  53. name: "",
  54. birthdate: "",
  55. sex: "",
  56. showEdit: false,
  57. ismember: false,
  58. canvasHidden: false,
  59. maskHidden: true,
  60. imagePath: '',
  61. appVersion: "",
  62. placeholder: '',
  63. userAvatarUrl: "",
  64. userName: "",
  65. },
  66. suerService() {
  67. console.log("打开客服")
  68. wx.openCustomerServiceChat({
  69. extInfo: { url: 'https://work.weixin.qq.com/kfid/kfc7f4a755cbb51fa99' },
  70. corpId: 'wwdc116b631d3ea35f',
  71. success(res) { },
  72. fail(res) {
  73. console.log(res);
  74. }
  75. })
  76. },
  77. checkUserStatus() {
  78. let that = this;
  79. Http.get({
  80. url: config.api.checkPhoneStatus,
  81. data: {}
  82. }).then(res => {
  83. wx.navigateTo({
  84. url: '/pages/edit/edit',
  85. })
  86. }).catch(err => {
  87. wx.navigateTo({
  88. url: `/pages/getphoneInfo/index?mineFlag=mine`,
  89. })
  90. })
  91. },
  92. gotoPhoneInfo() {
  93. /**
  94. * 将值传到用户手机号授权的页面
  95. *
  96. */
  97. wx.navigateTo({
  98. url: `/pages/getphoneInfo/index?path=main`
  99. });
  100. },
  101. //是否授权手机号
  102. ifPhoneInfo() {
  103. let that = this;
  104. Http.get({
  105. url: config.api.checkPhoneStatus,
  106. data: {}
  107. }).then(res => {
  108. return
  109. }).catch(err => {
  110. wx.navigateTo({
  111. url: `/pages/getphoneInfo/index?mineFlag=mine`,
  112. })
  113. })
  114. },
  115. /* 判断是否授权*/
  116. userAuthorization() {
  117. Http.get({
  118. url: config.api.checkUserStatus,
  119. data: {
  120. token: app.globalData.token
  121. }
  122. }).then(res => {
  123. this.ifPhoneInfo()
  124. }).catch(err => {
  125. app.globalData.type = 'uc'
  126. wx.navigateTo({
  127. url: `/pages/getuserinfo/index`,
  128. })
  129. })
  130. },
  131. /**
  132. * 跳转到成长值的页面
  133. */
  134. gotograde: function() {
  135. wx.navigateTo({
  136. url: '/pages/czdetail/czdetail',
  137. })
  138. },
  139. /**
  140. * 跳转到商场信息的页面
  141. */
  142. gomallInfo: function() {
  143. wx.navigateTo({
  144. url: '/pages/mallInfo/mallInfo',
  145. })
  146. },
  147. showVersion: function() {
  148. /**
  149. * 长按显示版本号
  150. */
  151. let that = this;
  152. if (that.data.flag == 'hidden') {
  153. that.setData({
  154. flag: 'show'
  155. });
  156. }
  157. },
  158. gotoedit: function() {
  159. this.checkUserStatus();
  160. },
  161. onLoad() {
  162. // this.getLocation();
  163. this.updateScene();
  164. // this.getRoomId();
  165. // this.getRoomList();
  166. console.log(wx.getExtConfigSync())
  167. },
  168. //获取房间列表
  169. getRoomList() {
  170. Http.get({
  171. url: config.api.getRoomList,
  172. data: {
  173. token: app.globalData.token,
  174. appId: config.weapp.AppId
  175. }
  176. }).then(res => {
  177. console.log(res)
  178. })
  179. },
  180. getRoomId() {
  181. let roomId = [3] // 填写具体的房间号,可通过下面【获取直播房间列表】 API 获取
  182. let customParams = encodeURIComponent(JSON.stringify({
  183. path: 'pages/index/index',
  184. pid: 1
  185. })) // 开发者在直播间页面路径上携带自定义参数(如示例中的path和pid参数),后续可以在分享卡片链接和跳转至商详页时获取,详见【获取自定义参数】、【直播间到商详页面携带参数】章节(上限600个字符,超过部分会被截断)
  186. console.log(customParams, 777777777)
  187. this.setData({
  188. roomId,
  189. customParams
  190. })
  191. },
  192. /**
  193. * 获得经纬度
  194. */
  195. // getLocation() {
  196. // let that = this;
  197. // wx.getLocation({
  198. // type: "wgs84",
  199. // success: function(res) {
  200. // console.log(res)
  201. // if (res && res.longitude && res.latitude) {
  202. // Http.post({
  203. // url: config.api.updateLBS,
  204. // data: {
  205. // latitude: res.latitude,
  206. // longitude: res.longitude
  207. // }
  208. // }).then(res => {
  209. // console.log(res)
  210. // })
  211. // }
  212. // },
  213. // fail: error => {
  214. // console.log(error);
  215. // }
  216. // })
  217. // },
  218. /**
  219. * 用户更新scene
  220. */
  221. updateScene() {
  222. Http.post({
  223. url: config.api.updateScene,
  224. data: {
  225. scene: app.globalData.scene
  226. }
  227. }).then(res => {
  228. console.log(res)
  229. })
  230. },
  231. /**
  232. * 生命周期函数--监听页面显示
  233. */
  234. onShow: function() {
  235. if (businessSwitch){
  236. let openId = wx.getStorageSync("openId")
  237. this.setData({
  238. goUrl: `plugin://auto-points-plugin/index?openid=${openId}&mch_id=${this.data.mch_id}`
  239. })
  240. }
  241. console.log(this.data.goUrl)
  242. let that = this;
  243. that.userAuthorization()
  244. if (typeof that.getTabBar === 'function' &&
  245. that.getTabBar()) {
  246. if (ifStoreApp == 1) {
  247. that.getTabBar().setData({
  248. selected: 1
  249. })
  250. } else if (ifStoreApp == 2) {
  251. that.getTabBar().setData({
  252. selected: 2
  253. })
  254. } else {
  255. that.getTabBar().setData({
  256. selected: 3,
  257. })
  258. }
  259. }
  260. that.setData({
  261. appVersion: extConfig.appVersion,
  262. })
  263. /**
  264. * couponNum
  265. * couponNum2
  266. */
  267. let num = wx.getStorageSync('couponNum');
  268. let num1 = wx.getStorageSync('couponNum2');
  269. // wx.hideTabBarRedDot({
  270. // index: 3
  271. // });
  272. if (num == 'couponNum1') {
  273. wx.setStorage({
  274. key: 'couponNum',
  275. data: "couponNum1",
  276. })
  277. that.setData({
  278. couponNum: "couponNum1"
  279. })
  280. } else if (num == 'couponNum') {
  281. that.setData({
  282. couponNum: "couponNum"
  283. })
  284. };
  285. if (num1 == 'couponNum3') {
  286. wx.setStorage({
  287. key: 'couponNum2',
  288. data: "couponNum3",
  289. })
  290. that.setData({
  291. couponNum2: "couponNum3"
  292. })
  293. } else if (num1 == 'couponNum2') {
  294. that.setData({
  295. couponNum2: "couponNum2"
  296. });
  297. };
  298. Http.get({
  299. url: config.api.getScore,
  300. data: {}
  301. }).then(res => {
  302. if (res.data.address && res.data.name && res.data.sex && res.data.birthdate) {
  303. that.setData({
  304. showEdit: true
  305. })
  306. }
  307. let curPhone = res.data.phone ? res.data.phone : '';
  308. if (curPhone) {
  309. let curPhoneList = curPhone.split('');
  310. let curPhoneList01 = [];
  311. curPhoneList.forEach((item, index) => {
  312. if (index >= 3 && index <= 6) {
  313. item = '*';
  314. }
  315. curPhoneList01.push(item);
  316. })
  317. curPhone = curPhoneList01.join('');
  318. }
  319. that.setData({
  320. score: res.data.score,
  321. credit: res.data.credit,
  322. curPhone: curPhone,
  323. levelName: res.data.levelName,
  324. userId: res.data.userId,
  325. userAvatarUrl: res.data.avatarUrl,
  326. userName: res.data.nickName
  327. })
  328. if (res.data.nickName) {
  329. that.setData({
  330. ismember: true,
  331. memberId: res.data.id
  332. })
  333. var size = this.setCanvasSize();
  334. var initUrl = JSON.stringify({
  335. flagid: res.data.id
  336. });
  337. }
  338. })
  339. .catch(err => {
  340. wx.showModal({
  341. title: '提示',
  342. content: err.errMsg,
  343. showCancel: false
  344. })
  345. })
  346. //暂时注释
  347. // that.getrun();
  348. //查询关于我们
  349. Http.get({
  350. url: config.api.getMallInfo,
  351. data: {}
  352. }).then(res => {
  353. if(res.code==200){
  354. this.setData({
  355. memberName:res.data.name,
  356. memberLogo:res.data.imgUrlH
  357. })
  358. }
  359. if (res.data.businessHours !== '[]') {
  360. that.setData({
  361. aboutShow: true
  362. })
  363. } else {
  364. that.setData({
  365. aboutShow: false
  366. })
  367. }
  368. })
  369. .catch(err => {})
  370. },
  371. //适配不同屏幕大小的canvas
  372. setCanvasSize: function() {
  373. var size = {};
  374. try {
  375. var res = wx.getSystemInfoSync();
  376. var scale = 750 / 500;
  377. //不同屏幕下canvas的适配比例;设计稿是750宽
  378. var width = res.windowWidth / scale;
  379. var height = width;
  380. //canvas画布为正方形
  381. size.w = width;
  382. size.h = height;
  383. } catch (e) {
  384. // Do something when catch error
  385. console.log("获取设备信息失败" + e);
  386. }
  387. return size;
  388. },
  389. });