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.

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