C端小程序
Non puoi selezionare più di 25 argomenti Gli argomenti devono iniziare con una lettera o un numero, possono includere trattini ('-') e possono essere lunghi fino a 35 caratteri.

632 righe
15 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.user2.banneColor,
  26. levelBg: bgColor.colorFirst.user.levelBg,
  27. view: bgColor.colorFirst.user2.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. ifSetUserInfo: false
  66. },
  67. suerService() {
  68. console.log("打开客服")
  69. wx.openCustomerServiceChat({
  70. extInfo: { url: 'https://work.weixin.qq.com/kfid/kfc7f4a755cbb51fa99' },
  71. corpId: 'wwdc116b631d3ea35f',
  72. success(res) { },
  73. fail(res) {
  74. console.log(res);
  75. }
  76. })
  77. },
  78. checkUserStatus() {
  79. let that = this;
  80. Http.get({
  81. url: config.api.checkPhoneStatus,
  82. data: {}
  83. }).then(res => {
  84. wx.navigateTo({
  85. url: '/pages/edit/edit',
  86. })
  87. }).catch(err => {
  88. wx.navigateTo({
  89. url: `/pages/getphoneInfo/index?mineFlag=mine`,
  90. })
  91. })
  92. },
  93. gotoPhoneInfo() {
  94. /**
  95. * 将值传到用户手机号授权的页面
  96. *
  97. */
  98. wx.navigateTo({
  99. url: `/pages/getphoneInfo/index?path=main`
  100. });
  101. },
  102. //是否授权手机号
  103. ifPhoneInfo() {
  104. let that = this;
  105. Http.get({
  106. url: config.api.checkPhoneStatus,
  107. data: {}
  108. }).then(res => {
  109. console.log(res, 'res');
  110. that.setData({
  111. ifSetUserInfo: true
  112. })
  113. // 手机号未授权
  114. const ifSetUserInfo = wx.getStorageSync('ifSetUserInfo')
  115. if (ifSetUserInfo == 1) {
  116. if (!that.data.ifSetUserInfo) return
  117. wx.showModal({
  118. title: '完善个人信息',
  119. content: '请继续完成个人信息哦',
  120. showCancel: true,
  121. cancelText: "以后再说",
  122. cancelColor: '',
  123. confirmText: "去完善",
  124. confirmColor: '#FD832D',
  125. complete: (res) => {
  126. if (res.cancel) {
  127. console.log('cancel');
  128. }
  129. if (res.confirm) {
  130. wx.navigateTo({
  131. url: '/pages3/setUserInfo/index',
  132. })
  133. }
  134. // 已完成手机号授权
  135. wx.setStorageSync('ifSetUserInfo', 2)
  136. }
  137. })
  138. }
  139. return
  140. }).catch(err => {
  141. console.log(err, 'err');
  142. that.setData({
  143. ifSetUserInfo: false
  144. })
  145. const ifSetUserInfo = wx.getStorageSync('ifSetUserInfo')
  146. if (ifSetUserInfo != 2) {
  147. wx.setStorageSync('ifSetUserInfo', 1) //手机号未授权
  148. }
  149. // wx.navigateTo({
  150. // url: `/pages/getphoneInfo/index?mineFlag=mine`,
  151. // })
  152. })
  153. },
  154. /* 判断是否授权*/
  155. userAuthorization() {
  156. Http.get({
  157. url: config.api.checkUserStatus,
  158. data: {
  159. token: app.globalData.token
  160. }
  161. }).then(res => {
  162. this.ifPhoneInfo()
  163. }).catch(err => {
  164. app.globalData.type = 'uc'
  165. wx.navigateTo({
  166. url: `/pages/getuserinfo/index`,
  167. })
  168. })
  169. },
  170. /**
  171. * 跳转到成长值的页面
  172. */
  173. gotograde: function () {
  174. if (this.data.ifSetUserInfo) {
  175. wx.navigateTo({
  176. url: '/pages/czdetail/czdetail',
  177. })
  178. } else {
  179. wx.navigateTo({
  180. url: `/pages/getphoneInfo/index?mineFlag=mine`,
  181. })
  182. }
  183. },
  184. goToOrder() {
  185. if (this.data.ifSetUserInfo) {
  186. wx.navigateTo({
  187. url: '/pages/order/index/index?id=all',
  188. })
  189. } else {
  190. wx.navigateTo({
  191. url: `/pages/getphoneInfo/index?mineFlag=mine`,
  192. })
  193. }
  194. },
  195. goToCouponorder() {
  196. if (this.data.ifSetUserInfo) {
  197. wx.navigateTo({
  198. url: '/pages/couponorder/index/index',
  199. })
  200. } else {
  201. wx.navigateTo({
  202. url: `/pages/getphoneInfo/index?mineFlag=mine`,
  203. })
  204. }
  205. },
  206. goToCardorder() {
  207. if (this.data.ifSetUserInfo) {
  208. wx.navigateTo({
  209. url: '/pages/cardorder/index/index',
  210. })
  211. } else {
  212. wx.navigateTo({
  213. url: `/pages/getphoneInfo/index?mineFlag=mine`,
  214. })
  215. }
  216. },
  217. goToIntegralmall() {
  218. if (this.data.ifSetUserInfo) {
  219. wx.navigateTo({
  220. url: '/pages/integralmall/index',
  221. })
  222. } else {
  223. wx.navigateTo({
  224. url: '/pages/integralmall/index',
  225. })
  226. // wx.navigateTo({
  227. // url: `/pages/getphoneInfo/index?mineFlag=mine`,
  228. // })
  229. }
  230. },
  231. goToBargain() {
  232. if (this.data.ifSetUserInfo) {
  233. wx.navigateTo({
  234. url: '/pages/bargain/bargain?from=myhtml',
  235. })
  236. } else {
  237. wx.navigateTo({
  238. url: `/pages/getphoneInfo/index?mineFlag=mine`,
  239. })
  240. }
  241. },
  242. goToSpellGroup() {
  243. if (this.data.ifSetUserInfo) {
  244. wx.navigateTo({
  245. url: '/pages/spellGroup/spellGroup?from=myhtml',
  246. })
  247. } else {
  248. wx.navigateTo({
  249. url: `/pages/getphoneInfo/index?mineFlag=mine`,
  250. })
  251. }
  252. },
  253. goToMyactivity() {
  254. if (this.data.ifSetUserInfo) {
  255. wx.navigateTo({
  256. url: '/pages/user/myactivity/index',
  257. })
  258. } else {
  259. wx.navigateTo({
  260. url: `/pages/getphoneInfo/index?mineFlag=mine`,
  261. })
  262. }
  263. },
  264. goToSetUserInfo() {
  265. if (this.data.ifSetUserInfo) {
  266. wx.navigateTo({
  267. url: '/pages3/setUserInfo/index',
  268. })
  269. } else {
  270. wx.navigateTo({
  271. url: `/pages/getphoneInfo/index?mineFlag=mine`,
  272. })
  273. }
  274. },
  275. goToSpecialcourtesy() {
  276. if (this.data.ifSetUserInfo) {
  277. wx.navigateTo({
  278. url: '/pages/specialcourtesy/specialcourtesy',
  279. })
  280. } else {
  281. wx.navigateTo({
  282. url: `/pages/getphoneInfo/index?mineFlag=mine`,
  283. })
  284. }
  285. },
  286. goToExchangeCard() {
  287. wx.navigateTo({
  288. url: '/pages/exchangeCard/exchangeCard',
  289. })
  290. // if (this.data.ifSetUserInfo) {
  291. // wx.navigateTo({
  292. // url: '/pages/exchangeCard/exchangeCard',
  293. // })
  294. // } else {
  295. // wx.navigateTo({
  296. // url: `/pages/getphoneInfo/index?mineFlag=mine`,
  297. // })
  298. // }
  299. },
  300. goToQuestionnaire() {
  301. if (this.data.ifSetUserInfo) {
  302. wx.navigateTo({
  303. url: '/pages/questionnaire/questionnaireLsit/questionnaireLsit',
  304. })
  305. } else {
  306. wx.navigateTo({
  307. url: '/pages/questionnaire/questionnaireLsit/questionnaireLsit',
  308. })
  309. // wx.navigateTo({
  310. // url: `/pages/getphoneInfo/index?mineFlag=mine`,
  311. // })
  312. }
  313. },
  314. goToComplaint() {
  315. if (this.data.ifSetUserInfo) {
  316. wx.navigateTo({
  317. url: '/pages/complaint/complaint',
  318. })
  319. } else {
  320. wx.navigateTo({
  321. url: '/pages/complaint/complaint',
  322. })
  323. // wx.navigateTo({
  324. // url: `/pages/getphoneInfo/index?mineFlag=mine`,
  325. // })
  326. }
  327. },
  328. goToBusinessSwitch() {
  329. if (this.data.ifSetUserInfo) {
  330. wx.navigateTo({
  331. url: this.data.goUrl,
  332. })
  333. } else {
  334. wx.navigateTo({
  335. url: `/pages/getphoneInfo/index?mineFlag=mine`,
  336. })
  337. }
  338. },
  339. share() {
  340. if (this.data.ifSetUserInfo) {
  341. wx.navigateTo({
  342. url: '/pages/shareFriend/shareFriend',
  343. })
  344. } else {
  345. wx.navigateTo({
  346. url: `/pages/getphoneInfo/index?mineFlag=mine`,
  347. })
  348. }
  349. },
  350. /**
  351. * 跳转到商场信息的页面
  352. */
  353. gomallInfo: function () {
  354. wx.navigateTo({
  355. url: '/pages/mallInfo/mallInfo',
  356. })
  357. },
  358. showVersion: function () {
  359. /**
  360. * 长按显示版本号
  361. */
  362. let that = this;
  363. if (that.data.flag == 'hidden') {
  364. that.setData({
  365. flag: 'show'
  366. });
  367. }
  368. },
  369. gotoedit: function () {
  370. // this.checkUserStatus();
  371. console.log('goSetAvatar');
  372. wx.navigateTo({
  373. url: '/pages3/setUserInfo/index'
  374. })
  375. },
  376. onLoad(options) {
  377. // this.getLocation();
  378. this.updateScene();
  379. // this.getRoomId();
  380. // this.getRoomList();
  381. console.log(wx.getExtConfigSync())
  382. },
  383. //获取房间列表
  384. getRoomList() {
  385. Http.get({
  386. url: config.api.getRoomList,
  387. data: {
  388. token: app.globalData.token,
  389. appId: config.weapp.AppId
  390. }
  391. }).then(res => {
  392. console.log(res)
  393. })
  394. },
  395. getRoomId() {
  396. let roomId = [3] // 填写具体的房间号,可通过下面【获取直播房间列表】 API 获取
  397. let customParams = encodeURIComponent(JSON.stringify({
  398. path: 'pages/index/index',
  399. pid: 1
  400. })) // 开发者在直播间页面路径上携带自定义参数(如示例中的path和pid参数),后续可以在分享卡片链接和跳转至商详页时获取,详见【获取自定义参数】、【直播间到商详页面携带参数】章节(上限600个字符,超过部分会被截断)
  401. console.log(customParams, 777777777)
  402. this.setData({
  403. roomId,
  404. customParams
  405. })
  406. },
  407. /**
  408. * 获得经纬度
  409. */
  410. // getLocation() {
  411. // let that = this;
  412. // wx.getLocation({
  413. // type: "wgs84",
  414. // success: function(res) {
  415. // console.log(res)
  416. // if (res && res.longitude && res.latitude) {
  417. // Http.post({
  418. // url: config.api.updateLBS,
  419. // data: {
  420. // latitude: res.latitude,
  421. // longitude: res.longitude
  422. // }
  423. // }).then(res => {
  424. // console.log(res)
  425. // })
  426. // }
  427. // },
  428. // fail: error => {
  429. // console.log(error);
  430. // }
  431. // })
  432. // },
  433. /**
  434. * 用户更新scene
  435. */
  436. updateScene() {
  437. Http.post({
  438. url: config.api.updateScene,
  439. data: {
  440. scene: app.globalData.scene
  441. }
  442. }).then(res => {
  443. console.log(res)
  444. })
  445. },
  446. /**
  447. * 生命周期函数--监听页面显示
  448. */
  449. onShow: function () {
  450. this.ifPhoneInfo()
  451. if (businessSwitch) {
  452. let openId = wx.getStorageSync("openId")
  453. this.setData({
  454. goUrl: `plugin://auto-points-plugin/index?openid=${openId}&mch_id=${this.data.mch_id}`
  455. })
  456. }
  457. console.log(this.data.goUrl)
  458. let that = this;
  459. that.userAuthorization()
  460. if (typeof that.getTabBar === 'function' &&
  461. that.getTabBar()) {
  462. if (ifStoreApp == 1) {
  463. that.getTabBar().setData({
  464. selected: 1
  465. })
  466. } else if (ifStoreApp == 2) {
  467. that.getTabBar().setData({
  468. selected: 2
  469. })
  470. } else {
  471. that.getTabBar().setData({
  472. selected: 3,
  473. })
  474. }
  475. }
  476. that.setData({
  477. appVersion: extConfig.appVersion,
  478. })
  479. /**
  480. * couponNum
  481. * couponNum2
  482. */
  483. let num = wx.getStorageSync('couponNum');
  484. let num1 = wx.getStorageSync('couponNum2');
  485. // wx.hideTabBarRedDot({
  486. // index: 3
  487. // });
  488. if (num == 'couponNum1') {
  489. wx.setStorage({
  490. key: 'couponNum',
  491. data: "couponNum1",
  492. })
  493. that.setData({
  494. couponNum: "couponNum1"
  495. })
  496. } else if (num == 'couponNum') {
  497. that.setData({
  498. couponNum: "couponNum"
  499. })
  500. };
  501. if (num1 == 'couponNum3') {
  502. wx.setStorage({
  503. key: 'couponNum2',
  504. data: "couponNum3",
  505. })
  506. that.setData({
  507. couponNum2: "couponNum3"
  508. })
  509. } else if (num1 == 'couponNum2') {
  510. that.setData({
  511. couponNum2: "couponNum2"
  512. });
  513. };
  514. Http.get({
  515. url: config.api.getScore,
  516. data: {}
  517. }).then(res => {
  518. if (res.data.address && res.data.name && res.data.sex && res.data.birthdate) {
  519. that.setData({
  520. showEdit: true
  521. })
  522. }
  523. let curPhone = res.data.phone ? res.data.phone : '';
  524. if (curPhone) {
  525. let curPhoneList = curPhone.split('');
  526. let curPhoneList01 = [];
  527. curPhoneList.forEach((item, index) => {
  528. if (index >= 3 && index <= 6) {
  529. item = '*';
  530. }
  531. curPhoneList01.push(item);
  532. })
  533. curPhone = curPhoneList01.join('');
  534. }
  535. that.setData({
  536. score: res.data.score,
  537. credit: res.data.credit,
  538. curPhone: curPhone,
  539. levelName: res.data.levelName,
  540. userId: res.data.userId,
  541. userAvatarUrl: res.data.avatarUrl,
  542. userName: res.data.nickName
  543. })
  544. if (res.data.nickName) {
  545. that.setData({
  546. ismember: true,
  547. memberId: res.data.id
  548. })
  549. var size = this.setCanvasSize();
  550. var initUrl = JSON.stringify({
  551. flagid: res.data.id
  552. });
  553. }
  554. })
  555. .catch(err => {
  556. wx.showModal({
  557. title: '提示',
  558. content: err.errMsg,
  559. showCancel: false
  560. })
  561. })
  562. //暂时注释
  563. // that.getrun();
  564. //查询关于我们
  565. Http.get({
  566. url: config.api.getMallInfo,
  567. data: {}
  568. }).then(res => {
  569. if (res.code == 200) {
  570. this.setData({
  571. memberName: res.data.name,
  572. memberLogo: res.data.imgUrlH
  573. })
  574. }
  575. if (res.data.businessHours !== '[]') {
  576. that.setData({
  577. aboutShow: true
  578. })
  579. } else {
  580. that.setData({
  581. aboutShow: false
  582. })
  583. }
  584. })
  585. .catch(err => { })
  586. },
  587. //适配不同屏幕大小的canvas
  588. setCanvasSize: function () {
  589. var size = {};
  590. try {
  591. var res = wx.getSystemInfoSync();
  592. var scale = 750 / 500;
  593. //不同屏幕下canvas的适配比例;设计稿是750宽
  594. var width = res.windowWidth / scale;
  595. var height = width;
  596. //canvas画布为正方形
  597. size.w = width;
  598. size.h = height;
  599. } catch (e) {
  600. // Do something when catch error
  601. console.log("获取设备信息失败" + e);
  602. }
  603. return size;
  604. },
  605. });