C端小程序
Nie możesz wybrać więcej, niż 25 tematów Tematy muszą się zaczynać od litery lub cyfry, mogą zawierać myślniki ('-') i mogą mieć do 35 znaków.

404 wiersze
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. console.log('goSetAvatar');
  161. wx.navigateTo({
  162. url: '/pages3/setUserInfo/index'
  163. })
  164. },
  165. onLoad() {
  166. // this.getLocation();
  167. this.updateScene();
  168. // this.getRoomId();
  169. // this.getRoomList();
  170. console.log(wx.getExtConfigSync())
  171. },
  172. //获取房间列表
  173. getRoomList() {
  174. Http.get({
  175. url: config.api.getRoomList,
  176. data: {
  177. token: app.globalData.token,
  178. appId: config.weapp.AppId
  179. }
  180. }).then(res => {
  181. console.log(res)
  182. })
  183. },
  184. getRoomId() {
  185. let roomId = [3] // 填写具体的房间号,可通过下面【获取直播房间列表】 API 获取
  186. let customParams = encodeURIComponent(JSON.stringify({
  187. path: 'pages/index/index',
  188. pid: 1
  189. })) // 开发者在直播间页面路径上携带自定义参数(如示例中的path和pid参数),后续可以在分享卡片链接和跳转至商详页时获取,详见【获取自定义参数】、【直播间到商详页面携带参数】章节(上限600个字符,超过部分会被截断)
  190. console.log(customParams, 777777777)
  191. this.setData({
  192. roomId,
  193. customParams
  194. })
  195. },
  196. /**
  197. * 获得经纬度
  198. */
  199. // getLocation() {
  200. // let that = this;
  201. // wx.getLocation({
  202. // type: "wgs84",
  203. // success: function(res) {
  204. // console.log(res)
  205. // if (res && res.longitude && res.latitude) {
  206. // Http.post({
  207. // url: config.api.updateLBS,
  208. // data: {
  209. // latitude: res.latitude,
  210. // longitude: res.longitude
  211. // }
  212. // }).then(res => {
  213. // console.log(res)
  214. // })
  215. // }
  216. // },
  217. // fail: error => {
  218. // console.log(error);
  219. // }
  220. // })
  221. // },
  222. /**
  223. * 用户更新scene
  224. */
  225. updateScene() {
  226. Http.post({
  227. url: config.api.updateScene,
  228. data: {
  229. scene: app.globalData.scene
  230. }
  231. }).then(res => {
  232. console.log(res)
  233. })
  234. },
  235. /**
  236. * 生命周期函数--监听页面显示
  237. */
  238. onShow: function () {
  239. if (businessSwitch) {
  240. let openId = wx.getStorageSync("openId")
  241. this.setData({
  242. goUrl: `plugin://auto-points-plugin/index?openid=${openId}&mch_id=${this.data.mch_id}`
  243. })
  244. }
  245. console.log(this.data.goUrl)
  246. let that = this;
  247. that.userAuthorization()
  248. if (typeof that.getTabBar === 'function' &&
  249. that.getTabBar()) {
  250. if (ifStoreApp == 1) {
  251. that.getTabBar().setData({
  252. selected: 1
  253. })
  254. } else if (ifStoreApp == 2) {
  255. that.getTabBar().setData({
  256. selected: 2
  257. })
  258. } else {
  259. that.getTabBar().setData({
  260. selected: 3,
  261. })
  262. }
  263. }
  264. that.setData({
  265. appVersion: extConfig.appVersion,
  266. })
  267. /**
  268. * couponNum
  269. * couponNum2
  270. */
  271. let num = wx.getStorageSync('couponNum');
  272. let num1 = wx.getStorageSync('couponNum2');
  273. // wx.hideTabBarRedDot({
  274. // index: 3
  275. // });
  276. if (num == 'couponNum1') {
  277. wx.setStorage({
  278. key: 'couponNum',
  279. data: "couponNum1",
  280. })
  281. that.setData({
  282. couponNum: "couponNum1"
  283. })
  284. } else if (num == 'couponNum') {
  285. that.setData({
  286. couponNum: "couponNum"
  287. })
  288. };
  289. if (num1 == 'couponNum3') {
  290. wx.setStorage({
  291. key: 'couponNum2',
  292. data: "couponNum3",
  293. })
  294. that.setData({
  295. couponNum2: "couponNum3"
  296. })
  297. } else if (num1 == 'couponNum2') {
  298. that.setData({
  299. couponNum2: "couponNum2"
  300. });
  301. };
  302. Http.get({
  303. url: config.api.getScore,
  304. data: {}
  305. }).then(res => {
  306. if (res.data.address && res.data.name && res.data.sex && res.data.birthdate) {
  307. that.setData({
  308. showEdit: true
  309. })
  310. }
  311. let curPhone = res.data.phone ? res.data.phone : '';
  312. if (curPhone) {
  313. let curPhoneList = curPhone.split('');
  314. let curPhoneList01 = [];
  315. curPhoneList.forEach((item, index) => {
  316. if (index >= 3 && index <= 6) {
  317. item = '*';
  318. }
  319. curPhoneList01.push(item);
  320. })
  321. curPhone = curPhoneList01.join('');
  322. }
  323. that.setData({
  324. score: res.data.score,
  325. credit: res.data.credit,
  326. curPhone: curPhone,
  327. levelName: res.data.levelName,
  328. userId: res.data.userId,
  329. userAvatarUrl: res.data.avatarUrl,
  330. userName: res.data.nickName
  331. })
  332. if (res.data.nickName) {
  333. that.setData({
  334. ismember: true,
  335. memberId: res.data.id
  336. })
  337. var size = this.setCanvasSize();
  338. var initUrl = JSON.stringify({
  339. flagid: res.data.id
  340. });
  341. }
  342. })
  343. .catch(err => {
  344. wx.showModal({
  345. title: '提示',
  346. content: err.errMsg,
  347. showCancel: false
  348. })
  349. })
  350. //暂时注释
  351. // that.getrun();
  352. //查询关于我们
  353. Http.get({
  354. url: config.api.getMallInfo,
  355. data: {}
  356. }).then(res => {
  357. if (res.code == 200) {
  358. this.setData({
  359. memberName: res.data.name,
  360. memberLogo: res.data.imgUrlH
  361. })
  362. }
  363. if (res.data.businessHours !== '[]') {
  364. that.setData({
  365. aboutShow: true
  366. })
  367. } else {
  368. that.setData({
  369. aboutShow: false
  370. })
  371. }
  372. })
  373. .catch(err => { })
  374. },
  375. //适配不同屏幕大小的canvas
  376. setCanvasSize: function () {
  377. var size = {};
  378. try {
  379. var res = wx.getSystemInfoSync();
  380. var scale = 750 / 500;
  381. //不同屏幕下canvas的适配比例;设计稿是750宽
  382. var width = res.windowWidth / scale;
  383. var height = width;
  384. //canvas画布为正方形
  385. size.w = width;
  386. size.h = height;
  387. } catch (e) {
  388. // Do something when catch error
  389. console.log("获取设备信息失败" + e);
  390. }
  391. return size;
  392. },
  393. });