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.

428 line
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') || 0
  241. if (ifSetUserInfo) {
  242. wx.showModal({
  243. title: '完善个人信息',
  244. content: '完善个人信息后可获得积分哦',
  245. showCancel: true,
  246. cancelText: "以后再说",
  247. cancelColor: '',
  248. confirmText: "去完善",
  249. confirmColor: '#FD832D',
  250. complete: (res) => {
  251. if (res.cancel) {
  252. console.log('cancel');
  253. }
  254. if (res.confirm) {
  255. wx.setStorageSync('ifSetUserInfo', 0)
  256. wx.navigateTo({
  257. url: '/pages3/setUserInfo/index',
  258. })
  259. }
  260. }
  261. })
  262. }
  263. if (businessSwitch) {
  264. let openId = wx.getStorageSync("openId")
  265. this.setData({
  266. goUrl: `plugin://auto-points-plugin/index?openid=${openId}&mch_id=${this.data.mch_id}`
  267. })
  268. }
  269. console.log(this.data.goUrl)
  270. let that = this;
  271. that.userAuthorization()
  272. if (typeof that.getTabBar === 'function' &&
  273. that.getTabBar()) {
  274. if (ifStoreApp == 1) {
  275. that.getTabBar().setData({
  276. selected: 1
  277. })
  278. } else if (ifStoreApp == 2) {
  279. that.getTabBar().setData({
  280. selected: 2
  281. })
  282. } else {
  283. that.getTabBar().setData({
  284. selected: 3,
  285. })
  286. }
  287. }
  288. that.setData({
  289. appVersion: extConfig.appVersion,
  290. })
  291. /**
  292. * couponNum
  293. * couponNum2
  294. */
  295. let num = wx.getStorageSync('couponNum');
  296. let num1 = wx.getStorageSync('couponNum2');
  297. // wx.hideTabBarRedDot({
  298. // index: 3
  299. // });
  300. if (num == 'couponNum1') {
  301. wx.setStorage({
  302. key: 'couponNum',
  303. data: "couponNum1",
  304. })
  305. that.setData({
  306. couponNum: "couponNum1"
  307. })
  308. } else if (num == 'couponNum') {
  309. that.setData({
  310. couponNum: "couponNum"
  311. })
  312. };
  313. if (num1 == 'couponNum3') {
  314. wx.setStorage({
  315. key: 'couponNum2',
  316. data: "couponNum3",
  317. })
  318. that.setData({
  319. couponNum2: "couponNum3"
  320. })
  321. } else if (num1 == 'couponNum2') {
  322. that.setData({
  323. couponNum2: "couponNum2"
  324. });
  325. };
  326. Http.get({
  327. url: config.api.getScore,
  328. data: {}
  329. }).then(res => {
  330. if (res.data.address && res.data.name && res.data.sex && res.data.birthdate) {
  331. that.setData({
  332. showEdit: true
  333. })
  334. }
  335. let curPhone = res.data.phone ? res.data.phone : '';
  336. if (curPhone) {
  337. let curPhoneList = curPhone.split('');
  338. let curPhoneList01 = [];
  339. curPhoneList.forEach((item, index) => {
  340. if (index >= 3 && index <= 6) {
  341. item = '*';
  342. }
  343. curPhoneList01.push(item);
  344. })
  345. curPhone = curPhoneList01.join('');
  346. }
  347. that.setData({
  348. score: res.data.score,
  349. credit: res.data.credit,
  350. curPhone: curPhone,
  351. levelName: res.data.levelName,
  352. userId: res.data.userId,
  353. userAvatarUrl: res.data.avatarUrl,
  354. userName: res.data.nickName
  355. })
  356. if (res.data.nickName) {
  357. that.setData({
  358. ismember: true,
  359. memberId: res.data.id
  360. })
  361. var size = this.setCanvasSize();
  362. var initUrl = JSON.stringify({
  363. flagid: res.data.id
  364. });
  365. }
  366. })
  367. .catch(err => {
  368. wx.showModal({
  369. title: '提示',
  370. content: err.errMsg,
  371. showCancel: false
  372. })
  373. })
  374. //暂时注释
  375. // that.getrun();
  376. //查询关于我们
  377. Http.get({
  378. url: config.api.getMallInfo,
  379. data: {}
  380. }).then(res => {
  381. if (res.code == 200) {
  382. this.setData({
  383. memberName: res.data.name,
  384. memberLogo: res.data.imgUrlH
  385. })
  386. }
  387. if (res.data.businessHours !== '[]') {
  388. that.setData({
  389. aboutShow: true
  390. })
  391. } else {
  392. that.setData({
  393. aboutShow: false
  394. })
  395. }
  396. })
  397. .catch(err => { })
  398. },
  399. //适配不同屏幕大小的canvas
  400. setCanvasSize: function () {
  401. var size = {};
  402. try {
  403. var res = wx.getSystemInfoSync();
  404. var scale = 750 / 500;
  405. //不同屏幕下canvas的适配比例;设计稿是750宽
  406. var width = res.windowWidth / scale;
  407. var height = width;
  408. //canvas画布为正方形
  409. size.w = width;
  410. size.h = height;
  411. } catch (e) {
  412. // Do something when catch error
  413. console.log("获取设备信息失败" + e);
  414. }
  415. return size;
  416. },
  417. });